Skip to content

Commit fa6005c

Browse files
author
Wayne Ren
committed
device: rs9113: update the code style of adapter interface
* update the code style Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
1 parent 4d9113f commit fa6005c

File tree

2 files changed

+82
-37
lines changed

2 files changed

+82
-37
lines changed

device/peripheral/wifi/rs9113/rs9113_adapter.c

Lines changed: 79 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
#include "dev_wnic.h"
3434
#include "embARC_error.h"
3535
//TODO: move SPI related part to emdk\drivers\pmwifi
36-
#include "board.h" //include board.h for SPI wiring and frequency
36+
/* include board.h for SPI wiring and frequency */
37+
#include "board.h"
3738
#include "rswifi_netif.h"
3839

3940
#include "rs9113_adapter.h"
@@ -47,16 +48,20 @@ typedef struct {
4748
uint8_t *buf;
4849
uint32_t len;
4950
uint32_t cur_index;
50-
}rs9113_pbuf_t, *rs9113_pbuf_t_ptr;
51+
} rs9113_pbuf_t, *rs9113_pbuf_t_ptr;
5152

52-
rs9113_pbuf_t rs9113_pbuf;
53-
void * driver_task_handle = NULL;
54-
#define RSI_WLAN_CTRL_BUFFER_SIZE 3680 //3680 is a suitable value for WLAN only, take reference to document and rsi_driver_init() for other cases
53+
static rs9113_pbuf_t rs9113_pbuf;
54+
static void *driver_task_handle = NULL;
55+
/*
56+
* 3680 is a suitable value for WLAN only, take reference to document and
57+
* rsi_driver_init() for other cases
58+
*/
59+
#define RSI_WLAN_CTRL_BUFFER_SIZE 3680
5560

5661
#define RSI_BUFFER_USE_MALLOC 0
5762
#if RSI_BUFFER_USE_MALLOC
5863
#else
59-
uint8_t rs_buffer[RSI_WLAN_CTRL_BUFFER_SIZE];
64+
static uint8_t rs_buffer[RSI_WLAN_CTRL_BUFFER_SIZE];
6065
#endif /*RSI_BUFFER_USE_MALLOC*/
6166

6267
static int32_t _rs9113_spi_open(uint32_t freq, uint32_t clk_mode)
@@ -67,15 +72,20 @@ static int32_t _rs9113_spi_open(uint32_t freq, uint32_t clk_mode)
6772
rsi_spi_ptr = spi_get_dev(BOARD_RSI_SPI_ID);
6873
RS9113_CHECK_EXP(rsi_spi_ptr != NULL, E_OBJ);
6974

70-
dbg_printf(DBG_MORE_INFO, "rsi_spi_open DEV_MASTER_MODE= 0x%x (%d),freq= 0x%x (%d) \r\n", DEV_MASTER_MODE, DEV_MASTER_MODE, freq, freq);
75+
dbg_printf(DBG_MORE_INFO, "rsi_spi_open DEV_MASTER_MODE= 0x%x (%d),freq= 0x%x (%d) \r\n",
76+
DEV_MASTER_MODE, DEV_MASTER_MODE, freq, freq);
77+
7178
ercd = rsi_spi_ptr->spi_open(DEV_MASTER_MODE, freq);
79+
7280
if ((ercd == E_OPNED) || (ercd == E_OK)) {
7381
ercd = rsi_spi_ptr->spi_control(SPI_CMD_SET_CLK_MODE, CONV2VOID(clk_mode));
7482
}
83+
7584
error_exit:
7685
return ercd;
7786
}
78-
static int32_t _rs9113_spi_close()
87+
88+
static int32_t _rs9113_spi_close(void)
7989
{
8090
int32_t ercd = E_OK;
8191
DEV_SPI_PTR rsi_spi_ptr;
@@ -94,14 +104,19 @@ static int32_t _rs9113_wnic_deinit(DEV_WNIC_PTR rs9113_wnic)
94104
int32_t ercd = E_OK;
95105
DEV_WNIC_INFO *rs9113_info;
96106
WIFI_IF_PTR rswifi_if_ptr;
107+
97108
RS9113_CHECK_EXP(rs9113_wnic!=NULL, E_OBJ);
109+
98110
rs9113_info = &(rs9113_wnic->wnic_info);
99111
rswifi_if_ptr = (WIFI_IF_PTR)(rs9113_info->extra);
100112
ercd = rsi_wireless_deinit();
113+
101114
#if RSI_BUFFER_USE_MALLOC
102-
if(rswifi_if_ptr->rsi_buffer != NULL){
115+
116+
if (rswifi_if_ptr->rsi_buffer != NULL) {
103117
free(rswifi_if_ptr->rsi_buffer);
104118
}
119+
105120
#else
106121
#endif
107122
_rs9113_spi_close();
@@ -140,10 +155,10 @@ int32_t rs9113_wnic_init(DEV_WNIC_PTR rs9113_wnic, uint32_t network_type)
140155
RS9113_CHECK_EXP(rs9113_wnic!=NULL, E_OBJ);
141156
rs9113_info = &(rs9113_wnic->wnic_info);
142157
RS9113_CHECK_EXP((rs9113_info->init_status==WNIC_NOT_INITIALIZED) \
143-
|| (rs9113_info->init_status==WNIC_INIT_FAILED), E_OPNED);
158+
|| (rs9113_info->init_status==WNIC_INIT_FAILED), E_OPNED);
144159

145160
RS9113_CHECK_EXP((network_type==WNIC_NETWORK_TYPE_INFRASTRUCTURE) \
146-
|| (network_type==WNIC_NETWORK_TYPE_ADHOC), E_PAR);
161+
|| (network_type==WNIC_NETWORK_TYPE_ADHOC), E_PAR);
147162

148163
rs9113_info->init_status = WNIC_DURING_INITIALIZATION; /* start initialization process */
149164
rs9113_info->network_type = network_type; /* set network type used next */
@@ -169,8 +184,9 @@ int32_t rs9113_wnic_init(DEV_WNIC_PTR rs9113_wnic, uint32_t network_type)
169184
RS9113_CHECK_EXP(ercd == E_OK, E_SYS);
170185

171186
//! Task created for Driver task
172-
if(driver_task_handle == NULL){
173-
rsi_task_create(rsi_wireless_driver_task, "driver_task", RSI_DRIVER_TASK_STACK_SIZE, NULL, RSI_DRIVER_TASK_PRIORITY, &driver_task_handle);
187+
if (driver_task_handle == NULL) {
188+
rsi_task_create(rsi_wireless_driver_task, "driver_task", RSI_DRIVER_TASK_STACK_SIZE, NULL, RSI_DRIVER_TASK_PRIORITY,
189+
&driver_task_handle);
174190
}
175191

176192
//a short delay to wait the device get ready
@@ -185,6 +201,7 @@ int32_t rs9113_wnic_init(DEV_WNIC_PTR rs9113_wnic, uint32_t network_type)
185201
rs9113_info->power_status = WNIC_POWER_NORMAL;
186202
rs9113_info->init_status = WNIC_INIT_SUCCESSFUL; /* stop initialization process */
187203
rs9113_on_ops = &(rs9113_wnic->wnic_on_ops);
204+
188205
if (rs9113_on_ops->on_init_success != NULL) {
189206
rs9113_on_ops->on_init_success(rs9113_wnic);
190207
}
@@ -231,7 +248,7 @@ int32_t rs9113_set_network_type(DEV_WNIC_PTR rs9113_wnic, uint32_t type)
231248
rs9113_info = &(rs9113_wnic->wnic_info);
232249
RS9113_CHECK_EXP((rs9113_info->init_status==WNIC_INIT_SUCCESSFUL), E_CLSED);
233250
RS9113_CHECK_EXP((type==WNIC_NETWORK_TYPE_INFRASTRUCTURE) \
234-
|| (type==WNIC_NETWORK_TYPE_ADHOC), E_PAR);
251+
|| (type==WNIC_NETWORK_TYPE_ADHOC), E_PAR);
235252

236253
rs9113_info->network_type = type;
237254

@@ -255,6 +272,7 @@ int32_t rs9113_set_macaddr(DEV_WNIC_PTR rs9113_wnic, uint8_t *mac)
255272
rs9113_info->mac_status = WNIC_MAC_UPDATED;
256273

257274
rs9113_on_ops = &(rs9113_wnic->wnic_on_ops);
275+
258276
if (rs9113_on_ops->on_mac_updated != NULL) {
259277
rs9113_on_ops->on_mac_updated(rs9113_wnic);
260278
}
@@ -284,7 +302,8 @@ int32_t rs9113_get_macaddr(DEV_WNIC_PTR rs9113_wnic, uint8_t *mac)
284302
return ercd;
285303
}
286304

287-
rsi_rsp_scan_t scan_result;
305+
static rsi_rsp_scan_t scan_result;
306+
288307
int32_t rs9113_start_scan(DEV_WNIC_PTR rs9113_wnic)
289308
{
290309
int32_t ercd = E_OK;
@@ -349,16 +368,17 @@ int32_t rs9113_get_scan_result_cnt(DEV_WNIC_PTR rs9113_wnic)
349368
} else {
350369
ercd = 0;
351370
}
371+
352372
error_exit:
353373
return ercd;
354374
}
355375

356-
static rsi_scan_info_t * p_scan_result = &(scan_result.scan_info);
376+
static rsi_scan_info_t *p_scan_result = &(scan_result.scan_info);
357377
int32_t rs9113_get_scan_result(DEV_WNIC_PTR rs9113_wnic, uint32_t index, WNIC_SCAN_RESULT *result)
358378
{
359379
int32_t ercd = E_OK;
360380
DEV_WNIC_INFO *rs9113_info;
361-
rsi_scan_info_t * p_scan_result_temp;
381+
rsi_scan_info_t *p_scan_result_temp;
362382
WNIC_AP_CONFIG apConfig_result;
363383

364384
RS9113_CHECK_EXP(rs9113_wnic!=NULL, E_OBJ);
@@ -374,26 +394,32 @@ int32_t rs9113_get_scan_result(DEV_WNIC_PTR rs9113_wnic, uint32_t index, WNIC_SC
374394
memcpy(result->ssid, p_scan_result_temp->ssid, WNIC_SSID_MAX_LEN);
375395
result->ssid[WNIC_SSID_MAX_LEN-1] = '\0'; /* make end of ssid */
376396
result->ssidlen = strlen((char *)result->ssid);
377-
switch(p_scan_result_temp->security_mode){
397+
398+
switch (p_scan_result_temp->security_mode) {
378399
case 0://open
379400
apConfig_result.ap_cfg.privacy = 0;
401+
380402
case 1://WPA
381403
apConfig_result.ap_cfg.wpa = 1;
382404
apConfig_result.ap_cfg.privacy = 1;
383405
break;
406+
384407
case 2://WPA2
385408
apConfig_result.ap_cfg.wpa2 = 1;
386409
apConfig_result.ap_cfg.wpa = 1;
387410
apConfig_result.ap_cfg.privacy = 1;
388411
break;
412+
389413
case 3://WEP
390414
apConfig_result.ap_cfg.privacy = 1;
391415
break;
416+
392417
case 4://WAP Enterprise
393418
case 5://WPA2 Enterprise
394419
default:
395420
break;
396421
}
422+
397423
result->ap_config.apConfig = apConfig_result.apConfig;
398424
result->rssi = p_scan_result_temp->rssi_val;
399425
result->bsstype = p_scan_result_temp->network_type;
@@ -421,7 +447,7 @@ int32_t rs9113_wnic_connect(DEV_WNIC_PTR rs9113_wnic, uint32_t security, const u
421447
RS9113_CHECK_EXP((rs9113_info->init_status==WNIC_INIT_SUCCESSFUL), E_CLSED);
422448
RS9113_CHECK_EXP((rs9113_info->busy_status==WNIC_IS_FREE), E_CLS);
423449
RS9113_CHECK_EXP((rs9113_info->conn_status==WNIC_NOT_CONNECTED) \
424-
|| (rs9113_info->conn_status==WNIC_CONNECTED), E_CLS);
450+
|| (rs9113_info->conn_status==WNIC_CONNECTED), E_CLS);
425451

426452
if (rs9113_info->conn_status == WNIC_CONNECTED) {
427453
/* if connected to a different ssid, just disconnect it */
@@ -436,14 +462,15 @@ int32_t rs9113_wnic_connect(DEV_WNIC_PTR rs9113_wnic, uint32_t security, const u
436462
} else {
437463
rs9113_wnic_disconnect(rs9113_wnic);
438464
}
465+
439466
rs9113_info->busy_status = WNIC_IS_BUSY;
440467

441468
rs9113_info->conn_status = WNIC_DURING_CONNECTION;
442469
memcpy(rs9113_info->ssid.ssid, ssid, ssid_len);
443470
rs9113_info->ssid.ssid_len = ssid_len;
444471

445-
rsi_security_mode_t rsi_security_type;
446-
void * rsi_secret_key;
472+
rsi_security_mode_t rsi_security_type;
473+
void *rsi_secret_key;
447474

448475
switch (security) {
449476
case AUTH_SECURITY_OPEN:
@@ -460,17 +487,20 @@ void * rsi_secret_key;
460487

461488
case AUTH_SECURITY_WPA_WITH_PASS_PHRASE:
462489
rsi_security_type = RSI_WPA;
463-
rsi_secret_key = (void *)key->key;//PSK string terminated with NULL. Length of PSK should be greater than equal to 8 and less than 64 bytes.
490+
rsi_secret_key = (void *)
491+
key->key;//PSK string terminated with NULL. Length of PSK should be greater than equal to 8 and less than 64 bytes.
464492
break;
465493

466494
case AUTH_SECURITY_WPA2_WITH_PASS_PHRASE:
467495
rsi_security_type = RSI_WPA2;
468-
rsi_secret_key = (void *)key->key;//PSK string terminated with NULL. Length of PSK should be greater than equal to 8 and less than 64 bytes.
496+
rsi_secret_key = (void *)
497+
key->key;//PSK string terminated with NULL. Length of PSK should be greater than equal to 8 and less than 64 bytes.
469498
break;
470499

471500
case AUTH_SECURITY_WPA_AUTO_WITH_PASS_PHRASE:
472501
rsi_security_type = RSI_WPA_WPA2_MIXED;
473-
rsi_secret_key = (void *)key->key;//PSK string terminated with NULL. Length of PSK should be greater than equal to 8 and less than 64 bytes.
502+
rsi_secret_key = (void *)
503+
key->key;//PSK string terminated with NULL. Length of PSK should be greater than equal to 8 and less than 64 bytes.
474504
break;
475505

476506
case AUTH_SECURITY_WPA_WITH_KEY:
@@ -493,35 +523,43 @@ void * rsi_secret_key;
493523
rsi_secret_key = (void *)key->key;//8 bytes WPS PIN
494524
break;
495525

496-
case AUTH_SECURITY_WPA_AUTO_WITH_KEY:
497-
//unsupported, need specify WPA/WPA2 PMK
526+
case AUTH_SECURITY_WPA_AUTO_WITH_KEY:
527+
528+
//unsupported, need specify WPA/WPA2 PMK
498529
default:
499-
dbg_printf(DBG_LESS_INFO, "RS9113 does not support security type %d \r\n", security);
530+
dbg_printf(DBG_LESS_INFO, "RS9113 does not support security type %d \r\n", security);
500531
rs9113_info->conn_status = WNIC_NOT_CONNECTED;
501532
rs9113_info->busy_status = WNIC_IS_FREE;
502533
ercd = E_PAR;
503534
goto error_exit;
504535
break;
505536
}
537+
506538
ercd = rsi_wlan_connect((int8_t *)ssid, rsi_security_type, rsi_secret_key);
507-
dbg_printf(DBG_MORE_INFO, "rsi_wlan_connect return 0x%x when connect ssid %s with security type %d\r\n", ercd, ssid, rsi_security_type);
539+
dbg_printf(DBG_MORE_INFO, "rsi_wlan_connect return 0x%x when connect ssid %s with security type %d\r\n", ercd, ssid,
540+
rsi_security_type);
508541
rs9113_info->busy_status = WNIC_IS_FREE;
509-
if(ercd != E_OK){
542+
543+
if (ercd != E_OK) {
510544
rs9113_info->conn_status = WNIC_NOT_CONNECTED;
511545
dbg_printf(DBG_LESS_INFO, "RS9113 wlan connect failed (return 0x%x )\r\n", ercd);
512546
return ercd;
513547
}
548+
514549
//register rs9113 on receive callback function
515550
rsi_wlan_register_callbacks(RSI_WLAN_DATA_RECEIVE_NOTIFY_CB, rswifi_on_input);
516551
rs9113_info->mac_status = WNIC_MAC_NOT_UPDATED;
517552
rs9113_info->conn_status = WNIC_CONNECTED;
518553
rs9113_on_ops = &(rs9113_wnic->wnic_on_ops);
554+
519555
if (rs9113_on_ops->on_init_success != NULL) {//update MAC address again
520556
rs9113_on_ops->on_init_success(rs9113_wnic);
521557
}
558+
522559
if (rs9113_on_ops->on_connected != NULL) {
523560
rs9113_on_ops->on_connected(rs9113_wnic);
524561
}
562+
525563
error_exit:
526564
return ercd;
527565
}
@@ -538,10 +576,12 @@ int32_t rs9113_poll_conn_status(DEV_WNIC_PTR rs9113_wnic)
538576
ercd = rs9113_info->conn_status;
539577
goto error_exit;
540578
}
579+
541580
if (rs9113_info->conn_status == WNIC_CONNECTED) {
542581
ercd = WNIC_CONNECTED;
543582
goto error_exit;
544583
}
584+
545585
ercd = rsi_wlan_get_status();
546586
dbg_printf(DBG_MORE_INFO, "rsi_wlan_get_status ret %d\r\n", ercd);
547587
rs9113_info->conn_status = ercd;
@@ -567,6 +607,7 @@ int32_t rs9113_wnic_disconnect(DEV_WNIC_PTR rs9113_wnic)
567607
dbg_printf(DBG_MORE_INFO, "rsi_wlan_disconnect ret %d\r\n", ercd);
568608
rs9113_info->conn_status = WNIC_NOT_CONNECTED;
569609
rs9113_on_ops = &(rs9113_wnic->wnic_on_ops);
610+
570611
if (rs9113_on_ops->on_disconnected != NULL) {
571612
rs9113_on_ops->on_disconnected(rs9113_wnic);
572613
}
@@ -580,13 +621,14 @@ int32_t rs9113_prepare_tx(DEV_WNIC_PTR rs9113_wnic, uint32_t tx_len)
580621
{
581622
int32_t ercd = E_OK;
582623
rs9113_pbuf.buf = malloc(tx_len);
583-
if(rs9113_pbuf.buf != NULL){
624+
625+
if (rs9113_pbuf.buf != NULL) {
584626
rs9113_pbuf.len = tx_len;
585-
}
586-
else{
627+
} else {
587628
rs9113_pbuf.len = 0;
588629
ercd = E_NOMEM;
589630
}
631+
590632
rs9113_pbuf.cur_index = 0;
591633

592634
error_exit:
@@ -604,9 +646,10 @@ int32_t rs9113_add_tx_data(DEV_WNIC_PTR rs9113_wnic, uint8_t *p_buf, uint32_t le
604646
rs9113_info = &(rs9113_wnic->wnic_info);
605647
RS9113_CHECK_EXP((rs9113_info->init_status==WNIC_INIT_SUCCESSFUL), E_CLSED);
606648

607-
if(rs9113_pbuf.cur_index + len > rs9113_pbuf.len){
649+
if (rs9113_pbuf.cur_index + len > rs9113_pbuf.len) {
608650
len = rs9113_pbuf.len - rs9113_pbuf.cur_index;
609651
}
652+
610653
uint8_t *dest = rs9113_pbuf.buf + rs9113_pbuf.cur_index;
611654
memcpy(dest, p_buf, len);
612655
rs9113_pbuf.cur_index += len;
@@ -634,9 +677,11 @@ int32_t rs9113_commit_tx(DEV_WNIC_PTR rs9113_wnic, uint32_t len)
634677

635678
error_exit:
636679
free(rs9113_pbuf.buf);
637-
if(rs9113_pbuf.buf != NULL){
680+
681+
if (rs9113_pbuf.buf != NULL) {
638682
rs9113_pbuf.buf = NULL;
639683
}
684+
640685
return ercd;
641686
}
642687

device/peripheral/wifi/rs9113/rs9113_adapter.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
*
2929
--------------------------------------------- */
30-
#ifndef RS9113_ADAPTER_H_
31-
#define RS9113_ADAPTER_H_
30+
#ifndef _RS9113_ADAPTER_H_
31+
#define _RS9113_ADAPTER_H_
3232

3333
#ifdef __cplusplus
3434
extern "C" {
@@ -123,4 +123,4 @@ extern void rs9113_period_process(DEV_WNIC *rs9113_wnic, void *ptr);
123123
}
124124
#endif
125125

126-
#endif /* RS9113_ADAPTER_H_ */
126+
#endif /* _RS9113_ADAPTER_H_ */

0 commit comments

Comments
 (0)