Exemplo n.º 1
0
void task_powerdown_init()
{
	//Lower F_CPU
	ClockSetSource(x2MHz);
	//disable other oscilators
	OSC.CTRL = 0b00000001;

	buttons_deinit();

	uart_stop();
	_delay_ms(10);

	turnoff_subsystems();

	uart_low_speed();
	_delay_ms(10);

	DEBUG(" *** POWER DOWN INIT ***\n");

	test_memory();

	//we do not want to enter sleep
	powerdown_loop_break = false;
	powerdown_lock.Lock();

	task_timer_setup(false);

	SD_EN_OFF;

	DEBUG("Using low speed uart\n");
}
Exemplo n.º 2
0
void task_system_loop()
{
	wdt_reset();

	//task switching outside interrupt
	if (new_task != actual_task)
	{
		DEBUG("Switching task %d to %d\n", actual_task, new_task);
		if (actual_task != NO_TASK)
		{
			task_stop_array[actual_task]();

			//XXX: this will guarantee that task switched from the powerdown task will be vanilla
			if (new_task == TASK_POWERDOWN)
				SystemReset();
		}

		actual_task = new_task;

		task_init_array[actual_task]();
	}

	//check USB and send IRQ
	if (usb_state != USB_CONNECTED)
	{
		usb_state = USB_CONNECTED;
		task_irqh(TASK_IRQ_USB, &usb_state);
	}

	buttons_step();
	if (powerdown_lock.Active() == false)
	{
		battery_step();
	}
}
Exemplo n.º 3
0
void buttons_step()
{
    if (config.gui.disp_flags & CFG_DISP_FLIP)
    {
        button_handle(2, GpioRead(SWITCH1));
        button_handle(0, GpioRead(SWITCH3));
    }
    else
    {
        button_handle(0, GpioRead(SWITCH1));
        button_handle(2, GpioRead(SWITCH3));
    }
    button_handle(1, GpioRead(SWITCH2));

    if (buttons_state[0] > BS_IDLE || buttons_state[1] > BS_IDLE || buttons_state[2] > BS_IDLE)
        button_lock.Lock();
    else
        button_lock.Unlock();
}
Exemplo n.º 4
0
void task_powerdown_loop()
{
	//do not go to the Power down when there is another lock pending (button, buzzer)
	if ((task_sleep_lock == 1 && powerdown_lock.Active()) && powerdown_loop_break == false)
	{
		uart_stop();

		powerdown_sleep();

		uart_low_speed();
	}
}
Exemplo n.º 5
0
void task_powerdown_stop()
{
	//Reinit all devices
	DEBUG("Restarting all devices\n");

	uart_stop();
	Setup();

	task_timer_setup();
	DEBUG("Restoring full speed uart\n");

	powerdown_lock.Unlock();
}
Exemplo n.º 6
0
void task_init()
{
	task_timer_setup();
	USB_CONNECTED_IRQ_ON;

	powerdown_lock.Unlock();

	//if ftest is not done
	if (!cfg_factory_passed())
		task_set(TASK_ACTIVE);

	//if is USB connected go directly to USB task
	if ((usb_state = USB_CONNECTED))
		task_set(TASK_USB);

	wdt_init(wdt_2s);
}