NFC: fix MFC timings (#2719)
* digital signal: add optimization * nfc test: more restrict tests * digital signal: build as separate library * digital signal: remove unused flags, format sources * digital signal: fix cflag name * target: fix build for f18 target Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
parent
3a7203e32e
commit
1d7966f74e
@ -27,6 +27,12 @@ static const uint32_t nfc_test_file_version = 1;
|
|||||||
#define NFC_TEST_DATA_MAX_LEN 18
|
#define NFC_TEST_DATA_MAX_LEN 18
|
||||||
#define NFC_TETS_TIMINGS_MAX_LEN 1350
|
#define NFC_TETS_TIMINGS_MAX_LEN 1350
|
||||||
|
|
||||||
|
// Maximum allowed time for buffer preparation to fit 500us nt message timeout
|
||||||
|
#define NFC_TEST_4_BYTE_BUILD_BUFFER_TIM_MAX (150)
|
||||||
|
#define NFC_TEST_16_BYTE_BUILD_BUFFER_TIM_MAX (640)
|
||||||
|
#define NFC_TEST_4_BYTE_BUILD_SIGNAL_TIM_MAX (110)
|
||||||
|
#define NFC_TEST_16_BYTE_BUILD_SIGNAL_TIM_MAX (440)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Storage* storage;
|
Storage* storage;
|
||||||
NfcaSignal* signal;
|
NfcaSignal* signal;
|
||||||
@ -89,13 +95,13 @@ static bool nfc_test_read_signal_from_file(const char* file_name) {
|
|||||||
|
|
||||||
static bool nfc_test_digital_signal_test_encode(
|
static bool nfc_test_digital_signal_test_encode(
|
||||||
const char* file_name,
|
const char* file_name,
|
||||||
uint32_t encode_max_time,
|
uint32_t build_signal_max_time_us,
|
||||||
|
uint32_t build_buffer_max_time_us,
|
||||||
uint32_t timing_tolerance,
|
uint32_t timing_tolerance,
|
||||||
uint32_t timings_sum_tolerance) {
|
uint32_t timings_sum_tolerance) {
|
||||||
furi_assert(nfc_test);
|
furi_assert(nfc_test);
|
||||||
|
|
||||||
bool success = false;
|
bool success = false;
|
||||||
uint32_t time = 0;
|
|
||||||
uint32_t dut_timings_sum = 0;
|
uint32_t dut_timings_sum = 0;
|
||||||
uint32_t ref_timings_sum = 0;
|
uint32_t ref_timings_sum = 0;
|
||||||
uint8_t parity[10] = {};
|
uint8_t parity[10] = {};
|
||||||
@ -109,17 +115,37 @@ static bool nfc_test_digital_signal_test_encode(
|
|||||||
|
|
||||||
// Encode signal
|
// Encode signal
|
||||||
FURI_CRITICAL_ENTER();
|
FURI_CRITICAL_ENTER();
|
||||||
time = DWT->CYCCNT;
|
uint32_t time_start = DWT->CYCCNT;
|
||||||
|
|
||||||
nfca_signal_encode(
|
nfca_signal_encode(
|
||||||
nfc_test->signal, nfc_test->test_data, nfc_test->test_data_len * 8, parity);
|
nfc_test->signal, nfc_test->test_data, nfc_test->test_data_len * 8, parity);
|
||||||
|
|
||||||
|
uint32_t time_signal =
|
||||||
|
(DWT->CYCCNT - time_start) / furi_hal_cortex_instructions_per_microsecond();
|
||||||
|
|
||||||
|
time_start = DWT->CYCCNT;
|
||||||
|
|
||||||
digital_signal_prepare_arr(nfc_test->signal->tx_signal);
|
digital_signal_prepare_arr(nfc_test->signal->tx_signal);
|
||||||
time = (DWT->CYCCNT - time) / furi_hal_cortex_instructions_per_microsecond();
|
|
||||||
|
uint32_t time_buffer =
|
||||||
|
(DWT->CYCCNT - time_start) / furi_hal_cortex_instructions_per_microsecond();
|
||||||
FURI_CRITICAL_EXIT();
|
FURI_CRITICAL_EXIT();
|
||||||
|
|
||||||
// Check timings
|
// Check timings
|
||||||
if(time > encode_max_time) {
|
if(time_signal > build_signal_max_time_us) {
|
||||||
FURI_LOG_E(
|
FURI_LOG_E(
|
||||||
TAG, "Encoding time: %ld us while accepted value: %ld us", time, encode_max_time);
|
TAG,
|
||||||
|
"Build signal time: %ld us while accepted value: %ld us",
|
||||||
|
time_signal,
|
||||||
|
build_signal_max_time_us);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(time_buffer > build_buffer_max_time_us) {
|
||||||
|
FURI_LOG_E(
|
||||||
|
TAG,
|
||||||
|
"Build buffer time: %ld us while accepted value: %ld us",
|
||||||
|
time_buffer,
|
||||||
|
build_buffer_max_time_us);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +182,16 @@ static bool nfc_test_digital_signal_test_encode(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
FURI_LOG_I(TAG, "Encoding time: %ld us. Acceptable time: %ld us", time, encode_max_time);
|
FURI_LOG_I(
|
||||||
|
TAG,
|
||||||
|
"Build signal time: %ld us. Acceptable time: %ld us",
|
||||||
|
time_signal,
|
||||||
|
build_signal_max_time_us);
|
||||||
|
FURI_LOG_I(
|
||||||
|
TAG,
|
||||||
|
"Build buffer time: %ld us. Acceptable time: %ld us",
|
||||||
|
time_buffer,
|
||||||
|
build_buffer_max_time_us);
|
||||||
FURI_LOG_I(
|
FURI_LOG_I(
|
||||||
TAG,
|
TAG,
|
||||||
"Timings sum difference: %ld [1/64MHZ]. Acceptable difference: %ld [1/64MHz]",
|
"Timings sum difference: %ld [1/64MHZ]. Acceptable difference: %ld [1/64MHz]",
|
||||||
@ -171,11 +206,19 @@ static bool nfc_test_digital_signal_test_encode(
|
|||||||
MU_TEST(nfc_digital_signal_test) {
|
MU_TEST(nfc_digital_signal_test) {
|
||||||
mu_assert(
|
mu_assert(
|
||||||
nfc_test_digital_signal_test_encode(
|
nfc_test_digital_signal_test_encode(
|
||||||
NFC_TEST_RESOURCES_DIR NFC_TEST_SIGNAL_SHORT_FILE, 500, 1, 37),
|
NFC_TEST_RESOURCES_DIR NFC_TEST_SIGNAL_SHORT_FILE,
|
||||||
|
NFC_TEST_4_BYTE_BUILD_SIGNAL_TIM_MAX,
|
||||||
|
NFC_TEST_4_BYTE_BUILD_BUFFER_TIM_MAX,
|
||||||
|
1,
|
||||||
|
37),
|
||||||
"NFC short digital signal test failed\r\n");
|
"NFC short digital signal test failed\r\n");
|
||||||
mu_assert(
|
mu_assert(
|
||||||
nfc_test_digital_signal_test_encode(
|
nfc_test_digital_signal_test_encode(
|
||||||
NFC_TEST_RESOURCES_DIR NFC_TEST_SIGNAL_LONG_FILE, 2000, 1, 37),
|
NFC_TEST_RESOURCES_DIR NFC_TEST_SIGNAL_LONG_FILE,
|
||||||
|
NFC_TEST_16_BYTE_BUILD_SIGNAL_TIM_MAX,
|
||||||
|
NFC_TEST_16_BYTE_BUILD_BUFFER_TIM_MAX,
|
||||||
|
1,
|
||||||
|
37),
|
||||||
"NFC long digital signal test failed\r\n");
|
"NFC long digital signal test failed\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
entry,status,name,type,params
|
entry,status,name,type,params
|
||||||
Version,+,28.1,,
|
Version,+,28.2,,
|
||||||
Header,+,applications/services/bt/bt_service/bt.h,,
|
Header,+,applications/services/bt/bt_service/bt.h,,
|
||||||
Header,+,applications/services/cli/cli.h,,
|
Header,+,applications/services/cli/cli.h,,
|
||||||
Header,+,applications/services/cli/cli_vcp.h,,
|
Header,+,applications/services/cli/cli_vcp.h,,
|
||||||
@ -80,6 +80,7 @@ Header,+,firmware/targets/furi_hal_include/furi_hal_usb_hid.h,,
|
|||||||
Header,+,firmware/targets/furi_hal_include/furi_hal_usb_hid_u2f.h,,
|
Header,+,firmware/targets/furi_hal_include/furi_hal_usb_hid_u2f.h,,
|
||||||
Header,+,firmware/targets/furi_hal_include/furi_hal_version.h,,
|
Header,+,firmware/targets/furi_hal_include/furi_hal_version.h,,
|
||||||
Header,+,firmware/targets/furi_hal_include/furi_hal_vibro.h,,
|
Header,+,firmware/targets/furi_hal_include/furi_hal_vibro.h,,
|
||||||
|
Header,+,lib/digital_signal/digital_signal.h,,
|
||||||
Header,+,lib/flipper_application/api_hashtable/api_hashtable.h,,
|
Header,+,lib/flipper_application/api_hashtable/api_hashtable.h,,
|
||||||
Header,+,lib/flipper_application/api_hashtable/compilesort.hpp,,
|
Header,+,lib/flipper_application/api_hashtable/compilesort.hpp,,
|
||||||
Header,+,lib/flipper_application/flipper_application.h,,
|
Header,+,lib/flipper_application/flipper_application.h,,
|
||||||
@ -617,6 +618,24 @@ Function,+,dialog_message_set_text,void,"DialogMessage*, const char*, uint8_t, u
|
|||||||
Function,+,dialog_message_show,DialogMessageButton,"DialogsApp*, const DialogMessage*"
|
Function,+,dialog_message_show,DialogMessageButton,"DialogsApp*, const DialogMessage*"
|
||||||
Function,+,dialog_message_show_storage_error,void,"DialogsApp*, const char*"
|
Function,+,dialog_message_show_storage_error,void,"DialogsApp*, const char*"
|
||||||
Function,-,difftime,double,"time_t, time_t"
|
Function,-,difftime,double,"time_t, time_t"
|
||||||
|
Function,-,digital_sequence_add,void,"DigitalSequence*, uint8_t"
|
||||||
|
Function,-,digital_sequence_alloc,DigitalSequence*,"uint32_t, const GpioPin*"
|
||||||
|
Function,-,digital_sequence_clear,void,DigitalSequence*
|
||||||
|
Function,-,digital_sequence_free,void,DigitalSequence*
|
||||||
|
Function,-,digital_sequence_send,_Bool,DigitalSequence*
|
||||||
|
Function,-,digital_sequence_set_sendtime,void,"DigitalSequence*, uint32_t"
|
||||||
|
Function,-,digital_sequence_set_signal,void,"DigitalSequence*, uint8_t, DigitalSignal*"
|
||||||
|
Function,-,digital_sequence_timebase_correction,void,"DigitalSequence*, float"
|
||||||
|
Function,-,digital_signal_add,void,"DigitalSignal*, uint32_t"
|
||||||
|
Function,-,digital_signal_add_pulse,void,"DigitalSignal*, uint32_t, _Bool"
|
||||||
|
Function,-,digital_signal_alloc,DigitalSignal*,uint32_t
|
||||||
|
Function,-,digital_signal_append,_Bool,"DigitalSignal*, DigitalSignal*"
|
||||||
|
Function,-,digital_signal_free,void,DigitalSignal*
|
||||||
|
Function,-,digital_signal_get_edge,uint32_t,"DigitalSignal*, uint32_t"
|
||||||
|
Function,-,digital_signal_get_edges_cnt,uint32_t,DigitalSignal*
|
||||||
|
Function,-,digital_signal_get_start_level,_Bool,DigitalSignal*
|
||||||
|
Function,-,digital_signal_prepare_arr,void,DigitalSignal*
|
||||||
|
Function,-,digital_signal_send,void,"DigitalSignal*, const GpioPin*"
|
||||||
Function,-,diprintf,int,"int, const char*, ..."
|
Function,-,diprintf,int,"int, const char*, ..."
|
||||||
Function,+,dir_walk_alloc,DirWalk*,Storage*
|
Function,+,dir_walk_alloc,DirWalk*,Storage*
|
||||||
Function,+,dir_walk_close,void,DirWalk*
|
Function,+,dir_walk_close,void,DirWalk*
|
||||||
|
|||||||
|
@ -1,5 +1,5 @@
|
|||||||
entry,status,name,type,params
|
entry,status,name,type,params
|
||||||
Version,+,28.1,,
|
Version,+,28.2,,
|
||||||
Header,+,applications/services/bt/bt_service/bt.h,,
|
Header,+,applications/services/bt/bt_service/bt.h,,
|
||||||
Header,+,applications/services/cli/cli.h,,
|
Header,+,applications/services/cli/cli.h,,
|
||||||
Header,+,applications/services/cli/cli_vcp.h,,
|
Header,+,applications/services/cli/cli_vcp.h,,
|
||||||
@ -86,6 +86,7 @@ Header,+,firmware/targets/furi_hal_include/furi_hal_usb_hid.h,,
|
|||||||
Header,+,firmware/targets/furi_hal_include/furi_hal_usb_hid_u2f.h,,
|
Header,+,firmware/targets/furi_hal_include/furi_hal_usb_hid_u2f.h,,
|
||||||
Header,+,firmware/targets/furi_hal_include/furi_hal_version.h,,
|
Header,+,firmware/targets/furi_hal_include/furi_hal_version.h,,
|
||||||
Header,+,firmware/targets/furi_hal_include/furi_hal_vibro.h,,
|
Header,+,firmware/targets/furi_hal_include/furi_hal_vibro.h,,
|
||||||
|
Header,+,lib/digital_signal/digital_signal.h,,
|
||||||
Header,+,lib/flipper_application/api_hashtable/api_hashtable.h,,
|
Header,+,lib/flipper_application/api_hashtable/api_hashtable.h,,
|
||||||
Header,+,lib/flipper_application/api_hashtable/compilesort.hpp,,
|
Header,+,lib/flipper_application/api_hashtable/compilesort.hpp,,
|
||||||
Header,+,lib/flipper_application/flipper_application.h,,
|
Header,+,lib/flipper_application/flipper_application.h,,
|
||||||
|
|||||||
|
@ -28,6 +28,7 @@
|
|||||||
"flipperformat",
|
"flipperformat",
|
||||||
"toolbox",
|
"toolbox",
|
||||||
"nfc",
|
"nfc",
|
||||||
|
"digital_signal",
|
||||||
"pulse_reader",
|
"pulse_reader",
|
||||||
"microtar",
|
"microtar",
|
||||||
"usb_stm32",
|
"usb_stm32",
|
||||||
|
|||||||
@ -27,6 +27,7 @@
|
|||||||
- `nfc` - NFC library, used by NFC application
|
- `nfc` - NFC library, used by NFC application
|
||||||
- `one_wire` - OneWire library, used by iButton application
|
- `one_wire` - OneWire library, used by iButton application
|
||||||
- `print` - Tiny printf implementation
|
- `print` - Tiny printf implementation
|
||||||
|
- `digital_signal` - Digital Signal library used by NFC for software implemented protocols
|
||||||
- `pulse_reader` - Pulse Reader library used by NFC for software implemented protocols
|
- `pulse_reader` - Pulse Reader library used by NFC for software implemented protocols
|
||||||
- `qrcode` - QR-Code library
|
- `qrcode` - QR-Code library
|
||||||
- `stm32wb_cmsis` - STM32WB series CMSIS headers, extends CMSIS Core
|
- `stm32wb_cmsis` - STM32WB series CMSIS headers, extends CMSIS Core
|
||||||
|
|||||||
@ -15,7 +15,6 @@ env.Append(
|
|||||||
Dir("u8g2"),
|
Dir("u8g2"),
|
||||||
Dir("update_util"),
|
Dir("update_util"),
|
||||||
Dir("print"),
|
Dir("print"),
|
||||||
Dir("pulse_reader"),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -95,6 +94,7 @@ libs = env.BuildModules(
|
|||||||
"mbedtls",
|
"mbedtls",
|
||||||
"subghz",
|
"subghz",
|
||||||
"nfc",
|
"nfc",
|
||||||
|
"digital_signal",
|
||||||
"pulse_reader",
|
"pulse_reader",
|
||||||
"appframe",
|
"appframe",
|
||||||
"misc",
|
"misc",
|
||||||
|
|||||||
20
lib/digital_signal/SConscript
Normal file
20
lib/digital_signal/SConscript
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
Import("env")
|
||||||
|
|
||||||
|
env.Append(
|
||||||
|
CPPPATH=[
|
||||||
|
"#/lib/digital_signal",
|
||||||
|
],
|
||||||
|
SDK_HEADERS=[
|
||||||
|
File("digital_signal.h"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
libenv = env.Clone(FW_LIB_NAME="digital_signal")
|
||||||
|
libenv.ApplyLibFlags()
|
||||||
|
libenv.Append(CCFLAGS=["-O3", "-funroll-loops", "-Ofast"])
|
||||||
|
|
||||||
|
sources = libenv.GlobRecursive("*.c*")
|
||||||
|
|
||||||
|
lib = libenv.StaticLibrary("${FW_LIB_NAME}", sources)
|
||||||
|
libenv.Install("${LIB_DIST_DIR}", lib)
|
||||||
|
Return("lib")
|
||||||
@ -212,8 +212,7 @@ void digital_signal_prepare_arr(DigitalSignal* signal) {
|
|||||||
internals->reload_reg_entries = 0;
|
internals->reload_reg_entries = 0;
|
||||||
|
|
||||||
for(size_t pos = 0; pos < signal->edge_cnt; pos++) {
|
for(size_t pos = 0; pos < signal->edge_cnt; pos++) {
|
||||||
uint32_t edge_scaled = (internals->factor * signal->edge_timings[pos]) / (1024 * 1024);
|
uint32_t pulse_duration = signal->edge_timings[pos] + internals->reload_reg_remainder;
|
||||||
uint32_t pulse_duration = edge_scaled + internals->reload_reg_remainder;
|
|
||||||
if(pulse_duration < 10 || pulse_duration > 10000000) {
|
if(pulse_duration < 10 || pulse_duration > 10000000) {
|
||||||
FURI_LOG_D(
|
FURI_LOG_D(
|
||||||
TAG,
|
TAG,
|
||||||
|
|||||||
@ -4,7 +4,6 @@ Import("env")
|
|||||||
|
|
||||||
env.Append(
|
env.Append(
|
||||||
CPPPATH=[
|
CPPPATH=[
|
||||||
"#/lib/digital_signal",
|
|
||||||
"#/lib/fnv1a_hash",
|
"#/lib/fnv1a_hash",
|
||||||
"#/lib/heatshrink",
|
"#/lib/heatshrink",
|
||||||
"#/lib/micro-ecc",
|
"#/lib/micro-ecc",
|
||||||
@ -26,7 +25,6 @@ libenv.ApplyLibFlags()
|
|||||||
sources = []
|
sources = []
|
||||||
|
|
||||||
libs_recurse = [
|
libs_recurse = [
|
||||||
"digital_signal",
|
|
||||||
"micro-ecc",
|
"micro-ecc",
|
||||||
"u8g2",
|
"u8g2",
|
||||||
"update_util",
|
"update_util",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user