int main(void) { system_init(); //! [setup_init] configure_usart(); configure_usart_callbacks(); //! [setup_init] //! [main] //! [enable_global_interrupts] system_interrupt_enable_global(); //! [enable_global_interrupts] //! [main_send_string] uint8_t string[] = "Hello World!\r\n"; usart_write_buffer_job(&usart_instance, string, sizeof(string)); //! [main_send_string] //! [main_loop] while (true) { //! [main_loop] //! [main_read] usart_read_buffer_job(&usart_instance, (uint8_t *)rx_buffer, MAX_RX_BUFFER_LENGTH); //! [main_read] } //! [main] }
void usart_debug_init(const struct UsartConfig * config) { /* Set up circular buffer for rx */ circularBufferInit(&rxcb, usart_debug_buffer, sizeof(usart_debug_buffer) / sizeof(char)); configure_usart(config); configure_usart_callbacks(); }
int main(void) { system_init(); configure_usart(); configure_usart_callbacks(); struct port_config pin_conf; port_get_config_defaults(&pin_conf); /* Configure LEDs as outputs, turn them off */ pin_conf.direction = PORT_PIN_DIR_OUTPUT; port_pin_set_config(LED_1_PIN, &pin_conf); port_pin_set_output_level(LED_1_PIN, LED_1_INACTIVE); /* Set buttons as inputs */ pin_conf.direction = PORT_PIN_DIR_INPUT; pin_conf.input_pull = PORT_PIN_PULL_UP; port_pin_set_config(BUTTON_1_PIN, &pin_conf); #if USE_EIC == true configure_extint(); #endif #if USE_INTERRUPTS == true # if USE_EIC == false configure_systick_handler(); # else configure_eic_callback(); # endif system_interrupt_enable_global(); uint16_t temp; while (true) { /* Do nothing - use interrupts */ //if (usart_read_wait(&usart_instance, &temp) == STATUS_OK) //{ //while (usart_write_wait(&usart_instance, temp) != STATUS_OK); //} usart_read_buffer_job(&usart_instance, (uint8_t *)rx_buffer, 1); //sleepmgr_sleep(SLEEPMGR_STANDBY); } #else # if USE_EIC == false while (true) { update_led_state(); } # else while (true) { if (extint_chan_is_detected(BUTTON_1_EIC_LINE)) { extint_chan_clear_detected(BUTTON_1_EIC_LINE); update_led_state(); } } # endif #endif }
/** * \brief getting-started Application entry point. * * \return Unused (ANSI-C compatibility). */ int main(void) { struct port_config pin; unsigned char c; system_init(); //Configure UART console. configure_console(); configure_usart_callbacks(); usart_enable_rx_interrupt(&cdc_uart_module,&c); usart_enable(&cdc_uart_module); //Configures TC driver configure_tc(); //Configures TC callback configure_tc_callbacks(); //Initialize the delay driver delay_init(); //Enable system interrupt system_interrupt_enable_global(); //Configures PORT for LED0 port_get_config_defaults(&pin); pin.direction = PORT_PIN_DIR_OUTPUT; port_pin_set_config(LED0_PIN, &pin); port_pin_set_output_level(LED0_PIN, LED0_INACTIVE); port_pin_set_output_level(LED0_PIN, LED0_INACTIVE); /*main loop*/ while(1) { if (is_running) { //Handle user's input // if (uart_getc(&c)) // { switch (c) { case 'w': case ' ': //ROTATE tetris_rotate(); break; case 's': //DOWN tetris_gravity(); break; case 'd': //RIGHT tetris_move_right(); break; case 'a': //LEFT tetris_move_left(); break; default: break; } c=0; // } // was here if(!iterate_game) if(iterate_game) { //Update game iterate_game = false; tetris_gravity(); tetris_check_lines(); terminal_cursor_home(); tetris_print(); if (tetris_is_game_over()) { is_running = false; } } } else { // if (uart_getc(&c)) // { if (c == 'n') { c=0; //Seed random function so we do not get same start condition //for each new game. In essence we will not start a new game //exactly at the same time. srand(tick); //New Game is_running = true; terminal_cursor_off(); terminal_clear(); tetris_init(); tetris_new_block(); terminal_cursor_home(); tetris_print(); } // } } } }