40 #include "rtimer-arch.h"
46 #define PRINTF(...) printf(__VA_ARGS__)
52 #define RTIMER_ARCH_CHANNEL (RTIMER_ARCH_PIT_DEV->CHANNEL[RTIMER_ARCH_PIT_CHANNEL])
54 #define RTIMER_ARCH_TIMER_ENABLE() (BITBAND_REG(RTIMER_ARCH_CHANNEL.TCTRL, PIT_TCTRL_TEN_SHIFT) = 1)
55 #define RTIMER_ARCH_TIMER_DISABLE() (BITBAND_REG(RTIMER_ARCH_CHANNEL.TCTRL, PIT_TCTRL_TEN_SHIFT) = 0)
58 static rtimer_clock_t offset;
60 static int free_running;
62 #define RTIMER_ARCH_FREE_RUNNING_LDVAL (PIT_LDVAL_TSV_MASK >> PIT_LDVAL_TSV_SHIFT)
75 RTIMER_ARCH_TIMER_DISABLE();
78 BITBAND_REG(RTIMER_ARCH_CHANNEL.TCTRL, PIT_TCTRL_TIE_SHIFT) = 1;
81 BITBAND_REG(RTIMER_ARCH_CHANNEL.TFLG, PIT_TFLG_TIF_MASK) = 1;
87 RTIMER_ARCH_TIMER_ENABLE();
93 int64_t err = ((int64_t)
SystemBusClock) - ((int64_t)RTIMER_SECOND);
94 err *= (int64_t)1000000ull;
95 err /= (int64_t)(RTIMER_SECOND);
96 PRINTF(
"rtimer_arch_init: Real rtimer frequency = %lu, RTIMER_SECOND = %lu\n", (
unsigned long)
SystemBusClock, (
unsigned long)RTIMER_SECOND);
97 PRINTF(
"rtimer_arch_init: Expect ca %ld ppm error on scheduled task times.\n", (
signed long)err);
99 PRINTF(
"rtimer_arch_init: Done\n");
104 if (t > 0xffffffffull) {
105 PRINTF(
"rtimer_arch_schedule: Schedule out of range! This task will run much sooner than expected.\n");
111 RTIMER_ARCH_CHANNEL.LDVAL = PIT_LDVAL_TSV(t);
117 RTIMER_ARCH_TIMER_DISABLE();
118 RTIMER_ARCH_TIMER_ENABLE();
120 PRINTF(
"rtimer_arch_schedule: %lu\n", (
unsigned long)t);
126 return offset + ((rtimer_clock_t)(
127 ((RTIMER_ARCH_CHANNEL.LDVAL & PIT_LDVAL_TSV_MASK) >> PIT_LDVAL_TSV_SHIFT) -
128 ((RTIMER_ARCH_CHANNEL.CVAL & PIT_CVAL_TVL_MASK) >> PIT_CVAL_TVL_SHIFT)));
135 static uint32_t prev_timeout;
136 prev_timeout = ((RTIMER_ARCH_CHANNEL.LDVAL & PIT_LDVAL_TSV_MASK) >> PIT_LDVAL_TSV_SHIFT);
139 BITBAND_REG(RTIMER_ARCH_CHANNEL.TFLG, PIT_TFLG_TIF_SHIFT) = 1;
156 RTIMER_ARCH_TIMER_DISABLE();
157 RTIMER_ARCH_TIMER_ENABLE();
162 offset += (rtimer_clock_t)prev_timeout;
167 if (free_running == 0) {
__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
Enable External Interrupt.
void rtimer_arch_init(void)
We don't need to explicitly initialise anything but this routine is required by the API...
#define RTIMER_ARCH_FREE_RUNNING_LDVAL
LDVAL of the free running timer.
#define SIM
Peripheral SIM base pointer.
K60 hardware register header wrapper.
#define rtimer_arch_now()
#define BITBAND_REG(Reg, Bit)
Macro to access a single bit of a peripheral register (bit band region 0x40000000 to 0x400FFFFF) usin...
void rtimer_arch_schedule(rtimer_clock_t t)
Schedules an rtimer task to be triggered at time t.
void rtimer_run_next(void)
Execute the next real-time task and schedule the next task, if any.
uint32_t SystemBusClock
Current bus clock frequency.