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