/**************************************************************************//** * @brief Cap sense values demo *****************************************************************************/ void capSenseBars(void) { int barNum; int sliderPos; const char bars[3] = {'{', '!', '1' }; char msg[8]; sliderPos = CAPLESENSE_getSliderPosition(); SegmentLCD_Number(sliderPos); if (sliderPos == -1) { SegmentLCD_Write("SLIDER"); } else { /* Clear the msg string */ snprintf(msg, 7, " "); /* There are 21 possible "bars" on the display, while there are 48 slider * positions. This maps these 48 into 21 slider positions. */ barNum = (sliderPos * 21) / 48; msg[barNum / 3] = bars[barNum %3]; SegmentLCD_Write(msg); } }
/**************************************************************************//** * @brief Hard fault exception handler. *****************************************************************************/ void HardFault_Handler( void ) /* We should never end up here ! */ { for(;;) { SegmentLCD_Write( " HARD "); Delay( 800 ); SegmentLCD_Write( " FAULT "); Delay( 800 ); } }
/**************************************************************************//** * @brief Button Handler * Shared by GPIO Even and GPIO Odd interrupt handlers *****************************************************************************/ void button_handler() { uint32_t interrupt_source = GPIO_IntGet(); /* Both buttons were pushed - toggle the timer */ if (pb1_is_pushed && pb0_is_pushed) { toggleTimer = true; } if (toggleTimer) { /* Wait for both buttons to be released */ if (!pb1_is_pushed && !pb0_is_pushed) { if (enableTimer) { SegmentLCD_Write("STOP"); time = old_time; SegmentLCD_Number(time); /* Disable RTC */ RTC_Enable(false); } else { SegmentLCD_Write("START"); old_time = time; /* Enable RTC */ RTC_Enable(true); } enableTimer = !enableTimer; toggleTimer = false; return; } } else { /* If only Push Button 0 was pressed - decrease the time */ if (!pb0_is_pushed && interrupt_source & 1 << PB0_PIN) { if (time > 0) time--; SegmentLCD_Number(time); } /* If only Push Button 1 was pressed - increase the time */ else if (!pb1_is_pushed && interrupt_source & 1 << PB1_PIN) { if (time < 9999) time++; SegmentLCD_Number(time); } } }
/**************************************************************************//** * @brief LCD Blink Test *****************************************************************************/ void BlinkTest(void) { SegmentLCD_EnergyMode(0, 1); SegmentLCD_EnergyMode(1, 1); SegmentLCD_EnergyMode(2, 1); SegmentLCD_EnergyMode(3, 1); SegmentLCD_EnergyMode(4, 1); /* 2 minutes to midnight */ SegmentLCD_Number(2358); SegmentLCD_Symbol(LCD_SYMBOL_COL10, 1); SegmentLCD_Symbol(LCD_SYMBOL_GECKO, 1); SegmentLCD_Symbol(LCD_SYMBOL_EFM32, 1); SegmentLCD_Write(" EFM32 "); LCD->BACTRL |= LCD_BACTRL_BLINKEN; while (LCD->SYNCBUSY) ; EM2Sleep(2000); SegmentLCD_EnergyMode(4, 0); EM2Sleep(62); SegmentLCD_EnergyMode(3, 0); EM2Sleep(62); SegmentLCD_EnergyMode(2, 0); EM2Sleep(62); SegmentLCD_EnergyMode(1, 0); EM2Sleep(62); SegmentLCD_EnergyMode(0, 0); LCD->BACTRL &= ~LCD_BACTRL_BLINKEN; while (LCD->SYNCBUSY) ; }
/**************************************************************************//** * @brief Cap sense values demo *****************************************************************************/ void capSenseValues(void) { char msg[8]; uint8_t channel; switch (subMode) { case(0): snprintf(msg, 7, "Pad 0"); channel = CAPLESENSE_getSegmentChannel(0); break; case(1): snprintf(msg, 7, "Pad 1"); channel = CAPLESENSE_getSegmentChannel(1); break; case(2): snprintf(msg, 7, "Pad 2"); channel = CAPLESENSE_getSegmentChannel(2); break; case(3): snprintf(msg, 7, "Pad 3"); channel = CAPLESENSE_getSegmentChannel(3); break; default: snprintf(msg, 7, "Pad 0"); channel = CAPLESENSE_getSegmentChannel(0); break; } SegmentLCD_Write(msg); SegmentLCD_Number(CAPLESENSE_getNormalizedVal(channel)); }
/**************************************************************************//** * @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); } }
/**************************************************************************//** * @brief LCD Blink Test *****************************************************************************/ void BlinkTest(void) { SegmentLCD_EnergyMode(0, 1); SegmentLCD_EnergyMode(1, 1); SegmentLCD_EnergyMode(2, 1); SegmentLCD_EnergyMode(3, 1); SegmentLCD_EnergyMode(4, 1); /* 2 minutes to midnight */ SegmentLCD_Number(2358); SegmentLCD_Symbol(LCD_SYMBOL_COL10, 1); SegmentLCD_Symbol(LCD_SYMBOL_GECKO, 1); SegmentLCD_Symbol(LCD_SYMBOL_EFM32, 1); SegmentLCD_Write(" EFM32 "); LCD_BlinkEnable(true); LCD_SyncBusyDelay(0xFFFFFFFF) ; EM2Sleep(2000); SegmentLCD_EnergyMode(4, 0); EM2Sleep(62); SegmentLCD_EnergyMode(3, 0); EM2Sleep(62); SegmentLCD_EnergyMode(2, 0); EM2Sleep(62); SegmentLCD_EnergyMode(1, 0); EM2Sleep(62); SegmentLCD_EnergyMode(0, 0); LCD_BlinkEnable(false); LCD_SyncBusyDelay(0xFFFFFFFF); }
/**************************************************************************//** * @brief LESENSE_IRQHandler * Interrupt Service Routine for LESENSE Interrupt Line *****************************************************************************/ void LESENSE_IRQHandler(void) { /* Read interrupts flags */ uint32_t intFlags = LESENSE_IntGet(); /* Clear interrupts */ LESENSE_IntClear(LESENSE_IFC_DEC | LESENSE_IFC_DECERR); /* Enable clock for LCD. */ CMU_ClockEnable(cmuClock_LCD, true); /* Wait until SYNCBUSY_CTRL flag is cleared. */ LCD_SyncBusyDelay(LCD_SYNCBUSY_CTRL); /* Enable LCD. */ LCD_Enable(true); /* If there is a decoder error stop trap execution in this loop */ if (intFlags & LESENSE_IF_DECERR) { /* DECODER ERROR */ SegmentLCD_Write(LCSENSE_ERROR_STRING); while (1) ; } /* Write PCNT counter number the LCD */ SegmentLCD_Number(PCNT_CounterGet(PCNT0)); /* Disable RTC first to reset counter */ RTC_Enable(false); /* Set compare value */ RTC_CompareSet(0, RTC_COMP_VALUE); /* Enable RTC */ RTC_Enable(true); }
/**************************************************************************//** * @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); } }
/**************************************************************************//** * @brief Main function *****************************************************************************/ int main(void) { /* Chip revision alignment and errata fixes */ CHIP_Init(); /* Set system frequency to 1 MHz */ CMU_HFRCOBandSet(cmuHFRCOBand_1MHz); /* Initialize LCD */ SegmentLCD_Init(false); /* Initialize TIMER0 */ initTimer(); /* Enable Sleep-om-Exit */ SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk; /* Initialize interrupt count */ interruptCount = 0; /* Enter EM1 until all TIMER0 interrupts are done * Notice that we only enter sleep once, as the MCU will fall asleep * immediately when the ISR is done without returning to main as long as * SLEEPONEXIT is set */ EMU_EnterEM1(); /* Signal that program is done */ SegmentLCD_Write("DONE"); while(1); }
/**************************************************************************//** * @brief Main function *****************************************************************************/ int main(void) { bool vboost = false; /* Chip revision alignment and errata fixes */ CHIP_Init(); /* Initialize DVK 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 board specific registers */ VDDCHECK_Init(); /* Check if voltage is below 3V, if so use voltage boost */ if (VDDCHECK_LowVoltage(2.9)) vboost = true; /* Disable Voltage Comparator */ VDDCHECK_Disable(); /* Run Energy Mode with LCD demo, see lcdtest.c */ SegmentLCD_Init(vboost); /* Display a message if vboost is enabled */ if ( vboost ) { SegmentLCD_Write("vboost"); RTCDRV_Delay(5000, false); } Test(); return 0; }
/* Notes :(1) The first line of code is used to prevent a compiler warning because 'p_arg' is not * used. The compiler should not generate any code for this statement. * * ********************************************************************************************************* */ void APP_TaskThree(void *p_arg) { OS_ERR err = OS_ERR_NONE; char indxChar; char MsgSize; char *pMsgContent; static char taskStringBuffer[APPDEF_LCD_TXT_SIZE+1U] = {'u','C','/','O','S','-','3','\0'}; static int ringPos = 0; (void)p_arg; /* Note(1) */ while (1) { /* Task body, always written as an infinite loop */ /* Turn previous ring segment off */ SegmentLCD_ARing(ringPos, 0); /* Increase ring position variable */ if (8u == ++ringPos) { ringPos = 0; /* 3bit overflow */ } /* Turn updated ring segment on */ SegmentLCD_ARing(ringPos, 1); /* Non-blocking reception of a message */ pMsgContent = OSQPend((OS_Q *) pSerialQueObj, (OS_TICK ) 0U, (OS_OPT ) OS_OPT_PEND_NON_BLOCKING, (OS_MSG_SIZE *)&MsgSize, (CPU_TS *) 0U, (OS_ERR *)&err); /* If a valid message was received... */ if ((void *)0 != pMsgContent) { /* ...shift left the whole string by one... */ for (indxChar = 0; indxChar < APPDEF_LCD_TXT_SIZE; indxChar++) { taskStringBuffer[indxChar] = taskStringBuffer[indxChar+1]; } /* ...and concatenate the new character to the end. */ taskStringBuffer[APPDEF_LCD_TXT_SIZE-1] = *pMsgContent; /* Write the string on serial port (USART0) */ printf("\nBuffer: %s", taskStringBuffer); /* Write the string on LCD */ SegmentLCD_Write(taskStringBuffer); } /* Delay task for 1 system tick (uC/OS-II suspends this task and executes * the next most important task) */ OSTimeDly(1U, OS_OPT_TIME_DLY, &err); } }
/**************************************************************************//** * @brief Update LCD with temperature * @param[in] temp Temperature to display. *****************************************************************************/ void temperatureUpdateLCD(TEMPSENS_Temp_TypeDef *temp) { char text[8]; TEMPSENS_Temp_TypeDef dtemp; /* Work with local copy in case conversion to Fahrenheit is required */ dtemp = *temp; memset(text, ' ', sizeof(text) - 1); text[sizeof(text) - 1] = 0; if (SHOW_FAHRENHEIT) { text[5] = 'F'; TEMPSENS_Celsius2Fahrenheit(&dtemp); } else { text[5] = 'C'; } /* Round temperature to nearest 0.5 */ if (dtemp.f >= 0) { dtemp.i += (dtemp.f + 2500) / 10000; dtemp.f = (((dtemp.f + 2500) % 10000) / 5000) * 5000; } else { dtemp.i += (dtemp.f - 2500) / 10000; dtemp.f = (((dtemp.f - 2500) % 10000) / 5000) * 5000; } /* 100s */ if (abs(dtemp.i) >= 100) text[0] = '0' + (abs(dtemp.i) / 100); /* 10s */ if (abs(dtemp.i) >= 10) text[1] = '0' + ((abs(dtemp.i) % 100) / 10); /* 1s */ text[2] = '0' + (abs(dtemp.i) % 10); /* 0.1s */ text[3] = '0' + (abs(dtemp.f) / 1000); SegmentLCD_Write(text); SegmentLCD_Symbol(LCD_SYMBOL_DP4, 1); if ((dtemp.i < 0) || (dtemp.f < 0)) { SegmentLCD_Symbol(LCD_SYMBOL_MINUS, 1); } else { SegmentLCD_Symbol(LCD_SYMBOL_MINUS, 0); } }
void lcd_write_string(const char* format, ...) { va_list args; va_start(args, format); uint8_t len = vsnprintf(NG(buffer), BUFFER_SIZE, format, args); va_end(args); SegmentLCD_Write(NG(buffer)); }
/********************************************//** * \brief run alarm, show alarm screen, * turn on screen_notification flag, which prevents screen updates by apps * and should be turned off by press buttons in GPIO irq handler * \param * \param * \return * ***********************************************/ void runAlarm(uint8_t alarm) { switch (alarm) { case 1: alarm = 0; alarm1.active = false; SegmentLCD_Write("ALARM 1"); screen_notification = true; break; case 2: alarm = 0; alarm2.active = false; SegmentLCD_Write("ALARM 2"); screen_notification = true; break; } }
/***************************************************************************//** * @brief * Update LCD Display * ******************************************************************************/ void lcd_scroll_update(void) { if (! lcd_scroll_length) return; SegmentLCD_Write((char *) (lcd_scroll_message + lcd_scroll_position)); lcd_scroll_position++; if (lcd_scroll_position >= lcd_scroll_length) lcd_scroll_position = 0; }
/**************************************************************************//** * @brief LcdPrint task which is showing numbers on the display * @param *pParameters pointer to parameters passed to the function *****************************************************************************/ static void LcdPrint(void *pParameters) { pParameters = pParameters; /* to quiet warnings */ for (;;) { /* Wait for semaphore, then display next number */ if (pdTRUE == xSemaphoreTake(sem, portMAX_DELAY)) { SegmentLCD_Write(text); } } }
/**************************************************************************//** * @brief RTC Handler * Interrupt Service Routine for Real Time Counter *****************************************************************************/ void flashTransferComplete(unsigned int channel, bool primary, void *user) { /* Clearing flag to indicate that transfer is complete */ flashTransferActive = false; /* Indicate that the transfer is complete */ SegmentLCD_Symbol(LCD_SYMBOL_ANT, true); /* Output the finished message */ SegmentLCD_Write(ramBuffer); }
/* Notes :(1) The first line of code is used to prevent a compiler warning because 'p_arg' is not * used. The compiler should not generate any code for this statement. * * ********************************************************************************************************* */ void APP_TaskThree(void *p_arg) { static char taskStringBuffer[APPDEF_LCD_TXT_SIZE+1U] = {'u','C','/','O','S','-','2','\0'}; static int ringPos = 0; char indxChar; char *pMsgContent; (void)p_arg; /* Note(1) */ while (1) { /* Task body, always written as an infinite loop */ /* Turn previous ring segment off */ SegmentLCD_ARing(ringPos, 0); /* Increase ring position variable */ if (8u == ++ringPos) { ringPos = 0; /* 3bit overflow */ } /* Turn updated ring segment on */ SegmentLCD_ARing(ringPos, 1); /* Non-blocking reception of a message */ pMsgContent = OSMboxAccept(pSerialMsgObj); /* If a valid message was received... */ if ((void *)0 != pMsgContent) { /* ...shift left the whole string by one... */ for (indxChar = 0; indxChar < APPDEF_LCD_TXT_SIZE; indxChar++) { taskStringBuffer[indxChar] = taskStringBuffer[indxChar+1]; } /* ...and concatenate the new character to the end. */ taskStringBuffer[APPDEF_LCD_TXT_SIZE-1] = *pMsgContent; /* Write the string on serial port */ printf("\nBuffer: %s", taskStringBuffer); /* Write the string on LCD */ SegmentLCD_Write(taskStringBuffer); } /* Delay task for 1 system tick (uC/OS-II suspends this task and executes * the next most important task) */ OSTimeDly(100); } }
/**************************************************************************//** * @brief GPIO Interrupt Handler *****************************************************************************/ void GPIO_IRQHandler_1(void) { /* Clear flag for Push Button 1 (pin D8) interrupt */ GPIO_IntClear(1 << PB0_PIN); /* Toggle enableCount to start/pause the stopwatch */ if (enableCount) { enableCount = false; SegmentLCD_Write("Pause"); } else { /* The interrupt handler is called to compute the proper time * for the next interrupt, since enableCount is 0, the time will not * be increased. */ RTC_IRQHandler(); SegmentLCD_Write("Start"); enableCount = true; } }
void setup_lcd() { // Enable LCD without voltage boost SegmentLCD_Init(false); // Turn on the colon in the time display SegmentLCD_Symbol(LCD_SYMBOL_COL10, 1); display_time(0,0); SegmentLCD_Write("OFF"); blink(TIME); }
/* Notes :(1) The first line of code is used to prevent a compiler warning because 'p_arg' is not * used. The compiler should not generate any code for this statement. * * ********************************************************************************************************* */ void APP_TaskThree(void *p_arg) { char text[APPDEF_LCD_TXT_SIZE+1U] = {'u','C','/','O','S','-','2','\0'}; int i; int msgContent; int ringPos = 0; INT8U err; (void)p_arg; /* Note(1) */ while (1) { /* Task body, always written as an infinite loop */ /* Turn previous ring segment off */ SegmentLCD_ARing(ringPos, 0); /* Increase ring position variable */ if (8u == ++ringPos) { ringPos = 0; /* 3bit overflow */ } /* Turn updated ring segment on */ SegmentLCD_ARing(ringPos, 1); msgContent = (int)OSQPend(pSerialQueObj, 1, &err); if ((void*)0 != (void*)msgContent) { /* Shift left the whole string by one... */ for (i = 0; i < APPDEF_LCD_TXT_SIZE; i++) { text[i] = text[i+1]; } /* ...and concatenate the new character to the end */ text[APPDEF_LCD_TXT_SIZE-1] = (char)msgContent; /* Write the string on serial port */ printf("\nBuffer: %s", text); /* Write the string on LCD */ SegmentLCD_Write(text); } /* Delay with 100 ms */ OSTimeDlyHMSM(0, 0, 0, 100); } }
/**************************************************************************//** * @brief LCD scrolls a text over the display, sort of "polled printf". *****************************************************************************/ static void ScrollText(char *scrolltext) { int i, len; char buffer[8]; buffer[7] = 0x00; len = strlen(scrolltext); if (len < 7) return; for (i = 0; i < (len - 7); i++) { memcpy(buffer, scrolltext + i, 7); SegmentLCD_Write(buffer); Delay( 200 ); } }
/**************************************************************************//** * @brief LCD scrolls a text over the display, sort of "polled printf" *****************************************************************************/ void ScrollText(char *scrolltext) { int i, len; char buffer[8]; buffer[7] = 0x00; len = strlen(scrolltext); if (len < 7) return; for (i = 0; (!recentlySaved) && (i < (len - 7)); i++) { memcpy(buffer, scrolltext + i, 7); SegmentLCD_Write(buffer); EM2Sleep(125); } }
/**************************************************************************//** * @brief main - the entrypoint after reset. *****************************************************************************/ int main( void ) { CHIP_Init(); /* If first word of user data page is non-zero, enable eA Profiler trace */ BSP_TraceProfilerSetup(); CMU_ClockSelectSet( cmuClock_HF, cmuSelect_HFXO ); CMU_OscillatorEnable(cmuOsc_LFXO, true, false); /* Initialize LCD driver */ SegmentLCD_Init(false); SegmentLCD_Write("usbcomp"); SegmentLCD_Symbol(LCD_SYMBOL_GECKO, true); /* Initialize LED driver */ BSP_LedsInit(); /* Initialize SLEEP driver, no calbacks are used */ SLEEP_Init(NULL, NULL); #if (configSLEEP_MODE < 3) /* do not let to sleep deeper than define */ SLEEP_SleepBlockBegin((SLEEP_EnergyMode_t)(configSLEEP_MODE + 1)); #endif /* Parameters value for taks*/ static LedTaskParams_t parametersToTask1 = { 1000 / portTICK_RATE_MS, 0 }; static LedTaskParams_t parametersToTask2 = { 500 / portTICK_RATE_MS, 1 }; static AdcTaskParams_t parametersToAdc = { .adcChannelsMask = 0x32, .uPrsChannel = 5, .uSampleRate = 1, .uTimer = 3 }; /*Create two task for blinking leds*/ xTaskCreate( UsbCDCTask, "UsbCDC", STACK_SIZE_FOR_TASK, NULL, TASK_PRIORITY, NULL); // xTaskCreate( LedTask, (const char *) "LedBlink1", STACK_SIZE_FOR_TASK, ¶metersToTask1, TASK_PRIORITY, NULL); // xTaskCreate( LedTask, (const char *) "LedBlink2", STACK_SIZE_FOR_TASK, ¶metersToTask2, TASK_PRIORITY, NULL); xTaskCreate( vAdcTask, "ADC", STACK_SIZE_FOR_TASK, ¶metersToAdc, TASK_PRIORITY + 1, NULL); xTaskCreate( vDacTask, "DAC", STACK_SIZE_FOR_TASK, NULL, TASK_PRIORITY, NULL); xTaskCreate( vEchoTask, "echo", STACK_SIZE_FOR_TASK, NULL, TASK_PRIORITY, NULL); NVIC_SetPriority(USB_IRQn, 7); NVIC_SetPriority(ADC0_IRQn, 7); vTaskStartScheduler(); }
/***************************************************************************//** * @brief * Start LCD Scroll of Character String * * @param[in] *s * Pointer to Character String * ******************************************************************************/ void lcd_scroll_start(const char *s) { lcd_scroll_length = strlen(s); if (lcd_scroll_length < 7) { SegmentLCD_Write((char *) s); lcd_scroll_length = 0; } else { lcd_scroll_message = s; lcd_scroll_position = 0; lcd_scroll_update(); } }
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(); } } }
/**************************************************************************//** * @brief * Thread 1: Print LCD thread *****************************************************************************/ void PrintLcdThread(void const *argument) { lcdText_t *rptr; osEvent evt; (void)argument; /* Unused parameter. */ while (1) { /* Wait for message */ evt = osMessageGet(msgBox, osWaitForever); if (evt.status == osEventMessage) { rptr = evt.value.p; SegmentLCD_Write(*rptr); /* Free memory allocated for message */ osPoolFree(mpool,rptr); } } }
/**************************************************************************//** * @brief Real Time Counter Interrupt Handler *****************************************************************************/ void RTC_IRQHandler(void) { /* Clear interrupt source */ RTC_IntClear(RTC_IFC_COMP0); time--; SegmentLCD_Number(time); if (time == 0) { SegmentLCD_Write("DONE"); time = old_time; /* Disable RTC */ RTC_Enable(false); enableTimer = false; } SegmentLCD_Number(time); }
/**************************************************************************//** * @brief GPIO Interrupt Handler *****************************************************************************/ void GPIO_IRQHandler_2(void) { /* Get the interrupt source, either Push Button 2 (pin B11) or pin D3 */ uint32_t interrupt_source = GPIO_IntGet(); /* Push Button 2 (pin B11) */ if (interrupt_source & (1 << PB1_PIN)) { GPIO_IntClear(1 << PB1_PIN); SegmentLCD_Write("Clear"); time = 0; enableCount = false; SegmentLCD_Number(time); } /* Pin D3 - channel 3 => 2^3 */ if (interrupt_source & (1 << 3)) { /* Operations can be made atomic, i.e. it cannot be interrupted by * interrupts with higher priorities, by disabling iterrupts. Uncomment * __disable_irq(); and __enable_irq(); to see how the update of the time * is delayed by the dummy loop below.*/ /* __disable_irq(); */ /* Toggle enableGecko */ if (enableGecko) enableGecko = false; else enableGecko = true; SegmentLCD_Symbol(LCD_SYMBOL_GECKO, enableGecko); /* This dummy loop is intended to illustrate the different levels of * priority. The timer will continue to update the LCD display, but * interrupts produced by Push Button 1 and 2 will not be served until * after this function has finished. */ for (uint32_t tmp = 0; tmp < 2000000; tmp++) ; GPIO_IntClear(1 << 3); /* Enable interrupts again */ /* __enable_irq(); */ } }