timer_dsp56k.h
Go to the documentation of this file.00001 #error This code must be revised for the new timer API
00002
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 #ifndef DRV_TIMER_DSP56K_H
00076 #define DRV_TIMER_DSP56K_H
00077
00078 #include "timer.h"
00079 #include <DSP56F807.h>
00080 #include <cfg/compiler.h>
00081 #include <hw.h>
00082 #include <drv/irq.h>
00083
00084
00085 #define REG_SYSTEM_TIMER PP_CAT(REG_TIMER_, SYSTEM_TIMER)
00086 #define SYSTEM_TIMER_IRQ_VECTOR PP_CAT(IRQ_TIMER_, SYSTEM_TIMER)
00087
00089 #define TIMER_PRESCALER 16
00090
00092 #define TIMER_HW_HPTICKS_PER_SEC (IPBUS_FREQ / TIMER_PRESCALER)
00093
00095 typedef uint16_t hptime_t;
00096
00097 static void system_timer_isr(UNUSED(iptr_t, arg));
00098
00099 static void timer_hw_init(void)
00100 {
00101 uint16_t compare;
00102
00103
00104 REG_SYSTEM_TIMER->SCR &= ~REG_TIMER_SCR_TCF;
00105 REG_SYSTEM_TIMER->SCR |= REG_TIMER_SCR_TCFIE;
00106
00107
00108
00109
00110
00111 compare = TIMER_HW_HPTICKS_PER_SEC / TICKS_PER_SEC;
00112 ASSERT((uint32_t)compare * TICKS_PER_SEC == IPBUS_FREQ / TIMER_PRESCALER);
00113 REG_SYSTEM_TIMER->CMP1 = compare;
00114
00115
00116 REG_SYSTEM_TIMER->LOAD = 0;
00117
00118
00119 irq_install(SYSTEM_TIMER_IRQ_VECTOR, &system_timer_isr, NULL);
00120 irq_setpriority(SYSTEM_TIMER_IRQ_VECTOR, IRQ_PRIORITY_SYSTEM_TIMER);
00121
00122
00123
00124 #define REG_CONTROL_PRESCALER PP_CAT(REG_TIMER_CTRL_PRIMARY_IPBY, TIMER_PRESCALER)
00125
00126
00127 REG_SYSTEM_TIMER->CTRL =
00128 REG_TIMER_CTRL_MODE_RISING |
00129 REG_CONTROL_PRESCALER |
00130 REG_TIMER_CTRL_LENGTH;
00131 }
00132
00133 INLINE void timer_hw_irq(void)
00134 {
00135
00136 REG_SYSTEM_TIMER->SCR &= ~REG_TIMER_SCR_TCF;
00137 }
00138
00139 INLINE hptime_t timer_hw_hpread(void)
00140 {
00141 return REG_SYSTEM_TIMER->CNTR;
00142 }
00143
00144 #define DEFINE_TIMER_ISR \
00145 static void system_timer_isr(UNUSED(iptr_t, arg))
00146
00147 #endif