123

Dependencies:   mbed

Fork of LG by igor Apu

Committer:
Kovalev_D
Date:
Wed Oct 19 10:55:05 2016 +0000
Revision:
197:7a05523bf588
Parent:
173:7f938afb0447
modul

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Diletant 156:e68ee0bcdcda 1 #include "Device.h"
Diletant 156:e68ee0bcdcda 2
Diletant 156:e68ee0bcdcda 3 extern Device device;
Diletant 173:7f938afb0447 4 extern unsigned int SystemCoreClock1;
Diletant 156:e68ee0bcdcda 5
Diletant 167:bedc0a9d559a 6 void InitMeasurementTimerDefaultSettings(void){
Diletant 173:7f938afb0447 7 //device.controller.timer[0].settings.match = 8064; //CCLK / 8064 = 12800.0Hz; Vibro: Timer1/32 = 400.0Hz;
Diletant 156:e68ee0bcdcda 8 }
Diletant 156:e68ee0bcdcda 9
Diletant 167:bedc0a9d559a 10 void InitMeasurementTimerState(void) {
Diletant 173:7f938afb0447 11 //TODO:
Diletant 173:7f938afb0447 12 //SystemCoreClock1 - 27 bit
Diletant 173:7f938afb0447 13 //device.dither.oscillation.state.frequency - 25 bit
Diletant 173:7f938afb0447 14 //device.controller.timer[0].state.MR0 - 13 bit
Diletant 173:7f938afb0447 15 device.controller.timer[0].state.MR0 = 0;
Diletant 173:7f938afb0447 16 device.controller.timer[0].state.MCR = 0;
Diletant 173:7f938afb0447 17 device.controller.timer[0].state.TCR = 0;
Diletant 156:e68ee0bcdcda 18 }
Diletant 156:e68ee0bcdcda 19
Diletant 167:bedc0a9d559a 20 void DeviceStartMeasurementTimer(void) {
Diletant 173:7f938afb0447 21 LPC_SC->PCONP |= (1<<2); //Power on timer 1
Diletant 173:7f938afb0447 22
Diletant 173:7f938afb0447 23 LPC_TIM1->MR0 = device.controller.timer[0].state.MR0;
Diletant 173:7f938afb0447 24
Diletant 173:7f938afb0447 25 device.controller.timer[0].state.MCR = 3;
Diletant 173:7f938afb0447 26 LPC_TIM1->MCR = device.controller.timer[0].state.MCR; //Interrupt and Reset on MR1
Diletant 173:7f938afb0447 27
Diletant 173:7f938afb0447 28 NVIC_EnableIRQ(TIMER1_IRQn);
Diletant 173:7f938afb0447 29
Diletant 156:e68ee0bcdcda 30 device.controller.timer[0].state.TCR = 1; //Bit 0: Counter Enable
Diletant 156:e68ee0bcdcda 31 LPC_TIM1->TCR = device.controller.timer[0].state.TCR;
Diletant 156:e68ee0bcdcda 32 return;
Diletant 156:e68ee0bcdcda 33 }
Diletant 156:e68ee0bcdcda 34
Diletant 173:7f938afb0447 35 void timersSetMeasurementPeriod(uint32_t period) {
Diletant 173:7f938afb0447 36 device.controller.timer[0].state.MR0 = period;
Diletant 173:7f938afb0447 37 LPC_TIM1->MR0 = device.controller.timer[0].state.MR0;
Diletant 173:7f938afb0447 38 }
Diletant 173:7f938afb0447 39
Diletant 167:bedc0a9d559a 40 void InitRegularTimerDefaultSettings(void){
Diletant 156:e68ee0bcdcda 41 }
Diletant 156:e68ee0bcdcda 42
Diletant 167:bedc0a9d559a 43 void InitRegularTimerState(void) {
Diletant 173:7f938afb0447 44 device.controller.timer[1].state.MR0 = 0;
Diletant 173:7f938afb0447 45 device.controller.timer[1].state.MCR = 0;
Diletant 173:7f938afb0447 46 device.controller.timer[1].state.TCR = 0;
Diletant 156:e68ee0bcdcda 47 }
Diletant 156:e68ee0bcdcda 48
Diletant 167:bedc0a9d559a 49 void DeviceStartRegularTimer(void) {
Diletant 173:7f938afb0447 50 LPC_SC->PCONP |= (1<<22);//Power on timer 2
Diletant 173:7f938afb0447 51
Diletant 173:7f938afb0447 52 LPC_TIM2->MR0 = device.controller.timer[1].state.MR0;
Diletant 173:7f938afb0447 53
Diletant 173:7f938afb0447 54 device.controller.timer[1].state.MCR = 3;
Diletant 173:7f938afb0447 55 LPC_TIM2->MCR = device.controller.timer[1].state.MCR; //Interrupt and Reset on MR0
Diletant 173:7f938afb0447 56
Diletant 173:7f938afb0447 57 NVIC_EnableIRQ(TIMER2_IRQn);
Diletant 173:7f938afb0447 58
Diletant 156:e68ee0bcdcda 59 device.controller.timer[1].state.TCR = 1; //Bit 0: Counter Enable
Diletant 156:e68ee0bcdcda 60 LPC_TIM2->TCR = device.controller.timer[1].state.TCR;
Diletant 156:e68ee0bcdcda 61 }
Diletant 173:7f938afb0447 62
Diletant 173:7f938afb0447 63 void timersSetRegularPeriod(uint32_t period) {
Diletant 173:7f938afb0447 64 device.controller.timer[1].state.MR0 = period;
Diletant 173:7f938afb0447 65 LPC_TIM2->MR0 = device.controller.timer[1].state.MR0;
Diletant 173:7f938afb0447 66 }
Diletant 156:e68ee0bcdcda 67 /*
Diletant 161:efd949e8d536 68 //Measurement floating cycle timer interrupt
Diletant 156:e68ee0bcdcda 69 __irq void TIMER1_IRQHandler(void) {
Diletant 156:e68ee0bcdcda 70 DeviceMeasurementInterruptHandler();
Diletant 156:e68ee0bcdcda 71
Diletant 156:e68ee0bcdcda 72 LPC_TIM1->IR = 1;
Diletant 156:e68ee0bcdcda 73 }
Diletant 156:e68ee0bcdcda 74
Diletant 161:efd949e8d536 75 //Regular cycle 100kHz timer interrupt
Diletant 156:e68ee0bcdcda 76 __irq void TIMER2_IRQHandler(void) {
Diletant 156:e68ee0bcdcda 77 DeviceRegularInterruptHandler();
Diletant 156:e68ee0bcdcda 78
Diletant 156:e68ee0bcdcda 79 LPC_TIM2->IR = 1;
Diletant 156:e68ee0bcdcda 80 }
Diletant 156:e68ee0bcdcda 81 */