int main(void) { hwInit(); SysTick_Config(SystemCoreClock/10); while(1) { } return 0; }
void METH(allocResource)( t_t1xhv_resource resource, Iresource_manager_api_inform_resource_status *cb) { t_uint16 resource_available = FALSE; /* check if sleep was entered or not, in case sleep was entered reset hwInitDone back to FALSE */ iIntSleep.statusInternalSleep(); /* First of all, initialize hardware */ if ((rmDebugMode == DBG_MODE_NORMAL) && (hwInitDone == FALSE)){ /* Normal mode and first usage of this component : Do the HW Init. */ hwInit(); /* Memorize first HW init has been done. */ hwInitDone = TRUE; } if (resource >= RESOURCE_MAX){ informRessource (STA_PARAM_ERROR, resource, cb); return; } if (is_rm_fifo_empty(resource)){ // no running ressource resource_available = TRUE; } if (rm_fifo_push(resource, cb) != FALSE) { /* Ok, there's a place to store pending resource. */ if (resource_available == TRUE){ /* inform sleep component that a resource is being allocated to prevent going into sleep */ iIntSleep.preventInternalSleep(); /* Launch immediatly the required process */ informRessource (STA_RESOURCE_FREE, resource, cb); } } else { /* No place, return an error. */ informRessource (STA_ERROR_ALLOC_FULL, resource, cb); } } /* end of allocResource() function */
int main( void ) { //disable interrupts cli(); //INITS hwInit(); // uartInit(); pwmInit(); // adcInit(); // WdInit(); // WdDisable(); adcStartConversion(); //enable interrupt Init_TWI(); sei(); //calibration des vitesses // adcCalibSeq(); //attend que la sw Start soit appuyer //pour lancer le reste du programme SLWaitForTheStartSw(); // WD_RESTART_WATCHDOG; while(1) { if(flag5ms) { count5ms++; if(count5ms>=10) { count5ms=0; Ping_sensor(); } } SLCheckSwStatus(); //verifie la switch d'arret cPMainCmdParser(); //Machine à état communication CalculMoteur(); //calculPWM et autre } }
int main(void) { uint8_t cmd; uint8_t dispMode = MODE_MAIN; static int8_t direction = PARAM_UP; hwInit(); showTimeMasked(); ds18x20Process(); sensTimer = TEMP_MEASURE_TIME; while(1) { // Update sensors with SENSOR_POLL_INTERVAL period if (!sensTimer == 0) { sensTimer = SENSOR_POLL_INTERVAL; ds18x20Process(); if (bmp180HaveSensor()) bmp180Convert(); dht22Read(); } // Check alarm checkAlarm(); // Update brightness only when not in brightness setup if (dispMode != MODE_BRIGHTNESS) calcBrightness(); // Get command from buttons cmd = getBtnCmd(); // Beep on button pressed if (cmd != BTN_STATE_0) { if (cmd < BTN_0_LONG) startBeeper(BEEP_SHORT); else startBeeper(BEEP_LONG); } // Stop scrolling on any button pressed if (cmd != BTN_STATE_0) matrixHwScroll(MATRIX_SCROLL_STOP); // Handle command switch (cmd) { case BTN_0: direction = PARAM_UP; switch (dispMode) { case MODE_EDIT_TIME: rtcNextEditParam(); break; case MODE_EDIT_ALARM: alarmNextEditParam(); break; } break; case BTN_1: direction = PARAM_UP; case BTN_2: if (cmd == BTN_2) direction = PARAM_DOWN; switch (dispMode) { case MODE_MAIN: startScroll(cmd - BTN_1); break; case MODE_EDIT_TIME: rtcChangeTime(direction); break; case MODE_EDIT_ALARM: alarmChange(direction); break; case MODE_BRIGHTNESS: changeBrightness(direction); break; case MODE_TEST: displayChangeRotate(direction); break; } break; case BTN_0_LONG: if (dispMode == MODE_MAIN) { dispMode = MODE_EDIT_TIME; rtcNextEditParam(); } else { rtc.etm = RTC_NOEDIT; alarmSave(); alarm.eam = ALARM_NOEDIT; dispMode = MODE_MAIN; showTimeMasked(); } break; case BTN_1_LONG: if (dispMode == MODE_MAIN) { dispMode = MODE_EDIT_ALARM; alarmNextEditParam(); } break; case BTN_2_LONG: if (dispMode == MODE_MAIN) { dispMode = MODE_BRIGHTNESS; showBrightness(direction, MASK_ALL); } break; case BTN_0_LONG | BTN_1_LONG: displaySwitchHourZero(); dispMode = MODE_MAIN; showTimeMasked(); break; case BTN_1_LONG | BTN_2_LONG: displaySwitchBigNum(); dispMode = MODE_MAIN; showTimeMasked(); break; case BTN_0_LONG | BTN_2_LONG: displaySwitchHourSignal(); dispMode = MODE_MAIN; showTimeMasked(); break; case BTN_0_LONG | BTN_1_LONG | BTN_2_LONG: dispMode = MODE_TEST; break; } // Show things switch (dispMode) { case MODE_MAIN: showMainScreen(); break; case MODE_EDIT_TIME: showTimeEdit(direction); break; case MODE_EDIT_ALARM: showAlarmEdit(direction); break; case MODE_BRIGHTNESS: showBrightness(direction, MASK_NONE); break; case MODE_TEST: showTest(); break; } } return 0; }
/* initial setting at driver start up time */ LOCAL ER kpStartUp(void) { W w[L_DEVCONF_VAL]; W dd, n; ER er; RawEvt evt; T_CMBF cmbf; T_CFLG cflg; ID datatsk; void* name; union { FlgInStat stat; UW uw; } u; /* extract ID of the mailbox for event notification to KB/PD driver */ dd = er = tk_opn_dev(devkbpd, TD_READ); if (er >= E_OK) { er = tk_srea_dev(dd, DN_KPINPUT, (VB*)&EvtMbx, sizeof(EvtMbx), &n); tk_cls_dev(dd, 0); } if (er < E_OK) goto EEXIT1; /* KBID is extracted from DEVCONF parameter */ KbdId = (GetDevConf("KBTYPE", w) == 1) ? w[0] : KID_IBM_JP; /* input message buffer creation */ SetOBJNAME(cmbf.exinf, "lkbM"); cmbf.mbfatr = TA_TFIFO; cmbf.bufsz = sizeof(InMsg) * MAX_INMSG; cmbf.maxmsz = sizeof(InMsg); if ((er = tk_cre_mbf(&cmbf)) < E_OK) goto EEXIT1; InpMbf = er; /* creating the event flag for command */ SetOBJNAME(cflg.exinf, "lkbC"); cflg.flgatr = TA_WMUL; cflg.iflgptn = 0; if ((er = tk_cre_flg(&cflg)) < E_OK) goto EEXIT2; CmdFlg = (ID)er; /* create and start data processing task */ SetOBJNAME(name, "lkbD"); er = kpCreTask((W)name, kpDataTask); if (er < E_OK) goto EEXIT3; datatsk = (ID)er; /* create and start command processing task */ SetOBJNAME(name, "lkbC"); er = kpCreTask((W)name, kpCmdTask); if (er < E_OK) goto EEXIT4; CmdTsk = (ID)er; /* registering event flag for commands */ u.uw = 0; evt.f.stat = u.stat; evt.f.stat.cmd = INP_FLG; evt.f.stat.kb = 1; evt.f.stat.kbid = KbdId; evt.f.stat.reg = 1; evt.f.flgid = CmdFlg; if ((er = kpSendMsg(&evt)) < E_OK) goto EEXIT5; /* device initialization processing */ er = hwInit(DC_OPEN); if (er < E_OK) goto EEXIT5; return E_OK; EEXIT5: tk_ter_tsk(CmdTsk); tk_del_tsk(CmdTsk); EEXIT4: tk_ter_tsk(datatsk); tk_del_tsk(datatsk); EEXIT3: tk_del_flg(CmdFlg); EEXIT2: tk_del_mbf(InpMbf); EEXIT1: DP(("kpStartUp: err=%#x\n", er)); return er; }
bool CLASS::increaseActivationLevel( UInt32 newLevel ) { bool success = false; switch (newLevel) { case kActivationLevelKDP: if ((fPCINub == 0) || (fPCINub->open(this) == false)) { ERROR_LOG("%s: open provider failed\n", getName()); break; } // Allocate software runtime resources. if (swInit() == false) { ERROR_LOG("%s: swInit failed\n", getName()); break; } // Issue hardware soft reset. if (hwReset() == false) { ERROR_LOG("%s: hwReset failed\n", getName()); break; } // Configure hardware but keep it disabled. hwInit(); // PHY and link layer programming. if (phySelectMedium(getSelectedMedium(), true) != kIOReturnSuccess) { ERROR_LOG("%s: phySelectMedium error\n", getName()); } // Enable transmit + receive. WriteReg(CR, CR_TXE | CR_RXE); fWatchdogTimer->setTimeoutMS(kWatchdogTimerPeriodMS); success = true; break; case kActivationLevelBSD: fTransmitQueue->setCapacity(kTransmitQueueCapacity); fTransmitQueue->start(); enableHardwareInterrupts(); success = true; break; } return success; }
int main(void) { int8_t encCnt = 0; uint8_t action = ACTION_NOACTION; /* Init hardware */ hwInit(); #if 0 if (extFunc == USE_DS18B20) { ds18x20ConvertTemp(); setSensTimer(TEMP_MEASURE_TIME); } #endif while (1) { #if 0 /* Control temperature */ if (extFunc == USE_DS18B20) { if (getSensTimer() == 0) { ds18x20GetAllTemps(); ds18x20ConvertTemp(); setSensTimer(SENSOR_POLL_INTERVAL); } tempControlProcess(); } #endif /* Emulate poweroff if any of timers expired */ if (getStbyTimer() == 0 || getSilenceTimer() == 0) action = CMD_RC_STBY; /* Check alarm and update time */ if (action == ACTION_NOACTION) action = checkAlarmAndTime(); /* Convert input command to action */ if (action == ACTION_NOACTION) action = getAction(); /* Handle action */ handleAction(action); /* Handle encoder */ encCnt = getEncoder(); /* Get value from encoder */ if (action == CMD_RC_VOL_UP) /* Emulate VOLUME_UP action as encoder action */ encCnt++; if (action == CMD_RC_VOL_DOWN) /* Emulate VOLUME_DOWN action as encoder action */ encCnt--; handleEncoder(encCnt); /* Reset silence timer on any action */ if (encCnt || (action != ACTION_NOACTION && action != ACTION_EXIT_STANDBY)) enableSilenceTimer(); /* Reset handled action */ action = ACTION_NOACTION; /* Check if we need exit to default mode*/ handleExitDefaultMode(); /* Switch to timer mode if it expires */ handleTimers(); /* Clear screen if mode has changed */ handleModeChange(); /* Show things */ showScreen(); } return 0; }
//--------------------------------------------------------------------------- int main() { hwInit(); OS::Run(); }
void _begin() { #if !defined(MY_DISABLED_SERIAL) hwInit(); #endif // Call before() in sketch (if it exists) if (before) before(); debug(PSTR("Starting " MY_NODE_TYPE " (" MY_CAPABILITIES ", " LIBRARY_VERSION ")\n")); signerInit(); #if defined(MY_RADIO_FEATURE) _failedTransmissions = 0; // Setup radio if (!transportInit()) { debug(PSTR("Radio init failed. Check wiring.\n")); // Nothing more we can do _infiniteLoop(); } else { debug(PSTR("Radio init successful.\n")); } #endif #if defined(MY_GATEWAY_FEATURE) #if defined(MY_INCLUSION_BUTTON_FEATURE) inclusionInit(); #endif // initialize the transport driver if (!gatewayTransportInit()) { debug(PSTR("Transport driver init fail\n")); // Nothing more we can do _infiniteLoop(); } #endif #if defined(MY_LEDS_BLINKING_FEATURE) ledsInit(); #endif // Read latest received controller configuration from EEPROM hwReadConfigBlock((void*)&_cc, (void*)EEPROM_CONTROLLER_CONFIG_ADDRESS, sizeof(ControllerConfig)); if (_cc.isMetric == 0xff) { // Eeprom empty, set default to metric _cc.isMetric = 0x01; } #if defined(MY_GATEWAY_FEATURE) // Set configuration for gateway _nc.parentNodeId = GATEWAY_ADDRESS; _nc.distance = 0; _nc.nodeId = GATEWAY_ADDRESS; #elif defined(MY_RADIO_FEATURE) // Read settings from eeprom hwReadConfigBlock((void*)&_nc, (void*)EEPROM_NODE_ID_ADDRESS, sizeof(NodeConfig)); #ifdef MY_OTA_FIRMWARE_FEATURE // Read firmware config from EEPROM, i.e. type, version, CRC, blocks hwReadConfigBlock((void*)&_fc, (void*)EEPROM_FIRMWARE_TYPE_ADDRESS, sizeof(NodeFirmwareConfig)); #endif _autoFindParent = MY_PARENT_NODE_ID == AUTO; if (!_autoFindParent) { _nc.parentNodeId = MY_PARENT_NODE_ID; // Save static parent id in eeprom (used by bootloader) hwWriteConfig(EEPROM_PARENT_NODE_ID_ADDRESS, MY_PARENT_NODE_ID); // We don't actually know the distance to gw here. Let's pretend it is 1. // If the current node is also repeater, be aware of this. _nc.distance = 1; } else if (!isValidParent(_nc.parentNodeId)) { // Auto find parent, but parent in eeprom is invalid. Try find one. transportFindParentNode(); } if (MY_NODE_ID != AUTO) { // Set static id _nc.nodeId = MY_NODE_ID; // Save static id in eeprom hwWriteConfig(EEPROM_NODE_ID_ADDRESS, MY_NODE_ID); } else if (_nc.nodeId == AUTO && isValidParent(_nc.parentNodeId)) { // Try to fetch node-id from gateway transportRequestNodeId(); } #endif #ifdef MY_NODE_LOCK_FEATURE // Check if node has been locked down if (hwReadConfig(EEPROM_NODE_LOCK_COUNTER) == 0) { // Node is locked, check if unlock pin is asserted, else hang the node pinMode(MY_NODE_UNLOCK_PIN, INPUT_PULLUP); // Make a short delay so we are sure any large external nets are fully pulled unsigned long enter = hwMillis(); while (hwMillis() - enter < 2); if (digitalRead(MY_NODE_UNLOCK_PIN) == 0) { // Pin is grounded, reset lock counter hwWriteConfig(EEPROM_NODE_LOCK_COUNTER, MY_NODE_LOCK_COUNTER_MAX); // Disable pullup pinMode(MY_NODE_UNLOCK_PIN, INPUT); debug(PSTR("Node is unlocked.\n")); } else { // Disable pullup pinMode(MY_NODE_UNLOCK_PIN, INPUT); nodeLock("LDB"); //Locked during boot } } else if (hwReadConfig(EEPROM_NODE_LOCK_COUNTER) == 0xFF) { // Reset walue hwWriteConfig(EEPROM_NODE_LOCK_COUNTER, MY_NODE_LOCK_COUNTER_MAX); } #endif // Call sketch setup if (setup) setup(); #if defined(MY_RADIO_FEATURE) transportPresentNode(); #endif if (presentation) presentation(); debug(PSTR("Init complete, id=%d, parent=%d, distance=%d\n"), _nc.nodeId, _nc.parentNodeId, _nc.distance); }