timer_dsp56k.h
Go to the documentation of this file.00001 #error This code must be revised for the new timer API
00002
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
00076 #ifndef DRV_TIMER_DSP56K_H
00077 #define DRV_TIMER_DSP56K_H
00078
00079 #include "timer.h"
00080 #include <DSP56F807.h>
00081 #include <cfg/compiler.h>
00082 #include <hw.h>
00083 #include <drv/irq.h>
00084
00085
00086 #define REG_SYSTEM_TIMER PP_CAT(REG_TIMER_, SYSTEM_TIMER)
00087 #define SYSTEM_TIMER_IRQ_VECTOR PP_CAT(IRQ_TIMER_, SYSTEM_TIMER)
00088
00090 #define TIMER_PRESCALER 16
00091
00093 #define TIMER_HW_HPTICKS_PER_SEC (IPBUS_FREQ / TIMER_PRESCALER)
00094
00096 typedef uint16_t hptime_t;
00097
00098 static void system_timer_isr(UNUSED(iptr_t, arg));
00099
00100 static void timer_hw_init(void)
00101 {
00102 uint16_t compare;
00103
00104
00105 REG_SYSTEM_TIMER->SCR &= ~REG_TIMER_SCR_TCF;
00106 REG_SYSTEM_TIMER->SCR |= REG_TIMER_SCR_TCFIE;
00107
00108
00109
00110
00111
00112 compare = TIMER_HW_HPTICKS_PER_SEC / TICKS_PER_SEC;
00113 ASSERT((uint32_t)compare * TICKS_PER_SEC == IPBUS_FREQ / TIMER_PRESCALER);
00114 REG_SYSTEM_TIMER->CMP1 = compare;
00115
00116
00117 REG_SYSTEM_TIMER->LOAD = 0;
00118
00119
00120 irq_install(SYSTEM_TIMER_IRQ_VECTOR, &system_timer_isr, NULL);
00121 irq_setpriority(SYSTEM_TIMER_IRQ_VECTOR, IRQ_PRIORITY_SYSTEM_TIMER);
00122
00123
00124
00125 #define REG_CONTROL_PRESCALER PP_CAT(REG_TIMER_CTRL_PRIMARY_IPBY, TIMER_PRESCALER)
00126
00127
00128 REG_SYSTEM_TIMER->CTRL =
00129 REG_TIMER_CTRL_MODE_RISING |
00130 REG_CONTROL_PRESCALER |
00131 REG_TIMER_CTRL_LENGTH;
00132 }
00133
00134 INLINE void timer_hw_irq(void)
00135 {
00136
00137 REG_SYSTEM_TIMER->SCR &= ~REG_TIMER_SCR_TCF;
00138 }
00139
00140 INLINE hptime_t timer_hw_hpread(void)
00141 {
00142 return REG_SYSTEM_TIMER->CNTR;
00143 }
00144
00145 #define DEFINE_TIMER_ISR \
00146 static void system_timer_isr(UNUSED(iptr_t, arg))
00147
00148 #endif