SingingCat 0
application
delay.c
1#include <main-header.h>
2#include "led.h"
3static volatile uint32_t TimingDelay;
4static volatile long systickctr = 0;
5static volatile int delay_counter[5];
6extern uint32_t acm_byte_received;
7void reset_delay_counter(int n) {
8 delay_counter[n] = 0;
9}
10int get_delay_counter(int n) {
11 return delay_counter[n];
12}
13
19void Delay(uint32_t nTime) {
20 TimingDelay = nTime;
21 //printf("Delay %D\r\n",nTime);
22 while (TimingDelay != 0) {
23 ;
24 }
25}
26
27
33void TimingDelay_Decrement(void) {
34 int i;
35
36 for (i = 0; i < 5; i++) {
37 delay_counter[i]++;
38 }
39 if (TimingDelay != 0) {
40 TimingDelay--;
41 }
42 dac_timer();
43}
44
48long get_systickctr() {
49 return systickctr;
50}
55long systick_diff(long timestamp) {
56 long tc = get_systickctr();
57
58 if (timestamp > tc) {
59 return 0xFFFFFFFF - (timestamp - tc);
60 }
61 return tc - timestamp;
62}
63void UserSysTick_Handler() {
64 systickctr++;
65 if (acm_byte_received != 0) {
66 acm_byte_received--;
67 }
68 TimingDelay_Decrement();
69}