Skip to content

Commit e7cbad4

Browse files
caixue1102adbridge
authored andcommitted
Update wifi driver for rda target UNO_91H
1 parent c8bc33c commit e7cbad4

File tree

10 files changed

+57
-81
lines changed

10 files changed

+57
-81
lines changed

features/netsocket/emac-drivers/TARGET_RDA_EMAC/RdaWiFiInterface.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,12 @@ nsapi_error_t RDAWiFiInterface::disconnect()
159159
if(sta_state < 2) {
160160
return NSAPI_ERROR_NO_CONNECTION;
161161
}
162+
void* wifi_disconnect_sem = rda_sem_create(0);
162163
msg.type = WLAND_DISCONNECT;
164+
msg.arg1 = (unsigned int)wifi_disconnect_sem;
163165
rda_mail_put(wland_msgQ, (void*)&msg, osWaitForever);
166+
rda_sem_wait(wifi_disconnect_sem, osWaitForever);
167+
rda_sem_delete(wifi_disconnect_sem);
164168
if (_interface) {
165169
return _interface->bringdown();
166170
}

features/netsocket/emac-drivers/TARGET_RDA_EMAC/lwip-wifi/arch/TARGET_RDA/TARGET_UNO_91H/inc/csl_mbed.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ typedef struct {
8888
void (*mbed_critical_sec_end)(void);
8989

9090
/* Create interrupt in mbed, input param: vector/priority/isr(function), */
91+
unsigned int (*mbed_critical_sec_counter_get)(void);
9192
/* return: interrupt handle, non-zero is valid */
9293
void * (*mbed_create_interrupt)(unsigned int vec, unsigned int pri, void *isr);
9394

features/netsocket/emac-drivers/TARGET_RDA_EMAC/lwip-wifi/arch/TARGET_RDA/TARGET_UNO_91H/inc/rda5991h_wland.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ typedef enum {
5252
WLAND_STAJOINED,
5353
WLAND_STAEXITED,
5454
WLAND_STADEAUTH,
55+
WLAND_STADELETETIMER,
5556
WLAND_MAC_CONNECTED,
5657
WLAND_MAC_AP_CONNECTED,
5758
WLAND_ADD_GTK,

features/netsocket/emac-drivers/TARGET_RDA_EMAC/lwip-wifi/arch/TARGET_RDA/TARGET_UNO_91H/src/maclib_task.c

Lines changed: 15 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
* Variables
4646
*/
4747
static int maclib_task_run = 0;
48-
static sys_mbox_t maclib_mbox;
48+
static void* maclib_mbox;
4949
static int g_event_num = 0;
5050
static int g_event_proc_done = 1;
5151
static sys_sem_t g_maclib_sem_sleep;
@@ -56,55 +56,13 @@ extern maclib_func_t *maclib_func_p;
5656
extern void rda_critical_sec_start(void);
5757
extern void rda_critical_sec_end(void);
5858
extern void wland_set_sta_sleep(unsigned char is_sleep);
59-
60-
#define MAX_MSG_POOL_NUM (64)
61-
maclib_msg_t msg_str_pool[MAX_MSG_POOL_NUM];
62-
int msg_str_pool_inited = 0;
63-
64-
void init_msg_str_pool(void)
65-
{
66-
int idx;
67-
for(idx = 0; idx < MAX_MSG_POOL_NUM; idx++) {
68-
msg_str_pool[idx].is_free = 1;
69-
}
70-
}
71-
72-
maclib_msg_t *alloc_msg_str(void)
73-
{
74-
int idx;
75-
maclib_msg_t *ret = NULL;
76-
rda_critical_sec_start();
77-
if (0 == msg_str_pool_inited) {
78-
init_msg_str_pool();
79-
msg_str_pool_inited = 1;
80-
}
81-
rda_critical_sec_end();
82-
for (idx = 0; idx < MAX_MSG_POOL_NUM; idx++) {
83-
rda_critical_sec_start();
84-
ret = &msg_str_pool[idx];
85-
if (1 == ret->is_free) {
86-
ret->is_free = 0;
87-
rda_critical_sec_end();
88-
break;
89-
}
90-
rda_critical_sec_end();
91-
}
92-
return ret;
93-
}
94-
95-
void free_msg_str(maclib_msg_t *p_msg)
96-
{
97-
rda_critical_sec_start();
98-
p_msg->is_free = 1;
99-
rda_critical_sec_end();
100-
}
101-
10259
/**
10360
* Functions
10461
*/
10562
/* maybe called in isr, should not use "printf", "malloc" */
10663
void mbed_event_handle_cb(unsigned int event)
10764
{
65+
static unsigned int sec_cnt = 0;
10866
MACLIB_EVENT_HANDLE_T type = (MACLIB_EVENT_HANDLE_T)event;
10967
if ((maclib_task_run == 0) && (MACLIB_EVENT_CLEANUP != type)) {
11068
mbed_error_printf("evntHndlCb_nulldata\r\n");
@@ -115,18 +73,13 @@ void mbed_event_handle_cb(unsigned int event)
11573
rda_critical_sec_start();
11674
g_event_num++;
11775
if((1 == g_event_num) && (1 == g_event_proc_done)) {
118-
maclib_msg_t *msg;
76+
maclib_msg_t msg;
11977
#if MACLIB_TASK_DEBUG
12078
mbed_error_printf("#1-1,%d(%08X)\r\n", g_event_num, __get_xPSR());
12179
#endif
122-
msg = alloc_msg_str();
123-
if(NULL == msg) {
124-
mbed_error_printf("malloc err\r\n");
125-
return;
126-
}
127-
msg->type = MACLIB_MSG_EVNT_HNDL;
128-
msg->msg = NULL;
129-
sys_mbox_trypost(&(maclib_mbox), msg);
80+
msg.type = MACLIB_MSG_EVNT_HNDL;
81+
msg.msg = NULL;
82+
rda_mail_put(maclib_mbox, (void*)&msg, 0);
13083
#if MACLIB_TASK_DEBUG
13184
mbed_error_printf("#1-2\r\n");
13285
#endif
@@ -205,24 +158,23 @@ void maclib_task(void *pvParameters)
205158
sys_sem_new(&g_maclib_sem_sleep, 0);
206159
//sleep_entry_register(&maclib_sleep_entry);
207160

208-
ret = sys_mbox_new(&(maclib_mbox), 8);
209-
if(0 != ret) {
210-
LWIP_DEBUGF(NETIF_DEBUG,"msgbox init err!\r\n");
161+
maclib_mbox = (void *)rda_mail_create(8, sizeof(maclib_msg_t));//ret = sys_mbox_new(&(maclib_mbox), 8);
162+
if(NULL == maclib_mbox) {
163+
mbed_error_printf("msgbox init err!\r\n");
211164
goto mac_lib_err;
212165
}
213166
#if MACLIB_TASK_DEBUG
214167
LWIP_DEBUGF(NETIF_DEBUG,"#mbox new\r\n");
215168
#endif
216169
maclib_task_run = 1;
217170
while(1) {
218-
int mem_free = 1;
219-
maclib_msg_t *msg = NULL;
220-
unsigned int time = sys_arch_mbox_fetch(&(maclib_mbox), (void **)&msg, 0);
221-
if ((SYS_ARCH_TIMEOUT == time) || (NULL == msg)) {
222-
LWIP_DEBUGF(NETIF_DEBUG, "ml_task: invalid msg\r\n");
171+
maclib_msg_t msg;
172+
osStatus_t status = rda_mail_get(maclib_mbox, (void *)&msg, osWaitForever);
173+
if(osOK != status) {
174+
mbed_error_printf("ml_task: invalid msg ret=%08X\r\n", status);
223175
continue;
224176
}
225-
switch(msg->type) {
177+
switch(msg.type) {
226178
case MACLIB_MSG_EVNT_HNDL: {
227179
rda_critical_sec_start();
228180
g_event_proc_done = 0;
@@ -246,11 +198,10 @@ void maclib_task(void *pvParameters)
246198
#if MACLIB_TASK_DEBUG
247199
mbed_error_printf("#2-1\r\n");
248200
#endif
249-
sys_mbox_trypost(&(maclib_mbox), msg);
201+
rda_mail_put(maclib_mbox, (void*)&msg, 0);
250202
#if MACLIB_TASK_DEBUG
251203
mbed_error_printf("#2-2\r\n");
252204
#endif
253-
mem_free = 0;
254205
}
255206
rda_critical_sec_end();
256207
#if MACLIB_TASK_DEBUG
@@ -261,12 +212,9 @@ void maclib_task(void *pvParameters)
261212
default:
262213
break;
263214
}
264-
if (mem_free) {
265-
free_msg_str(msg);
266215
#if MACLIB_TASK_DEBUG
267216
mbed_error_printf("#4\r\n");
268217
#endif
269-
}
270218
}
271219

272220
mac_lib_err:

features/netsocket/emac-drivers/TARGET_RDA_EMAC/lwip-wifi/arch/TARGET_RDA/TARGET_UNO_91H/src/rda5991h_wland.c

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void rda_netif_link_down(int netif)
110110
rda_msg msg;
111111
msg.type = 1;
112112
msg.arg1 = 0;
113-
rda_mail_put(packet_rx_queue, (void*)&msg, osWaitForever);
113+
rda_mail_put(packet_rx_queue, (void*)&msg, 0);
114114
}
115115

116116
void rda_netif_up(int netif)
@@ -127,7 +127,7 @@ void rda_netif_link_up(int netif)
127127
rda_msg msg;
128128
msg.type = 1;
129129
msg.arg1 = 1;
130-
rda_mail_put(packet_rx_queue, (void*)&msg, osWaitForever);
130+
rda_mail_put(packet_rx_queue, (void*)&msg, 0);
131131
return;
132132
}
133133

@@ -181,6 +181,32 @@ void rda_critical_sec_end(void)
181181
}
182182
}
183183

184+
unsigned int rda_critical_sec_counter_get(void)
185+
{
186+
if (__get_IPSR() == 0U) {
187+
return g_critical_sec_counter;
188+
} else {
189+
return 0xFFFFFFFF;
190+
}
191+
}
192+
193+
void rda_critical_sec_start_resume(unsigned int cnt)
194+
{
195+
unsigned int i = 0;
196+
for(i=0; i<cnt; i++) {
197+
rda_critical_sec_start();
198+
}
199+
}
200+
201+
unsigned int rda_critical_sec_end_all(void)
202+
{
203+
unsigned int ret = g_critical_sec_counter;
204+
while(g_critical_sec_counter !=0 ) {
205+
rda_critical_sec_end();
206+
}
207+
return ret;
208+
}
209+
184210
void * rda_create_interrupt(unsigned int vec, unsigned int pri, void *isr)
185211
{
186212
NVIC_SetPriority((IRQn_Type)vec, (uint32_t) pri);
@@ -278,18 +304,13 @@ static struct pbuf *r91h_low_level_input(struct netif *netif, u8_t *data, u32_t
278304
* \param[in] netif the lwip network interface structure
279305
* \param[in] idx index of packet to be read
280306
*/
281-
void *data_sem = NULL;
282307
void r91h_wifiif_input(struct netif *netif, u8_t *data, u32_t len, int idx)
283308
{
284-
if(data_sem == NULL)
285-
data_sem = rda_sem_create(0);
286309
rda_msg msg;
287310
msg.type = 0;
288311
msg.arg1 = (int)data;
289312
msg.arg2 = len;
290-
msg.arg3 = (int)data_sem;
291-
rda_mail_put(packet_rx_queue, (void*)&msg, osWaitForever);
292-
rda_sem_wait(data_sem, osWaitForever);
313+
rda_mail_put(packet_rx_queue, (void*)&msg, 0);
293314
return;
294315
}
295316

features/netsocket/emac-drivers/TARGET_RDA_EMAC/lwip-wifi/arch/TARGET_RDA/TARGET_UNO_91H/src/rda_sys_wrapper.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,13 @@ int rda_alarm_stop(void *handle)
239239
{
240240
if (NULL != handle) {
241241
osTimerId timer_id = (osTimerId)handle;
242-
osStatus retval = osTimerStop(timer_id);
243-
if (osOK != retval) {
244-
RDA_SYS_PRINT("Stop alarm error: %d\r\n", retval);
245-
return ERR;
242+
os_timer_t *timer = osRtxTimerId(timer_id);
243+
if(timer->state == osRtxTimerRunning){
244+
osStatus retval = osTimerStop(timer_id);
245+
if(osOK != retval) {
246+
RDA_SYS_PRINT("Stop alarm error: %d\r\n", retval);
247+
return ERR;
248+
}
246249
}
247250
return NO_ERR;
248251
}

features/netsocket/emac-drivers/TARGET_RDA_EMAC/rda5981x_emac.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,8 @@ void RDA5981x_EMAC::packet_rx()
172172
case 0:
173173
p = low_level_input((unsigned char*)msg.arg1, msg.arg2);
174174
if (p == NULL) {
175-
rda_sem_release((void*)msg.arg3);
176175
break;
177176
}
178-
rda_sem_release((void*)msg.arg3);
179177
if (p) {
180178
emac_link_input_cb(p);
181179
}

0 commit comments

Comments
 (0)