diff --git a/src/game.c b/src/game.c index a0d1ca9..31b2055 100644 --- a/src/game.c +++ b/src/game.c @@ -2,17 +2,15 @@ #include #include #include + #include "game.h" #include "io.h" void game_init(game_t* game, uint16_t ticks_per_sec) { - //Sysinit - + //gpio init io_init(); - //uart init - //lcd init LCD_Init(); LCD_Clear(GUI_COLOR_BLACK); @@ -46,50 +44,50 @@ bool game_check_line_collision(player_t* player, point_t start, point_t end, uin switch(player->direction){ case up: if(player->position.y > start.y && ((int16_t)player->position.y - pixels) <= start.y) { - return true; + return true; // going up and hitting a line segment } break; case down: if(player->position.y < start.y && ((int16_t)player->position.y + pixels) >= start.y) { - return true; + return true; // going down and hitting a line segment } break; case left: if(player->position.x > start.x && ((int16_t)player->position.x - pixels) <= start.x) { - return true; + return true; // going left and hitting a line segment } break; case right: if(player->position.x < start.x && ((int16_t)player->position.x + pixels) >= start.x) { - return true; + return true; // going right and hitting a line segment } break; } return false; } -bool game_check_bounding_collision(game_t* game, player_t* player, uint8_t pixels){ +bool game_check_boundary_collision(game_t* game, player_t* player, uint8_t pixels){ - // Check bounding collision + // Check boundary collision switch(player->direction){ case up: if((int16_t)(player->position.y) - pixels <= TFT_GAME_FIELD_TOP){ - return true; // Collision at top + return true; // Collision at top boundary } break; case down: if((int16_t)(player->position.y) + pixels >= (TFT_HEIGHT - TFT_GAME_FIELD_BOTTOM - 1)){ - return true; // Collision at bottom + return true; // Collision at bottom boundary } break; case left: if((int16_t)(player->position.x) - pixels <= TFT_GAME_FIELD_LEFT){ - return true; // Collision at left + return true; // Collision at left boundary } break; case right: if((int16_t)(player->position.x) + pixels >= (TFT_WIDTH - TFT_GAME_FIELD_RIGHT - 1)){ - return true; // Collision at right + return true; // Collision at right boundary } break; } @@ -122,11 +120,10 @@ bool game_check_player_collision(game_t* game, player_t* player, uint8_t pixels) } } -// Do all collision checks! -bool game_check_collision(game_t* game, player_t* player, uint8_t pixels){ +bool game_check_collision(game_t* game, player_t* player, uint8_t pixels){ // Check boundary and player collisions - // Check for collisions with boundings - if(game_check_bounding_collision(game, player, pixels)){ + // Check for collisions with boundarys + if(game_check_boundary_collision(game, player, pixels)){ return true; } @@ -140,39 +137,37 @@ bool game_check_collision(game_t* game, player_t* player, uint8_t pixels){ bool game_player_update(game_t* game, player_t* player, uint8_t pixels){ - bool directionChange = false; - bool stateChanged = false; + bool direction_change = false; + bool state_changed = false; // Check for button presses - if(io_button_has_edge(player->btn_left)) { - player->direction= (player->direction + (4 - 1)) % 4 ; // "decrement enum value" - directionChange = true; - } else if(io_button_has_edge(player->btn_right)) { - player->direction= (player->direction + 1) % 4 ; // "increment enum value" - directionChange = true; + if(io_button_has_edge(player->btn_left)) { // If left button is pressed + player->direction= (player->direction + (4 - 1)) % 4 ; // Decrement direction value (counterclockwise) + direction_change = true; + } else if(io_button_has_edge(player->btn_right)) { // If right button is pressed + player->direction= (player->direction + 1) % 4 ; // Increment direction value (clockwise) + direction_change = true; } // Check if player is alive if(player->state != alive){ - return stateChanged; + return state_changed; // If player is dead return state } // Change direction - if(directionChange) { - player_append_position(player,player->position); + if(direction_change) { + player_append_position(player,player->position); // Append new position if direction has changed } if(pixels) { - - // Check if a collision is about to happen - if(game_check_collision(game, player, pixels)){ - player->state=dead; - stateChanged=true; + if(game_check_collision(game, player, pixels)){ // Check if a collision is about to happen + player->state = dead; // If a collision is happening kill the player + state_changed = true; // return the state } - point_t last_point = player->past_positions[player->num_positions-1]; + point_t last_point = player->past_positions[player->num_positions-1]; // Get the players newest point - switch(player->direction) { - case down: + switch(player->direction) { // Get the players moving direction and render his move + case down: // render down player->position.y+=pixels; LCD_DrawRectF( player->position.x, last_point.y, @@ -180,7 +175,7 @@ bool game_player_update(game_t* game, player_t* player, uint8_t pixels){ player->position.y - last_point.y, player->color); break; - case left: + case left: // render left player->position.x-=pixels; LCD_DrawRectF( player->position.x, player->position.y, @@ -188,7 +183,7 @@ bool game_player_update(game_t* game, player_t* player, uint8_t pixels){ PLAYER_WIDTH, player->color); break; - case up: + case up: // render up player->position.y-=pixels; LCD_DrawRectF( player->position.x, player->position.y, @@ -196,7 +191,7 @@ bool game_player_update(game_t* game, player_t* player, uint8_t pixels){ last_point.y - player->position.y, player->color); break; - case right: + case right: // render right player->position.x+=pixels; LCD_DrawRectF( last_point.x, player->position.y, @@ -206,111 +201,116 @@ bool game_player_update(game_t* game, player_t* player, uint8_t pixels){ break; } } - return stateChanged; + + return state_changed; // return state } -bool game_step(game_t* game, uint64_t deltaTime) { +bool game_step(game_t* game, uint64_t delta_time) { // Calculate the next game step static long l = 0; + switch(game->state) { - case prestart: - //Draw welcome screen + case prestart: // If the game is in prestart state + // Draw welcome screen LCD_DrawRectF(10,10,100,50,GUI_COLOR_BLUE); - //wait on player to press start (host) + // Wait on player to press start while(!io_button_has_edge(BTN_START)); - //send game start request to slave - //wait on game accept response - - //setup - player_init(&(game->player[0]), - BTN_PLAYER_1_LEFT, - BTN_PLAYER_1_RIGHT, + // Setup the two players + player_init(&(game->player[0]), // Player object to fill + BTN_PLAYER_1_LEFT, // Left-button + BTN_PLAYER_1_RIGHT, // Right-button (point_t){ - .x=(TFT_GAME_FIELD_START_OFFSET + TFT_GAME_FIELD_LEFT), - .y=(((TFT_HEIGHT - TFT_GAME_FIELD_TOP - TFT_GAME_FIELD_BOTTOM) / 2) + TFT_GAME_FIELD_TOP) + .x=(TFT_GAME_FIELD_START_OFFSET + TFT_GAME_FIELD_LEFT), // x start coordinate + .y=(((TFT_HEIGHT - TFT_GAME_FIELD_TOP - TFT_GAME_FIELD_BOTTOM) / 2) + TFT_GAME_FIELD_TOP) // y start coordinate }, - GUI_COLOR_BLUE, - right); + GUI_COLOR_BLUE, // color + right); // default moving direction - player_init(&(game->player[1]), - BTN_PLAYER_2_LEFT, - BTN_PLAYER_2_RIGHT, + player_init(&(game->player[1]), // Player object to fill + BTN_PLAYER_2_LEFT, // Left-button + BTN_PLAYER_2_RIGHT, // Right-button (point_t){ - .x=(TFT_WIDTH - 1 - TFT_GAME_FIELD_RIGHT - TFT_GAME_FIELD_START_OFFSET), - .y=(((TFT_HEIGHT - TFT_GAME_FIELD_TOP - TFT_GAME_FIELD_BOTTOM) / 2) + TFT_GAME_FIELD_TOP) + .x=(TFT_WIDTH - 1 - TFT_GAME_FIELD_RIGHT - TFT_GAME_FIELD_START_OFFSET), // x start coordinate + .y=(((TFT_HEIGHT - TFT_GAME_FIELD_TOP - TFT_GAME_FIELD_BOTTOM) / 2) + TFT_GAME_FIELD_TOP) // y start coordinate }, - GUI_COLOR_RED, - left); + GUI_COLOR_RED, // color + left); // default moving direction - //switch state - game->state = running; - game->time = 0; + game->state = running; // Switch the game state to running + game->time = 0; // Reset the game time - LCD_Clear(GUI_COLOR_BLACK); - LCD_DrawRect(TFT_GAME_FIELD_LEFT, - TFT_GAME_FIELD_TOP, - (TFT_WIDTH - TFT_GAME_FIELD_LEFT - TFT_GAME_FIELD_RIGHT - 1), - (TFT_HEIGHT - TFT_GAME_FIELD_TOP - TFT_GAME_FIELD_BOTTOM - 1), - GUI_COLOR_WHITE); + LCD_Clear(GUI_COLOR_BLACK); // Clear the background - LCD_SetTextColor(GUI_COLOR_WHITE); - LCD_DisplayStringXY(TFT_GAME_HEADER_TIME_X, TFT_GAME_HEADER_TIME_Y, "Time: 0:00"); - for(int i = 0; i < PLAYER_COUNT; i++){ - static char buf[16]; - LCD_SetTextColor(game->player[i].color); - sprintf(buf, "Player%d: alive", (i+1)); - LCD_DisplayStringXY(TFT_GAME_HEADER_PLAYER_X+i*TFT_GAME_HEADER_PLAYER_WIDTH, TFT_GAME_HEADER_PLAYER_Y, buf); + // Draw the game boundary + LCD_DrawRect(TFT_GAME_FIELD_LEFT, // left top x + TFT_GAME_FIELD_TOP, // left top y + (TFT_WIDTH - TFT_GAME_FIELD_LEFT - TFT_GAME_FIELD_RIGHT - 1), // right bottom x + (TFT_HEIGHT - TFT_GAME_FIELD_TOP - TFT_GAME_FIELD_BOTTOM - 1), // right bottom y + GUI_COLOR_WHITE); // Color of the boundary + + LCD_SetTextColor(GUI_COLOR_WHITE); // Reset color to white + LCD_DisplayStringXY(TFT_GAME_HEADER_TIME_X, TFT_GAME_HEADER_TIME_Y, "Time: 0:00"); // Draw the zero-time + + for(int i = 0; i < PLAYER_COUNT; i++){ // For each player print its name and its state + static char buf[16]; // Text buffer + LCD_SetTextColor(game->player[i].color); // Set the text color according to the players color + sprintf(buf, "Player%d: alive", (i+1)); // Print the state and the players name to the text buffer + LCD_DisplayStringXY(TFT_GAME_HEADER_PLAYER_X+i*TFT_GAME_HEADER_PLAYER_WIDTH, TFT_GAME_HEADER_PLAYER_Y, buf); // Print everything } return true; case running: { - uint16_t ticks; + uint16_t ticks; uint16_t pixels = 0; - if(deltaTime) { - ticks = game->ticks_leftover + deltaTime; - pixels = ticks / game->ticks_per_pixel; - game->ticks_leftover = ticks % game->ticks_per_pixel; - game->ticks_sum_sec += deltaTime; + if(delta_time) { + ticks = game->ticks_leftover + delta_time; // Calculate the number of past ticks + pixels = ticks / game->ticks_per_pixel; // Calculate the number of pixels moved in the calculated amount of ticks + game->ticks_leftover = ticks % game->ticks_per_pixel; // Calculate the number of ticks which are left + game->ticks_sum_sec += delta_time; // Add the delta_time to the tick sum which is used to calculate the game time - uint16_t new_seconds = game->ticks_sum_sec / game->ticks_per_sec; + uint16_t new_seconds = game->ticks_sum_sec / game->ticks_per_sec; // Calculate number of seconds from past ticks - game->time += new_seconds; - game->ticks_sum_sec = game->ticks_sum_sec % game->ticks_per_sec; + game->time += new_seconds; // Add the new amount of seconds to the game time + game->ticks_sum_sec = game->ticks_sum_sec % game->ticks_per_sec; // Limit the tick sum used to calculate the amount of seconds - if(new_seconds > 0){ - static char buf[15]; - sprintf(buf, "Time: %d:%02d", (game->time / 60), (game->time % 60)); - LCD_SetTextColor(GUI_COLOR_WHITE); - LCD_DisplayStringXY(TFT_GAME_HEADER_TIME_X, TFT_GAME_HEADER_TIME_Y, buf); + if(new_seconds > 0){ // Print the time if it got updated + static char buf[15]; // Textbufer + sprintf(buf, "Time: %d:%02d", (game->time / 60), (game->time % 60)); // Format time and paste it to the textbuffer + LCD_SetTextColor(GUI_COLOR_WHITE); // Set the text color to white + LCD_DisplayStringXY(TFT_GAME_HEADER_TIME_X, TFT_GAME_HEADER_TIME_Y, buf); // Print the time } } + bool all_players_dead = true; // Assume all players are dead ;-) + // For each player do ... - bool all_players_dead = true; - for(int i = 0; i < PLAYER_COUNT; i++) { - player_t* player = &(game->player[i]); - if(game_player_update(game, player, pixels)) { //update player and execute if, when player state has changed - static char buf[15]; - const char* state_text = "alive"; - if(player->state==dead) { + for(int i = 0; i < PLAYER_COUNT; i++) { + player_t* player = &(game->player[i]); // Copy an object of the current player + + if(game_player_update(game, player, pixels)) { // Update player and execute if, when player state has changed + static char buf[15]; // Buffer to hold the text output + const char* state_text = "alive"; // Assume that the player is alive + + if(player->state==dead) { // If the player is dead change the text state_text="dead"; } - sprintf(buf, "Player%d: %s ", (i+1),state_text); - LCD_SetTextColor(player->color); - LCD_DisplayStringXY(TFT_GAME_HEADER_PLAYER_X+i*TFT_GAME_HEADER_PLAYER_WIDTH, TFT_GAME_HEADER_PLAYER_Y, buf); + + sprintf(buf, "Player%d: %s ", (i+1),state_text); // Format and paste the status to the buffer + LCD_SetTextColor(player->color); // Set the text color to the players color + LCD_DisplayStringXY(TFT_GAME_HEADER_PLAYER_X+i*TFT_GAME_HEADER_PLAYER_WIDTH, TFT_GAME_HEADER_PLAYER_Y, buf); // Print the status } - if(player->state!=dead) { + if(player->state!=dead) { // If the current player still lives not all players are dead ... all_players_dead=false; } } - if(all_players_dead) { - game->state=ended; + if(all_players_dead) { // End the game if all players are dead + game->state=ended; // Set the state to ended return true; } else { return false; @@ -318,9 +318,9 @@ bool game_step(game_t* game, uint64_t deltaTime) { } case ended: - while(!io_button_has_edge(BTN_START)); - LCD_Clear(GUI_COLOR_BLACK); - game->state= prestart; + while(!io_button_has_edge(BTN_START)); // Wait for the start button to be pressed again + LCD_Clear(GUI_COLOR_BLACK); // Clear the background + game->state= prestart; // Set the state to prestart return true; } } diff --git a/src/game.h b/src/game.h index dd40859..ae81f3f 100644 --- a/src/game.h +++ b/src/game.h @@ -6,18 +6,23 @@ #include #include"player.h" +// Player definitions #define PLAYER_COUNT 2 -#define PLAYER_WIDTH 0 // Don't change +#define PLAYER_WIDTH 0 // Don't change + +// Speed definitions #define SPEED_SLOW 10 #define SPEED_FAST 1 #define SPEED_DEFAULT (SPEED_FAST) +// Button definitions #define BTN_START 0 #define BTN_PLAYER_1_LEFT 3 #define BTN_PLAYER_1_RIGHT 2 #define BTN_PLAYER_2_LEFT 1 #define BTN_PLAYER_2_RIGHT 0 +// Display definitions #define TFT_GAME_FIELD_TOP 20 #define TFT_GAME_FIELD_BOTTOM 5 #define TFT_GAME_FIELD_LEFT 5 @@ -29,40 +34,44 @@ #define TFT_GAME_HEADER_PLAYER_Y 3 #define TFT_GAME_HEADER_PLAYER_WIDTH 100 +/** + * @brief Game data type which contains all game data and players. + * + */ typedef struct game_s{ - //public section + //public section ahead - uint16_t time; // seconds since game start - uint16_t ticks_per_sec; - int8_t winner_id; - uint8_t ticks_per_pixel; + uint16_t time; // Seconds since game start + uint16_t ticks_per_sec; // Number of game ticks per second + int8_t winner_id; // Player who won the previous round + uint8_t ticks_per_pixel; // Number of pixels you a player moves per tick player_t player[PLAYER_COUNT]; - enum{ + enum{ // Current state of the game prestart, running, ended } state; - //private section ahead: - uint8_t ticks_leftover; - uint8_t ticks_sum_sec; + //private section ahead + uint8_t ticks_leftover; // Ticks left to complete a second + uint8_t ticks_sum_sec; // Used to calculate the game time } game_t; /** @brief Initializes the game object - @param game - @param ticks_per_sec + @param game Game object + @param ticks_per_sec Number of game ticks per second */ void game_init(game_t* game, uint16_t ticks_per_sec); /** - @brief Calculates one step of the game - @param game Game to calculate a step for - @param deltaTime Time that passed since the last call to this method (in ticks) - @return true if the next call to this method should be made with a delta time of zero. - -*/ + * @brief Calculates one step of the game + * + * @param game Game to calculate a step for + * @param deltaTime Time that passed since the last call to this method (in ticks) + * @return true if the next call to this method should be made with a delta time of zero. + */ bool game_step(game_t* game, uint64_t deltaTime); #endif /* GAME_H */ diff --git a/src/io.c b/src/io.c index f7082b5..6a8f894 100644 --- a/src/io.c +++ b/src/io.c @@ -1,10 +1,10 @@ #include "io.h" -//-----------Local types & functions-------------------------- +// Local functions typedef struct pin_s { - GPIO_TypeDef* GPIO; - uint16_t pinmask; - bool input; + GPIO_TypeDef* GPIO; + uint16_t pinmask; + bool input; } pin_t; static void pin_create(pin_t* pin, GPIO_TypeDef* GPIO, uint8_t pinnr, bool input); @@ -12,90 +12,84 @@ static bool pin_get(pin_t* pin); static void pin_set(pin_t* pin, bool status); static void pin_toggle(pin_t* pin); - -//-------------Local Variables------------------------- +// Local variables static pin_t pin_t0; static pin_t pin_t1; static pin_t pin_t2; static pin_t pin_t3; - static uint8_t new = 0; static uint8_t old = 0; static volatile uint8_t edg = 0; -//---------------Implementation -------------------------------- void pin_create(pin_t* pin, GPIO_TypeDef* GPIO, uint8_t pinnr, bool input) { - GPIO_InitTypeDef gi; - GPIO_StructInit(&gi); + GPIO_InitTypeDef gi; // Create gpio init structure + GPIO_StructInit(&gi); // Fill gpio init structure with defaults - gi.GPIO_Pin = 1 << pinnr; + gi.GPIO_Pin = 1 << pinnr; // create bitmask out of pin number - if(input) { - gi.GPIO_Mode = GPIO_Mode_IN; - gi.GPIO_OType = GPIO_OType_OD; - gi.GPIO_PuPd = GPIO_PuPd_UP; - } else { - gi.GPIO_Mode = GPIO_Mode_OUT; - gi.GPIO_OType = GPIO_OType_PP; - gi.GPIO_PuPd = GPIO_PuPd_NOPULL; - } + if(input) { // If the pin is set to be an input + gi.GPIO_Mode = GPIO_Mode_IN; // Set mode to input + gi.GPIO_OType = GPIO_OType_OD; // Set type to open drain + gi.GPIO_PuPd = GPIO_PuPd_UP; // Set a pullup + } else { + gi.GPIO_Mode = GPIO_Mode_OUT; // Set mode to output + gi.GPIO_OType = GPIO_OType_PP; // Set type to pushpull + gi.GPIO_PuPd = GPIO_PuPd_NOPULL; // Set no pullup + } - GPIO_Init(GPIO,&gi); + GPIO_Init(GPIO,&gi); // Update the GPIO configuration - pin->GPIO=GPIO; - pin->pinmask=0x01<input = input; + pin->GPIO=GPIO; // Set the gpiopin in the pin structure + pin->pinmask=0x01<input = input; // Store the input information } - bool pin_get(pin_t* pin) { - if(pin->input) { - return GPIO_ReadInputDataBit(pin->GPIO,pin->pinmask); - } else { - return GPIO_ReadOutputDataBit(pin->GPIO,pin->pinmask); - } + if(pin->input) { // If the pin is an input + return GPIO_ReadInputDataBit(pin->GPIO,pin->pinmask); // Read its value + } else { // If the pin is an output + return GPIO_ReadOutputDataBit(pin->GPIO,pin->pinmask); // Read its set value + } } void pin_set(pin_t* pin, bool status) { - if(!pin->input) { - GPIO_WriteBit(pin->GPIO,pin->pinmask,status); - } + if(!pin->input) { // If the pin isn't an input + GPIO_WriteBit(pin->GPIO,pin->pinmask,status); // Set its value accordingly + } } void pin_toggle(pin_t* pin) { - if(!pin->input) { - pin_set(pin,!pin_get(pin)); - } + if(!pin->input) { // If the pin isn't an input + pin_set(pin,!pin_get(pin)); // Toggle its value + } } void io_init(void){ - //gpio init - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC,ENABLE); - pin_create(&pin_t0, GPIOC, 7, true); - pin_create(&pin_t1, GPIOB, 15, true); - pin_create(&pin_t2, GPIOB, 14, true); - pin_create(&pin_t3, GPIOI, 0, true); + RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC,ENABLE); // Enable gpio clock source + pin_create(&pin_t0, GPIOC, 7, true); // create pin_t0 + pin_create(&pin_t1, GPIOB, 15, true); // create pin_t1 + pin_create(&pin_t2, GPIOB, 14, true); // create pin_t2 + pin_create(&pin_t3, GPIOI, 0, true); // create pin_t3 } void io_process(void) { - new = pin_get(&pin_t0) | - pin_get(&pin_t1) << 1 | - pin_get(&pin_t2) << 2 | - pin_get(&pin_t3) << 3; + new = pin_get(&pin_t0) | + pin_get(&pin_t1) << 1 | + pin_get(&pin_t2) << 2 | + pin_get(&pin_t3) << 3; - edg |= (new ^ old) & new; // detect positive edge - old = new; + edg |= (new ^ old) & new; // detect positive edge + old = new; } bool io_button_has_edge(uint8_t btnnumber) { - - uint8_t bm = (1 << btnnumber); - bool status = ((edg & bm) > 0); - + uint8_t bm = (1 << btnnumber); // create bitmask + bool status = ((edg & bm) > 0); // check if button is pressed + if(status){ - edg &= ~bm; + edg &= ~bm; // clear edge bit } - return status; + return status; } diff --git a/src/io.h b/src/io.h index d945209..733ddaf 100644 --- a/src/io.h +++ b/src/io.h @@ -5,9 +5,23 @@ #include +/** + * @brief Initialize all used GPIOs and initialize their clock source. + */ void io_init(void); + +/** + * @brief Edge detection for the buttons which were initialized by io_init. + * Gets called by the systick timer. + */ void io_process(void); + +/** + * @brief Edge handler which clears the edge bit to make sure a button press gets only handled once per tick. + * + * @param btnnumber Button number + * @return True if the button has a positive edge. + */ bool io_button_has_edge(uint8_t btnnumber); - #endif /* IO_H */ diff --git a/src/player.h b/src/player.h index b9e4bce..3103303 100644 --- a/src/player.h +++ b/src/player.h @@ -4,38 +4,64 @@ #include #include -#define max_positions 320 +#define max_positions 320 // Maximum of points a player object is holding. + +/** + * @brief Direction data type, used to specify the direction when moving. + */ typedef enum direction_e { - right, - down, - left, - up + right, // going right + down, // going down + left, // going left + up // going up } direction_t; +/** + * @brief Point data type which is used to store a location for the LCD. + */ typedef struct point_s{ - uint16_t x; - uint8_t y; + uint16_t x; // x position on the display + uint8_t y; // y position on the display } point_t; +/** + * @brief Player data type which stores all data for a single player + */ typedef struct player_s { + uint8_t btn_left; // players left-button + uint8_t btn_right; // players right-button + uint16_t color; // players color + uint16_t num_positions; // players number of past edges + direction_t direction; // players current moving direction - uint8_t btn_left; - uint8_t btn_right; - uint16_t color; - uint16_t num_positions; - direction_t direction; - - enum{ + enum{ // players current state dead, alive, } state; - point_t past_positions[max_positions]; - point_t position; + point_t past_positions[max_positions]; // used to store players waypoints + point_t position; // current position } player_t; -void player_init(player_t* player, uint8_t btn_left, uint8_t btn_right, point_t pos, uint16_t color, direction_t direction); // reset all fields -void player_append_position(player_t* player, point_t point); // updates num_position and adds current position to the list +/** + * @brief Initialize a new player object and fill its data fields. + * + * @param player Player object + * @param btn_left Left-button for the new player + * @param btn_right Right-button for the new player + * @param pos Start position for the new player + * @param color Players color + * @param direction Players moving direction + */ +void player_init(player_t* player, uint8_t btn_left, uint8_t btn_right, point_t pos, uint16_t color, direction_t direction); + +/** + * @brief Updates num_position and adds current position to the list + * + * @param player Player object + * @param point Point to add to the player object + */ +void player_append_position(player_t* player, point_t point); #endif /* PLAYER_H */ diff --git a/src/startup.s b/src/startup.s index aa43e0f..ac89c88 100644 --- a/src/startup.s +++ b/src/startup.s @@ -1,22 +1,22 @@ /** ***************************************************************************** * - * @file startup.s - * @version 1.0 - * @date 2013-01-28 - * @author rct1 + * @file startup.s + * @version 1.0 + * @date 2013-01-28 + * @author rct1 * - * @brief Startup code and interrupt vector table. - * This module performs: - * - Set the initial SP - * - Set the initial PC == Reset_Handler, - * - Set the vector table entries with the exceptions - * ISR address - * - Configure the clock system - * - Branches to main in the C library (which eventually - * calls main()). - * After Reset the Cortex-M4 processor is in Thread mode, - * priority is Privileged, and the Stack is set to Main. + * @brief Startup code and interrupt vector table. + * This module performs: + * - Set the initial SP + * - Set the initial PC == Reset_Handler, + * - Set the vector table entries with the exceptions + * ISR address + * - Configure the clock system + * - Branches to main in the C library (which eventually + * calls main()). + * After Reset the Cortex-M4 processor is in Thread mode, + * priority is Privileged, and the Stack is set to Main. * ***************************************************************************** * @copyright @@ -53,512 +53,512 @@ .global Default_Handler /* Define Address spaces. defined in linker script. */ - .word _sidata /* start address for the initialization values of the - .data section. */ - .word _sdata /* start address for the .data section. */ - .word _edata /* end address for the .data section. */ - .word _sbss /* start address for the .bss section. */ - .word _ebss /* end address for the .bss section. */ - /* stack used for SystemInit_ExtMemCtl; always internal RAM used */ + .word _sidata /* start address for the initialization values of the + .data section. */ + .word _sdata /* start address for the .data section. */ + .word _edata /* end address for the .data section. */ + .word _sbss /* start address for the .bss section. */ + .word _ebss /* end address for the .bss section. */ + /* stack used for SystemInit_ExtMemCtl; always internal RAM used */ /*----- Section .text.Reset_Handler ----------------------------------------*/ /** - * \brief This is the code that gets called when the processor first - * starts execution following a reset event. Only the - * absolutely necessary set is performed, after which the - * application supplied main() routine is called. + * \brief This is the code that gets called when the processor first + * starts execution following a reset event. Only the + * absolutely necessary set is performed, after which the + * application supplied main() routine is called. */ -.section .text.Reset_Handler - .weak Reset_Handler - .type Reset_Handler, %function +.section .text.Reset_Handler + .weak Reset_Handler + .type Reset_Handler, %function Reset_Handler: - /* Copy the data segment initializers from flash to SRAM */ - MOVS r1, #0 - B LoopCopyDataInit + /* Copy the data segment initializers from flash to SRAM */ + MOVS r1, #0 + B LoopCopyDataInit CopyDataInit: - LDR r3, =_sidata - LDR r3, [r3, r1] - STR r3, [r0, r1] - ADDS r1, r1, #4 + LDR r3, =_sidata + LDR r3, [r3, r1] + STR r3, [r0, r1] + ADDS r1, r1, #4 LoopCopyDataInit: - LDR r0, =_sdata - LDR r3, =_edata - ADDS r2, r0, r1 - CMP r2, r3 - BCC CopyDataInit - LDR r2, =_sbss - B LoopFillZerobss + LDR r0, =_sdata + LDR r3, =_edata + ADDS r2, r0, r1 + CMP r2, r3 + BCC CopyDataInit + LDR r2, =_sbss + B LoopFillZerobss /* Zero fill the bss segment. */ FillZerobss: - MOVS r3, #0 - STR r3, [r2], #4 + MOVS r3, #0 + STR r3, [r2], #4 LoopFillZerobss: - LDR r3, =_ebss - CMP r2, r3 - BCC FillZerobss + LDR r3, =_ebss + CMP r2, r3 + BCC FillZerobss - BL SystemInit /* Call the clock system initialization */ - BL CARME_Init /* Call the CARME-M4 board initialization */ - BL __libc_init_array /* Call static constructors */ - BL main /* Call the application's entry point */ + BL SystemInit /* Call the clock system initialization */ + BL CARME_Init /* Call the CARME-M4 board initialization */ + BL __libc_init_array /* Call static constructors */ + BL main /* Call the application's entry point */ ProgramFinish: - B ProgramFinish /* while true do nothing */ - .size Reset_Handler, .-Reset_Handler + B ProgramFinish /* while true do nothing */ + .size Reset_Handler, .-Reset_Handler /*----- Section .text.Default_Handler --------------------------------------*/ /** - * \brief This is the code that gets called when the processor - * receives an unexpected interrupt. This simply enters an - * infinite loop, preserving the system state for examination - * by a debugger. + * \brief This is the code that gets called when the processor + * receives an unexpected interrupt. This simply enters an + * infinite loop, preserving the system state for examination + * by a debugger. */ -.section .text.Default_Handler, "ax", %progbits +.section .text.Default_Handler, "ax", %progbits dowait: - LDR r0, =0xA037A0 + LDR r0, =0xA037A0 dowaitloop: - SUBS r0, #1 - BNE dowaitloop - BX lr + SUBS r0, #1 + BNE dowaitloop + BX lr Default_Handler: - LDR r1, =0x40023800 // RCC_BASE - LDR r3, [r1, #0x30] // RCC->AHB1ENR - LDR r2, =0x100 // RCC_AHB1Periph_GPIOI - ORR r3, r3, r2 // RCC->AHB1ENR |= RCC_AHB1Periph_GPIOI - STR r3, [r1, #0x30] - LDR r1, =0x40022000 // GPIOI_BASE - /* GPIO port mode register */ - LDR r3, [r1, #0x00] // GPIOI->MODER - LDR r2, =0x0000C000 - BIC r3, r3, r2 - LDR r2, =0x00004000 - ORR r3, r3, r2 - STR r3, [r1, #0x00] - /* GPIO port output type register */ - LDR r3, [r1, #0x04] // GPIOI->OTYPER - LDR r2, =0x00000080 - BIC r3, r3, r2 - STR r3, [r1, #0x04] - /* GPIO port output speed register */ - LDR r3, [r1, #0x08] // GPIOI->OSPEEDR - LDR r2, =0x0000C000 - BIC r3, r3, r2 - STR r3, [r1, #0x08] - /* GPIO port pull-up/pull-down register */ - LDR r3, [r1, #0x0C] // GPIOI->PUPDR - LDR r2, =0x0000C000 - BIC r3, r3, r2 - STR r3, [r1, #0x0C] - /* GPIO port output data register */ - LDR r3, [r1, #0x14] // GPIOI->ODR - LDR r2, =0x00000080 + LDR r1, =0x40023800 // RCC_BASE + LDR r3, [r1, #0x30] // RCC->AHB1ENR + LDR r2, =0x100 // RCC_AHB1Periph_GPIOI + ORR r3, r3, r2 // RCC->AHB1ENR |= RCC_AHB1Periph_GPIOI + STR r3, [r1, #0x30] + LDR r1, =0x40022000 // GPIOI_BASE + /* GPIO port mode register */ + LDR r3, [r1, #0x00] // GPIOI->MODER + LDR r2, =0x0000C000 + BIC r3, r3, r2 + LDR r2, =0x00004000 + ORR r3, r3, r2 + STR r3, [r1, #0x00] + /* GPIO port output type register */ + LDR r3, [r1, #0x04] // GPIOI->OTYPER + LDR r2, =0x00000080 + BIC r3, r3, r2 + STR r3, [r1, #0x04] + /* GPIO port output speed register */ + LDR r3, [r1, #0x08] // GPIOI->OSPEEDR + LDR r2, =0x0000C000 + BIC r3, r3, r2 + STR r3, [r1, #0x08] + /* GPIO port pull-up/pull-down register */ + LDR r3, [r1, #0x0C] // GPIOI->PUPDR + LDR r2, =0x0000C000 + BIC r3, r3, r2 + STR r3, [r1, #0x0C] + /* GPIO port output data register */ + LDR r3, [r1, #0x14] // GPIOI->ODR + LDR r2, =0x00000080 Infinite_Loop: - ORR r3, r3, r2 - STR r3, [r1, #0x14] // Set LED - BL dowait - BIC r3, r3, r2 - STR r3, [r1, #0x14] // Reset LED - BL dowait - B Infinite_Loop - .size Default_Handler, .-Default_Handler + ORR r3, r3, r2 + STR r3, [r1, #0x14] // Set LED + BL dowait + BIC r3, r3, r2 + STR r3, [r1, #0x14] // Reset LED + BL dowait + B Infinite_Loop + .size Default_Handler, .-Default_Handler /*----- Section .isr_vector ------------------------------------------------*/ /** - * \brief The minimal vector table for a Cortex M4. Note that the - * proper constructs must be placed on this to ensure that it - * ends up at physical address 0x0000.0000. + * \brief The minimal vector table for a Cortex M4. Note that the + * proper constructs must be placed on this to ensure that it + * ends up at physical address 0x0000.0000. */ -.section .isr_vector, "a", %progbits - .type g_pfnVectors, %object - .size g_pfnVectors, .-g_pfnVectors +.section .isr_vector, "a", %progbits + .type g_pfnVectors, %object + .size g_pfnVectors, .-g_pfnVectors g_pfnVectors: - .word _estack - .word Reset_Handler - .word NMI_Handler - .word HardFault_Handler - .word MemManage_Handler - .word BusFault_Handler - .word UsageFault_Handler - .word 0 - .word 0 - .word 0 - .word 0 - .word SVC_Handler - .word DebugMon_Handler - .word 0 - .word PendSV_Handler - .word SysTick_Handler + .word _estack + .word Reset_Handler + .word NMI_Handler + .word HardFault_Handler + .word MemManage_Handler + .word BusFault_Handler + .word UsageFault_Handler + .word 0 + .word 0 + .word 0 + .word 0 + .word SVC_Handler + .word DebugMon_Handler + .word 0 + .word PendSV_Handler + .word SysTick_Handler - /* External Interrupts */ - .word WWDG_IRQHandler /* Window WatchDog */ - .word PVD_IRQHandler /* PVD through EXTI Line detection */ - .word TAMP_STAMP_IRQHandler /* Tamper and TimeStamps through the EXTI line */ - .word RTC_WKUP_IRQHandler /* RTC Wakeup through the EXTI line */ - .word FLASH_IRQHandler /* FLASH */ - .word RCC_IRQHandler /* RCC */ - .word EXTI0_IRQHandler /* EXTI Line0 */ - .word EXTI1_IRQHandler /* EXTI Line1 */ - .word EXTI2_IRQHandler /* EXTI Line2 */ - .word EXTI3_IRQHandler /* EXTI Line3 */ - .word EXTI4_IRQHandler /* EXTI Line4 */ - .word DMA1_Stream0_IRQHandler /* DMA1 Stream 0 */ - .word DMA1_Stream1_IRQHandler /* DMA1 Stream 1 */ - .word DMA1_Stream2_IRQHandler /* DMA1 Stream 2 */ - .word DMA1_Stream3_IRQHandler /* DMA1 Stream 3 */ - .word DMA1_Stream4_IRQHandler /* DMA1 Stream 4 */ - .word DMA1_Stream5_IRQHandler /* DMA1 Stream 5 */ - .word DMA1_Stream6_IRQHandler /* DMA1 Stream 6 */ - .word ADC_IRQHandler /* ADC1, ADC2 and ADC3s */ - .word CAN1_TX_IRQHandler /* CAN1 TX */ - .word CAN1_RX0_IRQHandler /* CAN1 RX0 */ - .word CAN1_RX1_IRQHandler /* CAN1 RX1 */ - .word CAN1_SCE_IRQHandler /* CAN1 SCE */ - .word EXTI9_5_IRQHandler /* External Line[9:5]s */ - .word TIM1_BRK_TIM9_IRQHandler /* TIM1 Break and TIM9 */ - .word TIM1_UP_TIM10_IRQHandler /* TIM1 Update and TIM10 */ - .word TIM1_TRG_COM_TIM11_IRQHandler /* TIM1 Trigger and Commutation and TIM11 */ - .word TIM1_CC_IRQHandler /* TIM1 Capture Compare */ - .word TIM2_IRQHandler /* TIM2 */ - .word TIM3_IRQHandler /* TIM3 */ - .word TIM4_IRQHandler /* TIM4 */ - .word I2C1_EV_IRQHandler /* I2C1 Event */ - .word I2C1_ER_IRQHandler /* I2C1 Error */ - .word I2C2_EV_IRQHandler /* I2C2 Event */ - .word I2C2_ER_IRQHandler /* I2C2 Error */ - .word SPI1_IRQHandler /* SPI1 */ - .word SPI2_IRQHandler /* SPI2 */ - .word USART1_IRQHandler /* USART1 */ - .word USART2_IRQHandler /* USART2 */ - .word USART3_IRQHandler /* USART3 */ - .word EXTI15_10_IRQHandler /* External Line[15:10]s */ - .word RTC_Alarm_IRQHandler /* RTC Alarm (A and B) through EXTI Line */ - .word OTG_FS_WKUP_IRQHandler /* USB OTG FS Wakeup through EXTI line */ - .word TIM8_BRK_TIM12_IRQHandler /* TIM8 Break and TIM12 */ - .word TIM8_UP_TIM13_IRQHandler /* TIM8 Update and TIM13 */ - .word TIM8_TRG_COM_TIM14_IRQHandler /* TIM8 Trigger and Commutation and TIM14 */ - .word TIM8_CC_IRQHandler /* TIM8 Capture Compare */ - .word DMA1_Stream7_IRQHandler /* DMA1 Stream7 */ - .word FSMC_IRQHandler /* FSMC */ - .word SDIO_IRQHandler /* SDIO */ - .word TIM5_IRQHandler /* TIM5 */ - .word SPI3_IRQHandler /* SPI3 */ - .word UART4_IRQHandler /* UART4 */ - .word UART5_IRQHandler /* UART5 */ - .word TIM6_DAC_IRQHandler /* TIM6 and DAC1&2 underrun errors */ - .word TIM7_IRQHandler /* TIM7 */ - .word DMA2_Stream0_IRQHandler /* DMA2 Stream 0 */ - .word DMA2_Stream1_IRQHandler /* DMA2 Stream 1 */ - .word DMA2_Stream2_IRQHandler /* DMA2 Stream 2 */ - .word DMA2_Stream3_IRQHandler /* DMA2 Stream 3 */ - .word DMA2_Stream4_IRQHandler /* DMA2 Stream 4 */ - .word ETH_IRQHandler /* Ethernet */ - .word ETH_WKUP_IRQHandler /* Ethernet Wakeup through EXTI line */ - .word CAN2_TX_IRQHandler /* CAN2 TX */ - .word CAN2_RX0_IRQHandler /* CAN2 RX0 */ - .word CAN2_RX1_IRQHandler /* CAN2 RX1 */ - .word CAN2_SCE_IRQHandler /* CAN2 SCE */ - .word OTG_FS_IRQHandler /* USB OTG FS */ - .word DMA2_Stream5_IRQHandler /* DMA2 Stream 5 */ - .word DMA2_Stream6_IRQHandler /* DMA2 Stream 6 */ - .word DMA2_Stream7_IRQHandler /* DMA2 Stream 7 */ - .word USART6_IRQHandler /* USART6 */ - .word I2C3_EV_IRQHandler /* I2C3 event */ - .word I2C3_ER_IRQHandler /* I2C3 error */ - .word OTG_HS_EP1_OUT_IRQHandler /* USB OTG HS End Point 1 Out */ - .word OTG_HS_EP1_IN_IRQHandler /* USB OTG HS End Point 1 In */ - .word OTG_HS_WKUP_IRQHandler /* USB OTG HS Wakeup through EXTI */ - .word OTG_HS_IRQHandler /* USB OTG HS */ - .word DCMI_IRQHandler /* DCMI */ - .word CRYP_IRQHandler /* CRYP crypto */ - .word HASH_RNG_IRQHandler /* Hash and Rng */ - .word FPU_IRQHandler /* FPU */ + /* External Interrupts */ + .word WWDG_IRQHandler /* Window WatchDog */ + .word PVD_IRQHandler /* PVD through EXTI Line detection */ + .word TAMP_STAMP_IRQHandler /* Tamper and TimeStamps through the EXTI line */ + .word RTC_WKUP_IRQHandler /* RTC Wakeup through the EXTI line */ + .word FLASH_IRQHandler /* FLASH */ + .word RCC_IRQHandler /* RCC */ + .word EXTI0_IRQHandler /* EXTI Line0 */ + .word EXTI1_IRQHandler /* EXTI Line1 */ + .word EXTI2_IRQHandler /* EXTI Line2 */ + .word EXTI3_IRQHandler /* EXTI Line3 */ + .word EXTI4_IRQHandler /* EXTI Line4 */ + .word DMA1_Stream0_IRQHandler /* DMA1 Stream 0 */ + .word DMA1_Stream1_IRQHandler /* DMA1 Stream 1 */ + .word DMA1_Stream2_IRQHandler /* DMA1 Stream 2 */ + .word DMA1_Stream3_IRQHandler /* DMA1 Stream 3 */ + .word DMA1_Stream4_IRQHandler /* DMA1 Stream 4 */ + .word DMA1_Stream5_IRQHandler /* DMA1 Stream 5 */ + .word DMA1_Stream6_IRQHandler /* DMA1 Stream 6 */ + .word ADC_IRQHandler /* ADC1, ADC2 and ADC3s */ + .word CAN1_TX_IRQHandler /* CAN1 TX */ + .word CAN1_RX0_IRQHandler /* CAN1 RX0 */ + .word CAN1_RX1_IRQHandler /* CAN1 RX1 */ + .word CAN1_SCE_IRQHandler /* CAN1 SCE */ + .word EXTI9_5_IRQHandler /* External Line[9:5]s */ + .word TIM1_BRK_TIM9_IRQHandler /* TIM1 Break and TIM9 */ + .word TIM1_UP_TIM10_IRQHandler /* TIM1 Update and TIM10 */ + .word TIM1_TRG_COM_TIM11_IRQHandler /* TIM1 Trigger and Commutation and TIM11 */ + .word TIM1_CC_IRQHandler /* TIM1 Capture Compare */ + .word TIM2_IRQHandler /* TIM2 */ + .word TIM3_IRQHandler /* TIM3 */ + .word TIM4_IRQHandler /* TIM4 */ + .word I2C1_EV_IRQHandler /* I2C1 Event */ + .word I2C1_ER_IRQHandler /* I2C1 Error */ + .word I2C2_EV_IRQHandler /* I2C2 Event */ + .word I2C2_ER_IRQHandler /* I2C2 Error */ + .word SPI1_IRQHandler /* SPI1 */ + .word SPI2_IRQHandler /* SPI2 */ + .word USART1_IRQHandler /* USART1 */ + .word USART2_IRQHandler /* USART2 */ + .word USART3_IRQHandler /* USART3 */ + .word EXTI15_10_IRQHandler /* External Line[15:10]s */ + .word RTC_Alarm_IRQHandler /* RTC Alarm (A and B) through EXTI Line */ + .word OTG_FS_WKUP_IRQHandler /* USB OTG FS Wakeup through EXTI line */ + .word TIM8_BRK_TIM12_IRQHandler /* TIM8 Break and TIM12 */ + .word TIM8_UP_TIM13_IRQHandler /* TIM8 Update and TIM13 */ + .word TIM8_TRG_COM_TIM14_IRQHandler /* TIM8 Trigger and Commutation and TIM14 */ + .word TIM8_CC_IRQHandler /* TIM8 Capture Compare */ + .word DMA1_Stream7_IRQHandler /* DMA1 Stream7 */ + .word FSMC_IRQHandler /* FSMC */ + .word SDIO_IRQHandler /* SDIO */ + .word TIM5_IRQHandler /* TIM5 */ + .word SPI3_IRQHandler /* SPI3 */ + .word UART4_IRQHandler /* UART4 */ + .word UART5_IRQHandler /* UART5 */ + .word TIM6_DAC_IRQHandler /* TIM6 and DAC1&2 underrun errors */ + .word TIM7_IRQHandler /* TIM7 */ + .word DMA2_Stream0_IRQHandler /* DMA2 Stream 0 */ + .word DMA2_Stream1_IRQHandler /* DMA2 Stream 1 */ + .word DMA2_Stream2_IRQHandler /* DMA2 Stream 2 */ + .word DMA2_Stream3_IRQHandler /* DMA2 Stream 3 */ + .word DMA2_Stream4_IRQHandler /* DMA2 Stream 4 */ + .word ETH_IRQHandler /* Ethernet */ + .word ETH_WKUP_IRQHandler /* Ethernet Wakeup through EXTI line */ + .word CAN2_TX_IRQHandler /* CAN2 TX */ + .word CAN2_RX0_IRQHandler /* CAN2 RX0 */ + .word CAN2_RX1_IRQHandler /* CAN2 RX1 */ + .word CAN2_SCE_IRQHandler /* CAN2 SCE */ + .word OTG_FS_IRQHandler /* USB OTG FS */ + .word DMA2_Stream5_IRQHandler /* DMA2 Stream 5 */ + .word DMA2_Stream6_IRQHandler /* DMA2 Stream 6 */ + .word DMA2_Stream7_IRQHandler /* DMA2 Stream 7 */ + .word USART6_IRQHandler /* USART6 */ + .word I2C3_EV_IRQHandler /* I2C3 event */ + .word I2C3_ER_IRQHandler /* I2C3 error */ + .word OTG_HS_EP1_OUT_IRQHandler /* USB OTG HS End Point 1 Out */ + .word OTG_HS_EP1_IN_IRQHandler /* USB OTG HS End Point 1 In */ + .word OTG_HS_WKUP_IRQHandler /* USB OTG HS Wakeup through EXTI */ + .word OTG_HS_IRQHandler /* USB OTG HS */ + .word DCMI_IRQHandler /* DCMI */ + .word CRYP_IRQHandler /* CRYP crypto */ + .word HASH_RNG_IRQHandler /* Hash and Rng */ + .word FPU_IRQHandler /* FPU */ /** - * \brief Provide weak aliases for each Exception handler to the - * Default_Handler. As they are weak aliases, any function - * with the same name will override this definition. + * \brief Provide weak aliases for each Exception handler to the + * Default_Handler. As they are weak aliases, any function + * with the same name will override this definition. */ - .weak NMI_Handler - .thumb_set NMI_Handler, Default_Handler + .weak NMI_Handler + .thumb_set NMI_Handler, Default_Handler - .weak HardFault_Handler - .thumb_set HardFault_Handler, Default_Handler + .weak HardFault_Handler + .thumb_set HardFault_Handler, Default_Handler - .weak MemManage_Handler - .thumb_set MemManage_Handler, Default_Handler + .weak MemManage_Handler + .thumb_set MemManage_Handler, Default_Handler - .weak BusFault_Handler - .thumb_set BusFault_Handler, Default_Handler + .weak BusFault_Handler + .thumb_set BusFault_Handler, Default_Handler - .weak UsageFault_Handler - .thumb_set UsageFault_Handler, Default_Handler + .weak UsageFault_Handler + .thumb_set UsageFault_Handler, Default_Handler - .weak SVC_Handler - .thumb_set SVC_Handler, Default_Handler + .weak SVC_Handler + .thumb_set SVC_Handler, Default_Handler - .weak DebugMon_Handler - .thumb_set DebugMon_Handler, Default_Handler + .weak DebugMon_Handler + .thumb_set DebugMon_Handler, Default_Handler - .weak PendSV_Handler - .thumb_set PendSV_Handler, Default_Handler + .weak PendSV_Handler + .thumb_set PendSV_Handler, Default_Handler - .weak SysTick_Handler - .thumb_set SysTick_Handler, Default_Handler + .weak SysTick_Handler + .thumb_set SysTick_Handler, Default_Handler - .weak WWDG_IRQHandler - .thumb_set WWDG_IRQHandler, Default_Handler + .weak WWDG_IRQHandler + .thumb_set WWDG_IRQHandler, Default_Handler - .weak PVD_IRQHandler - .thumb_set PVD_IRQHandler, Default_Handler + .weak PVD_IRQHandler + .thumb_set PVD_IRQHandler, Default_Handler - .weak TAMP_STAMP_IRQHandler - .thumb_set TAMP_STAMP_IRQHandler, Default_Handler + .weak TAMP_STAMP_IRQHandler + .thumb_set TAMP_STAMP_IRQHandler, Default_Handler - .weak RTC_WKUP_IRQHandler - .thumb_set RTC_WKUP_IRQHandler, Default_Handler + .weak RTC_WKUP_IRQHandler + .thumb_set RTC_WKUP_IRQHandler, Default_Handler - .weak FLASH_IRQHandler - .thumb_set FLASH_IRQHandler, Default_Handler + .weak FLASH_IRQHandler + .thumb_set FLASH_IRQHandler, Default_Handler - .weak RCC_IRQHandler - .thumb_set RCC_IRQHandler, Default_Handler + .weak RCC_IRQHandler + .thumb_set RCC_IRQHandler, Default_Handler - .weak EXTI0_IRQHandler - .thumb_set EXTI0_IRQHandler, Default_Handler + .weak EXTI0_IRQHandler + .thumb_set EXTI0_IRQHandler, Default_Handler - .weak EXTI1_IRQHandler - .thumb_set EXTI1_IRQHandler, Default_Handler + .weak EXTI1_IRQHandler + .thumb_set EXTI1_IRQHandler, Default_Handler - .weak EXTI2_IRQHandler - .thumb_set EXTI2_IRQHandler, Default_Handler + .weak EXTI2_IRQHandler + .thumb_set EXTI2_IRQHandler, Default_Handler - .weak EXTI3_IRQHandler - .thumb_set EXTI3_IRQHandler, Default_Handler + .weak EXTI3_IRQHandler + .thumb_set EXTI3_IRQHandler, Default_Handler - .weak EXTI4_IRQHandler - .thumb_set EXTI4_IRQHandler, Default_Handler + .weak EXTI4_IRQHandler + .thumb_set EXTI4_IRQHandler, Default_Handler - .weak DMA1_Stream0_IRQHandler - .thumb_set DMA1_Stream0_IRQHandler, Default_Handler + .weak DMA1_Stream0_IRQHandler + .thumb_set DMA1_Stream0_IRQHandler, Default_Handler - .weak DMA1_Stream1_IRQHandler - .thumb_set DMA1_Stream1_IRQHandler, Default_Handler + .weak DMA1_Stream1_IRQHandler + .thumb_set DMA1_Stream1_IRQHandler, Default_Handler - .weak DMA1_Stream2_IRQHandler - .thumb_set DMA1_Stream2_IRQHandler, Default_Handler + .weak DMA1_Stream2_IRQHandler + .thumb_set DMA1_Stream2_IRQHandler, Default_Handler - .weak DMA1_Stream3_IRQHandler - .thumb_set DMA1_Stream3_IRQHandler, Default_Handler + .weak DMA1_Stream3_IRQHandler + .thumb_set DMA1_Stream3_IRQHandler, Default_Handler - .weak DMA1_Stream4_IRQHandler - .thumb_set DMA1_Stream4_IRQHandler, Default_Handler + .weak DMA1_Stream4_IRQHandler + .thumb_set DMA1_Stream4_IRQHandler, Default_Handler - .weak DMA1_Stream5_IRQHandler - .thumb_set DMA1_Stream5_IRQHandler, Default_Handler + .weak DMA1_Stream5_IRQHandler + .thumb_set DMA1_Stream5_IRQHandler, Default_Handler - .weak DMA1_Stream6_IRQHandler - .thumb_set DMA1_Stream6_IRQHandler, Default_Handler + .weak DMA1_Stream6_IRQHandler + .thumb_set DMA1_Stream6_IRQHandler, Default_Handler - .weak ADC_IRQHandler - .thumb_set ADC_IRQHandler, Default_Handler + .weak ADC_IRQHandler + .thumb_set ADC_IRQHandler, Default_Handler - .weak CAN1_TX_IRQHandler - .thumb_set CAN1_TX_IRQHandler, Default_Handler + .weak CAN1_TX_IRQHandler + .thumb_set CAN1_TX_IRQHandler, Default_Handler - .weak CAN1_RX0_IRQHandler - .thumb_set CAN1_RX0_IRQHandler, Default_Handler + .weak CAN1_RX0_IRQHandler + .thumb_set CAN1_RX0_IRQHandler, Default_Handler - .weak CAN1_RX1_IRQHandler - .thumb_set CAN1_RX1_IRQHandler, Default_Handler + .weak CAN1_RX1_IRQHandler + .thumb_set CAN1_RX1_IRQHandler, Default_Handler - .weak CAN1_SCE_IRQHandler - .thumb_set CAN1_SCE_IRQHandler, Default_Handler + .weak CAN1_SCE_IRQHandler + .thumb_set CAN1_SCE_IRQHandler, Default_Handler - .weak EXTI9_5_IRQHandler - .thumb_set EXTI9_5_IRQHandler, Default_Handler + .weak EXTI9_5_IRQHandler + .thumb_set EXTI9_5_IRQHandler, Default_Handler - .weak TIM1_BRK_TIM9_IRQHandler - .thumb_set TIM1_BRK_TIM9_IRQHandler, Default_Handler + .weak TIM1_BRK_TIM9_IRQHandler + .thumb_set TIM1_BRK_TIM9_IRQHandler, Default_Handler - .weak TIM1_UP_TIM10_IRQHandler - .thumb_set TIM1_UP_TIM10_IRQHandler, Default_Handler + .weak TIM1_UP_TIM10_IRQHandler + .thumb_set TIM1_UP_TIM10_IRQHandler, Default_Handler - .weak TIM1_TRG_COM_TIM11_IRQHandler - .thumb_set TIM1_TRG_COM_TIM11_IRQHandler, Default_Handler + .weak TIM1_TRG_COM_TIM11_IRQHandler + .thumb_set TIM1_TRG_COM_TIM11_IRQHandler, Default_Handler - .weak TIM1_CC_IRQHandler - .thumb_set TIM1_CC_IRQHandler, Default_Handler + .weak TIM1_CC_IRQHandler + .thumb_set TIM1_CC_IRQHandler, Default_Handler - .weak TIM2_IRQHandler - .thumb_set TIM2_IRQHandler, Default_Handler + .weak TIM2_IRQHandler + .thumb_set TIM2_IRQHandler, Default_Handler - .weak TIM3_IRQHandler - .thumb_set TIM3_IRQHandler, Default_Handler + .weak TIM3_IRQHandler + .thumb_set TIM3_IRQHandler, Default_Handler - .weak TIM4_IRQHandler - .thumb_set TIM4_IRQHandler, Default_Handler + .weak TIM4_IRQHandler + .thumb_set TIM4_IRQHandler, Default_Handler - .weak I2C1_EV_IRQHandler - .thumb_set I2C1_EV_IRQHandler, Default_Handler + .weak I2C1_EV_IRQHandler + .thumb_set I2C1_EV_IRQHandler, Default_Handler - .weak I2C1_ER_IRQHandler - .thumb_set I2C1_ER_IRQHandler, Default_Handler + .weak I2C1_ER_IRQHandler + .thumb_set I2C1_ER_IRQHandler, Default_Handler - .weak I2C2_EV_IRQHandler - .thumb_set I2C2_EV_IRQHandler, Default_Handler + .weak I2C2_EV_IRQHandler + .thumb_set I2C2_EV_IRQHandler, Default_Handler - .weak I2C2_ER_IRQHandler - .thumb_set I2C2_ER_IRQHandler, Default_Handler + .weak I2C2_ER_IRQHandler + .thumb_set I2C2_ER_IRQHandler, Default_Handler - .weak SPI1_IRQHandler - .thumb_set SPI1_IRQHandler, Default_Handler + .weak SPI1_IRQHandler + .thumb_set SPI1_IRQHandler, Default_Handler - .weak SPI2_IRQHandler - .thumb_set SPI2_IRQHandler, Default_Handler + .weak SPI2_IRQHandler + .thumb_set SPI2_IRQHandler, Default_Handler - .weak USART1_IRQHandler - .thumb_set USART1_IRQHandler, Default_Handler + .weak USART1_IRQHandler + .thumb_set USART1_IRQHandler, Default_Handler - .weak USART2_IRQHandler - .thumb_set USART2_IRQHandler, Default_Handler + .weak USART2_IRQHandler + .thumb_set USART2_IRQHandler, Default_Handler - .weak USART3_IRQHandler - .thumb_set USART3_IRQHandler, Default_Handler + .weak USART3_IRQHandler + .thumb_set USART3_IRQHandler, Default_Handler - .weak EXTI15_10_IRQHandler - .thumb_set EXTI15_10_IRQHandler, Default_Handler + .weak EXTI15_10_IRQHandler + .thumb_set EXTI15_10_IRQHandler, Default_Handler - .weak RTC_Alarm_IRQHandler - .thumb_set RTC_Alarm_IRQHandler, Default_Handler + .weak RTC_Alarm_IRQHandler + .thumb_set RTC_Alarm_IRQHandler, Default_Handler - .weak OTG_FS_WKUP_IRQHandler - .thumb_set OTG_FS_WKUP_IRQHandler, Default_Handler + .weak OTG_FS_WKUP_IRQHandler + .thumb_set OTG_FS_WKUP_IRQHandler, Default_Handler - .weak TIM8_BRK_TIM12_IRQHandler - .thumb_set TIM8_BRK_TIM12_IRQHandler, Default_Handler + .weak TIM8_BRK_TIM12_IRQHandler + .thumb_set TIM8_BRK_TIM12_IRQHandler, Default_Handler - .weak TIM8_UP_TIM13_IRQHandler - .thumb_set TIM8_UP_TIM13_IRQHandler, Default_Handler + .weak TIM8_UP_TIM13_IRQHandler + .thumb_set TIM8_UP_TIM13_IRQHandler, Default_Handler - .weak TIM8_TRG_COM_TIM14_IRQHandler - .thumb_set TIM8_TRG_COM_TIM14_IRQHandler, Default_Handler + .weak TIM8_TRG_COM_TIM14_IRQHandler + .thumb_set TIM8_TRG_COM_TIM14_IRQHandler, Default_Handler - .weak TIM8_CC_IRQHandler - .thumb_set TIM8_CC_IRQHandler, Default_Handler + .weak TIM8_CC_IRQHandler + .thumb_set TIM8_CC_IRQHandler, Default_Handler - .weak DMA1_Stream7_IRQHandler - .thumb_set DMA1_Stream7_IRQHandler, Default_Handler + .weak DMA1_Stream7_IRQHandler + .thumb_set DMA1_Stream7_IRQHandler, Default_Handler - .weak FSMC_IRQHandler - .thumb_set FSMC_IRQHandler, Default_Handler + .weak FSMC_IRQHandler + .thumb_set FSMC_IRQHandler, Default_Handler - .weak SDIO_IRQHandler - .thumb_set SDIO_IRQHandler, Default_Handler + .weak SDIO_IRQHandler + .thumb_set SDIO_IRQHandler, Default_Handler - .weak TIM5_IRQHandler - .thumb_set TIM5_IRQHandler, Default_Handler + .weak TIM5_IRQHandler + .thumb_set TIM5_IRQHandler, Default_Handler - .weak SPI3_IRQHandler - .thumb_set SPI3_IRQHandler, Default_Handler + .weak SPI3_IRQHandler + .thumb_set SPI3_IRQHandler, Default_Handler - .weak UART4_IRQHandler - .thumb_set UART4_IRQHandler, Default_Handler + .weak UART4_IRQHandler + .thumb_set UART4_IRQHandler, Default_Handler - .weak UART5_IRQHandler - .thumb_set UART5_IRQHandler, Default_Handler + .weak UART5_IRQHandler + .thumb_set UART5_IRQHandler, Default_Handler - .weak TIM6_DAC_IRQHandler - .thumb_set TIM6_DAC_IRQHandler, Default_Handler + .weak TIM6_DAC_IRQHandler + .thumb_set TIM6_DAC_IRQHandler, Default_Handler - .weak TIM7_IRQHandler - .thumb_set TIM7_IRQHandler, Default_Handler + .weak TIM7_IRQHandler + .thumb_set TIM7_IRQHandler, Default_Handler - .weak DMA2_Stream0_IRQHandler - .thumb_set DMA2_Stream0_IRQHandler, Default_Handler + .weak DMA2_Stream0_IRQHandler + .thumb_set DMA2_Stream0_IRQHandler, Default_Handler - .weak DMA2_Stream1_IRQHandler - .thumb_set DMA2_Stream1_IRQHandler, Default_Handler + .weak DMA2_Stream1_IRQHandler + .thumb_set DMA2_Stream1_IRQHandler, Default_Handler - .weak DMA2_Stream2_IRQHandler - .thumb_set DMA2_Stream2_IRQHandler, Default_Handler + .weak DMA2_Stream2_IRQHandler + .thumb_set DMA2_Stream2_IRQHandler, Default_Handler - .weak DMA2_Stream3_IRQHandler - .thumb_set DMA2_Stream3_IRQHandler, Default_Handler + .weak DMA2_Stream3_IRQHandler + .thumb_set DMA2_Stream3_IRQHandler, Default_Handler - .weak DMA2_Stream4_IRQHandler - .thumb_set DMA2_Stream4_IRQHandler, Default_Handler + .weak DMA2_Stream4_IRQHandler + .thumb_set DMA2_Stream4_IRQHandler, Default_Handler - .weak ETH_IRQHandler - .thumb_set ETH_IRQHandler, Default_Handler + .weak ETH_IRQHandler + .thumb_set ETH_IRQHandler, Default_Handler - .weak ETH_WKUP_IRQHandler - .thumb_set ETH_WKUP_IRQHandler, Default_Handler + .weak ETH_WKUP_IRQHandler + .thumb_set ETH_WKUP_IRQHandler, Default_Handler - .weak CAN2_TX_IRQHandler - .thumb_set CAN2_TX_IRQHandler, Default_Handler + .weak CAN2_TX_IRQHandler + .thumb_set CAN2_TX_IRQHandler, Default_Handler - .weak CAN2_RX0_IRQHandler - .thumb_set CAN2_RX0_IRQHandler, Default_Handler + .weak CAN2_RX0_IRQHandler + .thumb_set CAN2_RX0_IRQHandler, Default_Handler - .weak CAN2_RX1_IRQHandler - .thumb_set CAN2_RX1_IRQHandler, Default_Handler + .weak CAN2_RX1_IRQHandler + .thumb_set CAN2_RX1_IRQHandler, Default_Handler - .weak CAN2_SCE_IRQHandler - .thumb_set CAN2_SCE_IRQHandler, Default_Handler + .weak CAN2_SCE_IRQHandler + .thumb_set CAN2_SCE_IRQHandler, Default_Handler - .weak OTG_FS_IRQHandler - .thumb_set OTG_FS_IRQHandler, Default_Handler + .weak OTG_FS_IRQHandler + .thumb_set OTG_FS_IRQHandler, Default_Handler - .weak DMA2_Stream5_IRQHandler - .thumb_set DMA2_Stream5_IRQHandler, Default_Handler + .weak DMA2_Stream5_IRQHandler + .thumb_set DMA2_Stream5_IRQHandler, Default_Handler - .weak DMA2_Stream6_IRQHandler - .thumb_set DMA2_Stream6_IRQHandler, Default_Handler + .weak DMA2_Stream6_IRQHandler + .thumb_set DMA2_Stream6_IRQHandler, Default_Handler - .weak DMA2_Stream7_IRQHandler - .thumb_set DMA2_Stream7_IRQHandler, Default_Handler + .weak DMA2_Stream7_IRQHandler + .thumb_set DMA2_Stream7_IRQHandler, Default_Handler - .weak USART6_IRQHandler - .thumb_set USART6_IRQHandler, Default_Handler + .weak USART6_IRQHandler + .thumb_set USART6_IRQHandler, Default_Handler - .weak I2C3_EV_IRQHandler - .thumb_set I2C3_EV_IRQHandler, Default_Handler + .weak I2C3_EV_IRQHandler + .thumb_set I2C3_EV_IRQHandler, Default_Handler - .weak I2C3_ER_IRQHandler - .thumb_set I2C3_ER_IRQHandler, Default_Handler + .weak I2C3_ER_IRQHandler + .thumb_set I2C3_ER_IRQHandler, Default_Handler - .weak OTG_HS_EP1_OUT_IRQHandler - .thumb_set OTG_HS_EP1_OUT_IRQHandler, Default_Handler + .weak OTG_HS_EP1_OUT_IRQHandler + .thumb_set OTG_HS_EP1_OUT_IRQHandler, Default_Handler - .weak OTG_HS_EP1_IN_IRQHandler - .thumb_set OTG_HS_EP1_IN_IRQHandler, Default_Handler + .weak OTG_HS_EP1_IN_IRQHandler + .thumb_set OTG_HS_EP1_IN_IRQHandler, Default_Handler - .weak OTG_HS_WKUP_IRQHandler - .thumb_set OTG_HS_WKUP_IRQHandler, Default_Handler + .weak OTG_HS_WKUP_IRQHandler + .thumb_set OTG_HS_WKUP_IRQHandler, Default_Handler - .weak OTG_HS_IRQHandler - .thumb_set OTG_HS_IRQHandler, Default_Handler + .weak OTG_HS_IRQHandler + .thumb_set OTG_HS_IRQHandler, Default_Handler - .weak DCMI_IRQHandler - .thumb_set DCMI_IRQHandler, Default_Handler + .weak DCMI_IRQHandler + .thumb_set DCMI_IRQHandler, Default_Handler - .weak CRYP_IRQHandler - .thumb_set CRYP_IRQHandler, Default_Handler + .weak CRYP_IRQHandler + .thumb_set CRYP_IRQHandler, Default_Handler - .weak HASH_RNG_IRQHandler - .thumb_set HASH_RNG_IRQHandler, Default_Handler + .weak HASH_RNG_IRQHandler + .thumb_set HASH_RNG_IRQHandler, Default_Handler - .weak FPU_IRQHandler - .thumb_set FPU_IRQHandler, Default_Handler + .weak FPU_IRQHandler + .thumb_set FPU_IRQHandler, Default_Handler - .weak vApplicationMallocFailedHook - .thumb_set vApplicationMallocFailedHook, Default_Handler + .weak vApplicationMallocFailedHook + .thumb_set vApplicationMallocFailedHook, Default_Handler - .weak vApplicationStackOverflowHook - .thumb_set vApplicationStackOverflowHook, Default_Handler + .weak vApplicationStackOverflowHook + .thumb_set vApplicationStackOverflowHook, Default_Handler diff --git a/src/syscalls.c b/src/syscalls.c index 046640a..e77807d 100644 --- a/src/syscalls.c +++ b/src/syscalls.c @@ -1,16 +1,16 @@ /** ***************************************************************************** - * @addtogroup CARME + * @addtogroup CARME * @{ - * @addtogroup USART + * @addtogroup USART * @{ * - * @file syscalls.c + * @file syscalls.c * - * @brief Atollic TrueSTUDIO Minimal System calls file\n - * For more information about which c-functions need which of - * these lowlevel functions please consult the Newlib - * libc-manual. + * @brief Atollic TrueSTUDIO Minimal System calls file\n + * For more information about which c-functions need which of + * these lowlevel functions please consult the Newlib + * libc-manual. * ***************************************************************************** * @copyright @@ -46,7 +46,7 @@ extern "C" { /*----- Macros -------------------------------------------------------------*/ #ifndef SYSCALL_USART -#define SYSCALL_USART USART1 /**< The IO USART to use in syscall */ +#define SYSCALL_USART USART1 /**< The IO USART to use in syscall */ #endif /*----- Data types ---------------------------------------------------------*/ @@ -84,147 +84,147 @@ void initialise_monitor_handles(void) { } int _getpid(void) { - return 1; + return 1; } int _kill(int32_t pid, int32_t sig) { - errno = EINVAL; - return -1; + errno = EINVAL; + return -1; } void _exit(int32_t status) { - _kill(status, -1); - while (1) { - /* Make sure we hang here */ - } + _kill(status, -1); + while (1) { + /* Make sure we hang here */ + } } int _write(int fd, char *str, int len) { - uint8_t i = 0U; + uint8_t i = 0U; - if (str == NULL) { - return -1; - } + if (str == NULL) { + return -1; + } - for (i = 0U; i < len; i++) { - while (USART_GetFlagStatus(SYSCALL_USART, USART_FLAG_TC) == RESET) { - } - USART_SendData(SYSCALL_USART, (uint16_t) *str); - str++; - } + for (i = 0U; i < len; i++) { + while (USART_GetFlagStatus(SYSCALL_USART, USART_FLAG_TC) == RESET) { + } + USART_SendData(SYSCALL_USART, (uint16_t) *str); + str++; + } - return len; + return len; } caddr_t _sbrk(int32_t incr) { - extern uint32_t _Min_Heap_Size; /* _Min_Heap_Size symbol defined in the linker script. */ - extern uint8_t end asm("end"); - const uint8_t *max_heap = (uint8_t*) ((uint32_t) &end - + (uint32_t) &_Min_Heap_Size); - static uint8_t *heap_end; - uint8_t *prev_heap_end; + extern uint32_t _Min_Heap_Size; /* _Min_Heap_Size symbol defined in the linker script. */ + extern uint8_t end asm("end"); + const uint8_t *max_heap = (uint8_t*) ((uint32_t) &end + + (uint32_t) &_Min_Heap_Size); + static uint8_t *heap_end; + uint8_t *prev_heap_end; - if (heap_end == 0) { - heap_end = &end; - } + if (heap_end == 0) { + heap_end = &end; + } - prev_heap_end = heap_end; - if ((heap_end + incr) > max_heap) { + prev_heap_end = heap_end; + if ((heap_end + incr) > max_heap) { /* - write(1, "Heap and stack collision\n", 25); - abort(); + write(1, "Heap and stack collision\n", 25); + abort(); */ - errno = ENOMEM; - return (caddr_t) -1; - } + errno = ENOMEM; + return (caddr_t) -1; + } - heap_end += incr; + heap_end += incr; - return (caddr_t) prev_heap_end; + return (caddr_t) prev_heap_end; } int _close(int32_t file) { - return -1; + return -1; } int _fstat(int32_t file, struct stat *st) { - st->st_mode = S_IFCHR; - return 0; + st->st_mode = S_IFCHR; + return 0; } int _isatty(int32_t file) { - return 1; + return 1; } int _lseek(int32_t file, int32_t ptr, int32_t dir) { - return 0; + return 0; } int _read(int32_t file, uint8_t *ptr, int32_t len) { - uint32_t i = 0U; - uint16_t res = 0U; + uint32_t i = 0U; + uint16_t res = 0U; - if (ptr == NULL) { - return -1; - } + if (ptr == NULL) { + return -1; + } - for (i = 0U; i < len; i++) { + for (i = 0U; i < len; i++) { - if (USART_GetFlagStatus(SYSCALL_USART, USART_FLAG_RXNE) == SET) { - res = USART_ReceiveData(SYSCALL_USART); - if (res <= 0xFF) { - *ptr = (uint8_t) (res & 0xFF); - ptr++; - } - } - else { - break; - } - } + if (USART_GetFlagStatus(SYSCALL_USART, USART_FLAG_RXNE) == SET) { + res = USART_ReceiveData(SYSCALL_USART); + if (res <= 0xFF) { + *ptr = (uint8_t) (res & 0xFF); + ptr++; + } + } + else { + break; + } + } - return (int) i; + return (int) i; } int _open(uint8_t *path, int32_t flags, ...) { - /* Pretend like we always fail */ - return -1; + /* Pretend like we always fail */ + return -1; } int _wait(int32_t *status) { - errno = ECHILD; - return -1; + errno = ECHILD; + return -1; } int _unlink(uint8_t *name) { - errno = ENOENT; - return -1; + errno = ENOENT; + return -1; } int _times(struct tms *buf) { - return -1; + return -1; } int _stat(uint8_t *file, struct stat *st) { - st->st_mode = S_IFCHR; - return 0; + st->st_mode = S_IFCHR; + return 0; } int _link(uint8_t *old, uint8_t *new) { - errno = EMLINK; - return -1; + errno = EMLINK; + return -1; } int _fork(void) { - errno = EAGAIN; - return -1; + errno = EAGAIN; + return -1; } int _execve(uint8_t *name, uint8_t **argv, uint8_t **env) { - errno = ENOMEM; - return -1; + errno = ENOMEM; + return -1; } #ifdef __cplusplus