123
Fork of LG by
DeviceTimers.c@161:efd949e8d536, 2016-05-15 (annotated)
- Committer:
- Diletant
- Date:
- Sun May 15 19:12:12 2016 +0000
- Revision:
- 161:efd949e8d536
- Parent:
- 156:e68ee0bcdcda
- Child:
- 167:bedc0a9d559a
Device & ... update. Not final!!!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Diletant | 156:e68ee0bcdcda | 1 | #include "Device.h" |
Diletant | 156:e68ee0bcdcda | 2 | |
Diletant | 156:e68ee0bcdcda | 3 | extern Device device; |
Diletant | 156:e68ee0bcdcda | 4 | |
Diletant | 156:e68ee0bcdcda | 5 | void InitMeasurementTimerWithDefaults(void){ |
Diletant | 156:e68ee0bcdcda | 6 | device.controller.timer[0].settings.match = 8064; //CCLK / 8064 = 12800.0Hz; Vibro: Timer1/32 = 400.0Hz; |
Diletant | 156:e68ee0bcdcda | 7 | } |
Diletant | 156:e68ee0bcdcda | 8 | |
Diletant | 156:e68ee0bcdcda | 9 | void InitMeasurementTimer(void) { |
Diletant | 156:e68ee0bcdcda | 10 | LPC_SC->PCONP |= (1<<2); //Power on timer 1 |
Diletant | 156:e68ee0bcdcda | 11 | device.controller.timer[0].state.MR0 = device.controller.timer[0].settings.match; |
Diletant | 156:e68ee0bcdcda | 12 | LPC_TIM1->MR0 = device.controller.timer[0].state.MR0; |
Diletant | 156:e68ee0bcdcda | 13 | device.controller.timer[0].state.MCR = 3; |
Diletant | 156:e68ee0bcdcda | 14 | LPC_TIM1->MCR = device.controller.timer[0].state.MCR; //Interrupt and Reset on MR1 |
Diletant | 156:e68ee0bcdcda | 15 | NVIC_EnableIRQ(TIMER1_IRQn); |
Diletant | 156:e68ee0bcdcda | 16 | } |
Diletant | 156:e68ee0bcdcda | 17 | |
Diletant | 156:e68ee0bcdcda | 18 | void DeviceEnableMeasurementTimer(void) { |
Diletant | 156:e68ee0bcdcda | 19 | device.controller.timer[0].state.TCR = 1; //Bit 0: Counter Enable |
Diletant | 156:e68ee0bcdcda | 20 | LPC_TIM1->TCR = device.controller.timer[0].state.TCR; |
Diletant | 156:e68ee0bcdcda | 21 | return; |
Diletant | 156:e68ee0bcdcda | 22 | } |
Diletant | 156:e68ee0bcdcda | 23 | |
Diletant | 156:e68ee0bcdcda | 24 | void InitRegularTimerWithDefaults(void){ |
Diletant | 156:e68ee0bcdcda | 25 | device.controller.timer[1].settings.match = 257; //CCLK / 4 / 258 = 100kHz |
Diletant | 156:e68ee0bcdcda | 26 | } |
Diletant | 156:e68ee0bcdcda | 27 | |
Diletant | 156:e68ee0bcdcda | 28 | void InitRegularTimer(void) { |
Diletant | 156:e68ee0bcdcda | 29 | LPC_SC->PCONP |= (1<<22);//Power on timer 2 |
Diletant | 156:e68ee0bcdcda | 30 | device.controller.timer[1].state.MR0 = device.controller.timer[1].settings.match; |
Diletant | 156:e68ee0bcdcda | 31 | LPC_TIM2->MR0 = device.controller.timer[1].state.MR0; |
Diletant | 156:e68ee0bcdcda | 32 | device.controller.timer[1].state.MCR = 3; |
Diletant | 156:e68ee0bcdcda | 33 | LPC_TIM2->MCR = device.controller.timer[1].state.MCR; //Interrupt and Reset on MR0 |
Diletant | 156:e68ee0bcdcda | 34 | NVIC_EnableIRQ(TIMER2_IRQn); |
Diletant | 156:e68ee0bcdcda | 35 | } |
Diletant | 156:e68ee0bcdcda | 36 | |
Diletant | 156:e68ee0bcdcda | 37 | void DeviceEnableRegularTimer(void) { |
Diletant | 156:e68ee0bcdcda | 38 | device.controller.timer[1].state.TCR = 1; //Bit 0: Counter Enable |
Diletant | 156:e68ee0bcdcda | 39 | LPC_TIM2->TCR = device.controller.timer[1].state.TCR; |
Diletant | 156:e68ee0bcdcda | 40 | } |
Diletant | 156:e68ee0bcdcda | 41 | |
Diletant | 156:e68ee0bcdcda | 42 | /* |
Diletant | 161:efd949e8d536 | 43 | //Measurement floating cycle timer interrupt |
Diletant | 156:e68ee0bcdcda | 44 | __irq void TIMER1_IRQHandler(void) { |
Diletant | 156:e68ee0bcdcda | 45 | DeviceMeasurementInterruptHandler(); |
Diletant | 156:e68ee0bcdcda | 46 | |
Diletant | 156:e68ee0bcdcda | 47 | LPC_TIM1->IR = 1; |
Diletant | 156:e68ee0bcdcda | 48 | } |
Diletant | 156:e68ee0bcdcda | 49 | |
Diletant | 161:efd949e8d536 | 50 | //Regular cycle 100kHz timer interrupt |
Diletant | 156:e68ee0bcdcda | 51 | __irq void TIMER2_IRQHandler(void) { |
Diletant | 156:e68ee0bcdcda | 52 | DeviceRegularInterruptHandler(); |
Diletant | 156:e68ee0bcdcda | 53 | |
Diletant | 156:e68ee0bcdcda | 54 | LPC_TIM2->IR = 1; |
Diletant | 156:e68ee0bcdcda | 55 | } |
Diletant | 156:e68ee0bcdcda | 56 | */ |