Skip to content

Commit

Permalink
Checking chip id
Browse files Browse the repository at this point in the history
  • Loading branch information
henols committed Nov 26, 2024
1 parent ba22425 commit 3304ec0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
3 changes: 3 additions & 0 deletions include/firestarter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions src/eprom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);
Expand Down
20 changes: 19 additions & 1 deletion src/firestarter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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");
}
}

Expand Down Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/flash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3304ec0

Please sign in to comment.