mirror of
https://github.com/markqvist/OpenModem.git
synced 2025-05-15 12:52:22 -04:00
Initial commit
This commit is contained in:
commit
05d62b594e
18 changed files with 1551 additions and 0 deletions
34
util/time.h
Normal file
34
util/time.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
#ifndef UTIL_TIME_H
|
||||
#define UTIL_TIME_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#define DIV_ROUND(dividend, divisor) (((dividend) + (divisor) / 2) / (divisor))
|
||||
#define CLOCK_TICKS_PER_SEC CONFIG_AFSK_DAC_SAMPLERATE
|
||||
|
||||
typedef int32_t ticks_t;
|
||||
typedef int32_t mtime_t;
|
||||
|
||||
volatile ticks_t _clock;
|
||||
|
||||
inline ticks_t timer_clock(void) {
|
||||
ticks_t result;
|
||||
|
||||
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
|
||||
result = _clock;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
inline ticks_t ms_to_ticks(mtime_t ms) {
|
||||
return ms * DIV_ROUND(CLOCK_TICKS_PER_SEC, 1000);
|
||||
}
|
||||
|
||||
inline void cpu_relax(void) {
|
||||
// Do nothing!
|
||||
}
|
||||
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue