Esempio n. 1
0
enum lpm_mode lpm_arch_set(enum lpm_mode target)
{
    enum lpm_mode last_mode = current_mode;

    switch(target) {
    case LPM_ON: /* EM0 mode */
        current_mode = LPM_ON;
        break;
    case LPM_IDLE: /* EM2 mode */
        /* Entering EM2 mode */
        /* High frequencies clocks are disabled, LFXO is still running */
        current_mode = LPM_IDLE;
#ifndef DISABLE_EM2
        EMU_EnterEM2(true);
#endif
        break;
    case LPM_SLEEP: /* EM2 mode */
        /* Entering EM2 mode */
        /* High frequencies clocks are disabled, LFXO is still running */
        current_mode = LPM_SLEEP;
#ifndef DISABLE_EM2
        EMU_EnterEM2(true);
#endif
        break;
    case LPM_POWERDOWN: /* not implemented */
        /* Fall-through */
    case LPM_OFF: /* not implemented */
        /* Fall-through */
    default:
        break;
    }

    return last_mode;
}
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
    TEMPSENS_Temp_TypeDef temp;

    /* Chip revision alignment and errata fixes */
    CHIP_Init();

    /* Initialize LCD controller without boost */
    SegmentLCD_Init(false);

    I2C_Tempsens_Init();

    /* Main loop - just read temperature and update LCD */
    while (1)
    {
        if (TEMPSENS_TemperatureGet(I2C0,
                                    TEMPSENS_DVK_ADDR,
                                    &temp) < 0)
        {
            SegmentLCD_Write("ERROR");
            /* Enter EM2, no wakeup scheduled */
            EMU_EnterEM2(true);
        }

        /* Update LCD display */
        temperatureUpdateLCD(&temp);

        /* Read every 2 seconds which is more than it takes worstcase to */
        /* finish measurement inside sensor. */
        RTCDRV_Trigger(2000, NULL);
        EMU_EnterEM2(true);
    }
}
Esempio n. 3
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  I2C_Init_TypeDef      i2cInit = I2C_INIT_DEFAULT;
  TEMPSENS_Temp_TypeDef temp;
  /* Define previous temp to invalid, just to ensure update first time */
  TEMPSENS_Temp_TypeDef prevTemp = {1000, 0};
  int                   prevShowFahrenheit = showFahrenheit;

  /* Initialize DK board register access */
  BSP_Init(BSP_INIT_DEFAULT);

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Initialize TFT */
  RETARGET_SerialInit();
  printf("\nEFM32 I2C temperature sensor example\n\n");

  /* Enable board control interrupts */
  BSP_InterruptDisable(0xffff);
  BSP_InterruptFlagsClear(0xffff);
  BSP_InterruptEnable(BC_INTEN_JOYSTICK);
  temperatureIRQInit();

  /* Initialize I2C driver, using standard rate. Devices on DK itself */
  /* supports fast mode, but in case some slower devices are added on */
  /* prototype board, we use standard mode. */
  I2CDRV_Init(&i2cInit);

  /* Main loop - just read temperature and update LCD */
  while (1)
  {
    if (TEMPSENS_TemperatureGet(I2C0,
                                TEMPSENS_DK_ADDR,
                                &temp) < 0)
    {
      printf("ERROR\n");
      /* Enter EM2, no wakeup scheduled */
      EMU_EnterEM2(true);
    }

    /* Update LCD display if any change. This is just an example of how */
    /* to save some energy, since the temperature normally is quite static. */
    /* The compare overhead is much smaller than actually updating the display. */
    if ((prevTemp.i != temp.i) ||
        (prevTemp.f != temp.f) ||
        (prevShowFahrenheit != showFahrenheit))
    {
      temperatureUpdate(&temp);
    }
    prevTemp           = temp;
    prevShowFahrenheit = showFahrenheit;

    /* Read every 2 seconds which is more than it takes worstcase to */
    /* finish measurement inside sensor. */
    RTCDRV_Trigger(2000, NULL);
    EMU_EnterEM2(true);
  }
}
Esempio n. 4
0
enum lpm_mode lpm_arch_set(enum lpm_mode target)
{
    switch (target) {
        case LPM_ON:
            /* nothing to do */
            break;
        case LPM_IDLE:
            /* wait for next event or interrupt */
            EMU_EnterEM1();
            break;
        case LPM_SLEEP:
            /* after exiting EM2, clocks are restored */
            EMU_EnterEM2(true);
            break;
        case LPM_POWERDOWN:
            /* after exiting EM3, clocks are restored */
            EMU_EnterEM3(true);
            break;
        case LPM_OFF:
            /* only a reset can wake up from EM4 */
            EMU_EnterEM4();
            break;

        /* do nothing here */
        case LPM_UNKNOWN:
        default:
            break;
    }

    /* no matter which case was selected, instructions executed in EM0 only */
    return LPM_ON;
}
Esempio n. 5
0
/******************************************************************************
 * @brief  
 *   Main function
 *****************************************************************************/
int main(void)
{
  /* Initialize chip - handle erratas */
  CHIP_Init();

  /* Setup RTC for periodic wake-ups */
  startRTCTick();

  /* Start LFXO. Do not wait until it is stable */
  CMU_OscillatorEnable(cmuOsc_LFXO, true, false);

  /* Wait in EM2 until LFXO is ready */
  while (!(CMU->STATUS & CMU_STATUS_LFXORDY))
  {
    EMU_EnterEM2(false);
  }
  /* Stop the RTC */
  stopRTCTick();

  while (1)
  {
    /* Go to sleep */
    EMU_EnterEM1();
  }
}
Esempio n. 6
0
/**************************************************************************//**
 * @brief Update clock and wait in EM2 for RTC tick.
 *****************************************************************************/
void clockLoop(void)
{
  LCD_FrameCountInit_TypeDef frameInit;
  LCD_AnimInit_TypeDef animInit;

  /* Write Gecko and display, and light up the colon between hours and minutes. */
  SegmentLCD_Symbol(LCD_SYMBOL_COL10, 1);
  SegmentLCD_Write("Wonder");

  /* Setup frame counter */
  frameInit.enable   = true;           /* Enable framecounter */
  frameInit.top      = 15;             /* Generate event every 15 frames. */
  frameInit.prescale = lcdFCPrescDiv1; /* No prescaling */

  LCD_FrameCountInit(&frameInit);

  /* Animate half ring - by special board design it is possible to achieve */
  /* "slide in/slide out" effect                                           */
  animInit.enable    = true;             /* Enable animation after initialization. */
  animInit.AReg      = 0x00;             /* Initial A register value */
  animInit.BReg      = 0x0F;             /* Initial B register value */
  animInit.AShift    = lcdAnimShiftLeft; /* Shift A register left */
  animInit.BShift    = lcdAnimShiftLeft; /* Shift B register left */
  animInit.animLogic = lcdAnimLogicOr;   /* Enable segment if A or B */
  animInit.startSeg  = 8;                /* Initial animation segment */

  LCD_AnimInit(&animInit);

  while (1)
  {
    checkVoltage();
    SegmentLCD_Number(hours * 100 + minutes);
    EMU_EnterEM2(true);
  }
}
void hw_enter_lowpower_mode(uint8_t mode)
{
    switch(mode)
    {
	case 0:
	{
	    EMU_EnterEM1();
	    break;	    
	}
	case 1:
	{
	    EMU_EnterEM2(true);
	    break;
	}
	case 2:
	{
	    EMU_EnterEM3(true);
	    break;
	}
	case 4:
	{
	    EMU_EnterEM4();
	    break;
	}
	default:
	{
	    assert(0);
	}
    }
}
Esempio n. 8
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Initialize chip */
  CHIP_Init();
  
  /* Enable Low energy clocking module clock. */
  CMU_ClockEnable(cmuClock_CORELE, true);

  /* Disable LFA and LFB clock domains to save power */
  CMU->LFCLKSEL = 0;
  
  /* Starting LFRCO and waiting until it is stable */
  CMU_OscillatorEnable(cmuOsc_LFRCO, true, true);

  /* Enable access to BURTC registers */
  RMU_ResetControl(rmuResetBU, false);

  /* Setting up burtc */
  setupBurtc();
  
  while (1)
  {
    /* Enter EM2. */
    EMU_EnterEM2(false);
  }
}
Esempio n. 9
0
void os_idle_demon(void)
{
  RTC_Init_TypeDef init;
  unsigned int sleep;

  /* The idle demon is a system thread, running when no other thread is      */
  /* ready to run.                                                           */

  /* Enable system clock for RTC */

  /* LFXO setup */
  /* Use 70% boost */
  CMU->CTRL = (CMU->CTRL & ~_CMU_CTRL_LFXOBOOST_MASK) | CMU_CTRL_LFXOBOOST_70PCENT;

  /* Ensure LE modules are accessible */
  CMU_ClockEnable(cmuClock_CORELE, true);

  /* Enable osc as LFACLK in CMU (will also enable oscillator if not enabled) */
  CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFXO);

  /* Use a 32 division prescaler to reduce power consumption. */
  CMU_ClockDivSet(cmuClock_RTC, cmuClkDiv_32);

  /* Enable clock to RTC module */
  CMU_ClockEnable(cmuClock_RTC, true);

  init.enable   = false;
  init.debugRun = false;
  init.comp0Top = false; /* Count to max value before wrapping */

  RTC_Init(&init);

  /* Disable interrupt generation from RTC0 */
  RTC_IntDisable(_RTC_IF_MASK);

  /* Enable interrupts */
  NVIC_ClearPendingIRQ(RTC_IRQn);
  NVIC_EnableIRQ(RTC_IRQn);

  for (;;)
  {
    /* os_suspend stops scheduler and returns time to next event in OS_TICK units */
    sleep = os_suspend();
    if (sleep)
    {
      RTC_CompareSet(0, sleep - 1);
      RTC_IntClear(RTC_IFC_COMP0);
      RTC_IntEnable(RTC_IF_COMP0);
      RTC_CounterReset();
      /* Enter EM2 low power mode - could be replaced with EM1 if required */
      EMU_EnterEM2(true);
      /* get information how long we were in sleep */
      sleep = RTC_CounterGet();
      RTC_Enable(false);
    };
    /* resume scheduler providing information how long MCU was sleeping */
    os_resume(sleep);
  }
}
Esempio n. 10
0
/**************************************************************************//**
 * @brief Sleeps in EM2 in given time unless some other IRQ sources has been
 *        enabled
 * @param msec Time in milliseconds
 *****************************************************************************/
void EM2Sleep(uint32_t msec)
{
  /* Wake us up after msec (or joystick pressed) */
  NVIC_DisableIRQ(LCD_IRQn);
  RTCDRV_Trigger(msec, NULL);
  EMU_EnterEM2(true);
  NVIC_EnableIRQ(LCD_IRQn);
}
Esempio n. 11
0
/**************************************************************************//**
 * @brief  Main function of clock example.
 *
 *****************************************************************************/
int main(void)
{  
  EMSTATUS status;
  bool redraw;
  ClockMode_t prevClockMode = CLOCK_MODE_DIGITAL;
  
  /* Chip errata */
  CHIP_Init();

  /* Use the 21 MHz band in order to decrease time spent awake.
     Note that 21 MHz is the highest HFRCO band on ZG. */
  CMU_ClockSelectSet( cmuClock_HF, cmuSelect_HFRCO  );
  CMU_HFRCOBandSet( cmuHFRCOBand_21MHz );

  /* Setup GPIO for pushbuttons. */
  gpioSetup();

  /* Initialize display module */    
  status = DISPLAY_Init();
  if (DISPLAY_EMSTATUS_OK != status)
    while (true)
      ;

  /* Initialize the DMD module for the DISPLAY device driver. */
  status = DMD_init(0);
  if (DMD_OK != status)
    while (true)
      ;

  status = GLIB_contextInit(&gc);
  if (GLIB_OK != status)
    while (true)
      ;
  
  /* Set PCNT to generate interrupt every second */
  pcntInit();
  
  /* Pre-compte positions for the analog graphics */
  analogClockInitGraphics();

  /* Enter infinite loop that switches between analog and digitcal clock
   * modes, toggled by pressing the button PB0. */
  while (true)
  {    
    redraw = (prevClockMode != clockMode);
    prevClockMode = clockMode;
    if (CLOCK_MODE_ANALOG == clockMode)
    {
      analogClockShow(redraw);
    }
    else
    {
      digitalClockShow(redraw);
    }
    /* Sleep between each frame update */
    EMU_EnterEM2(false);
  }
}
Esempio n. 12
0
int main(void) 
{
	
	CHIP_Init();

	if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) while (1) ;

  BSP_Init(BSP_INIT_DEFAULT);
	BSP_LedsSet(0);

  BSP_PeripheralAccess(BSP_AUDIO_IN, true);
  BSP_PeripheralAccess(BSP_AUDIO_OUT, true);

  RTCDRV_Trigger(1000, NULL);
  EMU_EnterEM2(true);

  initSource();

	setupCMU();
  setupDMA();
  
  //setupADC();
  //setupDAC();

  //setupDMAInput();
  //setupDMAOutput();

	//setupDMASplit();
	//setupDMAMerge();

  ADCConfig();
  DACConfig();

  TIMER_Init_TypeDef timerInit = TIMER_INIT_DEFAULT;
  TIMER_TopSet(TIMER0, CMU_ClockFreqGet(cmuClock_HFPER) / SAMPLE_RATE);
  TIMER_Init(TIMER0, &timerInit);

	Delay(100);
	BSP_LedsSet(3);
	Delay(500);
	BSP_LedsSet(0);
	Delay(100);

	while(1) {
		volatile bool result = test();
		if (result) {
			BSP_LedsSet(0x00FF);
		} else {
			BSP_LedsSet(0xFF00);			
		}
		Delay(1000);
    BSP_LedsSet(0x0);    
    Delay(1000);
	}

}
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
	TRACE_SWOSetup();
	
	allSensorsOff();
	
	AlarmManager * mgr = AlarmManager::getInstance();
	
	gps  = GPSSensor::getInstance();
	gps->initialize();
	gps->setParseOnReceive(true);
	gps->setSleepState(true);
		
	mgr->pause();
	mgr->createAlarm(READ_PERIOD, false, &wakeupHandler);
	AlarmID readID = mgr->createAlarm(READ_PERIOD, false, &readHandler);
	mgr->setAlarmTimeout(readID, READ_PERIOD+READ_OFFSET);
	mgr->resume();
	
	uint16_t size;
	GPSMessage * gpsMsg;
	SensorMessage * msg;
	
	while (1)
	{
		EMU_EnterEM2(true);
		
		if(wakeup)
		{
			printf("wakeup! \n");
			wakeup = false;
			gps->setSleepState(false);
		}
		
		if(read)
		{
			printf("read! \n");
			read = false;
			gps->sampleSensorData();
			gps->setSleepState(true);
			msg = (SensorMessage *) gps->readSensorData(&size);
			gpsMsg = (GPSMessage *) msg->sensorMsgArray;
			if(gpsMsg->validPosFix)
				printf("GPS: position fixed! \n");
			else
				printf("GPS: position not fixed \n");
			
			printf("GPS: %d %d %d, %d %d %d \n", gpsMsg->latitude.degree,
					 gpsMsg->latitude.minute, gpsMsg->latitude.second, 
				 	gpsMsg->longitude.degree, gpsMsg->longitude.minute, 
				 	gpsMsg->longitude.second);
			

		}
	}
}
Esempio n. 14
0
/**************************************************************************//**
 * @brief Sleeps in EM2 in given time unless some other IRQ sources has been
 *        enabled
 * @param msec Time in milliseconds
 *****************************************************************************/
void EM2Sleep(uint32_t msec)
{
  /* Wake us up after msec (or joystick pressed) */
  NVIC_DisableIRQ(LCD_IRQn);
  /* Tell AEM we're in EM2 */
  BSP_EnergyModeSet(2);
  RTCDRV_Trigger(msec, NULL);
  EMU_EnterEM2(true);
  BSP_EnergyModeSet(0);
  NVIC_EnableIRQ(LCD_IRQn);
}
Esempio n. 15
0
/** \brief the main function of the project
 *  check current state and switch apps respectively
 * \param 
 * \param 
 * \return 
 *
 */     
int main(void)
{
    /* Chip errata */
    CHIP_Init();

    /* If first word of user data page is non-zero, enable eA Profiler trace */
    BSP_TraceProfilerSetup();

    ////////////////////////////////////////////////////////////////////////
    setupSWO();
    /* Initialize LED driver */
    BSP_LedsInit();
    initButtons();
    initClock();
    initActivity();
    initVariables();
    SegmentLCD_Init(false);  /* Enable LCD without voltage boost */

    state = main_screen;

    /* Infinite blink loop */
    while (1)
    {
        //NOTE maybe button A(change state) must be checked here
        if(screen_notification == true)    // don't update screen until user reaction
        {
            EMU_EnterEM2(true);
            button = NO_BUTTON;
        }
        else
        {
            switch (state)
            {
            case main_screen:
                mainScreenApp();
                break;
            case pomodoro_screen:
                pomodoroApp();
                break;
            case activity_screen:
                activityApp();
                break;
            case time_setup_screen:
                setupTimeApp();
                break;
            case alarm_setup_screen:
                setupAlarmApp();
                break;
            }
        }
    }
}
Esempio n. 16
0
/***************************************************************************//**
 * @brief RTC delay function
 * @param msec Number of msec to delay
 * @param useEM2 Enter EM2 while waiting
 ******************************************************************************/
void RTCDRV_Delay(uint32_t msec, bool useEM2)
{
  rtcDelayComplete = false;
  RTCDRV_Trigger(msec, DelayCB);

  while (!rtcDelayComplete)
  {
    if (useEM2)
    {
      EMU_EnterEM2(true);
    }
  }
}
Esempio n. 17
0
int main()
{
  CHIP_Init();
  TRACE_SWOSetup();  
  UARTManager::getInstance()->getPort(UARTManagerPortLEUART0)->setSignalFrameHook(&frameHandler);
  UARTManager::getInstance()->getPort(UARTManagerPortLEUART0)->setRxHook(&rxHook);
  gps = GPSSensor::getInstance();
  
  while(1)
  {
    EMU_EnterEM2(true);
  }
}
Esempio n. 18
0
/**************************************************************************//**
 * @brief Sleeps in EM2 in given time
 * @param msec Time in milliseconds
 *****************************************************************************/
void EM2Sleep(uint32_t msec)
{
  /* Wake us up after msec */
  NVIC_DisableIRQ(LCD_IRQn);
  rtcFlag = true;
  RTCDRV_Trigger(msec, RTC_TimeOutHandler);
  /* The rtcFlag variable is set in the RTC interrupt routine using the callback
   * RTC_TimeOutHandler. This makes sure that the elapsed time is correct. */
  while (rtcFlag)
  {
    EMU_EnterEM2(true);
  }
  NVIC_EnableIRQ(LCD_IRQn);
}
Esempio n. 19
0
ERROR_CODE Statemachine::startApplication( STATUS_BLOCK *statusBlock )
{
	callingStatusBlock = currentStatusBlock;
	currentStatusBlock = statusBlock;

	if(!setupDone)
		return FSM_NotInitialized;


	// Run the FSM until the execution is stopped by the Application-Code.
	// The State-Function is called within the WHILE-STATEMENT !!!!
	while( ( *(stateDefinition)[statusBlock->nextState] )() )
	{
		// Is the State-Function, which is selected for execution in the next step a valid one?
		if( currentStatusBlock->nextState < maxNumberOfStates )
		{
			// Does the MCU have to enter a sleep-mode?
			if( currentStatusBlock->wantToSleep )
			{
				// Which sleep-mode has to be entered?
				switch( currentStatusBlock->sleepMode )
				{
				case 0:
					break;
				case 1:
					EMU_EnterEM1();
					break;
				case 2:
					EMU_EnterEM2( currentStatusBlock->restoreClockSetting );
					break;
				case 3:
					EMU_EnterEM3( currentStatusBlock->restoreClockSetting );
					break;
				case 4:
					EMU_EnterEM4();
				default:
					return EM_invalid; // Invalid sleep-mode!!!
				}
			}
		}

		else
			return StateID_Invalid; // Invalid State-Function number!!!
	}

	currentStatusBlock = callingStatusBlock;

	return FSM_finalized; // FSM-execution successfully finalized!!!
}
Esempio n. 20
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Initialize chip */
  CHIP_Init();
  
  setupSWO();

  BSP_LedsInit();

  /* Enable clock for GPIO module */
  CMU_ClockEnable(cmuClock_GPIO, true);

  /* Configure interrupt for Push Button 0 */
  GPIO_PinModeSet(PB0_PORT, PB0_PIN, gpioModeInput, 1);
#if defined(_EFM32_GIANT_FAMILY)
  NVIC_EnableIRQ(GPIO_ODD_IRQn);
#else
  NVIC_EnableIRQ(GPIO_EVEN_IRQn);
#endif
  GPIO_IntConfig(PB0_PORT, PB0_PIN, false, true, true);

  /* By turning on retention in EM4, the state of the GPIO pins
   * can be retained in all energy modes */
  GPIO->CTRL = GPIO_CTRL_EM4RET;

  /* Uncomment to drive LED in all energy modes */
  /* BSP_LedSet(0);*/

  while (1)
  {
    switch (STATE)
    {
    case EM0:
      break;
    case EM1:
      EMU_EnterEM1();
      break;
    case EM2:
      EMU_EnterEM2(true);
      break;
    case EM3:
      EMU_EnterEM3(true);
    case EM4:
      EMU_EnterEM4();
      break;
    }
  }
}
Esempio n. 21
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Chip errata */
  CHIP_Init();

  gpioSetup();
  SegmentLCD_Init(false); //init the segment lcd, bool used to check if power supply i low
  rtcSetup();
  leTimerSetup();
  leTimerTurnOff();

  /* Infinite loop */
  while (1) {
	  EMU_EnterEM2(true);
  }
}
Esempio n. 22
0
int main(void)
{
  /* Chip errata */
  CHIP_Init();
  
  /* Enable HFXO */
  CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);
    
  /* Enable deboug output over UART */
  RETARGET_SerialInit();                     
  RETARGET_SerialCrLf(1); 
  
  /* Enable the segment LCD */
  SegmentLCD_Init(false);
  SegmentLCD_Write("USB");
  
  printf("\nStarting USB Device...\n");
  
  /* Set up GPIO interrupts */
  gpioInit();
  
  /* Start USB stack. Callback routines in callbacks.c will be called
   * when connected to a host.  */
  USBD_Init(&initstruct);;

  /*
   * When using a debugger it is pratical to uncomment the following three
   * lines to force host to re-enumerate the device.
   */
  /* USBD_Disconnect(); */
  /* USBTIMER_DelayMs( 1000 ); */
  /* USBD_Connect(); */
    
  while(1)
  {
    if ( USBD_SafeToEnterEM2() )
    {
      /* Enter EM2 when in suspend or disconnected */
      EMU_EnterEM2(true);
    } 
    else
    {
      /* When USB is active we can sleep in EM1. */
      EMU_EnterEM1();
    }
  } 
}
int main(void)
{
	initializeMCU(true, false);
	
	alm = AlarmManager::getInstance();
	
	printf("initializing filesystem... \n");
	FATFS_initializeFilesystem();
	
	uint8_t testCount = 10;
		
	while(testCount--)
	{
		printf("Speed test - 8 KB: \n");
		FATFS_speedTest(8);
		alm->lowPowerDelay(900, sleepModeEM2);
	}
	
	testCount = 10;
	
	while(testCount--)
	{
		printf("Speed test - 256 KB: \n");
		FATFS_speedTest(256);
		alm->lowPowerDelay(900, sleepModeEM2);
	}
	
	testCount = 2;
	
	while(testCount--)
	{
		printf("Speed test - 512 KB: \n");
		FATFS_speedTest(512);
		alm->lowPowerDelay(900, sleepModeEM2);
	}
	
	
	printf("deinitializing filesystem... \n");
	FATFS_deinitializeFilesystem();
	printf("All speed tests finished! \n");
	
	while (1)
	{
		EMU_EnterEM2(true);	
	}

}
Esempio n. 24
0
/**
 * Sleep mode.
 * Enter the lowest possible sleep mode that is not blocked by ongoing activity.
 */
void sleep(void)
{
    if (sleep_block_counter[0] > 0) {
        /* Blocked everything below EM0, so just return */
        return;
    } else if (sleep_block_counter[1] > 0) {
        /* Blocked everything below EM1, enter EM1 */
        EMU_EnterEM1();
    } else if (sleep_block_counter[2] > 0) {
        /* Blocked everything below EM2, enter EM2 */
        EMU_EnterEM2(true);
    } else {
        /* Blocked everything below EM3, enter EM3 */
        EMU_EnterEM3(true);
    } /* Never enter EM4, as mbed has no way of configuring EM4 wakeup */
    return;
}
Esempio n. 25
0
/***************************************************************************//**
 * @brief
 *   Call the callbacks and enter the requested energy mode.
 *
 * @details
 *   This function is not part of the API, therefore it shall not be called by
 *   the user directly as it doesn not have any checks if the system is ready
 *   for sleep!
 *
 * @note
 *   The EM4 wakeup callback is not being called from this function because
 *   waking up from EM4 causes a reset.
 *   If SLEEP_EM4_WAKEUP_CALLBACK_ENABLED is set to true, SLEEP_Init() function
 *   checks for the cause of the reset and calls the wakeup callback if the
 *   reset was a wakeup from EM4.
 ******************************************************************************/
static void SLEEP_EnterEMx(SLEEP_EnergyMode_t eMode)
{
  EFM_ASSERT((eMode > sleepEM0) && (eMode <= sleepEM4));

  /* Call sleepCallback() before going to sleep. */
  if (NULL != sleepCallback)
  {
    /* Call the callback before going to sleep. */
    sleepCallback(eMode);
  }

  /* Enter the requested energy mode. */
  switch (eMode)
  {
  case sleepEM1:
  {
    EMU_EnterEM1();
  } break;

  case sleepEM2:
  {
    EMU_EnterEM2(true);
  } break;

  case sleepEM3:
  {
    EMU_EnterEM3(true);
  } break;

  case sleepEM4:
  {
    EMU_EnterEM4();
  } break;

  default:
  {
    /* Don't do anything, stay in EM0. */
  } break;
  }

  /* Call the callback after waking up from sleep. */
  if (NULL != wakeUpCallback)
  {
    wakeUpCallback(eMode);
  }
}
Esempio n. 26
0
/******************************************************************************
 * @brief  Main function
 * 
 *****************************************************************************/
int main( void ) 
{
  /* Initialize chip - handle erratas */
  CHIP_Init();

  /* Initialize the temperature compensated calendar */
  Clock_Init_TypeDef initialCalendar  = CLOCK_INIT_DEFAULT;
  initialCalendar.rtcCountsPerSec     = RTC_COUNTS_PER_SEC;
  initialCalendar.tempCompInterval    = TC_INTERVAL;
  clockInit(&initialCalendar);  

  /* Initialize user interface */
  uiInit();

  /* Setup RTC */
  rtcSetup();


  /* ---------- Eternal while loop ---------- */
  while (1)
  {
    /* Update display */
    if ( doDisplayUpdate )
    {
      /* Clear doDisplayUpdate flag */
      doDisplayUpdate = false;

      /* Get current time and write to display */
      time_t currentTime;
      time( &currentTime );
      uiDisplay( &currentTime );  
    }
    
    /* Perform temperature compensation */
    if ( doTemperatureCompensation )
    {
      /* Clear doTemperatureCompensation flag */
      doTemperatureCompensation = false;
      
      clockDoTemperatureCompensation();
    }

    /* Sleep while waiting for interrupt */
    EMU_EnterEM2(false);
  }
}
Esempio n. 27
0
/**************************************************************************//**
 * @brief Energy Mode 2 demonstration, no active perpherals
 *****************************************************************************/
void Demo_EM2(void)
{
  /* Disable DK interrupts */
  BSP_InterruptDisable(0xffff);

  /* Enable LFRCO */
  CMU->OSCENCMD = CMU_OSCENCMD_LFRCOEN;

  /* Disable all peripheral clocks */
  CMU->HFPERCLKEN0  = 0x00000000;
  CMU->HFCORECLKEN0 = 0x00000000;
  CMU->LFACLKEN0    = 0x00000000;
  CMU->LFBCLKEN0    = 0x00000000;

  /* Enter Energy Mode 2 - this will never wake up */
  EMU_EnterEM2(false);
  while(1) BSP_LedsSet(0xffff);
}
/***************************************************************************//**
* @brief
*   Delay ms function
*
* @param[in] ms
* 		32bit Time in ms for delay
*
*******************************************************************************/
void delay(uint32_t ms)
{
	uint32_t ticks;

	ticks = MSEC_TO_TICKS(ms);

	delay_done = false;

	if (ECODE_EMDRV_RTCDRV_OK != RTCDRV_StartTimer(delay_timer,
												   rtcdrvTimerTypeOneshot,
												   ticks,
												   delay_callback,
												   0))
		fatal("can't initialize delay timer");

	while (! delay_done)
		EMU_EnterEM2(true);
}
Esempio n. 29
0
/**************************************************************************//**
 * @brief main - the entrypoint after reset.
 *****************************************************************************/
int main( void )
{
#if !defined(BUSPOWERED)
  BSP_Init(BSP_INIT_DEFAULT);   /* Initialize DK board register access */

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();
#endif

  CMU_ClockSelectSet( cmuClock_HF, cmuSelect_HFXO );
  CMU_OscillatorEnable(cmuOsc_LFXO, true, false);

#if !defined(BUSPOWERED)
  RETARGET_SerialInit();        /* Initialize DK UART port */
  RETARGET_SerialCrLf( 1 );     /* Map LF to CRLF          */
  printf( "\nEFM32 Mass Storage Device example\n" );
#endif

  if ( !MSDDMEDIA_Init() )
  {
#if !defined(BUSPOWERED)
    printf( "\nMedia error !\n" );
#endif
    EFM_ASSERT( false );
    for( ;; ){}
  }

  MSDD_Init(gpioPortE, 1);

  for (;;)
  {
    if ( MSDD_Handler() )
    {
      /* There is no pending activity in the MSDD handler.  */
      /* Enter sleep mode to conserve energy.               */

      if ( USBD_SafeToEnterEM2() )
        EMU_EnterEM2(true);
      else
        EMU_EnterEM1();
    }
  }
}
Esempio n. 30
-1
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Initialize chip */
  CHIP_Init();

  /* Initialize the LCD */
  SegmentLCD_Init(true);

  /* Enable the DMA and TIMER0 clocks */
  CMU_ClockEnable(cmuClock_DMA, true);
  CMU_ClockEnable(cmuClock_TIMER0, true);

  /* Enable overflow interrupt */
  TIMER_IntEnable(TIMER0, TIMER_IF_OF);

  /* Enable TIMER0 interrupt vector in NVIC */
  NVIC_EnableIRQ(TIMER0_IRQn);

  /* Initialize TIMER0 */
  TIMER_Init_TypeDef timerInit =
  {
    .enable     = true,
    .debugRun   = true,
    .prescale   = timerPrescale64,
    .clkSel     = timerClkSelHFPerClk,
    .fallAction = timerInputActionNone,
    .riseAction = timerInputActionNone,
    .mode       = timerModeUp,
    .dmaClrAct  = false,
    .quadModeX4 = false,
    .oneShot    = false,
    .sync       = false,
  };
  TIMER_Init(TIMER0, &timerInit);

  /* Initialize DMA */
  DMA_Init_TypeDef dmaInit;
  dmaInit.hprot        = 0;
  dmaInit.controlBlock = dmaControlBlock;
  DMA_Init(&dmaInit);

  /* Configure the DMA and perform the transfer */
  performFlashTransfer();

  while (1)
  {
    /* The transfer has finished. We wish to display the result on the LCD
     * but use as little power as possible; go to EM2 (the LCD requires EM2). */
    EMU_EnterEM2(true);
  }
}