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

}
Пример #2
0
static void EnterShippingMode(void)
{
  /* Turn off the watchdog timer */
  WDTCTL = WDTPW + WDTHOLD;
#ifdef DIGITAL
  ClearLcd();
#endif
  ConfigResetPin(RST_PIN_ENABLED);
  
  __delay_cycles(100000);
  
  __disable_interrupt();
  __no_operation();
  
  DisableRtosTick();
  
  /* 
   * the radio draws more current in reset than it does after 
   * the patch is loaded
   */
  
  DISABLE_DISPLAY_POWER();
  DISABLE_LCD_ENABLE();
  BATTERY_CHARGE_DISABLE();
  LIGHT_SENSOR_SHUTDOWN();
  BATTERY_SENSE_DISABLE();
  HARDWARE_CFG_SENSE_DISABLE();
  APPLE_POWER_DISABLE();
  ACCELEROMETER_INT_DISABLE();
  DISABLE_BUTTONS();
  
#ifdef DIGITAL
  /* SHIPPING */
  ENABLE_SHIPPING_WAKEUP();
#endif
  
  SELECT_ACLK(SELA__REFOCLK);                
  SELECT_FLLREF(SELREF__REFOCLK); 
  UCSCTL8 &= ~SMCLKREQEN;
  UCSCTL6 |= SMCLKOFF;
  /* disable aclk */
  P11SEL &= ~BIT0;
  XT1_Stop();
  
  /* turn off the regulator */
  PMMCTL0_H = PMMPW_H;
  PMMCTL0_L = PMMREGOFF;
  __low_power_mode_4();
  __no_operation();
  __no_operation();
  
  /* should not get here without a power event */
  SoftwareReset();
}
Пример #3
0
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  
}