123

Dependencies:   mbed

Fork of LG by igor Apu

Revision:
156:e68ee0bcdcda
Child:
161:efd949e8d536
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DeviceTimers.c	Mon May 09 20:03:26 2016 +0000
@@ -0,0 +1,59 @@
+#include "Device.h"
+
+extern Device device;
+
+void InitMeasurementTimerWithDefaults(void){
+ device.controller.timer[0].settings.match = 8064; //CCLK / 8064 = 12800.0Hz; Vibro: Timer1/32 = 400.0Hz;
+}
+
+//void DeviceInitMeasurementTimer(unsigned int TimerInterval) {
+void InitMeasurementTimer(void) {
+  LPC_SC->PCONP |= (1<<2); //Power on timer 1
+  //LPC_TIM1->MR0 = TimerInterval;
+  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 = 3; //Interrupt and Reset on MR1
+  LPC_TIM1->MCR = device.controller.timer[0].state.MCR; //Interrupt and Reset on MR1
+  NVIC_EnableIRQ(TIMER1_IRQn);
+}
+
+void DeviceEnableMeasurementTimer(void) {
+  device.controller.timer[0].state.TCR = 1; //Bit 0: Counter Enable
+  LPC_TIM1->TCR = device.controller.timer[0].state.TCR;
+  return;
+}
+
+void InitRegularTimerWithDefaults(void){
+ device.controller.timer[1].settings.match = 257; //CCLK / 4 / 258 = 100kHz
+}
+
+void InitRegularTimer(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);
+}
+
+void DeviceEnableRegularTimer(void) {
+  device.controller.timer[1].state.TCR = 1; //Bit 0: Counter Enable
+  LPC_TIM2->TCR = device.controller.timer[1].state.TCR;
+}
+
+/*
+//Measurement cycle timer interrupt
+__irq void TIMER1_IRQHandler(void) {
+  DeviceMeasurementInterruptHandler();
+
+  LPC_TIM1->IR = 1;
+}
+
+//Regular cycle timer interrupt
+__irq void TIMER2_IRQHandler(void) {
+  DeviceRegularInterruptHandler();
+  
+  LPC_TIM2->IR = 1;
+}
+*/
\ No newline at end of file