From e6540d1d79b551f0967d3080b8dbdcec939b1235 Mon Sep 17 00:00:00 2001 From: forest-rain <693097971@qq.com> Date: Thu, 29 Oct 2020 15:58:20 +0800 Subject: [PATCH] optimize and rename delay_ms --- lora-radio/sx126x/lora-radio-sx126x.c | 4 ++-- lora-radio/sx126x/lora-spi-sx126x.c | 3 +++ ports/lora-module/inc/sx126x-board.h | 3 ++- .../stm32_adapter/SX1262_ASR6500S/sx126x-board.c | 6 +++--- .../stm32_adapter/SX1262_LSD4RF-2R822N30/sx1262-board.c | 6 +++--- .../stm32_adapter/SX1268_LSD4RF-2R717N40/sx1268-board.c | 6 +++--- ports/lora-module/stm32_adapter/SX1278_Ra-01/sx1278-board.c | 4 ++-- 7 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lora-radio/sx126x/lora-radio-sx126x.c b/lora-radio/sx126x/lora-radio-sx126x.c index 8671d31..c950bab 100644 --- a/lora-radio/sx126x/lora-radio-sx126x.c +++ b/lora-radio/sx126x/lora-radio-sx126x.c @@ -690,7 +690,7 @@ bool RadioIsChannelFree( RadioModems_t modem, uint32_t freq, int16_t rssiThresh, RadioRx( 0 ); - DelayMs( 1 ); + SX126X_DELAY_MS( 1 ); carrierSenseTime = TimerGetCurrentTime( ); @@ -1152,7 +1152,7 @@ void RadioSleep( void ) params.Fields.WarmStart = 1; SX126xSetSleep( params ); - DelayMs(2); + SX126X_BLOCK_DELAY_1MS(); } void RadioStandby( void ) diff --git a/lora-radio/sx126x/lora-spi-sx126x.c b/lora-radio/sx126x/lora-spi-sx126x.c index d6e2723..6db4156 100644 --- a/lora-radio/sx126x/lora-spi-sx126x.c +++ b/lora-radio/sx126x/lora-spi-sx126x.c @@ -23,6 +23,9 @@ void SX126xWakeup( void ) // Wait for chip to be ready. SX126xWaitOnBusy( ); + + // Update operating mode context variable + SX126xSetOperatingMode( MODE_STDBY_RC ); #else #endif diff --git a/ports/lora-module/inc/sx126x-board.h b/ports/lora-module/inc/sx126x-board.h index 10ca5ad..62434e7 100644 --- a/ports/lora-module/inc/sx126x-board.h +++ b/ports/lora-module/inc/sx126x-board.h @@ -82,7 +82,8 @@ */ #define BOARD_TCXO_WAKEUP_TIME 2 -#define DelayMs( ms ) rt_thread_mdelay(ms) +#define SX126X_DELAY_MS( ms ) rt_thread_mdelay(ms) +#define SX126X_BLOCK_DELAY_1MS() rt_hw_us_delay(999) /*! * \brief Initializes the radio I/Os pins interface diff --git a/ports/lora-module/stm32_adapter/SX1262_ASR6500S/sx126x-board.c b/ports/lora-module/stm32_adapter/SX1262_ASR6500S/sx126x-board.c index c273253..00dd418 100644 --- a/ports/lora-module/stm32_adapter/SX1262_ASR6500S/sx126x-board.c +++ b/ports/lora-module/stm32_adapter/SX1262_ASR6500S/sx126x-board.c @@ -49,12 +49,12 @@ uint32_t SX126xGetBoardTcxoWakeupTime( void ) void SX126xReset( void ) { - DelayMs( 20 ); + SX126X_DELAY_MS( 20 ); rt_pin_mode(LORA_RADIO_RESET_PIN, PIN_MODE_OUTPUT); rt_pin_write(LORA_RADIO_RESET_PIN, PIN_LOW); - DelayMs( 40 ); + SX126X_DELAY_MS( 40 ); rt_pin_mode(LORA_RADIO_RESET_PIN, PIN_MODE_INPUT); - DelayMs( 20 ); + SX126X_DELAY_MS( 20 ); } void SX126xWaitOnBusy( void ) diff --git a/ports/lora-module/stm32_adapter/SX1262_LSD4RF-2R822N30/sx1262-board.c b/ports/lora-module/stm32_adapter/SX1262_LSD4RF-2R822N30/sx1262-board.c index b6ac37d..818c3bd 100644 --- a/ports/lora-module/stm32_adapter/SX1262_LSD4RF-2R822N30/sx1262-board.c +++ b/ports/lora-module/stm32_adapter/SX1262_LSD4RF-2R822N30/sx1262-board.c @@ -111,13 +111,13 @@ uint32_t SX126xGetBoardTcxoWakeupTime( void ) void SX126xReset( void ) { - DelayMs( 10 ); + SX126X_DELAY_MS( 10 ); rt_pin_mode(LORA_RADIO_RESET_PIN, PIN_MODE_OUTPUT); rt_pin_write(LORA_RADIO_RESET_PIN, PIN_LOW); - DelayMs( 20 ); + SX126X_DELAY_MS( 20 ); // internal pull-up rt_pin_mode(LORA_RADIO_RESET_PIN, PIN_MODE_INPUT); - DelayMs( 10 ); + SX126X_DELAY_MS( 10 ); } void SX126xWaitOnBusy( void ) diff --git a/ports/lora-module/stm32_adapter/SX1268_LSD4RF-2R717N40/sx1268-board.c b/ports/lora-module/stm32_adapter/SX1268_LSD4RF-2R717N40/sx1268-board.c index 559abc1..cdafacd 100644 --- a/ports/lora-module/stm32_adapter/SX1268_LSD4RF-2R717N40/sx1268-board.c +++ b/ports/lora-module/stm32_adapter/SX1268_LSD4RF-2R717N40/sx1268-board.c @@ -114,13 +114,13 @@ uint32_t SX126xGetBoardTcxoWakeupTime( void ) void SX126xReset( void ) { - DelayMs( 10 ); + SX126X_DELAY_MS( 10 ); rt_pin_mode(LORA_RADIO_RESET_PIN, PIN_MODE_OUTPUT); rt_pin_write(LORA_RADIO_RESET_PIN, PIN_LOW); - DelayMs( 20 ); + SX126X_DELAY_MS( 20 ); // internal pull-up rt_pin_mode(LORA_RADIO_RESET_PIN, PIN_MODE_INPUT); - DelayMs( 10 ); + SX126X_DELAY_MS( 10 ); } void SX126xWaitOnBusy( void ) diff --git a/ports/lora-module/stm32_adapter/SX1278_Ra-01/sx1278-board.c b/ports/lora-module/stm32_adapter/SX1278_Ra-01/sx1278-board.c index 2ab9654..7153586 100644 --- a/ports/lora-module/stm32_adapter/SX1278_Ra-01/sx1278-board.c +++ b/ports/lora-module/stm32_adapter/SX1278_Ra-01/sx1278-board.c @@ -159,13 +159,13 @@ void SX127xReset( void ) rt_pin_write(LORA_RADIO_RESET_PIN, PIN_LOW); // Wait 1 ms - DelayMs( 1 ); + SX127X_DELAY_MS( 1 ); // Configure RESET as input rt_pin_mode(LORA_RADIO_RESET_PIN, PIN_MODE_INPUT); // Wait 6 ms - DelayMs( 6 ); + SX127X_DELAY_MS( 6 ); } void SX127xSetAntSwLowPower( bool status )