/* =============================================================================== Name : bootloader.c Author : $(author) Version : Copyright : $(copyright) Description : main definition =============================================================================== */ #ifdef __USE_CMSIS #include "LPC17xx.h" #endif #include #include #include #include "uart_commands.h" error_code status; char okk[4] = "OK\r\n"; char errr[5] = "ERR\r\n"; char buff[256]; 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 int main(void) { uart_init(115200); //iap_read_part_id(); //iap_copy_to_flash(0x8000,(uint8_t*)test, 4); while(1){ uart_receive_command(buff); uart_parse_command(buff, &cmd); if (strcmp("GETID", cmd.argv[0])==0){ uart_commands_getid(&status); }else if(strcmp("GETSERIAL", cmd.argv[0])==0){ uart_commands_getserial(&status); }else if(strcmp("PROG", cmd.argv[0])==0){ 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; }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]); uart_commands_data(&status, size, &crc_data, local_checksum, offset_pointer); if(status == 0) offset_pointer += size; }else if(strcmp("CHECK", cmd.argv[0])==0){ if(crc_prog == crc_data){ uart_send(okk, 5); }else{ uart_send(errr, 6); } } //uart_commands_data(&status, 0x00004000, 0x00048f40, 0x4); } while(1); return 0 ; }