rt-thread-official/bsp/ls1cdev/libraries/ls1c_delay.c

81 lines
1.4 KiB
C
Raw Normal View History

// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱԴ<CAB1>ļ<EFBFBD>
#include "ls1c_clock.h"
/*
* <EFBFBD><EFBFBD>ʱָ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>λms
* @j <EFBFBD><EFBFBD>ʱʱ<EFBFBD><EFBFBD><EFBFBD>λms
*/
void delay_ms(int j)
{
int k_max = clk_get_cpu_rate()/1000/3; // <20><><EFBFBD><EFBFBD>1000<30><30>ʾms<6D><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><33><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õľ<C3B5><C4BE><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>ڲ<EFBFBD>ѭ<EFBFBD><D1AD>ִ<EFBFBD><D6B4>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>ʱ<EFBFBD>Ӹ<EFBFBD><D3B8><EFBFBD>)
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)
{
int count_1us = clk_get_cpu_rate() / 1000000 / 3; // <20><>ʱ1us<75><73>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int count_max; // <20><>ʱn΢<6E><CEA2><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int tmp;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>΢<EFBFBD><CEA2><><EFBFBD><E2A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6>Ż<EFBFBD><C5BB>ģ<EFBFBD>cpuƵ<75>ʸı<CAB8><C4B1>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>Ż<EFBFBD><C5BB><EFBFBD><EFBFBD><EFBFBD>ʱcpuƵ<75><C6B5>Ϊ252Mhz)
if (10 >= n) // <=10us
{
count_1us -= 35;
}
else if (100 >= n) // <= 100us
{
count_1us -= 6;
}
else // > 100us
{
count_1us -= 1;
}
count_max = n * count_1us;
// <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 ;
}