fix lora function bug in webserver

This commit is contained in:
Liu_Weichao
2024-01-10 17:47:17 +08:00
parent cc7109af18
commit 348d53df91
8 changed files with 98 additions and 21 deletions

View File

@@ -479,6 +479,7 @@ uint8_t RadioRxPayload[255];
bool IrqFired = false;
static bool lora_radio_init = false;
static bool lora_spi_init = false;
/*
* SX126x DIO IRQ callback functions prototype
*/
@@ -552,6 +553,16 @@ static TimerEvent_t RxTimeoutTimer;
uint8_t RadioCheck(void)
{
uint8_t test = 0;
if( lora_spi_init == false ) {
int ret = lora_radio_spi_init();
if (ret < 0) {
LORA_RADIO_DEBUG_LOG(LR_DBG_INTERFACE, LOG_LEVEL, "SX126x SPI Init Failed\n");
return false;
}
lora_spi_init = true;
LORA_RADIO_DEBUG_LOG(LR_DBG_INTERFACE, LOG_LEVEL, "SX126x SPI Init Succeed\n");
}
LORA_RADIO_DEBUG_LOG(LR_DBG_INTERFACE, LOG_LEVEL, "Packet Type is %s\n",( SX126x.PacketParams.PacketType == PACKET_TYPE_LORA )? "LoRa":"FSK");
@@ -668,13 +679,13 @@ bool RadioInit( RadioEvents_t *events )
lora_radio_init = true;
}
#elif defined LORA_RADIO_DRIVER_USING_RTOS_XIUOS
if( lora_radio_init == false ) {
if( lora_spi_init == false ) {
int ret = lora_radio_spi_init();
if (ret < 0) {
LORA_RADIO_DEBUG_LOG(LR_DBG_INTERFACE, LOG_LEVEL, "SX126x SPI Init Failed\n");
return false;
}
lora_spi_init = true;
LORA_RADIO_DEBUG_LOG(LR_DBG_INTERFACE, LOG_LEVEL, "SX126x SPI Init Succeed\n");
}
#else

View File

@@ -88,7 +88,7 @@ void SX126xProcessIrqs( void );
void SX126xInit( DioIrqHandler dioIrq )
{
SX126xReset( );
// SX126xReset( );
SX126xIoIrqInit( dioIrq );

View File

@@ -28,6 +28,10 @@ if LORA_RADIO_DRIVER_USING_XISHUTONG_ARM32
string "lora device pin driver path"
default "/dev/spi2_dev0"
config LORA_RADIO_BUSY_PIN
int "xishutong-arm32 board lora chip busy pin[PC12]"
default "141"
config LORA_RADIO_RESET_PIN
int "xishutong-arm32 board lora chip reset pin[PD02]"
default "144"

View File

@@ -191,18 +191,20 @@ void SX126xIoInit( void )
return;
}
}
#ifdef LORA_RADIO_DRIVER_USING_EDU_ARM32
struct PinParam pin_param;
struct PinStat pin_stat;
struct PrivIoctlCfg ioctl_cfg;
#ifdef LORA_RADIO_DRIVER_USING_EDU_ARM32
pin_param.cmd = GPIO_CONFIG_MODE;
pin_param.mode = GPIO_CFG_OUTPUT;
pin_param.pin = LORA_RADIO_RFSW1_PIN;
struct PrivIoctlCfg ioctl_cfg;
ioctl_cfg.ioctl_driver_type = PIN_TYPE;
ioctl_cfg.args = &pin_param;
PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg);
struct PinStat pin_stat;
pin_stat.pin = LORA_RADIO_RFSW1_PIN;
pin_stat.val = GPIO_LOW;
PrivWrite(pin_fd, &pin_stat, 1);
@@ -218,6 +220,7 @@ void SX126xIoInit( void )
pin_stat.pin = LORA_RADIO_RFSW2_PIN;
pin_stat.val = GPIO_LOW;
PrivWrite(pin_fd, &pin_stat, 1);
#endif
pin_param.cmd = GPIO_CONFIG_MODE;
pin_param.mode = GPIO_CFG_INPUT;
@@ -230,7 +233,6 @@ void SX126xIoInit( void )
pin_stat.pin = LORA_RADIO_BUSY_PIN;
pin_stat.val = GPIO_LOW;
PrivWrite(pin_fd, &pin_stat, 1);
#endif
}
void SX126xIoIrqInit( DioIrqHandler dioIrq )

View File

@@ -131,6 +131,10 @@ Modification:
#define LORA_RADIO_RESET_PIN 144//PD02 on xishutong-arm32
#endif
#ifndef LORA_RADIO_BUSY_PIN
#define LORA_RADIO_BUSY_PIN 141//PC12 on xishutong-arm32
#endif
#ifndef LORA_SPI_DEV_NAME
#define LORA_SPI_DEV_NAME "/dev/spi2_dev0"
#endif

View File

@@ -92,7 +92,7 @@ static uint8_t lora_chip_initialized;
static bool master_flag = true;
static bool rx_only_flag = false;
static bool tx_only_flag = false;
static bool tx_continues = false;
static int tx_continues = false;
static lora_radio_test_t lora_radio_test_paras =
{
@@ -1119,7 +1119,7 @@ static void *lora_radio_test_thread_entry(void *parameter)
TX_LED_TOGGLE;
if (tx_only_flag == false) {
radio_rx();
} else if (tx_continues) {
} else if (tx_seq_cnt < tx_continues) {
PrivTaskDelay(1000);
PrivEvenTrigger(radio_event, EV_RADIO_TX_START);
} else {
@@ -1142,7 +1142,10 @@ static void *lora_radio_test_thread_entry(void *parameter)
LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON_DISABLE,
true, 0, 0, lora_radio_test_paras.iq_inversion, tx_timeout );
send_ping_packet(master_address,slaver_address,payload_len);
if (tx_seq_cnt < tx_continues) {
send_ping_packet(master_address,slaver_address,payload_len);
}
} else {
/* tx_seq_cnt start from 0 */
if( tx_seq_cnt < max_tx_nbtrials ) {
@@ -1226,6 +1229,18 @@ int TestLoraRadio(int argc, char *argv[])
LORA_RADIO_DEBUG_LOG(LR_DBG_SHELL, LOG_LVL_INFO, "\n");
} else {
const char *cmd0 = argv[1];
if (!strcmp(cmd0, "check")) {
LORA_RADIO_DEBUG_LOG(LR_DBG_SHELL, LOG_LVL_INFO, "LoRa Modules start to check using SPI");
if( Radio.Check() ) {
LORA_RADIO_DEBUG_LOG(LR_DBG_SHELL, LOG_LVL_INFO, "LoRa Modules check ok!");
return 1;
} else {
LORA_RADIO_DEBUG_LOG(LR_DBG_SHELL, LOG_LVL_INFO, "LoRa Modules check failed!\n!");
return -1;
}
}
if( lora_radio_tester_init() == false ) {
LORA_RADIO_DEBUG_LOG(LR_DBG_SHELL, LOG_LVL_INFO, "LoRa Chip Init Failed");
@@ -1304,10 +1319,10 @@ int TestLoraRadio(int argc, char *argv[])
}
PrivEvenTrigger(radio_event, EV_RADIO_INIT);
} else if(!strcmp(cmd0, "tx")) {
/* eg: lora tx 1 0 */
/* eg: lora tx 1 0 1 */
master_flag = true;
tx_only_flag = true;
tx_continues = true;
tx_continues = 4;
if (argc >= 3) {
tx_only_flag = atol(argv[2]);
@@ -1315,6 +1330,9 @@ int TestLoraRadio(int argc, char *argv[])
if (argc >= 4) {
tx_timeout = atol(argv[3]);
}
if (argc >= 5) {
tx_continues = atol(argv[4]);
}
PrivEvenTrigger(radio_event, EV_RADIO_INIT);
} else if(!strcmp(cmd0, "txdone")) {
tx_continues = false;