Exemplo n.º 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);


}
Exemplo n.º 2
0
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]);
	}
}
Exemplo n.º 3
0
Arquivo: kbd.c Projeto: mtarek/BeRTOS
/**
 * Initialize keyboard ports and softtimer
 */
void kbd_init(void)
{
#if CONFIG_KBD_BEEP
    MOD_CHECK(buzzer);
#endif

    KBD_HW_INIT;

    /* Init handlers lists */
    LIST_INIT(&kbd_handlers);
    LIST_INIT(&kbd_rawHandlers);

    /* Add debounce keyboard handler */
    kbd_debHandler.hook = kbd_debHandlerFunc;
    kbd_debHandler.pri = 100; /* high priority */
    kbd_debHandler.flags = KHF_RAWKEYS;
    kbd_addHandler(&kbd_debHandler);

#if CONFIG_KBD_LONGPRESS
    /* Add long pression keyboard handler */
    kbd_lngHandler.hook = kbd_lngHandlerFunc;
    kbd_lngHandler.pri = 90; /* high priority */
    kbd_lngHandler.flags = KHF_RAWKEYS;
    kbd_addHandler(&kbd_lngHandler);
#endif

    /* Add repeat keyboard handler */
    kbd_rptHandler.hook = kbd_rptHandlerFunc;
    kbd_rptHandler.pri = 80; /* high priority */
    kbd_rptHandler.flags = KHF_RAWKEYS;
    kbd_addHandler(&kbd_rptHandler);

    /* Add default keyboard handler */
    kbd_defHandler.hook = kbd_defHandlerFunc;
    kbd_defHandler.pri = -128; /* lowest priority */
    kbd_addHandler(&kbd_defHandler);

#if CONFIG_KBD_OBSERVER
    observer_InitSubject(&kbd_subject);
#endif

#if CONFIG_KBD_POLL == KBD_POLL_SOFTINT

    MOD_CHECK(timer);

    /* Add kbd handler to soft timers list */
    event_initSoftint(&kbd_timer.expire, kbd_softint, NULL);
    timer_setDelay(&kbd_timer, ms_to_ticks(KBD_CHECK_INTERVAL));
    timer_add(&kbd_timer);

#else
#error "Define keyboard poll method"

#endif

    MOD_INIT(kbd);
}
Exemplo n.º 4
0
static void timer_test_async(void)
{
	size_t i;

	for (i = 0; i < countof(test_timers); ++i)
	{
		Timer *timer = &test_timers[i];
		timer_setDelay(timer, ms_to_ticks(test_delays[i]));
		timer_setSoftint(timer, timer_test_hook, (iptr_t)timer);
		timer_add(timer);
	}
}
Exemplo n.º 5
0
/**
 * Sleep until any of the signals in \a sigs or \a timeout ticks elapse.
 * If the timeout elapse a SIG_TIMEOUT is added to the received signal(s).
 * \return the signal(s) that have awoken the process.
 * \note Caller must check return value to check which signal awoke the process.
 */
sigmask_t sig_waitTimeout(sigmask_t sigs, ticks_t timeout)
{
	Timer t;
	sigmask_t res;
	cpu_flags_t flags;

	ASSERT(!sig_check(SIG_TIMEOUT));
	ASSERT(!(sigs & SIG_TIMEOUT));
	/* IRQ are needed to run timer */
	ASSERT(IRQ_ENABLED());

	timer_set_event_signal(&t, proc_current(), SIG_TIMEOUT);
	timer_setDelay(&t, timeout);
	timer_add(&t);
	res = sig_wait(SIG_TIMEOUT | sigs);

	IRQ_SAVE_DISABLE(flags);
	/* Remove timer if sigs occur before timer signal */
	if (!(res & SIG_TIMEOUT) && !sig_check(SIG_TIMEOUT))
		timer_abort(&t);
	IRQ_RESTORE(flags);
	return res;
}