add timeout for adapter_lora.c PrivSemaphoreObtainWait function

This commit is contained in:
wgzAIIT 2022-05-24 16:29:46 +08:00
parent 60e35914a5
commit a9410bd9b1
2 changed files with 18 additions and 13 deletions

View File

@ -50,6 +50,8 @@ extern AdapterProductInfoType E220Attach(struct Adapter *adapter);
#define ADAPTER_LORA_RECEIVE_ERROR_CNT 1
#define DEFAULT_SEM_TIMEOUT 10
//need to change status if the lora client wants to quit the net when timeout or a certain event
//eg.can also use sem to trigger quit function
static int g_adapter_lora_quit_flag = 0;
@ -453,7 +455,10 @@ static int LoraClientDataAnalyze(struct Adapter *adapter, void *send_buf, int le
int ret = 0;
uint8_t client_id = adapter->net_role_id;
ret = PrivSemaphoreObtainWait(&adapter->sem, NULL);
struct timespec abstime;
abstime.tv_sec = DEFAULT_SEM_TIMEOUT;
ret = PrivSemaphoreObtainWait(&adapter->sem, &abstime);
if (0 == ret) {
//only handle this client_id information from gateway
if ((client_recv_data_format[client_id - 1].client_id == adapter->net_role_id) &&
@ -681,6 +686,8 @@ static void *LoraReceiveTask(void *parameter)
void LoraGatewayProcess(struct Adapter *lora_adapter, struct LoraGatewayParam *gateway)
{
int i, ret = 0;
struct timespec abstime;
abstime.tv_sec = DEFAULT_SEM_TIMEOUT;
#ifdef GATEWAY_CMD_MODE
for (i = 0; i < gateway->client_num; i ++) {
@ -692,7 +699,7 @@ void LoraGatewayProcess(struct Adapter *lora_adapter, struct LoraGatewayParam *g
continue;
}
ret = PrivSemaphoreObtainWait(&gateway_recv_data_sem, NULL);
ret = PrivSemaphoreObtainWait(&gateway_recv_data_sem, &abstime);
if (0 == ret) {
printf("LoraGatewayProcess receive client %d data done\n", gateway->client_id[i]);
}

View File

@ -29,6 +29,7 @@
#include <stdint.h>
#include <nuttx/wireless/lpwan/sx127x.h>
#include <nuttx/ioexpander/gpio.h>
#include <termios.h>
typedef uint8_t uint8;
typedef uint16_t uint16;
@ -44,23 +45,23 @@ typedef int64_t int64;
extern "C" {
#endif
#define OPE_INT 0x0000
#define OPE_CFG 0x0001
#define OPE_INT 0x0000
#define OPE_CFG 0x0001
#define NAME_NUM_MAX 32
#define NAME_NUM_MAX 32
/*********************GPIO define*********************/
#define GPIO_LOW 0x00
#define GPIO_HIGH 0x01
#define GPIO_CFG_OUTPUT 0x00
#define GPIO_CFG_INPUT 0x01
#define GPIO_CFG_INPUT_PULLUP 0x02
#define GPIO_CFG_OUTPUT 0x00
#define GPIO_CFG_INPUT 0x01
#define GPIO_CFG_INPUT_PULLUP 0x02
#define GPIO_CFG_INPUT_PULLDOWN 0x03
#define GPIO_CFG_OUTPUT_OD 0x04
#define GPIO_CFG_OUTPUT_OD 0x04
#define GPIO_CONFIG_MODE 0xffffffff
#define GPIO_CONFIG_MODE 0xffffffff
/********************SERIAL define*******************/
#define BAUD_RATE_2400 2400
@ -174,9 +175,6 @@ int PrivMutexDelete(pthread_mutex_t *p_mutex);
int PrivMutexObtain(pthread_mutex_t *p_mutex);
int PrivMutexAbandon(pthread_mutex_t *p_mutex);
/*********************semaphore**********************/
int PrivSemaphoreCreate(sem_t *sem, int pshared, unsigned int value);