yeah mylab2_test works as well
This commit is contained in:
parent
49b56a0c12
commit
41414634b6
|
@ -9,6 +9,12 @@ void digit_to_str(char* str, uint32_t number){
|
|||
itoa(number,str,16);
|
||||
}
|
||||
|
||||
int addr_to_sector(int addr){
|
||||
int tmp = addr & 0xfffff;
|
||||
tmp = tmp >> 12;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void uart_commands_getid(error_code* status){
|
||||
char hex[15] = "0x26113f37\r\n";
|
||||
//char hex[15];
|
||||
|
@ -31,19 +37,37 @@ void uart_commands_getserial(error_code* status){
|
|||
//sprintf(hex, "0x%x%x%x%x\r\n", res[0], res[1], res[2], res[3]);
|
||||
if(*status == 0){
|
||||
uart_send_ok();
|
||||
uart_send(hex, 35);
|
||||
uart_send(hex, strlen(hex));
|
||||
}
|
||||
}
|
||||
|
||||
crc_t uart_commands_prog(error_code* status, int size){
|
||||
iap_prepare_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+5);
|
||||
iap_erase_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+5);
|
||||
iap_prepare_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+5);
|
||||
//iap_prepare_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+5);
|
||||
iap_prepare_sectors(status, addr_to_sector(APP_OFFSET), addr_to_sector(APP_OFFSET+size)+1);
|
||||
char digit;
|
||||
if(*status != ok){
|
||||
uart_send_err();
|
||||
itoa(*status, &digit, 10);
|
||||
uart_send(digit, 1);
|
||||
}
|
||||
iap_erase_sectors(status, addr_to_sector(APP_OFFSET), addr_to_sector(APP_OFFSET+size)+1);
|
||||
if(*status != ok){
|
||||
uart_send_err();
|
||||
itoa(*status, &digit, 10);
|
||||
uart_send(digit, 1);
|
||||
}
|
||||
iap_prepare_sectors(status, addr_to_sector(APP_OFFSET), addr_to_sector(APP_OFFSET+size)+1);
|
||||
if(*status != ok){
|
||||
uart_send_err();
|
||||
itoa(*status, &digit, 10);
|
||||
uart_send(digit, 1);
|
||||
}
|
||||
uart_send_ok();
|
||||
return crc_init();
|
||||
}
|
||||
|
||||
error_code uart_commands_data(error_code* status, int size, crc_t* checksum_global, crc_t checksum_loc, int offset){
|
||||
char digit;
|
||||
uart_receive_data(data, size);
|
||||
crc_t checksum_tmp = crc_init();
|
||||
checksum_tmp = crc_update(checksum_tmp, data, size);
|
||||
|
@ -53,7 +77,7 @@ error_code uart_commands_data(error_code* status, int size, crc_t* checksum_glob
|
|||
int tmp = size;
|
||||
//iap_prepare_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+1);
|
||||
//iap_erase_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+1);
|
||||
iap_prepare_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+5);
|
||||
iap_prepare_sectors(status, addr_to_sector(offset), addr_to_sector(offset+size)+1);
|
||||
*checksum_global = crc_update(*checksum_global, data, size);
|
||||
//verify if size == 4095 if smaller
|
||||
if(size == 0x0400)
|
||||
|
@ -64,14 +88,18 @@ error_code uart_commands_data(error_code* status, int size, crc_t* checksum_glob
|
|||
}
|
||||
if(*status != ok){
|
||||
uart_send_err();
|
||||
itoa(*status, &digit, 10);
|
||||
uart_send(digit, 1);
|
||||
return *status;
|
||||
}
|
||||
uart_send_ok();
|
||||
return ok;
|
||||
}else{
|
||||
uart_send_err();
|
||||
return local_checksum;
|
||||
itoa(*status, &digit, 10);
|
||||
uart_send(digit, 1);
|
||||
}
|
||||
return local_checksum;
|
||||
}
|
||||
|
||||
error_code uart_commands_check(crc_t crc_received, crc_t crc_calculated){
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include "crc.h"
|
||||
|
||||
#define DELIMIERS ","
|
||||
#define APP_OFFSET 4
|
||||
#define APP_OFFSET 0x4000
|
||||
|
||||
|
||||
|
||||
|
@ -35,6 +35,8 @@ void uart_send_ok();
|
|||
|
||||
void uart_send_err();
|
||||
|
||||
int addr_to_sector(int addr);
|
||||
|
||||
void digit_to_str(char* str, uint32_t number);
|
||||
|
||||
uint32_t uart_string_to_int(const char* str);
|
||||
|
|
Loading…
Reference in New Issue