System Management code
Dependencies: CANBuffer mbed SystemManagement mbed-rtos
System Management code for Penn Electric Racing
Functions:
Controls Fans and Pumps via instruction from CAN Messages, ramps them up over time to prevent damage
Turns on/off DC-DC converter via instruction from CAN Messages
Diff: SysMngmt.cpp
- Revision:
- 1:e02eb179aed3
- Parent:
- 0:e516fcccccda
- Child:
- 2:baeb80c778f7
--- a/SysMngmt.cpp Wed Oct 01 12:52:26 2014 +0000 +++ b/SysMngmt.cpp Sat Oct 04 16:19:45 2014 +0000 @@ -43,13 +43,28 @@ } */ +/* + http://developer.mbed.org/users/AjK/notebook/getting-closer-to-the-hardware/ + + extern "C" means this is linked assuming it's C code + C++ linker appearently adds extra crap with the function arguments keeping functions of this kind from linking properly + + Interrupt handler, This is probably linked to the Timer 2 interrupt request somewhere by the libraries +*/ extern "C" void TIMER2_IRQHandler(void) { if((LPC_TIM2->IR & 0x01) == 0x01) // if MR0 interrupt { - //printf("Every 1ms\n\r"); + // This probably shouldn't be here, never have a printf() in an interrupt, locks up the main thread + // printf("Every 1ms\n\r"); + LPC_TIM2->IR |= 1 << 0; // Clear MR0 interrupt flag + // gonna hope all these calculations are correct + // writes to RTC store, but there's no read code here + // 2 misleading things. First, RTC store writes to a general purpose register + // secondly, no code reads from this register in this .cpp, but maybe some other code does + Bat_I_Ratio=BatISense.read(); BATA_msec=(((Bat_I_Ratio*3.3) - BAT_ISENSE_OFFSET_V)/BAT_ISENSE_INCREMENT); BATmA_Hr+=(BATA_msec*MSEC_HRS); @@ -60,11 +75,14 @@ store.write(DCA_msec,1); LPC_TIM2->TCR |= (1<<1); //Reset Timer1 - LPC_TIM2->TCR &= ~(1<<1); //Re Enable Timer1 + LPC_TIM2->TCR &= ~(1<<1); //Re Enable Timer1 } } - +/* + Appears to read a whole bunch of DigitalOut pins in void PollSwitch(), store the value in uint16_t Rxpoll, + and write the result to the CAN bus +*/ void Poll() { uint16_t Rxpoll; @@ -214,7 +232,8 @@ ->MR0 0x4009 0018 (Match Register) - ->MCR 0x4009 0014 (Match Control Register) + ->MCR 0x4009 0014 (Match Control Register) What to do when Match Register matches the Timer Counter + |= (1<<0); 0 Bit (Interrupt on MR0, interrupt generated when MR0 matches the value in TC) */ LPC_SC->PCONP |= (1<<22); //PoewerOn Timer/Counter2 @@ -223,6 +242,21 @@ LPC_TIM2->MR0 = 11999; // 1msec LPC_TIM2->MCR |= (1<<0); + /* + Nested Vectored Interrupt Controller (NVIC) + + NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) + sets priority of an interrupt + + IRQn_Type + Interrupt number definitions + Interrupt Request (IRQ) + + NVIC_EnableIRQ(IRQn_Type IRQn) + Enable external interrupt (in this case, the TIMER2_IRQHandler(void) function above gets called every time + Timer2 generates an interrupt signal) + + */ NVIC_SetPriority(TIMER0_IRQn,200); //IMD Capture Interrupt NVIC_SetPriority(TIMER1_IRQn,200); //IMD 1msec sampling Interrupt NVIC_SetPriority(TIMER2_IRQn,1); //Battery 1msec sampling Interrupt