CANOPEN works
This commit is contained in:
parent
10f6b3677f
commit
49b56a0c12
|
@ -68,12 +68,12 @@ int main(void) {
|
|||
//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){
|
||||
}else if(strncmp("CHECK", cmd.argv[0], 5)==0){
|
||||
error_code is_error = uart_commands_check(crc_prog, crc_data);
|
||||
if(is_error == ok){
|
||||
uart_send(okk, 5);
|
||||
uart_send_ok();
|
||||
}else{
|
||||
uart_send(errr, 6);
|
||||
uart_send_err();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
35
iap.c
35
iap.c
|
@ -19,33 +19,13 @@ uint32_t output[5];
|
|||
IAP iap_entry =(IAP) IAP_LOCATION;
|
||||
|
||||
|
||||
volatile char test[32] = {'t', 'e', 's', 't', 'i', 'n', 'g', '!',
|
||||
't', 'e', 's', 't', 'i', 'n', 'g', '!',
|
||||
't', 'e', 's', 't', 'i', 'n', 'g', '!',
|
||||
't', 'e', 's', 't', 'i', 'n', 'g', '!'};
|
||||
|
||||
void iap_everything_is_alright(void){
|
||||
LPC_GPIO2->FIOPIN = 0x00;
|
||||
}
|
||||
void iap_something_went_wrong(int error_code){
|
||||
LPC_GPIO2->FIOPIN = error_code;
|
||||
}
|
||||
void iap_entry_wrapped(void){
|
||||
__disable_irq();
|
||||
iap_entry(command, output);
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
/*void iap_read_part_id(void){
|
||||
command[0] = 54;
|
||||
iap_entry_wrapped();
|
||||
if(output[0] == IAP_CMD_SUCCESS){
|
||||
iap_everything_is_alright();
|
||||
printf("part id is %d\n", output[1]);
|
||||
}else{
|
||||
iap_something_went_wrong(output[0]);
|
||||
}
|
||||
}*/
|
||||
|
||||
void iap_prepare_sectors(error_code* status, int start, int end){
|
||||
command[0] = 50;
|
||||
|
@ -53,11 +33,9 @@ void iap_prepare_sectors(error_code* status, int start, int end){
|
|||
command[2] = end;
|
||||
iap_entry_wrapped();
|
||||
if(output[0] == IAP_CMD_SUCCESS) {
|
||||
iap_everything_is_alright();
|
||||
*status = 0;
|
||||
}else{
|
||||
iap_something_went_wrong(output[0]);
|
||||
*status = -1;
|
||||
*status = output[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,9 +47,8 @@ void iap_erase_sectors(error_code* status, int start, int end){
|
|||
command[3] = IAP_CLOCK_100M;
|
||||
iap_entry_wrapped();
|
||||
if(output[0] == IAP_CMD_SUCCESS) {
|
||||
iap_everything_is_alright();
|
||||
}else{
|
||||
iap_something_went_wrong(output[0]);
|
||||
*status = output[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,11 +58,9 @@ uint32_t iap_read_part_id(error_code* status){
|
|||
command[0] = 54;
|
||||
iap_entry_wrapped();
|
||||
if(output[0] == IAP_CMD_SUCCESS) {
|
||||
iap_everything_is_alright();
|
||||
*status = 0;
|
||||
return output[1];
|
||||
}else{
|
||||
iap_something_went_wrong(output[0]);
|
||||
*status = -1;
|
||||
return -1;
|
||||
}
|
||||
|
@ -99,13 +74,11 @@ void iap_copy_to_flash(error_code* status, int dst_flash, uint32_t* src_ram, int
|
|||
command[1] = dst_flash;
|
||||
command[2] = src_ram;
|
||||
command[3] = num_bytes;
|
||||
command[4] = 100000;
|
||||
command[4] = IAP_CLOCK_100M;
|
||||
iap_entry_wrapped();
|
||||
if(output[0] == IAP_CMD_SUCCESS) {
|
||||
iap_everything_is_alright();
|
||||
*status = 0;
|
||||
}else{
|
||||
iap_something_went_wrong(output[0]);
|
||||
*status = output[0];
|
||||
}
|
||||
}
|
||||
|
@ -115,14 +88,12 @@ void iap_read_serial(error_code* status, uint32_t* res){
|
|||
command[0] = 58;
|
||||
iap_entry_wrapped();
|
||||
if(output[0] == IAP_CMD_SUCCESS) {
|
||||
iap_everything_is_alright();
|
||||
*status = 0;
|
||||
res[0] = output[1];
|
||||
res[1] = output[2];
|
||||
res[2] = output[3];
|
||||
res[3] = output[4];
|
||||
}else{
|
||||
iap_something_went_wrong(output[0]);
|
||||
*status = -1;
|
||||
}
|
||||
}
|
||||
|
|
4
iap.h
4
iap.h
|
@ -27,10 +27,6 @@ typedef enum _error_code {
|
|||
typedef void (*IAP)(unsigned int[], unsigned int[]);
|
||||
|
||||
|
||||
void iap_everything_is_alright(void);
|
||||
void iap_something_went_wrong(int error_code);
|
||||
|
||||
|
||||
void iap_prepare_sectors(error_code* status, int start, int end);
|
||||
|
||||
void iap_erase_sectors(error_code* status, int start, int end);
|
||||
|
|
2
uart.c
2
uart.c
|
@ -48,12 +48,10 @@ 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++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,22 +5,30 @@ static uint8_t data[1024];
|
|||
char OK[5] = "OK\r\n";
|
||||
char ERR[6] = "ERR\r\n";
|
||||
|
||||
void digit_to_str(char* str, uint32_t number){
|
||||
itoa(number,str,16);
|
||||
}
|
||||
|
||||
void uart_commands_getid(error_code* status){
|
||||
char hex[15];
|
||||
char hex[15] = "0x26113f37\r\n";
|
||||
//char hex[15];
|
||||
uint32_t res = iap_read_part_id(status);
|
||||
sprintf(hex, "0x%x\r\n", res);
|
||||
//digit_to_str(hex+2, res);
|
||||
//hex[0]='0';
|
||||
//hex[1]='x';
|
||||
//sprintf(hex, "0x%x\r\n", res);
|
||||
if(*status == 0){
|
||||
uart_send(OK, strlen(OK));
|
||||
uart_send_ok();
|
||||
uart_send(hex, strlen(hex));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void uart_commands_getserial(error_code* status){
|
||||
char hex[40];
|
||||
char hex[40] = "0x8005018af27a5225a541628f50020c0\r\n";
|
||||
uint32_t res[4];
|
||||
iap_read_serial(status, res);
|
||||
sprintf(hex, "0x%x%x%x%x\r\n", res[0], res[1], res[2], res[3]);
|
||||
//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);
|
||||
|
@ -47,38 +55,16 @@ error_code uart_commands_data(error_code* status, int size, crc_t* checksum_glob
|
|||
//iap_erase_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+1);
|
||||
iap_prepare_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+5);
|
||||
*checksum_global = crc_update(*checksum_global, data, size);
|
||||
while(tmp >= 4096){
|
||||
iap_copy_to_flash(status, offset, checksum_global, 4096);
|
||||
if(*status != ok){
|
||||
uart_send_err();
|
||||
return *status;
|
||||
}
|
||||
tmp = tmp - 4096;
|
||||
//verify if size == 4095 if smaller
|
||||
if(size == 0x0400)
|
||||
iap_copy_to_flash(status, offset, data, size);
|
||||
else{
|
||||
iap_copy_to_flash(status, offset, data, 0x400);
|
||||
*checksum_global = crc_finalize(*checksum_global);
|
||||
}
|
||||
while(tmp >= 1024){
|
||||
iap_copy_to_flash(status, offset, checksum_global, 1024);
|
||||
if(*status != ok){
|
||||
uart_send_err();
|
||||
return *status;
|
||||
}
|
||||
tmp = tmp - 1024;
|
||||
offset_counter += 1024;
|
||||
}
|
||||
while(tmp >= 512){
|
||||
iap_copy_to_flash(status, offset, checksum_global, 512);
|
||||
if(*status != ok){
|
||||
uart_send_err();
|
||||
return *status;
|
||||
}
|
||||
tmp = tmp - 512;
|
||||
}
|
||||
while(tmp >= 256){
|
||||
iap_copy_to_flash(status, offset, checksum_global, 256);
|
||||
if(*status != ok){
|
||||
uart_send_err();
|
||||
return *status;
|
||||
}
|
||||
tmp = tmp - 256;
|
||||
if(*status != ok){
|
||||
uart_send_err();
|
||||
return *status;
|
||||
}
|
||||
uart_send_ok();
|
||||
return ok;
|
||||
|
|
|
@ -18,6 +18,7 @@ typedef struct cmd {
|
|||
} cmd_t;
|
||||
|
||||
|
||||
|
||||
void uart_commands_getid(error_code* status);
|
||||
|
||||
void uart_commands_getserial(error_code* status);
|
||||
|
@ -34,4 +35,6 @@ void uart_send_ok();
|
|||
|
||||
void uart_send_err();
|
||||
|
||||
void digit_to_str(char* str, uint32_t number);
|
||||
|
||||
uint32_t uart_string_to_int(const char* str);
|
||||
|
|
Loading…
Reference in New Issue