Skip to content

Commit

Permalink
Merge pull request #10461 from caixue1102/mbed-os-rda
Browse files Browse the repository at this point in the history
Update wifi driver for rda target UNO_91H
  • Loading branch information
adbridge committed Apr 26, 2019
2 parents a98157a + d6730f5 commit 1b63aad
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 81 deletions.
Expand Up @@ -159,8 +159,12 @@ nsapi_error_t RDAWiFiInterface::disconnect()
if(sta_state < 2) {
return NSAPI_ERROR_NO_CONNECTION;
}
void* wifi_disconnect_sem = rda_sem_create(0);
msg.type = WLAND_DISCONNECT;
msg.arg1 = (unsigned int)wifi_disconnect_sem;
rda_mail_put(wland_msgQ, (void*)&msg, osWaitForever);
rda_sem_wait(wifi_disconnect_sem, osWaitForever);
rda_sem_delete(wifi_disconnect_sem);
if (_interface) {
return _interface->bringdown();
}
Expand Down
Expand Up @@ -88,6 +88,7 @@ typedef struct {
void (*mbed_critical_sec_end)(void);

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

Expand Down
Expand Up @@ -52,6 +52,7 @@ typedef enum {
WLAND_STAJOINED,
WLAND_STAEXITED,
WLAND_STADEAUTH,
WLAND_STADELETETIMER,
WLAND_MAC_CONNECTED,
WLAND_MAC_AP_CONNECTED,
WLAND_ADD_GTK,
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Expand Up @@ -45,7 +45,7 @@
* Variables
*/
static int maclib_task_run = 0;
static sys_mbox_t maclib_mbox;
static void* maclib_mbox;
static int g_event_num = 0;
static int g_event_proc_done = 1;
static sys_sem_t g_maclib_sem_sleep;
Expand All @@ -56,55 +56,13 @@ extern maclib_func_t *maclib_func_p;
extern void rda_critical_sec_start(void);
extern void rda_critical_sec_end(void);
extern void wland_set_sta_sleep(unsigned char is_sleep);

#define MAX_MSG_POOL_NUM (64)
maclib_msg_t msg_str_pool[MAX_MSG_POOL_NUM];
int msg_str_pool_inited = 0;

void init_msg_str_pool(void)
{
int idx;
for(idx = 0; idx < MAX_MSG_POOL_NUM; idx++) {
msg_str_pool[idx].is_free = 1;
}
}

maclib_msg_t *alloc_msg_str(void)
{
int idx;
maclib_msg_t *ret = NULL;
rda_critical_sec_start();
if (0 == msg_str_pool_inited) {
init_msg_str_pool();
msg_str_pool_inited = 1;
}
rda_critical_sec_end();
for (idx = 0; idx < MAX_MSG_POOL_NUM; idx++) {
rda_critical_sec_start();
ret = &msg_str_pool[idx];
if (1 == ret->is_free) {
ret->is_free = 0;
rda_critical_sec_end();
break;
}
rda_critical_sec_end();
}
return ret;
}

void free_msg_str(maclib_msg_t *p_msg)
{
rda_critical_sec_start();
p_msg->is_free = 1;
rda_critical_sec_end();
}

/**
* Functions
*/
/* maybe called in isr, should not use "printf", "malloc" */
void mbed_event_handle_cb(unsigned int event)
{
static unsigned int sec_cnt = 0;
MACLIB_EVENT_HANDLE_T type = (MACLIB_EVENT_HANDLE_T)event;
if ((maclib_task_run == 0) && (MACLIB_EVENT_CLEANUP != type)) {
mbed_error_printf("evntHndlCb_nulldata\r\n");
Expand All @@ -115,18 +73,13 @@ void mbed_event_handle_cb(unsigned int event)
rda_critical_sec_start();
g_event_num++;
if((1 == g_event_num) && (1 == g_event_proc_done)) {
maclib_msg_t *msg;
maclib_msg_t msg;
#if MACLIB_TASK_DEBUG
mbed_error_printf("#1-1,%d(%08X)\r\n", g_event_num, __get_xPSR());
#endif
msg = alloc_msg_str();
if(NULL == msg) {
mbed_error_printf("malloc err\r\n");
return;
}
msg->type = MACLIB_MSG_EVNT_HNDL;
msg->msg = NULL;
sys_mbox_trypost(&(maclib_mbox), msg);
msg.type = MACLIB_MSG_EVNT_HNDL;
msg.msg = NULL;
rda_mail_put(maclib_mbox, (void*)&msg, 0);
#if MACLIB_TASK_DEBUG
mbed_error_printf("#1-2\r\n");
#endif
Expand Down Expand Up @@ -205,24 +158,23 @@ void maclib_task(void *pvParameters)
sys_sem_new(&g_maclib_sem_sleep, 0);
//sleep_entry_register(&maclib_sleep_entry);

ret = sys_mbox_new(&(maclib_mbox), 8);
if(0 != ret) {
LWIP_DEBUGF(NETIF_DEBUG,"msgbox init err!\r\n");
maclib_mbox = (void *)rda_mail_create(8, sizeof(maclib_msg_t));//ret = sys_mbox_new(&(maclib_mbox), 8);
if(NULL == maclib_mbox) {
mbed_error_printf("msgbox init err!\r\n");
goto mac_lib_err;
}
#if MACLIB_TASK_DEBUG
LWIP_DEBUGF(NETIF_DEBUG,"#mbox new\r\n");
#endif
maclib_task_run = 1;
while(1) {
int mem_free = 1;
maclib_msg_t *msg = NULL;
unsigned int time = sys_arch_mbox_fetch(&(maclib_mbox), (void **)&msg, 0);
if ((SYS_ARCH_TIMEOUT == time) || (NULL == msg)) {
LWIP_DEBUGF(NETIF_DEBUG, "ml_task: invalid msg\r\n");
maclib_msg_t msg;
osStatus_t status = rda_mail_get(maclib_mbox, (void *)&msg, osWaitForever);
if(osOK != status) {
mbed_error_printf("ml_task: invalid msg ret=%08X\r\n", status);
continue;
}
switch(msg->type) {
switch(msg.type) {
case MACLIB_MSG_EVNT_HNDL: {
rda_critical_sec_start();
g_event_proc_done = 0;
Expand All @@ -246,11 +198,10 @@ void maclib_task(void *pvParameters)
#if MACLIB_TASK_DEBUG
mbed_error_printf("#2-1\r\n");
#endif
sys_mbox_trypost(&(maclib_mbox), msg);
rda_mail_put(maclib_mbox, (void*)&msg, 0);
#if MACLIB_TASK_DEBUG
mbed_error_printf("#2-2\r\n");
#endif
mem_free = 0;
}
rda_critical_sec_end();
#if MACLIB_TASK_DEBUG
Expand All @@ -261,12 +212,9 @@ void maclib_task(void *pvParameters)
default:
break;
}
if (mem_free) {
free_msg_str(msg);
#if MACLIB_TASK_DEBUG
mbed_error_printf("#4\r\n");
#endif
}
}

mac_lib_err:
Expand Down
Expand Up @@ -110,7 +110,7 @@ void rda_netif_link_down(int netif)
rda_msg msg;
msg.type = 1;
msg.arg1 = 0;
rda_mail_put(packet_rx_queue, (void*)&msg, osWaitForever);
rda_mail_put(packet_rx_queue, (void*)&msg, 0);
}

void rda_netif_up(int netif)
Expand All @@ -127,7 +127,7 @@ void rda_netif_link_up(int netif)
rda_msg msg;
msg.type = 1;
msg.arg1 = 1;
rda_mail_put(packet_rx_queue, (void*)&msg, osWaitForever);
rda_mail_put(packet_rx_queue, (void*)&msg, 0);
return;
}

Expand Down Expand Up @@ -181,6 +181,32 @@ void rda_critical_sec_end(void)
}
}

unsigned int rda_critical_sec_counter_get(void)
{
if (__get_IPSR() == 0U) {
return g_critical_sec_counter;
} else {
return 0xFFFFFFFF;
}
}

void rda_critical_sec_start_resume(unsigned int cnt)
{
unsigned int i = 0;
for(i=0; i<cnt; i++) {
rda_critical_sec_start();
}
}

unsigned int rda_critical_sec_end_all(void)
{
unsigned int ret = g_critical_sec_counter;
while(g_critical_sec_counter !=0 ) {
rda_critical_sec_end();
}
return ret;
}

void * rda_create_interrupt(unsigned int vec, unsigned int pri, void *isr)
{
NVIC_SetPriority((IRQn_Type)vec, (uint32_t) pri);
Expand Down Expand Up @@ -278,18 +304,13 @@ static struct pbuf *r91h_low_level_input(struct netif *netif, u8_t *data, u32_t
* \param[in] netif the lwip network interface structure
* \param[in] idx index of packet to be read
*/
void *data_sem = NULL;
void r91h_wifiif_input(struct netif *netif, u8_t *data, u32_t len, int idx)
{
if(data_sem == NULL)
data_sem = rda_sem_create(0);
rda_msg msg;
msg.type = 0;
msg.arg1 = (int)data;
msg.arg2 = len;
msg.arg3 = (int)data_sem;
rda_mail_put(packet_rx_queue, (void*)&msg, osWaitForever);
rda_sem_wait(data_sem, osWaitForever);
rda_mail_put(packet_rx_queue, (void*)&msg, 0);
return;
}

Expand Down
Expand Up @@ -239,10 +239,13 @@ int rda_alarm_stop(void *handle)
{
if (NULL != handle) {
osTimerId timer_id = (osTimerId)handle;
osStatus retval = osTimerStop(timer_id);
if (osOK != retval) {
RDA_SYS_PRINT("Stop alarm error: %d\r\n", retval);
return ERR;
os_timer_t *timer = osRtxTimerId(timer_id);
if(timer->state == osRtxTimerRunning){
osStatus retval = osTimerStop(timer_id);
if(osOK != retval) {
RDA_SYS_PRINT("Stop alarm error: %d\r\n", retval);
return ERR;
}
}
return NO_ERR;
}
Expand Down
Expand Up @@ -172,10 +172,8 @@ void RDA5981x_EMAC::packet_rx()
case 0:
p = low_level_input((unsigned char*)msg.arg1, msg.arg2);
if (p == NULL) {
rda_sem_release((void*)msg.arg3);
break;
}
rda_sem_release((void*)msg.arg3);
if (p) {
emac_link_input_cb(p);
}
Expand Down

0 comments on commit 1b63aad

Please sign in to comment.