1 /* 2 * Copyright (c) 2006-2018, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2017-09-06 ��Ϊ�� first version 9 */ 10 11 12 #include "ls1c_clock.h" 13 14 15 16 17 /* 18 * ��ʱָ��ʱ�䣬��λms 19 * @j ��ʱʱ�䣬��λms 20 */ delay_ms(int j)21void delay_ms(int j) 22 { 23 int k_max = clk_get_cpu_rate()/1000/92; // ����1000��ʾms������һ������Ϊʵ���õľ���ֵ 24 int k = k_max; 25 26 for ( ; j > 0; j--) 27 { 28 for (k = k_max; k > 0; k--) 29 { 30 __asm__ ("nop"); // ע�⣬���������������࣬����ᱻ�Ż��� 31 } 32 } 33 34 return ; 35 } 36 37 38 /* 39 * ��ʱָ��ʱ�䣬��λus 40 * @n ��ʱʱ�䣬��λus 41 */ delay_us(int n)42void delay_us(int n) 43 { 44 int count_1us = 252000000 / 1000000 / 84; // ��ʱ1us��ѭ������ 45 // 252000000ΪcpuƵ�ʣ�����1000000��ʾ��ʱ��λΪus��92Ϊʵ���õľ���ֵ 46 int count_max; // ��ʱn���ѭ������ 47 int tmp; 48 49 // �� 50 count_max = n * count_1us; 51 if (10 >= n) // <=10us 52 { 53 count_max = count_max / 3; 54 } 55 else if (100 >= n) // <= 100us 56 { 57 count_max = count_max - count_max / 5; 58 } 59 else // > 100us 60 { 61 count_max = count_max - count_max / 10; 62 } 63 64 // ��ʱ 65 for (tmp = count_max; tmp > 0; tmp--) 66 { 67 __asm__ ("nop"); // ע�⣬���������������࣬����ᱻ�Ż��� 68 } 69 70 return ; 71 } 72 73 74 /* 75 * ��ʱָ��ʱ�䣬��λs 76 * @i ��ʱʱ�䣬��λs 77 */ delay_s(int i)78void delay_s(int i) 79 { 80 for ( ; i > 0; i--) 81 { 82 delay_ms(1000); 83 } 84 85 return ; 86 } 87 88 89 90