123
Fork of LG by
Diff: DeviceTimers.c
- Revision:
- 173:7f938afb0447
- Parent:
- 167:bedc0a9d559a
--- a/DeviceTimers.c Fri Jun 17 13:54:50 2016 +0000 +++ b/DeviceTimers.c Sun Jun 19 03:54:35 2016 +0000 @@ -1,43 +1,69 @@ #include "Device.h" extern Device device; +extern unsigned int SystemCoreClock1; void InitMeasurementTimerDefaultSettings(void){ - device.controller.timer[0].settings.match = 8064; //CCLK / 8064 = 12800.0Hz; Vibro: Timer1/32 = 400.0Hz; + //device.controller.timer[0].settings.match = 8064; //CCLK / 8064 = 12800.0Hz; Vibro: Timer1/32 = 400.0Hz; } void InitMeasurementTimerState(void) { - LPC_SC->PCONP |= (1<<2); //Power on timer 1 - device.controller.timer[0].state.MR0 = device.controller.timer[0].settings.match; - LPC_TIM1->MR0 = device.controller.timer[0].state.MR0; - device.controller.timer[0].state.MCR = 3; - LPC_TIM1->MCR = device.controller.timer[0].state.MCR; //Interrupt and Reset on MR1 - NVIC_EnableIRQ(TIMER1_IRQn); + //TODO: + //SystemCoreClock1 - 27 bit + //device.dither.oscillation.state.frequency - 25 bit + //device.controller.timer[0].state.MR0 - 13 bit + device.controller.timer[0].state.MR0 = 0; + device.controller.timer[0].state.MCR = 0; + device.controller.timer[0].state.TCR = 0; } void DeviceStartMeasurementTimer(void) { + LPC_SC->PCONP |= (1<<2); //Power on timer 1 + + LPC_TIM1->MR0 = device.controller.timer[0].state.MR0; + + device.controller.timer[0].state.MCR = 3; + LPC_TIM1->MCR = device.controller.timer[0].state.MCR; //Interrupt and Reset on MR1 + + NVIC_EnableIRQ(TIMER1_IRQn); + device.controller.timer[0].state.TCR = 1; //Bit 0: Counter Enable LPC_TIM1->TCR = device.controller.timer[0].state.TCR; return; } +void timersSetMeasurementPeriod(uint32_t period) { + device.controller.timer[0].state.MR0 = period; + LPC_TIM1->MR0 = device.controller.timer[0].state.MR0; +} + void InitRegularTimerDefaultSettings(void){ - device.controller.timer[1].settings.match = 257; //CCLK / 4 / 258 = 100kHz } void InitRegularTimerState(void) { - LPC_SC->PCONP |= (1<<22);//Power on timer 2 - device.controller.timer[1].state.MR0 = device.controller.timer[1].settings.match; - LPC_TIM2->MR0 = device.controller.timer[1].state.MR0; - device.controller.timer[1].state.MCR = 3; - LPC_TIM2->MCR = device.controller.timer[1].state.MCR; //Interrupt and Reset on MR0 - NVIC_EnableIRQ(TIMER2_IRQn); + device.controller.timer[1].state.MR0 = 0; + device.controller.timer[1].state.MCR = 0; + device.controller.timer[1].state.TCR = 0; } void DeviceStartRegularTimer(void) { + LPC_SC->PCONP |= (1<<22);//Power on timer 2 + + LPC_TIM2->MR0 = device.controller.timer[1].state.MR0; + + device.controller.timer[1].state.MCR = 3; + LPC_TIM2->MCR = device.controller.timer[1].state.MCR; //Interrupt and Reset on MR0 + + NVIC_EnableIRQ(TIMER2_IRQn); + device.controller.timer[1].state.TCR = 1; //Bit 0: Counter Enable LPC_TIM2->TCR = device.controller.timer[1].state.TCR; } + +void timersSetRegularPeriod(uint32_t period) { + device.controller.timer[1].state.MR0 = period; + LPC_TIM2->MR0 = device.controller.timer[1].state.MR0; +} /* //Measurement floating cycle timer interrupt __irq void TIMER1_IRQHandler(void) {