Exemplo n.º 1
0
void uart_task(void)
{
#if (UART_RST_SVALE_ENABLED == 1)
	if(usart_rst_slave_flag != 0)
	{
		LED_Off(LED_VBUS);

		irqflags_t flags = cpu_irq_save();
		usart_rst_slave_flag = 0;
		cpu_irq_restore(flags);
		timeout_start_singleshot(TIMEOUT_RST_SLAVE, UART_RST_SLAVE_TIMEOUT);
		gpio_configure_pin(GPIO_PUSH_BUTTON_0, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW);
		gpio_configure_pin(GPIO_PUSH_BUTTON_1, IOPORT_DIR_OUTPUT | IOPORT_INIT_LOW);
	}
	
	if(timeout_test_and_clear_expired(TIMEOUT_RST_SLAVE))
	{
		gpio_configure_pin(GPIO_PUSH_BUTTON_1, IOPORT_DIR_INPUT | IOPORT_PULL_UP);
		delay_ms(10);
		gpio_configure_pin(GPIO_PUSH_BUTTON_0, IOPORT_DIR_INPUT | IOPORT_PULL_UP);
		LED_On(LED_VBUS);
	}
#endif
	
	if(timeout_test_expired(TIMEOUT_RX))
	{
		LED_Off(LED_RX);
	}
	if(timeout_test_expired(TIMEOUT_TX))
	{
		LED_Off(LED_TX);
	}
}
Exemplo n.º 2
0
/**
 * \brief Timeout example 2 main application routine
 */
int main( void )
{
	// Initialize drivers
	sysclk_init();
	board_init();
	pmic_init();
	timeout_init();
	cpu_irq_enable();

	bool button_pressed;
	bool button_previous_state_pressed = false;

	// Initialize LEDs
	gpio_set_pin_group_high(LED_PORT, LED_PORT_MASK);

	while (1) {

		button_pressed = gpio_pin_is_low(GPIO_PUSH_BUTTON_0);

		// Test for any change in state since last sample
		if (button_previous_state_pressed != button_pressed) {
			/* Start debounce timeout. This will cancel any
			   currently running timeout for selected id. */
			timeout_start_singleshot(DEBOUNCE_TIMEOUT,
					DEBOUNCE_TICKS);
			button_previous_state_pressed = button_pressed;
		}

		// Check for debounce timeout expire
		if (timeout_test_and_clear_expired(DEBOUNCE_TIMEOUT)) {
			// Toggle LED0 if button is pressed down
			if (button_pressed) {
				gpio_toggle_pin(LED0_GPIO);
			}
		}

		// No debounce filter on button 1
		if (gpio_pin_is_low(GPIO_PUSH_BUTTON_1)) {
			gpio_toggle_pin(LED1_GPIO);
		}
	}
}