state machine, error handling, and twinkling led
This commit is contained in:
parent
a94c55d4a6
commit
b21b8dbf2d
23
bootloader.c
23
bootloader.c
|
@ -18,6 +18,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "uart_commands.h"
|
#include "uart_commands.h"
|
||||||
|
#include "timer.h"
|
||||||
|
|
||||||
error_code status;
|
error_code status;
|
||||||
|
|
||||||
|
@ -66,7 +67,10 @@ int is_code_valid(){
|
||||||
if(is_error == ok){
|
if(is_error == ok){
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else return 0;
|
else{
|
||||||
|
set_colour(RED);//code invalid, red led
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int is_b_pressed(){
|
int is_b_pressed(){
|
||||||
|
@ -99,9 +103,12 @@ void launch_program(){
|
||||||
|
|
||||||
void manage_bootloader(){
|
void manage_bootloader(){
|
||||||
cmd.argv = (char**)argvs;
|
cmd.argv = (char**)argvs;
|
||||||
while(1){
|
int var = 1;
|
||||||
|
char digit;
|
||||||
|
while(var){
|
||||||
uart_receive_command(buff);
|
uart_receive_command(buff);
|
||||||
uart_parse_command(buff, &cmd);
|
uart_parse_command(buff, &cmd);
|
||||||
|
set_colour(GREEN);
|
||||||
if ((state == S1) && (strncmp("GETID", cmd.argv[0], 5)==0)){
|
if ((state == S1) && (strncmp("GETID", cmd.argv[0], 5)==0)){
|
||||||
uart_commands_getid(&status);
|
uart_commands_getid(&status);
|
||||||
|
|
||||||
|
@ -137,11 +144,16 @@ void manage_bootloader(){
|
||||||
uart_send_ok();
|
uart_send_ok();
|
||||||
uart_send("bla\r\n", 5);//putting bla here so OK will show up
|
uart_send("bla\r\n", 5);//putting bla here so OK will show up
|
||||||
//removing bla for the moment will make ok not show up
|
//removing bla for the moment will make ok not show up
|
||||||
|
var = 0;
|
||||||
|
LPC_GPIO2->FIOCLR0 = 0xff;
|
||||||
launch_program();
|
launch_program();
|
||||||
}else{
|
}else{
|
||||||
state = S2;
|
state = S2;
|
||||||
uart_send_err();
|
uart_send_err();
|
||||||
//flash LED red
|
set_colour(RED);
|
||||||
|
itoa(is_error, &digit, 10);
|
||||||
|
uart_send(&digit, 1);
|
||||||
|
//flash LED red, and stays in the bootloader mode
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
uart_send_cmd_illeg();
|
uart_send_cmd_illeg();
|
||||||
|
@ -150,11 +162,8 @@ void manage_bootloader(){
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
//verify b is pressed
|
|
||||||
//checksum is correct (
|
|
||||||
//bootloader_init();
|
|
||||||
uart_init(115200);
|
uart_init(115200);
|
||||||
LPC_GPIO0->FIODIR &=~(1<<19); //do I really need this line?
|
timer_0();
|
||||||
if(is_b_pressed() == 0){
|
if(is_b_pressed() == 0){
|
||||||
if(is_code_valid()){
|
if(is_code_valid()){
|
||||||
launch_program();
|
launch_program();
|
||||||
|
|
122
uart_commands.c
122
uart_commands.c
|
@ -9,100 +9,6 @@ char CMD_ILLEGAL[13] = "CMD_ILLEGAL\r\n";
|
||||||
void digit_to_str(char* str, uint32_t number, int base){
|
void digit_to_str(char* str, uint32_t number, int base){
|
||||||
itoa(number,str,16);
|
itoa(number,str,16);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
void digit_to_str(char* str, uint32_t number, int base){
|
|
||||||
char tmp_char[32];
|
|
||||||
uint32_t tmp = number;
|
|
||||||
int tmp_counter = 0;
|
|
||||||
for(int i = 0; i<32; i++);
|
|
||||||
switch (tmp & 15)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
tmp_char[tmp_counter] = '0';
|
|
||||||
tmp_counter++;
|
|
||||||
tmp=tmp/base;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
tmp_char[tmp_counter] = '1';
|
|
||||||
tmp_counter++;
|
|
||||||
tmp=tmp/base;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
tmp_char[tmp_counter] = '2';
|
|
||||||
tmp_counter++;
|
|
||||||
tmp=tmp/base;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
tmp_char[tmp_counter] = '3';
|
|
||||||
tmp_counter++;
|
|
||||||
tmp=tmp/base;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
tmp_char[tmp_counter] = '4';
|
|
||||||
tmp_counter++;
|
|
||||||
tmp=tmp/base;
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
tmp_char[tmp_counter] = '5';
|
|
||||||
tmp_counter++;
|
|
||||||
tmp=tmp/base;
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
tmp_char[tmp_counter] = '6';
|
|
||||||
tmp_counter++;
|
|
||||||
tmp=tmp/base;
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
tmp_char[tmp_counter] = '7';
|
|
||||||
tmp_counter++;
|
|
||||||
tmp=tmp/base;
|
|
||||||
break;
|
|
||||||
case 8:
|
|
||||||
tmp_char[tmp_counter] = '8';
|
|
||||||
tmp_counter++;
|
|
||||||
tmp=tmp/base;
|
|
||||||
break;
|
|
||||||
case 9:
|
|
||||||
tmp_char[tmp_counter] = '9';
|
|
||||||
tmp_counter++;
|
|
||||||
tmp=tmp/base;
|
|
||||||
break;
|
|
||||||
case 10:
|
|
||||||
tmp_char[tmp_counter] = 'a';
|
|
||||||
tmp_counter++;
|
|
||||||
tmp=tmp/base;
|
|
||||||
break;
|
|
||||||
case 11:
|
|
||||||
tmp_char[tmp_counter] = 'b';
|
|
||||||
tmp_counter++;
|
|
||||||
tmp=tmp/base;
|
|
||||||
break;
|
|
||||||
case 12:
|
|
||||||
tmp_char[tmp_counter] = 'c';
|
|
||||||
tmp_counter++;
|
|
||||||
tmp=tmp/base;
|
|
||||||
break;
|
|
||||||
case 13:
|
|
||||||
tmp_char[tmp_counter] = 'd';
|
|
||||||
tmp_counter++;
|
|
||||||
tmp=tmp/base;
|
|
||||||
break;
|
|
||||||
case 14:
|
|
||||||
tmp_char[tmp_counter] = 'e';
|
|
||||||
tmp_counter++;
|
|
||||||
tmp=tmp/base;
|
|
||||||
break;
|
|
||||||
case 15:
|
|
||||||
tmp_char[tmp_counter] = 'f';
|
|
||||||
tmp_counter++;
|
|
||||||
tmp=tmp/base;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
for(int i = 0; i<tmp_counter; i++){
|
|
||||||
str[i] = tmp_char[tmp_counter-i];
|
|
||||||
}
|
|
||||||
str[tmp_counter] = '\0';
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
void uart_commands_getid(error_code* status){
|
void uart_commands_getid(error_code* status){
|
||||||
|
@ -117,30 +23,36 @@ void uart_commands_getid(error_code* status){
|
||||||
uart_send_ok();
|
uart_send_ok();
|
||||||
uart_send(hex, strlen(hex));
|
uart_send(hex, strlen(hex));
|
||||||
uart_send("\r\n", 2);
|
uart_send("\r\n", 2);
|
||||||
}
|
}else{
|
||||||
|
uart_send_err();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void uart_commands_getserial(error_code* status){
|
void uart_commands_getserial(error_code* status){
|
||||||
//char hex[40] = "0x8005018af27a5225a541628f50020c0\r\n";
|
char digit;
|
||||||
char hex[40];
|
char hex[40];
|
||||||
uint32_t res[4];
|
uint32_t res[4];
|
||||||
iap_read_serial(status, res);
|
iap_read_serial(status, res);
|
||||||
digit_to_str(hex+2, res[0], 16);
|
digit_to_str(hex+2, res[0], 16);
|
||||||
hex[0]='0';
|
hex[0]='0';
|
||||||
hex[1]='x';
|
hex[1]='x';
|
||||||
if(*status == 0){
|
if(*status != ok){
|
||||||
|
uart_send_err();
|
||||||
|
itoa(*status, &digit, 10);
|
||||||
|
uart_send(&digit, 1);
|
||||||
|
}
|
||||||
|
if(*status == ok){
|
||||||
uart_send_ok();
|
uart_send_ok();
|
||||||
uart_send(hex, strlen(hex));
|
uart_send(hex, strlen(hex));
|
||||||
|
digit_to_str(hex, res[1], 16);
|
||||||
|
uart_send(hex, strlen(hex));
|
||||||
|
digit_to_str(hex, res[2], 16);
|
||||||
|
uart_send(hex, strlen(hex));
|
||||||
|
digit_to_str(hex, res[3], 16);
|
||||||
|
uart_send(hex, strlen(hex));
|
||||||
|
uart_send("\r\n", 2);
|
||||||
}
|
}
|
||||||
digit_to_str(hex, res[1], 16);
|
|
||||||
uart_send(hex, strlen(hex));
|
|
||||||
digit_to_str(hex, res[2], 16);
|
|
||||||
uart_send(hex, strlen(hex));
|
|
||||||
digit_to_str(hex, res[3], 16);
|
|
||||||
uart_send(hex, strlen(hex));
|
|
||||||
uart_send("\r\n", 2);
|
|
||||||
//sprintf(hex, "0x%x%x%x%x\r\n", res[0], res[1], res[2], res[3]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
crc_t uart_commands_prog(error_code* status, int size){
|
crc_t uart_commands_prog(error_code* status, int size){
|
||||||
|
|
Loading…
Reference in New Issue