Exemple #1
0
//=====[ 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);


}
Exemple #2
0
// The task to process Console events
static void cmd_task(iptr_t timer) {
//static void cmd_task(struct Event *evt) {
	//Silence "args not used" warning.
	(void)timer;

	//kprintf("Parse CMD\n");
	//console_run((KFile*)(evt->Ev.Int.user_data));
	console_run(&dbg_port.fd);

	// Reset suspended CHs mask
	if (!chResumeCountdown)
		chSuspended = 0x0000;
	else
		chResumeCountdown--;

	// Check for periodic re-calibration
	recalibrationCountdown--;
	if (!recalibrationCountdown) {
		resetCalibrationCountdown();
		LOG_INFO("\n\n!!!!! Ri-calibrazione periodica !!!!!\n\n");
		controlCalibration();
	}

	// Reschedule this timer
	synctimer_add(&cmd_tmr, &timers_lst);
}
Exemple #3
0
// The task to process SMS events
static void sms_task(iptr_t timer) {
	//Silence "args not used" warning.
	(void)timer;
	int8_t smsIndex = 0;

	DB(LOG_INFO("\r\nChecking SMS...\r\n"));

	// Update signal level
	GSM(updateCSQ());

	// Flush SMS buffer
	GSM(gsmBufferCleanup(&msg));

	// Retrive the first SMS into memory
	GSM(smsIndex = gsmSMSByIndex(&msg, 1));
	if (smsIndex==1) {
		command_parse(&dbg_port.fd, msg.text);
		DELAY(500);
		GSM(gsmSMSDel(1));
	}

	// Process SMS commands
	smsSplitAndParse(msg.from, msg.text);

	// Restart GSM at each countdown
	if (--gsmRestartCountdown == 0) {
		LOG_INFO("\r\nRestarting GSM...");
		GSM(gsmPowerOff());
		gsmRestartCountdown = GSM_RESTART_COUNTDOWN;
	}

	// Reschedule this timer
	synctimer_add(&sms_tmr, &timers_lst);
}
static void synctimer_test(void)
{
	size_t i;

	LIST_INIT(&synctimer_list);
	for (i = 0; i < countof(synctimer_timers); ++i)
	{
		Timer *timer = &synctimer_timers[i];
		timer_setDelay(timer, ms_to_ticks(test_delays[i]));
		timer_setSoftint(timer, synctimer_test_hook, (iptr_t)timer);
		synctimer_add(timer, &synctimer_list);
	}

	int secs = 0;
	mtime_t start_time = ticks_to_ms(timer_clock());
	mtime_t now;

	while (secs <= 10)
	{
		now = ticks_to_ms(timer_clock());
		synctimer_poll(&synctimer_list);
		if (now - start_time >= 1000)
		{
			++secs;
			start_time += 1000;
			kprintf("seconds = %d, ticks=%lu\n", secs, (unsigned long)now);
		}
		wdt_reset();
	}

	for (i = 0; i < countof(synctimer_timers); ++i)
	{
		synctimer_abort(&synctimer_timers[i]);
	}
}
Exemple #5
0
static void buttonHandler(void) {

	// Button pressed
	if (!signal_status(SIGNAL_PLAT_BUTTON)) {
		// Schedule timer task
		synctimer_add(&btn_tmr, &timers_lst);
		return;
	}

	// Button released
	synctimer_abort(&btn_tmr);

}
static void synctimer_test_hook(iptr_t _timer)
{
	Timer *timer = (Timer *)(void *)_timer;
	kprintf("Sync timer process %lu expired\n", (unsigned long)ticks_to_ms(timer->_delay));
	synctimer_add(timer, &synctimer_list);
}