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

90 lines
1.6 KiB
C
Raw Permalink Normal View History

/*
* 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
*/
#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/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>ֵ
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 = 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>ֵ
int count_max; // <20><>ʱn΢<6E><CEA2><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int tmp;
// ΢<><CEA2>
count_max = n * count_1us;
if (10 >= n) // <=10us
{
count_max = count_max / 3;
}
else if (100 >= n) // <= 100us
{
count_max = count_max - count_max / 5;
}
else // > 100us
{
count_max = count_max - count_max / 10;
}
// <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 ;
}