mirror of
https://github.com/RfidResearchGroup/ChameleonUltra.git
synced 2026-09-11 18:30:14 -07:00
Add logic to automatically initialize some factory data in main.
This commit is contained in:
@@ -365,6 +365,9 @@ static void check_wakeup_src(void) {
|
||||
memset(noinit_addr, 0xFF, 0x8000);
|
||||
NRF_LOG_INFO("Reset noinit ram done.");
|
||||
|
||||
// 初始化默认卡槽数据。
|
||||
tag_emulation_factory_init();
|
||||
|
||||
ledblink2(0, !dir, 11);
|
||||
ledblink2(1, dir, 11);
|
||||
ledblink2(2, !dir, 11);
|
||||
|
||||
@@ -51,14 +51,14 @@ static tag_slot_config_t slotConfig ALIGN_U32 = {
|
||||
.config = { .activated = 0, .reserved1 = 0, .reserved2 = 0, .reserved3 = 0, },
|
||||
// 配置卡槽组
|
||||
.group = {
|
||||
{ .enable = true, .reserved1 = 0, .reserved2 = 0, .tag_hf = TAG_TYPE_MIFARE_1024, .tag_lf = TAG_TYPE_EM410X, }, // 1
|
||||
{ .enable = true, .reserved1 = 0, .reserved2 = 0, .tag_hf = TAG_TYPE_UNKNOWN, .tag_lf = TAG_TYPE_EM410X, }, // 2
|
||||
{ .enable = true, .reserved1 = 0, .reserved2 = 0, .tag_hf = TAG_TYPE_MIFARE_1024, .tag_lf = TAG_TYPE_UNKNOWN, }, // 3
|
||||
{ .enable = false, .reserved1 = 0, .reserved2 = 0, .tag_hf = TAG_TYPE_UNKNOWN, .tag_lf = TAG_TYPE_UNKNOWN, }, // 4
|
||||
{ .enable = false, .reserved1 = 0, .reserved2 = 0, .tag_hf = TAG_TYPE_UNKNOWN, .tag_lf = TAG_TYPE_UNKNOWN, }, // 5
|
||||
{ .enable = false, .reserved1 = 0, .reserved2 = 0, .tag_hf = TAG_TYPE_UNKNOWN, .tag_lf = TAG_TYPE_UNKNOWN, }, // 6
|
||||
{ .enable = false, .reserved1 = 0, .reserved2 = 0, .tag_hf = TAG_TYPE_UNKNOWN, .tag_lf = TAG_TYPE_UNKNOWN, }, // 7
|
||||
{ .enable = false, .reserved1 = 0, .reserved2 = 0, .tag_hf = TAG_TYPE_UNKNOWN, .tag_lf = TAG_TYPE_UNKNOWN, }, // 8
|
||||
{ .enable = true, .reserved1 = 0, .reserved2 = 0, .tag_hf = TAG_TYPE_MIFARE_1024, .tag_lf = TAG_TYPE_EM410X, }, // 1
|
||||
{ .enable = true, .reserved1 = 0, .reserved2 = 0, .tag_hf = TAG_TYPE_MIFARE_1024, .tag_lf = TAG_TYPE_UNKNOWN, }, // 2
|
||||
{ .enable = true, .reserved1 = 0, .reserved2 = 0, .tag_hf = TAG_TYPE_UNKNOWN, .tag_lf = TAG_TYPE_EM410X, }, // 3
|
||||
{ .enable = false, .reserved1 = 0, .reserved2 = 0, .tag_hf = TAG_TYPE_UNKNOWN, .tag_lf = TAG_TYPE_UNKNOWN, }, // 4
|
||||
{ .enable = false, .reserved1 = 0, .reserved2 = 0, .tag_hf = TAG_TYPE_UNKNOWN, .tag_lf = TAG_TYPE_UNKNOWN, }, // 5
|
||||
{ .enable = false, .reserved1 = 0, .reserved2 = 0, .tag_hf = TAG_TYPE_UNKNOWN, .tag_lf = TAG_TYPE_UNKNOWN, }, // 6
|
||||
{ .enable = false, .reserved1 = 0, .reserved2 = 0, .tag_hf = TAG_TYPE_UNKNOWN, .tag_lf = TAG_TYPE_UNKNOWN, }, // 7
|
||||
{ .enable = false, .reserved1 = 0, .reserved2 = 0, .tag_hf = TAG_TYPE_UNKNOWN, .tag_lf = TAG_TYPE_UNKNOWN, }, // 8
|
||||
},
|
||||
};
|
||||
// 卡槽配置特有的CRC,一旦slot配置发生变动,可通过CRC检查出来
|
||||
@@ -550,3 +550,42 @@ void tag_emulation_change_type(uint8_t slot, tag_specific_type_t tag_type) {
|
||||
NRF_LOG_INFO("reload data success.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 模拟卡的工厂初始化函数
|
||||
* 可用于初始化默认出厂的一些数据
|
||||
*/
|
||||
void tag_emulation_factory_init(void) {
|
||||
fds_slot_record_map_t map_info;
|
||||
|
||||
if (slotConfig.group[0].enable && slotConfig.group[0].tag_hf != TAG_TYPE_UNKNOWN && slotConfig.group[0].tag_lf != TAG_TYPE_UNKNOWN) {
|
||||
// 在卡槽一初始化一张双频卡,如果其不存在历史记录,默认其是全新出厂状态。
|
||||
get_fds_map_by_slot_sense_type_for_dump(0, TAG_SENSE_HF, &map_info);
|
||||
bool is_slot1_hf_data_exists = fds_is_exists(map_info.id, map_info.key);
|
||||
get_fds_map_by_slot_sense_type_for_dump(0, TAG_SENSE_LF, &map_info);
|
||||
bool is_slot1_lf_data_exists = fds_is_exists(map_info.id, map_info.key);
|
||||
// 此处判断卡槽1的高频卡和低频卡都不存在
|
||||
if (!is_slot1_hf_data_exists && !is_slot1_lf_data_exists) {
|
||||
tag_emulation_factory_data(0, slotConfig.group[0].tag_hf);
|
||||
tag_emulation_factory_data(0, slotConfig.group[0].tag_lf);
|
||||
}
|
||||
}
|
||||
|
||||
if (slotConfig.group[1].enable && slotConfig.group[1].tag_hf != TAG_TYPE_UNKNOWN) {
|
||||
// 在卡槽2初始化一张高频m1卡,如果其不存在的话。
|
||||
get_fds_map_by_slot_sense_type_for_dump(1, TAG_SENSE_HF, &map_info);
|
||||
bool is_slot2_hf_data_exists = fds_is_exists(map_info.id, map_info.key);
|
||||
if (!is_slot2_hf_data_exists) {
|
||||
tag_emulation_factory_data(1, slotConfig.group[1].tag_hf);
|
||||
}
|
||||
}
|
||||
|
||||
if (slotConfig.group[2].enable && slotConfig.group[2].tag_lf != TAG_TYPE_UNKNOWN) {
|
||||
// 在卡槽3初始化一张低频em410x卡,如果其不存在的话。
|
||||
get_fds_map_by_slot_sense_type_for_dump(2, TAG_SENSE_LF, &map_info);
|
||||
bool is_slot3_lf_data_exists = fds_is_exists(map_info.id, map_info.key);
|
||||
if (!is_slot3_lf_data_exists) {
|
||||
tag_emulation_factory_data(2, slotConfig.group[2].tag_lf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,6 +101,8 @@ bool tag_emulation_slot_is_enable(uint8_t slot);
|
||||
void tag_emulation_slot_set_enable(uint8_t slot, bool enable);
|
||||
// 获取对应卡槽的模拟卡类型
|
||||
void tag_emulation_get_specific_type_by_slot(uint8_t slot, tag_specific_type_t tag_type[2]);
|
||||
// 初始化某些出厂数据
|
||||
void tag_emulation_factory_init(void);
|
||||
|
||||
// 在某个方向上查询任何一个使能的卡槽
|
||||
uint8_t tag_emulation_slot_find_next(uint8_t slot_now);
|
||||
|
||||
@@ -37,7 +37,7 @@ static bool fds_find_record(uint16_t id, uint16_t key, fds_record_desc_t *desc)
|
||||
* @return true on record exists
|
||||
* @return false on no found
|
||||
*/
|
||||
bool fds_record_exists(uint16_t id, uint16_t key) {
|
||||
bool fds_is_exists(uint16_t id, uint16_t key) {
|
||||
fds_record_desc_t record_desc;
|
||||
if (fds_find_record(id, key, &record_desc)) {
|
||||
return true;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
bool fds_read_sync(uint16_t id, uint16_t key, uint16_t max_length, uint8_t* buffer);
|
||||
bool fds_write_sync(uint16_t id, uint16_t key, uint16_t data_length_words, void* buffer);
|
||||
int fds_delete_sync(uint16_t id, uint16_t key);
|
||||
bool fds_record_exists(uint16_t id, uint16_t key);
|
||||
bool fds_is_exists(uint16_t id, uint16_t key);
|
||||
void fds_util_init(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -99,7 +99,7 @@ void hw_connect_init(void) {
|
||||
|
||||
// TODO 请实现此处,实现硬件版本号的读取
|
||||
// 测试的时候可以直接改写此版本号
|
||||
m_hw_ver = 1;
|
||||
m_hw_ver = 2;
|
||||
|
||||
|
||||
#if defined(PROJECT_CHAMELEON_ULTRA)
|
||||
@@ -142,14 +142,14 @@ void hw_connect_init(void) {
|
||||
LED_R = (NRF_GPIO_PIN_MAP(0, 24));
|
||||
LED_G = (NRF_GPIO_PIN_MAP(0, 22));
|
||||
LED_B = (NRF_GPIO_PIN_MAP(1, 0));
|
||||
LED_8 = (NRF_GPIO_PIN_MAP(0, 20));
|
||||
LED_7 = (NRF_GPIO_PIN_MAP(0, 17));
|
||||
LED_6 = (NRF_GPIO_PIN_MAP(0, 15));
|
||||
LED_5 = (NRF_GPIO_PIN_MAP(0, 13));
|
||||
LED_4 = (NRF_GPIO_PIN_MAP(0, 12));
|
||||
LED_3 = (NRF_GPIO_PIN_MAP(1, 9));
|
||||
LED_2 = (NRF_GPIO_PIN_MAP(0, 8));
|
||||
LED_1 = (NRF_GPIO_PIN_MAP(0, 6));
|
||||
LED_1 = (NRF_GPIO_PIN_MAP(0, 20));
|
||||
LED_2 = (NRF_GPIO_PIN_MAP(0, 17));
|
||||
LED_3 = (NRF_GPIO_PIN_MAP(0, 15));
|
||||
LED_4 = (NRF_GPIO_PIN_MAP(0, 13));
|
||||
LED_5 = (NRF_GPIO_PIN_MAP(0, 12));
|
||||
LED_6 = (NRF_GPIO_PIN_MAP(1, 9));
|
||||
LED_7 = (NRF_GPIO_PIN_MAP(0, 8));
|
||||
LED_8 = (NRF_GPIO_PIN_MAP(0, 6));
|
||||
RGB_LIST_NUM = 8;
|
||||
RGB_CTRL_NUM = 3;
|
||||
|
||||
@@ -165,8 +165,8 @@ void hw_connect_init(void) {
|
||||
HF_SPI_SCK = (NRF_GPIO_PIN_MAP(1, 4));
|
||||
HF_ANT_SEL = (NRF_GPIO_PIN_MAP(1, 10));
|
||||
|
||||
BUTTON_1 = (NRF_GPIO_PIN_MAP(0, 26));
|
||||
BUTTON_2 = (NRF_GPIO_PIN_MAP(1, 2));
|
||||
BUTTON_2 = (NRF_GPIO_PIN_MAP(0, 26));
|
||||
BUTTON_1 = (NRF_GPIO_PIN_MAP(1, 2));
|
||||
|
||||
BAT_SENSE = (NRF_GPIO_PIN_MAP(0, 4));
|
||||
READER_POWER = (NRF_GPIO_PIN_MAP(1, 15));
|
||||
|
||||
Reference in New Issue
Block a user