uart_receive_data works
This commit is contained in:
parent
3f39d5714e
commit
87afcd70cf
|
@ -39,6 +39,7 @@ crc_t crc_prog, crc_data;
|
|||
// TODO: insert other definitions and declarations here
|
||||
|
||||
char buff[256];
|
||||
|
||||
int main(void) {
|
||||
uart_init(115200);
|
||||
while(1){
|
||||
|
@ -60,7 +61,8 @@ int main(void) {
|
|||
}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);
|
||||
//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;
|
||||
|
||||
}else if(strcmp("CHECK", cmd.argv[0])==0){
|
||||
|
|
5
iap.c
5
iap.c
|
@ -92,8 +92,9 @@ 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){
|
||||
iap_prepare_sectors(status, dst_flash, dst_flash+num_bytes);
|
||||
//iap_prepare_sectors(2, 9);
|
||||
//iap_prepare_sectors(status, dst_flash, dst_flash+num_bytes);
|
||||
//iap_erase_sectors(status, dst_flash, dst_flash+num_bytes);
|
||||
//iap_prepare_sectors(status, dst_flash, dst_flash+num_bytes);
|
||||
command[0] = 51;
|
||||
command[1] = dst_flash;
|
||||
command[2] = *src_ram;
|
||||
|
|
16
uart.c
16
uart.c
|
@ -45,21 +45,27 @@ void uart_send(char* buff, uint32_t length){
|
|||
|
||||
void uart_receive_command(char* chara){
|
||||
char* curr = chara;
|
||||
while(((LPC_UART0->LSR)&(1)) == 0);
|
||||
*curr = LPC_UART0->RBR;
|
||||
//while(strncmp("\r\n",curr, 2) != 0){
|
||||
while(*curr != '\n'){
|
||||
if((*curr != '\n')) curr++;
|
||||
while(((LPC_UART0->LSR)&(1)) == 0);
|
||||
*curr = LPC_UART0->RBR;
|
||||
//if(strncmp("\r\n",curr, 2) != 0) curr++;
|
||||
if((*curr != '\n')) curr++;
|
||||
}
|
||||
}
|
||||
|
||||
void uart_receive_data(uint8_t* chara){
|
||||
void uart_receive_data(uint8_t* chara, int size){
|
||||
//size parameter add while size != size_given
|
||||
uint8_t* curr = chara;
|
||||
while(*curr != '\0'){
|
||||
//while(((LPC_UART0->LSR)&(1)) == 0);
|
||||
for(int i = 0; i < size/2; i++){
|
||||
while(((LPC_UART0->LSR)&(1)) == 0);
|
||||
*curr = LPC_UART0->RBR;
|
||||
curr++;
|
||||
curr[2*i] = LPC_UART0->RBR;
|
||||
while(((LPC_UART0->LSR)&(1)) == 0);
|
||||
curr[2*i+1] = LPC_UART0->RBR;
|
||||
//while(((LPC_UART0->LSR)&(1)) == 0);
|
||||
//curr[2*i] = LPC_UART0->RBR;
|
||||
}
|
||||
}
|
||||
|
|
2
uart.h
2
uart.h
|
@ -44,7 +44,7 @@ void uart_send(char* buff, uint32_t length);
|
|||
|
||||
void uart_receive_command(char* chara);
|
||||
|
||||
void uart_receive_data(uint8_t* chara);
|
||||
void uart_receive_data(uint8_t* chara, int size);
|
||||
|
||||
|
||||
#define THRE (1<<5)
|
||||
|
|
|
@ -28,39 +28,43 @@ void uart_commands_getserial(error_code* status){
|
|||
}
|
||||
|
||||
crc_t uart_commands_prog(void){
|
||||
return crc_init();
|
||||
uart_send(OK, 5);
|
||||
return crc_init();
|
||||
}
|
||||
|
||||
error_code uart_commands_data(error_code* status, int size, crc_t* checksum_global, crc_t checksum_loc, int offset){
|
||||
uart_receive_data(data);
|
||||
uart_receive_data(data, size);
|
||||
crc_t checksum_tmp = crc_init();
|
||||
checksum_tmp = crc_update(checksum_tmp, data, size);
|
||||
checksum_tmp = crc_finalize(checksum_tmp);
|
||||
if(checksum_loc == checksum_tmp){
|
||||
int tmp = size;
|
||||
while(tmp > 4096){
|
||||
iap_copy_to_flash(status, offset, &checksum_loc, 4096);
|
||||
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+1);
|
||||
while(tmp >= 4096){
|
||||
iap_copy_to_flash(status, offset/0x1000, &checksum_loc, 4096);
|
||||
if(*status != ok){
|
||||
uart_send(ERR, 6);
|
||||
}
|
||||
tmp = tmp - 4096;
|
||||
}
|
||||
while(tmp > 1024){
|
||||
iap_copy_to_flash(status, offset, &checksum_loc, 1024);
|
||||
while(tmp >= 1024){
|
||||
iap_copy_to_flash(status, offset/0x1000, &checksum_loc, 1024);
|
||||
if(*status != ok){
|
||||
uart_send(ERR, 6);
|
||||
}
|
||||
tmp = tmp - 1024;
|
||||
}
|
||||
while(tmp > 512){
|
||||
iap_copy_to_flash(status, offset, &checksum_loc, 512);
|
||||
while(tmp >= 512){
|
||||
iap_copy_to_flash(status, offset/0x1000, &checksum_loc, 512);
|
||||
if(*status != ok){
|
||||
uart_send(ERR, 6);
|
||||
}
|
||||
tmp = tmp - 512;
|
||||
}
|
||||
while(tmp > 256){
|
||||
iap_copy_to_flash(status, offset, &checksum_loc, 256);
|
||||
while(tmp >= 256){
|
||||
iap_copy_to_flash(status, offset/0x1000, &checksum_loc, 256);
|
||||
if(*status != ok){
|
||||
uart_send(ERR, 6);
|
||||
}
|
||||
|
@ -108,6 +112,6 @@ int uart_parse_command(char *user_input, cmd_t *cmd) {
|
|||
uint32_t uart_string_to_int(const char *str) {
|
||||
// Convert input in port number
|
||||
char* tmp;
|
||||
unsigned long int hex = strtoul(str, tmp, 16);
|
||||
unsigned long long int hex = strtoull(str, &tmp, 16);
|
||||
return hex;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
#include "iap.h"
|
||||
#include "crc.h"
|
||||
|
||||
#define DELIMIERS ','
|
||||
#define DELIMIERS ","
|
||||
#define APP_OFFSET 4
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue