42#include <AppHardwareApi.h>
43#include <PeripheralRegs.h>
44#include <MicroSpecific.h>
45#include "dev/watchdog.h"
53#define PRINTF(...) printf(__VA_ARGS__)
58#define RTIMER_TIMER_ISR_DEV E_AHI_DEVICE_SYSCTRL
60#define MAX_VALUE 0xFFFFFFFF
62#define START_VALUE (60 * RTIMER_ARCH_SECOND)
63#define WRAPAROUND_VALUE ((uint64_t)0x1FFFFFFFFFF)
65static volatile rtimer_clock_t scheduled_time;
66static volatile uint8_t has_next;
70timerISR(uint32 u32Device, uint32 u32ItemBitmap)
72 PRINTF(
"\ntimer isr %u %u\n", u32Device, u32ItemBitmap);
73 if(u32Device != RTIMER_TIMER_ISR_DEV) {
77 if(u32ItemBitmap & TICK_TIMER_MASK) {
79 uint32_t ticks_late = WRAPAROUND_VALUE - u64AHI_WakeTimerReadLarge(TICK_TIMER);
81 PRINTF(
"\nrtimer oflw, missed ticks %u\n", ticks_late);
83 vAHI_WakeTimerStartLarge(TICK_TIMER, MAX_VALUE - ticks_late);
86 if(u32ItemBitmap & WAKEUP_TIMER_MASK) {
94 if(RTIMER_CLOCK_LT(now + 1, scheduled_time)) {
95 vAHI_WakeTimerEnable(WAKEUP_TIMER, TRUE);
96 vAHI_WakeTimerStartLarge(WAKEUP_TIMER, scheduled_time - now);
110 vAHI_TickTimerIntEnable(0);
111 vAHI_TickTimerConfigure(E_AHI_TICK_TIMER_DISABLE);
112 vAHI_TickTimerWrite(0);
113 vAHI_TickTimerConfigure(E_AHI_TICK_TIMER_CONT);
115 vAHI_SysCtrlRegisterCallback(timerISR);
117 vAHI_InterruptSetPriority(MICRO_ISR_MASK_SYSCTRL, 15);
119 vAHI_WakeTimerEnable(WAKEUP_TIMER, TRUE);
121 vAHI_WakeTimerEnable(TICK_TIMER, TRUE);
123 vAHI_WakeTimerStartLarge(TICK_TIMER, START_VALUE);
129rtimer_arch_reinit(rtimer_clock_t sleep_start, rtimer_clock_t sleep_ticks)
133 uint32_t wakeup_time = sleep_start + (uint64_t)sleep_ticks * (F_CPU / 2) /
RTIMER_SECOND;
136 vAHI_TickTimerConfigure(E_AHI_TICK_TIMER_DISABLE);
137 vAHI_TickTimerIntEnable(0);
139 vAHI_TickTimerWrite(wakeup_time);
140 vAHI_TickTimerConfigure(E_AHI_TICK_TIMER_CONT);
154 return START_VALUE - (rtimer_clock_t)u64AHI_WakeTimerReadLarge(TICK_TIMER);
160 PRINTF(
"rtimer_arch_schedule time %lu\n", t);
161 vAHI_WakeTimerEnable(WAKEUP_TIMER, TRUE);
168rtimer_arch_time_to_rtimer(
void)
172 return scheduled_time >= now ? scheduled_time - now : 0;
175 return (rtimer_clock_t)-1;
void rtimer_arch_init(void)
We don't need to explicitly initialise anything but this routine is required by the API.
#define rtimer_arch_now()
Returns the current real-time clock time.
void rtimer_arch_schedule(rtimer_clock_t t)
Schedules an rtimer task to be triggered at time t.
void watchdog_start(void)
Starts the WDT in watchdog mode if enabled by user configuration, maximum interval.
int process_nevents(void)
Number of events waiting to be processed.
void rtimer_run_next(void)
Execute the next real-time task and schedule the next task, if any.
#define RTIMER_SECOND
Number of rtimer ticks for 1 second.
#define RTIMER_NOW()
Get the current clock time.
Header file for the Contiki process interface.
Header file for the real-time timer module.