2022-05-19 08:57:38 -04:00
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
Name : bootloader.c
|
|
|
|
Author : $(author)
|
|
|
|
Version :
|
|
|
|
Copyright : $(copyright)
|
|
|
|
Description : main definition
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __USE_CMSIS
|
|
|
|
#include "LPC17xx.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <cr_section_macros.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "uart_commands.h"
|
|
|
|
|
|
|
|
error_code status;
|
|
|
|
|
|
|
|
char okk[4] = "OK\r\n";
|
|
|
|
char errr[5] = "ERR\r\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmd_t cmd;
|
|
|
|
|
|
|
|
uint32_t offset, total_size, offset_pointer;
|
|
|
|
|
|
|
|
crc_t crc_prog, crc_data;
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: insert other include files here
|
|
|
|
|
|
|
|
// TODO: insert other definitions and declarations here
|
|
|
|
|
2022-05-19 15:37:51 -04:00
|
|
|
char buff[256];
|
2022-05-22 13:52:44 -04:00
|
|
|
|
2022-05-19 08:57:38 -04:00
|
|
|
int main(void) {
|
|
|
|
uart_init(115200);
|
|
|
|
while(1){
|
|
|
|
uart_receive_command(buff);
|
|
|
|
uart_parse_command(buff, &cmd);
|
2022-05-19 15:37:51 -04:00
|
|
|
if (strncmp("GETID", cmd.argv[0], 5)==0){
|
2022-05-19 08:57:38 -04:00
|
|
|
uart_commands_getid(&status);
|
2022-05-19 15:37:51 -04:00
|
|
|
|
|
|
|
}else if(strncmp("GETSE", cmd.argv[0], 5)==0){
|
2022-05-19 08:57:38 -04:00
|
|
|
uart_commands_getserial(&status);
|
2022-05-19 15:37:51 -04:00
|
|
|
|
|
|
|
}else if(strncmp("PROG", cmd.argv[0], 4)==0){
|
2022-05-19 08:57:38 -04:00
|
|
|
crc_prog = uart_string_to_int(cmd.argv[3]);
|
|
|
|
total_size = uart_string_to_int(cmd.argv[2]);
|
|
|
|
offset = uart_string_to_int(cmd.argv[1]);
|
|
|
|
crc_data = uart_commands_prog();
|
|
|
|
offset_pointer = offset;
|
2022-05-19 15:37:51 -04:00
|
|
|
|
2022-05-19 08:57:38 -04:00
|
|
|
}else if(strcmp("DATA", cmd.argv[0])==0){
|
|
|
|
int size = uart_string_to_int(cmd.argv[1]);
|
|
|
|
crc_t local_checksum = uart_string_to_int(cmd.argv[2]);
|
2022-05-22 13:52:44 -04:00
|
|
|
//uart_commands_data(&status, size, &crc_data, local_checksum, offset_pointer);
|
|
|
|
uart_commands_data(&status, size, &crc_data, crc_data, offset_pointer);
|
2022-05-19 08:57:38 -04:00
|
|
|
if(status == 0) offset_pointer += size;
|
2022-05-19 15:37:51 -04:00
|
|
|
|
2022-05-19 08:57:38 -04:00
|
|
|
}else if(strcmp("CHECK", cmd.argv[0])==0){
|
2022-05-19 15:37:51 -04:00
|
|
|
error_code is_error = uart_commands_check(crc_prog, crc_data);
|
|
|
|
if(is_error == ok){
|
2022-05-19 08:57:38 -04:00
|
|
|
uart_send(okk, 5);
|
|
|
|
}else{
|
|
|
|
uart_send(errr, 6);
|
|
|
|
}
|
|
|
|
|
2022-05-19 15:37:51 -04:00
|
|
|
}
|
2022-05-19 08:57:38 -04:00
|
|
|
}
|
|
|
|
while(1);
|
|
|
|
return 0 ;
|
|
|
|
}
|