void MSP430_LPM_ENTER(void) { #ifdef LPM_ENABLED /* Turn off the watchdog timer */ WDTCTL = WDTPW | WDTHOLD; /* * Enter a critical section to do so that we do not get switched out by the * OS in the middle of stopping the OS Scheduler. */ __disable_interrupt(); __no_operation(); DisableRtosTick(); // Select a nice mode int smclk = 1;//IsSmClkInUse(); if (smclk) { LPMcurrent = LPM0_bits; } else { LPMcurrent = LPM3_bits; } MCLK_DIV(2); // Errata PMM11 sleep++; if (sleep == 5) { __no_operation(); } //__enable_interrupt(); int state = LPMcurrent | GIE; _bis_SR_register(state); __no_operation(); wake++; // if (!smclk) { /* errata PMM11 - wait to put MCLK into normal mode */ __delay_cycles(100); MCLK_DIV(1); } /* Generate a vTickIsr by setting the flag to trigger an interrupt * You can't call vTaskIncrementTick and vTaskSwitchContext from within a * task so do it with an ISR. We need to cause an OS tick here so that tasks * blocked on an event sent by an ISR will run. FreeRTOS queues them for * the next system tick. */ EnableRtosTick(); RTOS_TICK_SET_IFG(); __no_operation(); #endif }
static void EnterLpm3(void) { #if LPM_ENABLED /* * we are already in critical section so that we do not get switched out by the * OS in the middle of stopping the OS Scheduler. */ DisableRtosTick(); /* errata PMM11 + PMM12 divide MCLK by two before going to sleep */ if ( QueryErrataGroup1() ) { MCLK_DIV(2); } DEBUG1_HIGH(); __enable_interrupt(); LPM3; __no_operation(); DEBUG1_LOW(); /* errata PMM11 + PMM12 - wait to put MCLK into normal mode */ if ( QueryErrataGroup1() ) { __delay_cycles(100); MCLK_DIV(1); } /* Generate a vTickIsr by setting the flag to trigger an interrupt * You can't call vTaskIncrementTick and vTaskSwitchContext from within a * task so do it with an ISR. We need to cause an OS tick here so that tasks * blocked on an event sent by an ISR will run. FreeRTOS queues them for * the next system tick. */ EnableRtosTick(); RTOS_TICK_SET_IFG(); __no_operation(); #endif }
/* * Setup timer to generate the RTOS tick */ void SetupRtosTimer(void) { /* Ensure the timer is stopped */ TA0CTL = 0; /* Clear everything to start with */ TA0CTL |= TACLR; /* divide clock by 8 * the total divide is by 32 * 32768 kHz -> 1024 kHz -> 0.9765625 ms */ TA0EX0 = 0x7; Timer0Users = 0; EnableRtosTick(); }