int main(void)
{
	system_init();

//! [setup_init]
	configure_tc();
	configure_tc_callbacks();
//! [setup_init]

//! [main]
	//! [enable_global_interrupts]
	system_interrupt_enable_global();
	//! [enable_global_interrupts]

	//! [main_loop]
	while (true) {
	}
	//! [main_loop]
//! [main]
}
Esempio n. 2
0
/**
 *  \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();
            }
            //	}
        }
    }
}