Compare commits

..

No commits in common. "6d4ca4fccdf442d8388990be2795ef7a166fabe8" and "b8b934d6c6ec8f9545e5466856e4b4dfb5e53e1a" have entirely different histories.

6 changed files with 22 additions and 36 deletions

View File

@ -39,7 +39,6 @@ crc_t crc_prog, crc_data;
// TODO: insert other definitions and declarations here // TODO: insert other definitions and declarations here
char buff[256]; char buff[256];
int main(void) { int main(void) {
uart_init(115200); uart_init(115200);
while(1){ while(1){
@ -61,8 +60,7 @@ int main(void) {
}else if(strcmp("DATA", cmd.argv[0])==0){ }else if(strcmp("DATA", cmd.argv[0])==0){
int size = uart_string_to_int(cmd.argv[1]); int size = uart_string_to_int(cmd.argv[1]);
crc_t local_checksum = uart_string_to_int(cmd.argv[2]); crc_t local_checksum = uart_string_to_int(cmd.argv[2]);
//uart_commands_data(&status, size, &crc_data, local_checksum, offset_pointer); uart_commands_data(&status, size, &crc_data, local_checksum, offset_pointer);
uart_commands_data(&status, size, &crc_data, crc_data, offset_pointer);
if(status == 0) offset_pointer += size; if(status == 0) offset_pointer += size;
}else if(strcmp("CHECK", cmd.argv[0])==0){ }else if(strcmp("CHECK", cmd.argv[0])==0){

5
iap.c
View File

@ -92,9 +92,8 @@ uint32_t iap_read_part_id(error_code* status){
} }
void iap_copy_to_flash(error_code* status, int dst_flash, uint32_t* src_ram, int num_bytes){ void iap_copy_to_flash(error_code* status, int dst_flash, uint32_t* src_ram, int num_bytes){
//iap_prepare_sectors(status, dst_flash, dst_flash+num_bytes); iap_prepare_sectors(status, dst_flash, dst_flash+num_bytes);
//iap_erase_sectors(status, dst_flash, dst_flash+num_bytes); //iap_prepare_sectors(2, 9);
//iap_prepare_sectors(status, dst_flash, dst_flash+num_bytes);
command[0] = 51; command[0] = 51;
command[1] = dst_flash; command[1] = dst_flash;
command[2] = *src_ram; command[2] = *src_ram;

16
uart.c
View File

@ -45,27 +45,21 @@ void uart_send(char* buff, uint32_t length){
void uart_receive_command(char* chara){ void uart_receive_command(char* chara){
char* curr = chara; char* curr = chara;
while(((LPC_UART0->LSR)&(1)) == 0);
*curr = LPC_UART0->RBR;
//while(strncmp("\r\n",curr, 2) != 0){ //while(strncmp("\r\n",curr, 2) != 0){
while(*curr != '\n'){ while(*curr != '\n'){
if((*curr != '\n')) curr++;
while(((LPC_UART0->LSR)&(1)) == 0); while(((LPC_UART0->LSR)&(1)) == 0);
*curr = LPC_UART0->RBR; *curr = LPC_UART0->RBR;
//if(strncmp("\r\n",curr, 2) != 0) curr++; //if(strncmp("\r\n",curr, 2) != 0) curr++;
if((*curr != '\n')) curr++;
} }
} }
void uart_receive_data(uint8_t* chara, int size){ void uart_receive_data(uint8_t* chara){
//size parameter add while size != size_given //size parameter add while size != size_given
uint8_t* curr = chara; uint8_t* curr = chara;
//while(((LPC_UART0->LSR)&(1)) == 0); while(*curr != '\0'){
for(int i = 0; i < size/2; i++){
while(((LPC_UART0->LSR)&(1)) == 0); while(((LPC_UART0->LSR)&(1)) == 0);
curr[2*i] = LPC_UART0->RBR; *curr = LPC_UART0->RBR;
while(((LPC_UART0->LSR)&(1)) == 0); curr++;
curr[2*i+1] = LPC_UART0->RBR;
//while(((LPC_UART0->LSR)&(1)) == 0);
//curr[2*i] = LPC_UART0->RBR;
} }
} }

2
uart.h
View File

@ -44,7 +44,7 @@ void uart_send(char* buff, uint32_t length);
void uart_receive_command(char* chara); void uart_receive_command(char* chara);
void uart_receive_data(uint8_t* chara, int size); void uart_receive_data(uint8_t* chara);
#define THRE (1<<5) #define THRE (1<<5)

View File

@ -28,43 +28,39 @@ void uart_commands_getserial(error_code* status){
} }
crc_t uart_commands_prog(void){ crc_t uart_commands_prog(void){
uart_send(OK, 5);
return crc_init(); return crc_init();
uart_send(OK, 5);
} }
error_code uart_commands_data(error_code* status, int size, crc_t* checksum_global, crc_t checksum_loc, int offset){ error_code uart_commands_data(error_code* status, int size, crc_t* checksum_global, crc_t checksum_loc, int offset){
uart_receive_data(data, size); uart_receive_data(data);
crc_t checksum_tmp = crc_init(); crc_t checksum_tmp = crc_init();
checksum_tmp = crc_update(checksum_tmp, data, size); checksum_tmp = crc_update(checksum_tmp, data, size);
checksum_tmp = crc_finalize(checksum_tmp);
if(checksum_loc == checksum_tmp){ if(checksum_loc == checksum_tmp){
int tmp = size; int tmp = size;
iap_prepare_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+1); while(tmp > 4096){
iap_erase_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+1); iap_copy_to_flash(status, offset, &checksum_loc, 4096);
iap_prepare_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+1);
while(tmp >= 4096){
iap_copy_to_flash(status, offset/0x1000, &checksum_loc, 4096);
if(*status != ok){ if(*status != ok){
uart_send(ERR, 6); uart_send(ERR, 6);
} }
tmp = tmp - 4096; tmp = tmp - 4096;
} }
while(tmp >= 1024){ while(tmp > 1024){
iap_copy_to_flash(status, offset/0x1000, &checksum_loc, 1024); iap_copy_to_flash(status, offset, &checksum_loc, 1024);
if(*status != ok){ if(*status != ok){
uart_send(ERR, 6); uart_send(ERR, 6);
} }
tmp = tmp - 1024; tmp = tmp - 1024;
} }
while(tmp >= 512){ while(tmp > 512){
iap_copy_to_flash(status, offset/0x1000, &checksum_loc, 512); iap_copy_to_flash(status, offset, &checksum_loc, 512);
if(*status != ok){ if(*status != ok){
uart_send(ERR, 6); uart_send(ERR, 6);
} }
tmp = tmp - 512; tmp = tmp - 512;
} }
while(tmp >= 256){ while(tmp > 256){
iap_copy_to_flash(status, offset/0x1000, &checksum_loc, 256); iap_copy_to_flash(status, offset, &checksum_loc, 256);
if(*status != ok){ if(*status != ok){
uart_send(ERR, 6); uart_send(ERR, 6);
} }
@ -112,6 +108,6 @@ int uart_parse_command(char *user_input, cmd_t *cmd) {
uint32_t uart_string_to_int(const char *str) { uint32_t uart_string_to_int(const char *str) {
// Convert input in port number // Convert input in port number
char* tmp; char* tmp;
unsigned long long int hex = strtoull(str, &tmp, 16); unsigned long int hex = strtoul(str, tmp, 16);
return hex; return hex;
} }

View File

@ -6,8 +6,7 @@
#include "iap.h" #include "iap.h"
#include "crc.h" #include "crc.h"
#define DELIMIERS "," #define DELIMIERS ','
#define APP_OFFSET 4