2018-12-24 18:49:00 +08:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2006-2018, RT-Thread Development Team
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*
|
|
|
|
|
* Change Logs:
|
|
|
|
|
* Date Author Notes
|
|
|
|
|
* 2017-09-06 <EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD> first version
|
|
|
|
|
*/
|
2017-07-18 11:15:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "ls1c_clock.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* <EFBFBD><EFBFBD>ʱָ<EFBFBD><EFBFBD>ʱ<EFBFBD>䣬<EFBFBD><EFBFBD>λms
|
|
|
|
|
* @j <EFBFBD><EFBFBD>ʱʱ<EFBFBD>䣬<EFBFBD><EFBFBD>λms
|
|
|
|
|
*/
|
|
|
|
|
void delay_ms(int j)
|
|
|
|
|
{
|
2018-12-24 18:49:00 +08:00
|
|
|
|
int k_max = clk_get_cpu_rate()/1000/92; // <20><><EFBFBD><EFBFBD>1000<30><30>ʾms<6D><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊʵ<CEAA><CAB5><EFBFBD><EFBFBD><EFBFBD>õľ<C3B5><C4BE><EFBFBD>ֵ
|
2017-07-18 11:15:10 +08:00
|
|
|
|
int k = k_max;
|
|
|
|
|
|
|
|
|
|
for ( ; j > 0; j--)
|
|
|
|
|
{
|
|
|
|
|
for (k = k_max; k > 0; k--)
|
|
|
|
|
{
|
|
|
|
|
__asm__ ("nop"); // ע<>⣬<EFBFBD><E2A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>࣬<EFBFBD><E0A3AC><EFBFBD><EFBFBD><EFBFBD>ᱻ<EFBFBD>Ż<EFBFBD><C5BB><EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* <EFBFBD><EFBFBD>ʱָ<EFBFBD><EFBFBD>ʱ<EFBFBD>䣬<EFBFBD><EFBFBD>λus
|
|
|
|
|
* @n <EFBFBD><EFBFBD>ʱʱ<EFBFBD>䣬<EFBFBD><EFBFBD>λus
|
|
|
|
|
*/
|
|
|
|
|
void delay_us(int n)
|
|
|
|
|
{
|
2018-12-24 18:49:00 +08:00
|
|
|
|
int count_1us = 252000000 / 1000000 / 84; // <20><>ʱ1us<75><73>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
// 252000000ΪcpuƵ<75>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD>1000000<30><30>ʾ<EFBFBD><CABE>ʱ<EFBFBD><CAB1>λΪus<75><73>92Ϊʵ<CEAA><CAB5><EFBFBD><EFBFBD><EFBFBD>õľ<C3B5><C4BE><EFBFBD>ֵ
|
2017-07-18 11:15:10 +08:00
|
|
|
|
int count_max; // <20><>ʱn<6E><CEA2><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
int tmp;
|
|
|
|
|
|
2018-12-24 18:49:00 +08:00
|
|
|
|
// <><CEA2>
|
|
|
|
|
count_max = n * count_1us;
|
2017-07-18 11:15:10 +08:00
|
|
|
|
if (10 >= n) // <=10us
|
|
|
|
|
{
|
2018-12-24 18:49:00 +08:00
|
|
|
|
count_max = count_max / 3;
|
2017-07-18 11:15:10 +08:00
|
|
|
|
}
|
|
|
|
|
else if (100 >= n) // <= 100us
|
|
|
|
|
{
|
2018-12-24 18:49:00 +08:00
|
|
|
|
count_max = count_max - count_max / 5;
|
2017-07-18 11:15:10 +08:00
|
|
|
|
}
|
|
|
|
|
else // > 100us
|
|
|
|
|
{
|
2018-12-24 18:49:00 +08:00
|
|
|
|
count_max = count_max - count_max / 10;
|
2017-07-18 11:15:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><>ʱ
|
|
|
|
|
for (tmp = count_max; tmp > 0; tmp--)
|
|
|
|
|
{
|
|
|
|
|
__asm__ ("nop"); // ע<>⣬<EFBFBD><E2A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>࣬<EFBFBD><E0A3AC><EFBFBD><EFBFBD><EFBFBD>ᱻ<EFBFBD>Ż<EFBFBD><C5BB><EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* <EFBFBD><EFBFBD>ʱָ<EFBFBD><EFBFBD>ʱ<EFBFBD>䣬<EFBFBD><EFBFBD>λs
|
|
|
|
|
* @i <EFBFBD><EFBFBD>ʱʱ<EFBFBD>䣬<EFBFBD><EFBFBD>λs
|
|
|
|
|
*/
|
|
|
|
|
void delay_s(int i)
|
|
|
|
|
{
|
|
|
|
|
for ( ; i > 0; i--)
|
|
|
|
|
{
|
|
|
|
|
delay_ms(1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|