Contiki 2.6
|
00001 #include "rtimer-arch.h" 00002 #include <AT91SAM7S64.h> 00003 #include "rtimer-arch-interrupt.h" 00004 00005 #define DEBUG 1 00006 #if DEBUG 00007 #include <stdio.h> 00008 #define PRINTF(...) printf(__VA_ARGS__) 00009 #else 00010 #define PRINTF(...) 00011 #endif 00012 00013 static rtimer_clock_t offset; 00014 00015 void 00016 rtimer_arch_init(void) 00017 { 00018 offset = 0; 00019 RTIMER_ARCH_TIMER_BASE->TC_CMR = 00020 (AT91C_TC_WAVE | AT91C_TC_WAVESEL_UP | AT91C_TC_CLKS_TIMER_DIV5_CLOCK); 00021 RTIMER_ARCH_TIMER_BASE->TC_RA = 0xffff; 00022 RTIMER_ARCH_TIMER_BASE->TC_IER = AT91C_TC_CPAS; 00023 *AT91C_PMC_PCER = (1 << RTIMER_ARCH_TIMER_ID); 00024 AT91C_AIC_SMR[RTIMER_ARCH_TIMER_ID] = 00025 AT91C_AIC_SRCTYPE_INT_POSITIVE_EDGE | 6; 00026 AT91C_AIC_SVR[RTIMER_ARCH_TIMER_ID] = (unsigned long)rtimer_interrupt; 00027 *AT91C_AIC_IECR = (1 << RTIMER_ARCH_TIMER_ID); 00028 RTIMER_ARCH_TIMER_BASE->TC_CCR = AT91C_TC_SWTRG | AT91C_TC_CLKEN; 00029 PRINTF("rtimer_arch_init: Done\n"); 00030 } 00031 00032 void 00033 rtimer_arch_schedule(rtimer_clock_t t) 00034 { 00035 RTIMER_ARCH_TIMER_BASE->TC_RA = t + offset; 00036 PRINTF("rtimer_arch_schedule: %d\n",t); 00037 } 00038 00039 void 00040 rtimer_arch_set(rtimer_clock_t t) 00041 { 00042 offset = t - RTIMER_ARCH_TIMER_BASE->TC_CV; 00043 } 00044 00045 rtimer_clock_t 00046 rtimer_arch_now(void) 00047 { 00048 return RTIMER_ARCH_TIMER_BASE->TC_CV + offset; 00049 }