123
Fork of LG by
DeviceTimers.c@156:e68ee0bcdcda, 2016-05-09 (annotated)
- Committer:
- Diletant
- Date:
- Mon May 09 20:03:26 2016 +0000
- Revision:
- 156:e68ee0bcdcda
- Child:
- 161:efd949e8d536
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 DeviceInitMeasurementTimer(unsigned int TimerInterval) { |
Diletant | 156:e68ee0bcdcda | 10 | void InitMeasurementTimer(void) { |
Diletant | 156:e68ee0bcdcda | 11 | LPC_SC->PCONP |= (1<<2); //Power on timer 1 |
Diletant | 156:e68ee0bcdcda | 12 | //LPC_TIM1->MR0 = TimerInterval; |
Diletant | 156:e68ee0bcdcda | 13 | device.controller.timer[0].state.MR0 = device.controller.timer[0].settings.match; |
Diletant | 156:e68ee0bcdcda | 14 | LPC_TIM1->MR0 = device.controller.timer[0].state.MR0; |
Diletant | 156:e68ee0bcdcda | 15 | device.controller.timer[0].state.MCR = 3; |
Diletant | 156:e68ee0bcdcda | 16 | //LPC_TIM1->MCR = 3; //Interrupt and Reset on MR1 |
Diletant | 156:e68ee0bcdcda | 17 | LPC_TIM1->MCR = device.controller.timer[0].state.MCR; //Interrupt and Reset on MR1 |
Diletant | 156:e68ee0bcdcda | 18 | NVIC_EnableIRQ(TIMER1_IRQn); |
Diletant | 156:e68ee0bcdcda | 19 | } |
Diletant | 156:e68ee0bcdcda | 20 | |
Diletant | 156:e68ee0bcdcda | 21 | void DeviceEnableMeasurementTimer(void) { |
Diletant | 156:e68ee0bcdcda | 22 | device.controller.timer[0].state.TCR = 1; //Bit 0: Counter Enable |
Diletant | 156:e68ee0bcdcda | 23 | LPC_TIM1->TCR = device.controller.timer[0].state.TCR; |
Diletant | 156:e68ee0bcdcda | 24 | return; |
Diletant | 156:e68ee0bcdcda | 25 | } |
Diletant | 156:e68ee0bcdcda | 26 | |
Diletant | 156:e68ee0bcdcda | 27 | void InitRegularTimerWithDefaults(void){ |
Diletant | 156:e68ee0bcdcda | 28 | device.controller.timer[1].settings.match = 257; //CCLK / 4 / 258 = 100kHz |
Diletant | 156:e68ee0bcdcda | 29 | } |
Diletant | 156:e68ee0bcdcda | 30 | |
Diletant | 156:e68ee0bcdcda | 31 | void InitRegularTimer(void) { |
Diletant | 156:e68ee0bcdcda | 32 | LPC_SC->PCONP |= (1<<22);//Power on timer 2 |
Diletant | 156:e68ee0bcdcda | 33 | device.controller.timer[1].state.MR0 = device.controller.timer[1].settings.match; |
Diletant | 156:e68ee0bcdcda | 34 | LPC_TIM2->MR0 = device.controller.timer[1].state.MR0; |
Diletant | 156:e68ee0bcdcda | 35 | device.controller.timer[1].state.MCR = 3; |
Diletant | 156:e68ee0bcdcda | 36 | LPC_TIM2->MCR = device.controller.timer[1].state.MCR; //Interrupt and Reset on MR0 |
Diletant | 156:e68ee0bcdcda | 37 | NVIC_EnableIRQ(TIMER2_IRQn); |
Diletant | 156:e68ee0bcdcda | 38 | } |
Diletant | 156:e68ee0bcdcda | 39 | |
Diletant | 156:e68ee0bcdcda | 40 | void DeviceEnableRegularTimer(void) { |
Diletant | 156:e68ee0bcdcda | 41 | device.controller.timer[1].state.TCR = 1; //Bit 0: Counter Enable |
Diletant | 156:e68ee0bcdcda | 42 | LPC_TIM2->TCR = device.controller.timer[1].state.TCR; |
Diletant | 156:e68ee0bcdcda | 43 | } |
Diletant | 156:e68ee0bcdcda | 44 | |
Diletant | 156:e68ee0bcdcda | 45 | /* |
Diletant | 156:e68ee0bcdcda | 46 | //Measurement cycle timer interrupt |
Diletant | 156:e68ee0bcdcda | 47 | __irq void TIMER1_IRQHandler(void) { |
Diletant | 156:e68ee0bcdcda | 48 | DeviceMeasurementInterruptHandler(); |
Diletant | 156:e68ee0bcdcda | 49 | |
Diletant | 156:e68ee0bcdcda | 50 | LPC_TIM1->IR = 1; |
Diletant | 156:e68ee0bcdcda | 51 | } |
Diletant | 156:e68ee0bcdcda | 52 | |
Diletant | 156:e68ee0bcdcda | 53 | //Regular cycle timer interrupt |
Diletant | 156:e68ee0bcdcda | 54 | __irq void TIMER2_IRQHandler(void) { |
Diletant | 156:e68ee0bcdcda | 55 | DeviceRegularInterruptHandler(); |
Diletant | 156:e68ee0bcdcda | 56 | |
Diletant | 156:e68ee0bcdcda | 57 | LPC_TIM2->IR = 1; |
Diletant | 156:e68ee0bcdcda | 58 | } |
Diletant | 156:e68ee0bcdcda | 59 | */ |