ACK command and use delayed reset

This commit is contained in:
Augusto Zanellato
2023-08-18 22:35:39 +02:00
parent 4ab131d10a
commit 7b76aefd5e
5 changed files with 39 additions and 16 deletions
+1
View File
@@ -30,6 +30,7 @@ SRC_FILES += \
$(PROJ_DIR)/rfid/nfctag/hf/nfc_ntag.c \
$(PROJ_DIR)/rfid/nfctag/lf/lf_tag_em.c \
$(PROJ_DIR)/utils/dataframe.c \
$(PROJ_DIR)/utils/delayed_reset.c \
$(PROJ_DIR)/utils/fds_util.c \
$(PROJ_DIR)/utils/syssleep.c \
$(PROJ_DIR)/utils/timeslot.c \
+4 -9
View File
@@ -13,6 +13,7 @@
#include "tag_persistence.h"
#include "nrf_pwr_mgmt.h"
#include "settings.h"
#include "delayed_reset.h"
#define NRF_LOG_MODULE_NAME app_cmd
@@ -359,15 +360,9 @@ data_frame_tx_t* cmd_processor_get_slot_info(uint16_t cmd, uint16_t status, uint
data_frame_tx_t* cmd_processor_wipe_fds(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
bool success = fds_wipe();
if (!success) {
return data_frame_make(cmd, STATUS_FLASH_WRITE_FAIL, 0, NULL);
}
while (NRF_LOG_PROCESS());
ret_code_t ret = sd_nvic_SystemReset();
APP_ERROR_CHECK(ret);
while (1) {
__NOP();
}
status = success ? STATUS_DEVICE_SUCCESS : STATUS_FLASH_WRITE_FAIL;
delayed_reset(50);
return data_frame_make(cmd, status, 0, NULL);
}
data_frame_tx_t* cmd_processor_set_em410x_emu_id(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
@@ -0,0 +1,26 @@
#include "app_timer.h"
#include "delayed_reset.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
APP_TIMER_DEF(m_reset_timer);
static void delayed_reset_event_handler(void* ctx) {
while (NRF_LOG_PROCESS());
ret_code_t ret = sd_nvic_SystemReset();
APP_ERROR_CHECK(ret);
while (1) {
__NOP();
}
}
void delayed_reset(uint32_t delay) {
NRF_LOG_INFO("Resetting in %d ms...", delay);
ret_code_t ret;
ret = app_timer_create(&m_reset_timer, APP_TIMER_MODE_SINGLE_SHOT, delayed_reset_event_handler);
APP_ERROR_CHECK(ret);
ret = app_timer_start(m_reset_timer, APP_TIMER_TICKS(delay), NULL);
APP_ERROR_CHECK(ret);
}
@@ -0,0 +1,3 @@
#pragma once
void delayed_reset(uint32_t delay);
+5 -7
View File
@@ -1084,11 +1084,9 @@ class HWFactoryReset(DeviceRequiredUnit):
if not args.i_know_what_im_doing:
print("This time your data's safe. Read the command documentation next time.")
return
try:
resp = self.cmd_positive.factory_reset()
if resp.status != chameleon_status.Device.STATUS_DEVICE_SUCCESS:
print(" - Reset failed!")
return
except KeyError:
print(" - A Serial Error above is normal, please ignore it")
resp = self.cmd_positive.factory_reset()
if resp.status == chameleon_status.Device.STATUS_DEVICE_SUCCESS:
print(" - Reset successful! Please reconnect.")
print(" - A Serial Error below is normal, please ignore it")
else:
print(" - Reset failed!")