diff --git a/include/firestarter.h b/include/firestarter.h index 7608d29..d27ea59 100644 --- a/include/firestarter.h +++ b/include/firestarter.h @@ -18,6 +18,7 @@ #define STATE_WRITE 2 #define STATE_ERASE 3 #define STATE_BLANK_CHECK 4 +#define STATE_CHECK_CHIP_ID 5 // #define STATE_READ_VPE 10 #define STATE_READ_VPP 11 #define STATE_READ_VPE 12 @@ -76,6 +77,8 @@ typedef struct firestarter_handle { void (*firestarter_blank_check)(struct firestarter_handle*); + void (*firestarter_check_chip_id)(struct firestarter_handle*); + void (*firestarter_set_address)(struct firestarter_handle*, uint32_t); void (*firestarter_set_control_register)(struct firestarter_handle*, register_t, bool); diff --git a/src/eprom.cpp b/src/eprom.cpp index 3b366c1..e3e095d 100644 --- a/src/eprom.cpp +++ b/src/eprom.cpp @@ -21,8 +21,10 @@ void eprom_blank_check(firestarter_handle_t* handle); void eprom_read_init(firestarter_handle_t* handle); void eprom_write_init(firestarter_handle_t* handle); void eprom_write_data(firestarter_handle_t* handle); -uint16_t eprom_get_chip_id(firestarter_handle_t* handle); +void eprom_check_chip_id(firestarter_handle_t* handle); + void eprom_set_control_register(firestarter_handle_t* handle, register_t bit, bool state); +uint16_t eprom_get_chip_id(firestarter_handle_t* handle); void (*set_control_register)(struct firestarter_handle*, register_t, bool); @@ -35,9 +37,10 @@ void configure_eprom(firestarter_handle_t* handle) { handle->firestarter_set_control_register = eprom_set_control_register; handle->firestarter_erase = eprom_erase; handle->firestarter_blank_check = eprom_blank_check; + handle->firestarter_check_chip_id = eprom_check_chip_id; } -uint16_t eprom_get_chip_id(firestarter_handle_t* handle) { +uint16_t epromget_chip_id(firestarter_handle_t* handle) { handle->firestarter_set_control_register(handle, REGULATOR, 1); delay(50); @@ -52,7 +55,7 @@ uint16_t eprom_get_chip_id(firestarter_handle_t* handle) { } void eprom_check_chip_id(firestarter_handle_t* handle) { - uint16_t chip_id = eprom_get_chip_id(handle); + uint16_t chip_id = epromget_chip_id(handle); if (chip_id != handle->chip_id) { handle->response_code = handle->force ? RESPONSE_CODE_WARNING : RESPONSE_CODE_ERROR; format(handle->response_msg, "Chip ID %#x dont match expected ID %#x", chip_id, handle->chip_id); diff --git a/src/firestarter.cpp b/src/firestarter.cpp index 38c8ffb..ebaf7dc 100644 --- a/src/firestarter.cpp +++ b/src/firestarter.cpp @@ -108,6 +108,21 @@ void eraseProm(firestarter_handle_t* handle) { } } +void checkChipId(firestarter_handle_t* handle) { + debug("Check Chip ID"); + if (handle->firestarter_check_chip_id ) { + int res = executeFunction(handle->firestarter_check_chip_id, handle); + if (res <= 0) { + return; + } + logOkBuf(handle->response_msg, "Chip ID matches"); + handle->state = STATE_DONE; + } + else { + logError("Check Chip ID is not supported"); + } +} + void blankCheck(firestarter_handle_t* handle) { debug("Blank check PROM"); if (handle->firestarter_blank_check) { @@ -119,7 +134,7 @@ void blankCheck(firestarter_handle_t* handle) { handle->state = STATE_DONE; } else { - logError("Blank check not supported"); + logError("Blank check is not supported"); } } @@ -370,6 +385,9 @@ void loop() { case STATE_BLANK_CHECK: blankCheck(&handle); break; + case STATE_CHECK_CHIP_ID: + checkChipId(&handle); + break; case STATE_DONE: stateDone(&handle); break; diff --git a/src/flash.cpp b/src/flash.cpp index e507cf7..e6c86bf 100644 --- a/src/flash.cpp +++ b/src/flash.cpp @@ -26,9 +26,9 @@ void flash_blank_check(firestarter_handle_t* handle); void flash_read_init(firestarter_handle_t* handle); void flash_write_init(firestarter_handle_t* handle); void flash_write_data(firestarter_handle_t* handle); -uint16_t flash_get_chip_id(firestarter_handle_t* handle); void flash_check_chip_id(firestarter_handle_t* handle); +uint16_t flash_get_chip_id(firestarter_handle_t* handle); void enable_write(firestarter_handle_t* handle); void internal_erase(firestarter_handle_t* handle); void flip_data(firestarter_handle_t* handle, uint32_t address, uint8_t data); @@ -40,9 +40,10 @@ void configure_flash(firestarter_handle_t* handle) { debug("Configuring Flash"); handle->firestarter_read_init = flash_read_init; handle->firestarter_write_init = flash_write_init; + handle->firestarter_write_data = flash_write_data; handle->firestarter_erase = flash_erase; handle->firestarter_blank_check = flash_blank_check; - handle->firestarter_write_data = flash_write_data; + handle->firestarter_check_chip_id = flash_check_chip_id; } void flash_read_init(firestarter_handle_t* handle) { diff --git a/src/memory.cpp b/src/memory.cpp index 7dc95ea..2c9efa8 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -30,6 +30,7 @@ void configure_memory(firestarter_handle_t* handle) { handle->firestarter_write_data = memory_write_data; handle->firestarter_erase = NULL; handle->firestarter_blank_check = NULL; + handle->firestarter_check_chip_id = NULL; handle->firestarter_get_data = memory_get_data; handle->firestarter_set_data = memory_set_data;