nfc test on MQX4.1
[nfc-test.git] / delay.c
blobcacd2c0061f8d2ec77f42fa72663c12074adde39
2 #include "common.h"
3 #include "pn51x.h"
5 #ifdef PCD_TIMER_USE_PIT
6 uint32_t pcd_tick = 0;
7 static void PCD_TIMER_ISR(pointer p)
9 _pcd_clear_int(PCD_TIMER_INT);
10 /* increase tick */
11 pcd_tick ++;
12 /* Enable PIT interrupt neeed due to errata on Kinetis PIT */
13 _pcd_timer_unmask_int(PCD_TIMER_INT);
16 static void pcd_timer_init(void)
18 if(_int_install_isr(PCD_TIMER_INT, PCD_TIMER_ISR, NULL) == NULL) {
19 return;
20 } /* Endif */
21 _bsp_int_init(AUDIO_INT, 2, 0, TRUE);
23 #endif
25 void Delay1us(uint32_t delay)
27 #ifdef PCD_TIMER_USE_PIT
28 uint32_t savedTime = PIT_CVAL(TIMER_FOR_PCD);
29 uint32_t currentTime = savedTime;
30 uint32_t endTime = savedTime + (delay * (PCD_TIMER_FREQUENCY / 1000000));
32 while (currentTime <= savedTime){
33 savedTime = currentTime;
34 currentTime = PIT_CVAL(TIMER_FOR_PCD);
37 while ((currentTime > endTime) && (currentTime <= savedTime)) {
38 savedTime = currentTime;
39 currentTime = PIT_CVAL(TIMER_FOR_PCD);
41 #else
42 unsigned long ovfl;
43 MQX_TICK_STRUCT cur_tick,last_tick;
44 _time_get_elapsed_ticks_fast(&cur_tick);
46 do {
47 _time_get_elapsed_ticks_fast(&last_tick);
48 } while( _time_diff_milliseconds(&last_tick,&cur_tick,&ovfl) >= delay);
49 #endif
53 void Delay256us(uint8_t delay)
55 volatile uint8_t i;
57 while (delay--) {
58 Delay1us(200);
59 for(i = 0; i < 134; i++);
63 void Delay256P2us(uint8_t delay)
65 uint8_t i;
67 for(i = 0; i < delay; i++) {
68 Delay256us(0xFF);
69 Delay256us(0x01);
73 void Delay256P3us(uint8_t delay)
75 uint8_t i;
77 for(i = 0; i < delay; i++)
79 Delay256P2us(0xFF);
80 Delay256P2us(0x01);
84 void Delay1ms(uint32 delay)
86 OS_Time_delay(delay + 2);
89 void Delay1s(uint8_t delay)
91 uint8_t i;
92 for(i = 0; i < delay; i++) {
93 Delay1ms(1000);
97 void SetTimer100us(uint16_t timeOut)
99 set_pn51x_timer(timeOut);