/* * Name : RTC_Delay * * Goes into a loop for specified number of ticks where one tick equals to 1/128th of a second . * * E.g. Usage : * * /RTC_Delay (256); / - Goes into a delay loop for 2 seconds */ void RTC_Delay(unsigned int delayUnits) { void (*fptr)(); TIMSK|=_BV(TOIE0); fptr=rtcInterrupt; rtcInterrupt=NULL; rtcCount=delayUnits; RTC_Start(); while(rtcCount>0); RTC_Pause(); }
/** * initial transition **/ static QState MenuAO_initial(MenuAO *me, QEvent const *e) { // TODO subscribe to published events QActive_subscribe(MenuAOBase, BUTTON_SHORTPRESS_SIG); QActive_subscribe(MenuAOBase, BUTTON_LONGPRESS_SIG); QActive_subscribe(MenuAOBase, AD_VALUE_SIG); QActive_subscribe(MenuAOBase, ALARM_SIG); // Initialize RTC RTC_Init(); RTC_Start(); return Q_TRAN(&MenuAO_Idle); }
void Initial() { CyGlobalIntEnable; //Check_Boot(); Timer_RTOS_Start(); PWM_Start(); I2C_Start(); UART_Start(); RTC_Start(); RTC_SetPeriod(1,1000); RTOS_Start(); SetTask(Brightles_PID_Controll); LCD_WS0010Start(); SetTask(WaitPowerStab); SetTimerTask(OPT_Get_Result, 1300); //BLE_Status(); GlobalStruct.OS_Status = 0; SetTimerTask(Display_Controll, 2000); }
/* Initialization function for the APP. Configures the registers based on options selected in UI. */ RTC_STATUS_t RTC_Init(RTC_t *const handler) { XMC_RTC_STATUS_t status; RTC_STATUS_t rtc_initstatus; bool interrupt_configured; XMC_ASSERT("RTC_Init: NULL Handler", handler != NULL); status = XMC_RTC_STATUS_OK; rtc_initstatus = RTC_STATUS_FAILURE; #if (RTC_INTERRUPT_ENABLED == 1) #if (UC_FAMILY == XMC4) rtc_initstatus = (RTC_STATUS_t)GLOBAL_SCU_XMC4_Init(GLOBAL_SCU_HANDLE); #else rtc_initstatus = (RTC_STATUS_t)GLOBAL_SCU_XMC1_Init(GLOBAL_SCU_HANDLE); #endif if (rtc_initstatus == RTC_STATUS_SUCCESS) { #endif if (handler->initialized == false) { /* Initialize the clock source and pre-scalar */ status = XMC_RTC_Init(handler->time_alarm_config); if (status == XMC_RTC_STATUS_OK) { /* Configure periodic, alarm and hibernate periodic interrupts */ interrupt_configured = RTC_lConfigureInterrupts(handler); if (interrupt_configured == true) { status = RTC_lRegister_Callbacks(handler); } if (status == XMC_RTC_STATUS_OK) { /* Check RTC start during init is set or not in UI */ if (handler->config->start == RTC_START_ENABLE) { RTC_Start(); } handler->initialized = true; rtc_initstatus = RTC_STATUS_SUCCESS; } } else { rtc_initstatus = RTC_STATUS_FAILURE; } } else { rtc_initstatus = RTC_STATUS_SUCCESS; } #if (RTC_INTERRUPT_ENABLED == 1) } /* end of if(rtc_initstatus == GLOBAL_SCU_XMC4_STATUS_OK) */ #endif return (rtc_initstatus); }
/** * ClockMenu state handler **/ static QState MenuAO_ClockMenu(MenuAO *me, QEvent const *e) { switch ( e->sig ) { case Q_INIT_SIG: { return Q_HANDLED(); } case Q_ENTRY_SIG: { // get current time RTC_GetTime(&rtcTime); // display clock menu (1st row of LCD) sprintf(output, "1: Clock %02d:%02d", rtcTime.RTC_Hour, rtcTime.RTC_Min); lcd_clear(); set_cursor(0, 0); lcd_print((unsigned char*)output); // send BREWSTRENGTH_SET_SIG to CoffeeMachineAO l_BrewStrengthSetEvt.brewStrength = me->brewStrength; QActive_postFIFO(CoffeeMachineAOBase, (QEvent*)&l_BrewStrengthSetEvt); return Q_HANDLED(); } case BUTTON_SHORTPRESS_SIG: { // short press > proceed to next submenu if (!me->waitingForSetTime) // guard condition: only if not waiting for set time return Q_TRAN(&MenuAO_BrewStrengthMenu); else return Q_HANDLED(); } case BUTTON_LONGPRESS_SIG: { if (me->waitingForSetTime != true) { // long press > send change time request and wait for response me->waitingForSetTime = true; // send ENTER_SET_TIME_SIG to SetTimeAO QActive_postFIFO(SetTimeAOBase, (QEvent*)&l_EnterSetTimeEvt); } return Q_HANDLED(); } case TIME_SET_SIG: { TimeSetEvt* evt = (TimeSetEvt*)e; me->waitingForSetTime = false; // display new time (1st row of LCD) sprintf(output, "1: Clock %02d:%02d", evt->time.RTC_Hour, evt->time.RTC_Min); lcd_clear(); set_cursor(0, 0); lcd_print((unsigned char*)output); // save time at RTC RTC_Stop(); RTC_SetTime(&evt->time); RTC_Start(); return Q_HANDLED(); } case TIME_UPDATE_SIG: { // display updated time TimeUpdateEvt* evt = (TimeUpdateEvt*)e; sprintf(output, "1: Clock %02d:%02d", evt->time.RTC_Hour, evt->time.RTC_Min); set_cursor(0, 0); lcd_print((unsigned char*)output); return Q_HANDLED(); } case Q_EXIT_SIG: { return Q_HANDLED(); } } return Q_SUPER(&MenuAO_Idle); }
/******************************************************************************* * Function Name: BLE_StackEventHandler ******************************************************************************** * * Summary: * BLE stack generic event handler routine for handling connection, discovery, * security etc. events. * * Parameters: * event - event that triggered this callback * eventParam - parameters for the event. * * Return: * None *******************************************************************************/ void BLE_StackEventHandler(uint32 event, void* eventParam) { #if (RESTART_ADV_ON_DISCONNECTION) CYBLE_API_RESULT_T apiResult; #endif /* End of #if (RESTART_ADV_ON_DISCONNECTION) */ CYBLE_GATTC_ERR_RSP_PARAM_T *errorResponse; switch (event) { /********************************************************** * General Events ***********************************************************/ case CYBLE_EVT_STACK_ON: /* This event is received when component is Started */ /* Enter in to discoverable mode so that remote can search it. */ (void) CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST); #if(CONSOLE_LOG_ENABLED) printf("Advertising... \r\n\n"); #endif /* End of #if(CONSOLE_LOG_ENABLED) */ break; case CYBLE_EVT_TIMEOUT: #if (BLE_GATT_CLIENT_ENABLE) if(*(uint8 *)eventParam == CYBLE_GATT_RSP_TO && bleStatus == BLE_DISCOVEER_GATT_SERVICES) { /* The peer device didn't respond to service discovery, enable RTC in free run mode if configured */ bleStatus = BLE_TIME_SERVER_ABSENT; #if (RTC_ENABLE) RTC_Start(); #endif /* End of #if (RTC_ENABLE) */ #if DISCONNECT_BLE_AFTER_TIME_SYNC BLE_RequestDisconnection(); #endif /* End of #if DISCONNECT_BLE_AFTER_TIME_SYNC */ } #endif /* End of #if (BLE_GATT_CLIENT_ENABLE) */ break; /********************************************************** * GAP Events ***********************************************************/ case CYBLE_EVT_GAP_AUTH_COMPLETE: /* we initiated the authentication with the iOS device and the authentication is now complete. Proceed * to characteristic value read after this */ bleStatus = BLE_READ_TIME; break; case CYBLE_EVT_GAP_DEVICE_DISCONNECTED: #if RESTART_ADV_ON_DISCONNECTION BLE_Engine_Reinit(); /* Re-initialize application data structures */ /* Put the device to discoverable mode so that remote can search it. */ apiResult = CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST); if(apiResult != CYBLE_ERROR_OK) { CYASSERT(0); } #endif /* End of #if RESTART_ADV_ON_DISCONNECTION */ break; /********************************************************** * GATT Events ***********************************************************/ case CYBLE_EVT_GATT_CONNECT_IND: bleStatus = BLE_CONNECTED; break; case CYBLE_EVT_GATT_DISCONNECT_IND: bleStatus = BLE_DISCONNECTED; #if(CONSOLE_LOG_ENABLED) printf("Disconnected!\r\n\n"); #endif break; case CYBLE_EVT_GATTC_DISCOVERY_COMPLETE: if(cyBle_ctsc.currTimeCharacteristics[CYBLE_CTS_CURRENT_TIME].valueHandle == 0x0000) { bleStatus = BLE_TIME_SERVER_ABSENT; #if (RTC_ENABLE)/* If the time server is absent, let the RTC run in free run mode */ RTC_Start(); #endif /* End of #if (RTC_ENABLE) */ #if DISCONNECT_BLE_AFTER_TIME_SYNC BLE_RequestDisconnection(); #endif /* End of #if DISCONNECT_BLE_AFTER_TIME_SYNC */ } else { bleStatus = BLE_READ_TIME; } break; case CYBLE_EVT_GATTC_ERROR_RSP: errorResponse = (CYBLE_GATTC_ERR_RSP_PARAM_T*) eventParam; /* characteristic read requires an authenticated link */ if(errorResponse -> errorCode == CYBLE_GATT_ERR_INSUFFICIENT_AUTHENTICATION) { bleStatus = BLE_INITIATE_AUTHENTICATION; } break; default: break; } }