|
|
@ -8,9 +8,9 @@ |
|
|
|
using namespace std; |
|
|
|
using namespace iflytop; |
|
|
|
|
|
|
|
#define SECTOR_SIZE (128)
|
|
|
|
#define SECTOR_NUM (2 * 8) // 2k
|
|
|
|
#define MAX_SIZE (SECTOR_SIZE * SECTOR_NUM)
|
|
|
|
#define SECTOR_SIZE (64)
|
|
|
|
#define SECTOR_NUM (4 * 8)
|
|
|
|
#define MAX_SIZE (SECTOR_SIZE * SECTOR_NUM)// 2k
|
|
|
|
|
|
|
|
#define TAG "EEPROMService"
|
|
|
|
|
|
|
@ -55,6 +55,11 @@ void EEPROMService::initialize(int id, I2C_HandleTypeDef* i2c_handle, ProtocolEv |
|
|
|
// write_test_data_rom(&m_subdevice_p24c16);
|
|
|
|
// write_test_data_rom(&m_subdevice_m24lrxxe);
|
|
|
|
|
|
|
|
// MAX_SIZE
|
|
|
|
m_idcardcache = (uint8_t*)malloc(MAX_SIZE + 10); |
|
|
|
ZASSERT(m_idcardcache); |
|
|
|
memset(m_idcardcache, 0, MAX_SIZE + 10); |
|
|
|
|
|
|
|
start_monitor_status(); |
|
|
|
} |
|
|
|
|
|
|
@ -116,22 +121,37 @@ void EEPROMService::detect_online() { |
|
|
|
* |
|
|
|
* @param i2c_ping_state |
|
|
|
*/ |
|
|
|
|
|
|
|
bool detect = false; |
|
|
|
if (i2c_ping_state[0x50] && i2c_ping_state[0x51] && i2c_ping_state[0x52]) { |
|
|
|
m_nowonline = &m_subdevice_p24c16; |
|
|
|
change_is_online_flag(true); |
|
|
|
m_writeunlock = false; |
|
|
|
ZLOGI(TAG, "detect eerpom p24c16"); |
|
|
|
detect = true; |
|
|
|
} else if (!i2c_ping_state[0x50] && i2c_ping_state[0x53] && i2c_ping_state[0x57]) { |
|
|
|
m_nowonline = &m_subdevice_m24lrxxe; |
|
|
|
change_is_online_flag(true); |
|
|
|
m_writeunlock = false; |
|
|
|
ZLOGI(TAG, "detect eerpom M24LR16E"); //
|
|
|
|
// uint32_t rdbak = 0;
|
|
|
|
// m_subdevice_m24lrxxe.readCfgReg(2332, &rdbak);
|
|
|
|
// ZLOGI(TAG, "m24lrxxe cfg reg: %08x", rdbak);
|
|
|
|
detect = true; |
|
|
|
} |
|
|
|
if (!detect) return; |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief |
|
|
|
* 直接读取数据进行缓存 |
|
|
|
* |
|
|
|
*/ |
|
|
|
|
|
|
|
for (uint16_t i = 0; i < SECTOR_NUM; i++) { |
|
|
|
int32_t len = SECTOR_SIZE; |
|
|
|
int32_t suc = m_nowonline->read(i * SECTOR_SIZE, m_idcardcache + i * SECTOR_SIZE, &len); |
|
|
|
if (suc != 0) { |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ZLOGI(TAG, "detect_online: %d", m_nowonline->isOnline()); |
|
|
|
|
|
|
|
m_writeunlock = false; |
|
|
|
change_is_online_flag(true); |
|
|
|
|
|
|
|
} else { |
|
|
|
if (!m_nowonline->isOnline()) { |
|
|
|
m_nowonline = nullptr; |
|
|
@ -148,19 +168,27 @@ int32_t EEPROMService::a8000_idcard_reader_read_raw(int32_t index, uint8_t* data |
|
|
|
uint16_t add = index * SECTOR_SIZE; |
|
|
|
*len = SECTOR_SIZE; |
|
|
|
|
|
|
|
ZLOGI(TAG, "read: %d, %d", add, *len); |
|
|
|
int32_t val = m_nowonline->read(add, data, len); |
|
|
|
// dumpbuf(data, *len);
|
|
|
|
return val; |
|
|
|
memcpy(data, m_idcardcache + add, *len); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
int32_t EEPROMService::a8000_idcard_write_raw(int32_t add, uint8_t* data, int32_t len) { |
|
|
|
zlock_guard guard(m_mutex); |
|
|
|
/**
|
|
|
|
* @brief 每次写入需要大于5ms |
|
|
|
*/ |
|
|
|
if (!m_nowonline) return err::kdevice_offline; |
|
|
|
if (!m_writeunlock) return err::killegal_operation; |
|
|
|
if (add % 4 != 0) return err::kparam_out_of_range; |
|
|
|
if (len != 4) return err::kparam_out_of_range; |
|
|
|
if (add >= MAX_SIZE) return err::kparam_out_of_range; |
|
|
|
if (HAL_GetTick() - m_lastwritetime < 5) return err::kdevice_is_busy; |
|
|
|
|
|
|
|
ZLOGI(TAG, "write: 0x%08x, 0x%08x ", add, *(uint32_t*)data); |
|
|
|
m_nowonline->write(add, data, len); |
|
|
|
m_nowonline->read(add, m_idcardcache + add, &len); |
|
|
|
|
|
|
|
ZLOGI(TAG, "write: 0x%08x, %d", add, len); |
|
|
|
m_nowonline->write(add, (uint8_t*)&data, len); |
|
|
|
m_lastwritetime = HAL_GetTick(); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|