Koduino
system_clock.h
1 
19 #ifndef _system_clock_
20 #define _system_clock_
21 
22 // Uses interrupts and timer 16 for millis() and micros() time keeping
23 #include <stdint.h>
24 #include "chip.h"
25 #include "types.h"
26 
27 #ifdef __cplusplus
28 extern "C"{
29 #endif // __cplusplus
30 
31 
33 void systemClockInit();
34 
35 // Private
36 void systemClockISR();
37 
38 
42 extern volatile uint32_t _millis;
43 extern int microsDivider;
49 static inline uint32_t millis() __attribute__((always_inline, unused));
50 static inline uint32_t millis() {
51  volatile uint32_t ret = _millis;
52  return ret;
53 }
54 
55 
61 static inline uint32_t micros() __attribute__((always_inline, unused));
62 static inline uint32_t micros()
63 {
64  // OLD--using timer
65  // return _millis * 1000 + TIM_GetCounter(TIMER_MAP[ TIMEBASE_MAP[ SYSCLK_TIMEBASE ].timer ].TIMx);
66  // systick is a downcounter
67  volatile uint32_t ret = _millis * 1000 + 1000 - SysTick->VAL/microsDivider;
68  return ret;
69 }
70 
78 void delay(uint32_t nTime);
79 
86 void delayMicroseconds(uint32_t nTime);
87 
97 void delayNB(uint32_t nTime, ISRType iterate);
98  // end of addtogroup
100 
101 
102 
103 #ifdef __cplusplus
104 } // extern "C"
105 #endif // __cplusplus
106 
107 #endif
void delayNB(uint32_t nTime, ISRType iterate)
Non-blocking delay.
Definition: system_clock.c:70
Definition: types.h:108
void delayMicroseconds(uint32_t nTime)
Blocks execution for a specified number of microseconds.
Definition: system_clock.c:56
static uint32_t millis() __attribute__((always_inline
Definition: system_clock.h:50
static uint32_t micros() __attribute__((always_inline
Definition: system_clock.h:62
void delay(uint32_t nTime)
Blocks execution for a specified number of milliseconds.
Definition: system_clock.c:64
volatile uint32_t _millis
Definition: system_clock.c:29