/** * Initialize a serial port. * * \param fd KFile Serial struct interface. * \param unit Serial unit to open. Possible values are architecture dependant. */ static struct Serial *ser_open(struct Serial *fd, unsigned int unit) { ASSERT(unit < countof(ser_handles)); ser_handles[unit] = fd; ASSERT(!fd->is_open); DB(fd->is_open = true); fd->unit = unit; fd->hw = ser_hw_getdesc(unit); /* Initialize circular buffers */ ASSERT(fd->hw->txbuffer); ASSERT(fd->hw->rxbuffer); fifo_init(&fd->txfifo, fd->hw->txbuffer, fd->hw->txbuffer_size); fifo_init(&fd->rxfifo, fd->hw->rxbuffer, fd->hw->rxbuffer_size); fd->hw->table->init(fd->hw, fd); /* Set default values */ #if CONFIG_SER_RXTIMEOUT != -1 || CONFIG_SER_TXTIMEOUT != -1 ser_settimeouts(fd, CONFIG_SER_RXTIMEOUT, CONFIG_SER_TXTIMEOUT); #endif #if CONFIG_SER_DEFBAUDRATE ser_setbaudrate(fd, CONFIG_SER_DEFBAUDRATE); #endif /* Clear error flags */ ser_setstatus(fd, 0); return fd; }
//=====[ Control Loop ]========================================================= void controlSetup(void) { // Init list of synchronous timers LIST_INIT(&timers_lst); // Schedule SMS handling task GSM(gsmSMSDelRead()); timer_setDelay(&sms_tmr, ms_to_ticks(SMS_CHECK_SEC*1000)); timer_setSoftint(&sms_tmr, sms_task, (iptr_t)&sms_tmr); synctimer_add(&sms_tmr, &timers_lst); // Schedule Console handling task timer_setDelay(&cmd_tmr, ms_to_ticks(CMD_CHECK_SEC*1000)); timer_setSoftint(&cmd_tmr, cmd_task, (iptr_t)&cmd_tmr); synctimer_add(&cmd_tmr, &timers_lst); // Setup Button handling task timer_setDelay(&btn_tmr, ms_to_ticks(BTN_CHECK_SEC*1000)); timer_setSoftint(&btn_tmr, btn_task, (iptr_t)&btn_tmr); // Setup console RX timeout console_init(&dbg_port.fd); ser_settimeouts(&dbg_port, 0, 1000); // Dump ADE7753 configuration meter_ade7753_dumpConf(); // Get bitmask of enabled channels chEnabled = ee_getEnabledChMask(); // Get bitmask of enabled channels chCritical = ee_getCriticalChMask(); // Enabling calibration only for enabled channels chCalib = chEnabled; // Setup channels calibration data for (uint8_t ch=0; ch<16; ch++) loadCalibrationData(ch); // Update signal level GSM(updateCSQ()); // Setup Re-Calibration Weeks resetCalibrationCountdown(); // Enabling the watchdog for the control loop WATCHDOG_ENABLE(); // Initi the analog MUX to current channel switchAnalogMux(curCh); }