// Sends requested bytes of data to host. void readHexRecord() { uint8_t i, bytes; uint16_t addr; CE_LOW(); // Get memory address and number of bytes to read. bytes = MSG_RE_BYTE_COUNT; addr = MSG_RE_ADDR; // Copy flash memory bytes to temporary idata buffer. PCON |= PMW; hal_flash_bytes_read(addr, temp_data, bytes); PCON &= ~PMW; // If request is for reset vector, read from non-volatile mem. if (addr == 0x0000) { hal_flash_bytes_read(FW_RESET_OPCODE, temp_data, 3); } // Copy to send buffer for (i = 0; i < bytes; i++) { send_buf[i+1] = temp_data[i]; } send(CMD_ACK); return; }
void ReadflashInterval(void) //¶Á³ö¼ä¸ô { PCON &= ~0x10;//PMW hal_flash_bytes_read(0xFC00,&timinteval_1,1); //¶ÁÈë·¢Éä¼ä¸ô hal_flash_bytes_read(0xFC01,&timinteval_2,1); //¶ÁÈë·¢Éä¼ä¸ô timinteval = timinteval_1; timinteval = (timinteval << 8); timinteval = timinteval + timinteval_2; }
bool gzp_get_host_id(uint8_t* dst) { if(hal_flash_byte_read(GZP_PARAMS_STORAGE_ADR) == 0) { hal_flash_bytes_read(GZP_PARAMS_STORAGE_ADR + 1, dst, GZP_HOST_ID_LENGTH); return true; } else { return false; } }
void WriteflashBoatnum(void) //дÈë´¬Ãû { ReadflashInterval(); ReadflashCode(); ReadStartTask(); hal_flash_page_erase(34); PCON &= ~0x10;//PMW hal_flash_bytes_write(0xFC02,&(com_buf[2]),16); delay(1000); hal_flash_bytes_read (0xFC02,boatnum,16); hal_flash_bytes_write(0xFC00,&timinteval_1,1); //ÔÙдÈë·¢Éä¼ä¸ô hal_flash_bytes_write(0xFC01,&timinteval_2,1); hal_flash_bytes_write(0xFC30,&codeflag,1); // hal_flash_bytes_write(0xFC31,&taskstart,1); }
void ReadflashCode() //¶ÁÃÜÂë { PCON &= ~0x10;//PMW hal_flash_bytes_read(0xFC30,&codeflag,1); }
void ReadflashBoatnum(void) //¶Á³ö´¬Ãû { PCON &= ~0x10;//PMW hal_flash_bytes_read(0xFC02,boatnum,16); }
// Verifies that update-start command is valid. // Will enter RECEIVING_FIRMWARE state if everything checks out. void startFirmwareUpdate(state_t *state, uint16_t *bytes_total, uint16_t *bytes_received, uint8_t *firmware_number) { uint8_t i, checksum = 0, reset_vector[3]; uint16_t bytes = 0; // Calculate checksum for (i = 0; i < UPDATE_START_LENGTH; i++) { checksum += MSG_PAYLOAD(i); } // Checksum fail if (checksum != 0) { send_buf[1] = ERROR_CHECKSUM_FAIL; send(CMD_NACK); return; } // Get firmware size bytes = MSG_ST_BYTES; // Check that firmware is within legal size range. if (bytes > FLASH_FW_MAX_SIZE) { // Send error report to host. send_buf[1] = ERROR_ILLEGAL_SIZE; send(CMD_NACK); return; } *bytes_total = bytes; // Get firmware's reset vector. temp_data[0] = MSG_ST_RESET_OPCODE; temp_data[1] = MSG_ST_RESET_ADDR_H; temp_data[2] = MSG_ST_RESET_ADDR_L; // Write reset vector to non-volatile flash hal_flash_page_erase(FW_NV_DATA_PAGE); hal_flash_bytes_write(FW_RESET_VECTOR, temp_data, 3); // Get firmware serial number. Will be written to NV when update complete. *firmware_number = MSG_ST_NUMBER; *bytes_received = 0; // Read out old reset vector. PCON |= PMW; hal_flash_bytes_read(0x0000, reset_vector, 3); PCON &= ~PMW; // Erase first page, containing reset vector. hal_flash_page_erase(0); // Write back the old reset vector. PCON |= PMW; hal_flash_bytes_write(0x0000, reset_vector, 3); PCON &= ~PMW; // Erase the reset of pages available to firmware. for (i = 1; i < FLASH_FW_PAGES; i++) { hal_flash_page_erase(i); } send(CMD_ACK); if (send_success) { *state = RECEIVING_FIRMWARE; } else { *state = LISTENING; } return; }
static void gzp_params_db_read(uint8_t* dst_element, uint8_t index) { hal_flash_bytes_read(GZP_PARAMS_DB_ADR + (index * GZP_PARAMS_DB_ELEMENT_SIZE), dst_element, GZP_PARAMS_DB_ELEMENT_SIZE); }