mirror of https://github.com/ARMmbed/mbed-os.git
Update BSP and WifiInterface for WHD Changes
parent
5d819ebc81
commit
e64fdba7fc
|
@ -36,19 +36,18 @@
|
|||
((((unsigned char*)a)[5])==(((unsigned char*)b)[5])))
|
||||
|
||||
struct whd_scan_userdata {
|
||||
Semaphore *sema;
|
||||
rtos::Semaphore *sema;
|
||||
WiFiAccessPoint *aps;
|
||||
std::vector<whd_scan_result_t> *result_buff;
|
||||
unsigned count;
|
||||
unsigned offset;
|
||||
whd_interface_t ifp;
|
||||
bool scan_in_progress;
|
||||
};
|
||||
|
||||
static whd_scan_userdata interal_scan_data;
|
||||
static whd_scan_result_t internal_scan_result;
|
||||
|
||||
extern "C" void whd_emac_wifi_link_state_changed(bool state_up, whd_interface_t ifp);
|
||||
extern "C" void whd_emac_wifi_link_state_changed(whd_interface_t ifp, whd_bool_t state_up);
|
||||
|
||||
|
||||
int whd_toerror(whd_result_t res)
|
||||
|
@ -182,8 +181,8 @@ nsapi_error_t WhdSTAInterface::set_credentials(const char *ssid, const char *pas
|
|||
{
|
||||
if ((ssid == NULL) ||
|
||||
(strlen(ssid) == 0) ||
|
||||
(pass == NULL && ( security != NSAPI_SECURITY_NONE && security != NSAPI_SECURITY_WPA2_ENT)) ||
|
||||
(strlen(pass) == 0 && ( security != NSAPI_SECURITY_NONE && security != NSAPI_SECURITY_WPA2_ENT)) ||
|
||||
(pass == NULL && (security != NSAPI_SECURITY_NONE && security != NSAPI_SECURITY_WPA2_ENT)) ||
|
||||
(strlen(pass) == 0 && (security != NSAPI_SECURITY_NONE && security != NSAPI_SECURITY_WPA2_ENT)) ||
|
||||
(strlen(pass) > 63 && (security == NSAPI_SECURITY_WPA2 || security == NSAPI_SECURITY_WPA || security == NSAPI_SECURITY_WPA_WPA2))
|
||||
) {
|
||||
return NSAPI_ERROR_PARAMETER;
|
||||
|
@ -256,7 +255,7 @@ nsapi_error_t WhdSTAInterface::connect()
|
|||
}
|
||||
|
||||
if (whd_wifi_is_ready_to_transceive(_whd_emac.ifp) == WHD_SUCCESS) {
|
||||
whd_emac_wifi_link_state_changed(true, _whd_emac.ifp);
|
||||
whd_emac_wifi_link_state_changed(_whd_emac.ifp, WHD_TRUE);
|
||||
}
|
||||
|
||||
// bring up
|
||||
|
@ -351,7 +350,7 @@ static void whd_scan_handler(whd_scan_result_t **result_ptr,
|
|||
}
|
||||
}
|
||||
|
||||
if (data->count > 0) {
|
||||
if (data->count > 0 && data->aps != NULL) {
|
||||
// get ap stats
|
||||
nsapi_wifi_ap ap;
|
||||
|
||||
|
@ -388,7 +387,6 @@ int WhdSTAInterface::scan(WiFiAccessPoint *aps, unsigned count)
|
|||
interal_scan_data.aps = aps;
|
||||
interal_scan_data.count = count;
|
||||
interal_scan_data.offset = 0;
|
||||
interal_scan_data.ifp = _whd_emac.ifp;
|
||||
interal_scan_data.scan_in_progress = true;
|
||||
interal_scan_data.result_buff = new std::vector<whd_scan_result_t>();
|
||||
whd_result_t whd_res;
|
||||
|
@ -400,12 +398,8 @@ int WhdSTAInterface::scan(WiFiAccessPoint *aps, unsigned count)
|
|||
if (whd_res != WHD_SUCCESS) {
|
||||
res = whd_toerror(whd_res);
|
||||
} else {
|
||||
int tok = interal_scan_data.sema->wait();
|
||||
if (tok < 1) {
|
||||
res = NSAPI_ERROR_WOULD_BLOCK;
|
||||
} else {
|
||||
res = interal_scan_data.offset;
|
||||
}
|
||||
interal_scan_data.sema->acquire();
|
||||
res = interal_scan_data.offset;
|
||||
}
|
||||
|
||||
delete interal_scan_data.sema;
|
||||
|
@ -415,6 +409,9 @@ int WhdSTAInterface::scan(WiFiAccessPoint *aps, unsigned count)
|
|||
|
||||
int WhdSTAInterface::is_interface_connected(void)
|
||||
{
|
||||
if (!_whd_emac.ifp) {
|
||||
return WHD_INTERFACE_NOT_UP;
|
||||
}
|
||||
_whd_emac.ifp->role = WHD_STA_ROLE;
|
||||
if ((whd_wifi_is_ready_to_transceive(_whd_emac.ifp) == WHD_SUCCESS)) {
|
||||
return WHD_SUCCESS;
|
||||
|
@ -489,6 +486,13 @@ int WhdSTAInterface::wifi_set_ioctl_value(uint32_t ioctl, uint32_t value)
|
|||
return res;
|
||||
}
|
||||
|
||||
int WhdSTAInterface::wifi_get_ifp(whd_interface_t *ifp)
|
||||
{
|
||||
int res = WHD_SUCCESS;
|
||||
*ifp = _whd_emac.ifp;
|
||||
return res;
|
||||
}
|
||||
|
||||
int WhdSTAInterface::wifi_set_up(void)
|
||||
{
|
||||
int res = WHD_SUCCESS;
|
||||
|
@ -502,3 +506,10 @@ int WhdSTAInterface::wifi_set_down(void)
|
|||
res = whd_wifi_set_down(_whd_emac.ifp);
|
||||
return res;
|
||||
}
|
||||
|
||||
int WhdSTAInterface::wifi_set_coex_config(whd_coex_config_t *coex_config)
|
||||
{
|
||||
int res = WHD_SUCCESS;
|
||||
res = whd_wifi_set_coex_config(_whd_emac.ifp, coex_config);
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -161,12 +161,18 @@ public:
|
|||
/* set ioctl value */
|
||||
int wifi_set_ioctl_value(uint32_t ioctl, uint32_t value) ;
|
||||
|
||||
/* get WHD ifp value */
|
||||
int wifi_get_ifp(whd_interface_t *ifp);
|
||||
|
||||
/* set wifi interface up */
|
||||
int wifi_set_up(void);
|
||||
|
||||
/* set wifi interface down */
|
||||
int wifi_set_down(void);
|
||||
|
||||
/* set wifi coex configuration */
|
||||
int wifi_set_coex_config(whd_coex_config_t *coex_config);
|
||||
|
||||
/** Set Offload Manager Information
|
||||
* NOTE: Only allowed while disconnected
|
||||
*
|
||||
|
@ -211,5 +217,4 @@ private:
|
|||
OlmInterface *_olm;
|
||||
};
|
||||
|
||||
extern int wiced_leave_ap(int interface);
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Wiced implementation of NetworkInterfaceAPI
|
||||
* Copyright (c) 2017-2019 ARM Limited
|
||||
/*
|
||||
* Copyright (c) 2018-2019 ARM Limited
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -15,6 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#include "nsapi.h"
|
||||
#include "lwipopts.h"
|
||||
#include "WhdSoftAPInterface.h"
|
||||
|
@ -29,11 +30,33 @@
|
|||
extern int whd_toerror(whd_result_t res);
|
||||
extern nsapi_security_t whd_tosecurity(whd_security_t sec);
|
||||
extern whd_security_t whd_fromsecurity(nsapi_security_t sec);
|
||||
extern "C" void whd_emac_wifi_link_state_changed(bool state_up, whd_interface_t ifp);
|
||||
extern "C" void whd_emac_wifi_link_state_changed(whd_interface_t ifp, whd_bool_t state_up);
|
||||
|
||||
static const whd_event_num_t ap_events[] = { WLC_E_LINK, WLC_E_IF, WLC_E_DEAUTH, WLC_E_DEAUTH_IND, WLC_E_DISASSOC, WLC_E_DISASSOC_IND, WLC_E_ASSOC_IND, WLC_E_REASSOC_IND, WLC_E_NONE };
|
||||
|
||||
static void *whd_default_handle_softap_events(whd_interface_t ifp, const whd_event_header_t *event_header,
|
||||
const uint8_t *event_data, void *handler_user_data)
|
||||
{
|
||||
whd_driver_t whd_driver = ifp->whd_driver;
|
||||
|
||||
UNUSED_PARAMETER(event_header);
|
||||
UNUSED_PARAMETER(event_data);
|
||||
UNUSED_PARAMETER(handler_user_data);
|
||||
|
||||
WHD_IOCTL_LOG_ADD_EVENT(whd_driver, event_header->event_type, event_header->flags, event_header->reason);
|
||||
|
||||
if ((event_header->event_type == (whd_event_num_t)WLC_E_LINK) ||
|
||||
(event_header->event_type == WLC_E_IF)) {
|
||||
if (osSemaphoreGetCount(whd_driver->ap_info.whd_wifi_sleep_flag) < 1) {
|
||||
osStatus_t result = osSemaphoreRelease(whd_driver->ap_info.whd_wifi_sleep_flag);
|
||||
if (result != osOK) {
|
||||
printf("Release whd_wifi_sleep_flag ERROR: %d", result);
|
||||
}
|
||||
}
|
||||
}
|
||||
return handler_user_data;
|
||||
}
|
||||
|
||||
static const whd_event_num_t ap_client_events[] = { WLC_E_DEAUTH, WLC_E_DEAUTH_IND, WLC_E_DISASSOC, WLC_E_DISASSOC_IND, WLC_E_ASSOC_IND, WLC_E_REASSOC_IND, WLC_E_NONE };
|
||||
static uint16_t ap_event_entry = 2;
|
||||
|
||||
WhdSoftAPInterface::WhdSoftAPInterface(WHD_EMAC &emac, OnboardNetworkStack &stack)
|
||||
: EMACInterface(emac, stack),
|
||||
|
@ -44,18 +67,24 @@ WhdSoftAPInterface::WhdSoftAPInterface(WHD_EMAC &emac, OnboardNetworkStack &stac
|
|||
|
||||
|
||||
int WhdSoftAPInterface::start(const char *ssid, const char *pass, nsapi_security_t security, uint8_t channel,
|
||||
bool start_dhcp_server, const whd_custom_ie_info_t *ie_info)
|
||||
bool start_dhcp_server, const whd_custom_ie_info_t *ie_info, bool ap_sta_concur)
|
||||
{
|
||||
nsapi_error_t err;
|
||||
|
||||
/* set up our interface */
|
||||
if (!_interface) {
|
||||
nsapi_error_t err = _stack.add_ethernet_interface(_emac, true, &_interface);
|
||||
if (err != NSAPI_ERROR_OK) {
|
||||
_interface = NULL;
|
||||
return err;
|
||||
// power up primary emac interface first
|
||||
if (ap_sta_concur) {
|
||||
WHD_EMAC &emac_prime = WHD_EMAC::get_instance(WHD_STA_ROLE);
|
||||
if (!emac_prime.power_up()) {
|
||||
printf("Primary interface power up ERROR!\n");
|
||||
return NSAPI_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
_interface->attach(_connection_status_cb);
|
||||
}
|
||||
|
||||
// set concurrency mode and power up secondary, the bsp init is done by primary emac
|
||||
_whd_emac.ap_sta_concur = ap_sta_concur;
|
||||
if (!_whd_emac.power_up()) {
|
||||
printf("Secondary interface power up ERROR!\n");
|
||||
return NSAPI_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
// setup ssid
|
||||
|
@ -75,6 +104,27 @@ int WhdSoftAPInterface::start(const char *ssid, const char *pass, nsapi_security
|
|||
return err;
|
||||
}
|
||||
|
||||
// update default softap interface event handler
|
||||
err = unregister_event_handler();
|
||||
if (err != NSAPI_ERROR_OK) {
|
||||
printf("unregister_event_handler() ERROR: %d\n", err);
|
||||
return err;
|
||||
}
|
||||
err = register_event_handler(whd_default_handle_softap_events);
|
||||
if (err != NSAPI_ERROR_OK) {
|
||||
printf("register_event_handler() ERROR: %d\n", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
if (!_interface) {
|
||||
nsapi_error_t err = _stack.add_ethernet_interface(_whd_emac, true, &_interface);
|
||||
if (err != NSAPI_ERROR_OK) {
|
||||
_interface = NULL;
|
||||
return err;
|
||||
}
|
||||
_interface->attach(_connection_status_cb);
|
||||
}
|
||||
|
||||
if (ie_info) {
|
||||
err = whd_wifi_manage_custom_ie(_whd_emac.ifp, WHD_ADD_CUSTOM_IE, (const uint8_t *)ie_info->oui,
|
||||
ie_info->subtype, (const void *)ie_info->data, ie_info->length, ie_info->which_packets);
|
||||
|
@ -94,10 +144,9 @@ int WhdSoftAPInterface::start(const char *ssid, const char *pass, nsapi_security
|
|||
set_dhcp(false);
|
||||
|
||||
if (whd_wifi_is_ready_to_transceive(_whd_emac.ifp) == WHD_SUCCESS) {
|
||||
whd_emac_wifi_link_state_changed(true, _whd_emac.ifp);
|
||||
whd_emac_wifi_link_state_changed(_whd_emac.ifp, WHD_TRUE);
|
||||
}
|
||||
|
||||
// bring up
|
||||
err = _interface->bringup(_dhcp,
|
||||
_ip_address[0] ? _ip_address : 0,
|
||||
_netmask[0] ? _netmask : 0,
|
||||
|
@ -130,10 +179,11 @@ int WhdSoftAPInterface::get_associated_client_list(void *client_list_buffer, uin
|
|||
|
||||
int WhdSoftAPInterface::register_event_handler(whd_event_handler_t softap_event_handler)
|
||||
{
|
||||
return whd_management_set_event_handler(_whd_emac.ifp, ap_client_events, softap_event_handler, NULL, &ap_event_entry);
|
||||
uint16_t ap_events_entry = _whd_emac.ifp->event_reg_list[WHD_AP_EVENT_ENTRY];
|
||||
return whd_management_set_event_handler(_whd_emac.ifp, ap_events, softap_event_handler, NULL, &ap_events_entry);
|
||||
}
|
||||
|
||||
int WhdSoftAPInterface::unregister_event_handler(void)
|
||||
{
|
||||
return whd_wifi_deregister_event_handler(_whd_emac.ifp, ap_event_entry);
|
||||
return whd_wifi_deregister_event_handler(_whd_emac.ifp, _whd_emac.ifp->event_reg_list[WHD_AP_EVENT_ENTRY]);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* WHD SoftAP implementation of SoftAPInterface
|
||||
* Copyright (c) 2017-2019 ARM Limited
|
||||
/*
|
||||
* Copyright (c) 2018-2019 ARM Limited
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -70,14 +70,15 @@ public:
|
|||
* @param pass Security passphrase for connection to SoftAP
|
||||
* @param security Type of encryption for connection
|
||||
* @param channel Channel for SoftAP
|
||||
* @param start_dhcp_server start dhcp server for connection
|
||||
* @param[in] Optional Custom IE
|
||||
* @param start_dhcp_server Start dhcp server for connection
|
||||
* @param whd_custom_ie Optional Custom IE
|
||||
* @param ap_sta_concur Enable STA+AP concurrency mode
|
||||
*
|
||||
* @return 0 on success, or error code on failure
|
||||
* see @a nsapi_error
|
||||
*/
|
||||
int start(const char *ssid, const char *pass, nsapi_security_t security, uint8_t channel,
|
||||
bool start_dhcp_server = true, const whd_custom_ie_info_t *ie_info = NULL);
|
||||
bool start_dhcp_server = true, const whd_custom_ie_info_t *ie_info = NULL, bool ap_sta_concur = false);
|
||||
|
||||
/**
|
||||
* Remove Wi-Fi custom IE
|
||||
|
|
|
@ -27,34 +27,35 @@
|
|||
#include "mbed_shared_queues.h"
|
||||
#include "whd_wlioctl.h"
|
||||
#include "whd_buffer_api.h"
|
||||
#include "cybsp_api_wifi.h"
|
||||
#include "cybsp_wifi.h"
|
||||
#include "emac_eapol.h"
|
||||
#include "cy_result.h"
|
||||
|
||||
#define NULL_MAC(a) ( ( ( ( (unsigned char *)a )[0] ) == 0 ) && \
|
||||
( ( ( (unsigned char *)a )[1] ) == 0 ) && \
|
||||
( ( ( (unsigned char *)a )[2] ) == 0 ) && \
|
||||
( ( ( (unsigned char *)a )[3] ) == 0 ) && \
|
||||
( ( ( (unsigned char *)a )[4] ) == 0 ) && \
|
||||
( ( ( (unsigned char *)a )[5] ) == 0 ) )
|
||||
|
||||
extern "C"
|
||||
{
|
||||
eapol_packet_handler_t emac_eapol_packet_handler = NULL;
|
||||
void whd_emac_wifi_link_state_changed(whd_interface_t ifp, whd_bool_t state_up);
|
||||
} // extern "C"
|
||||
|
||||
WHD_EMAC::WHD_EMAC(whd_interface_role_t role)
|
||||
WHD_EMAC::WHD_EMAC(whd_interface_role_t role, const uint8_t *mac_addr)
|
||||
: interface_type(role)
|
||||
{
|
||||
if (mac_addr) {
|
||||
set_hwaddr(mac_addr);
|
||||
}
|
||||
}
|
||||
|
||||
WHD_EMAC::WHD_EMAC()
|
||||
: interface_type(WHD_STA_ROLE)
|
||||
WHD_EMAC &WHD_EMAC::get_instance(whd_interface_role_t role, const uint8_t *mac_addr)
|
||||
{
|
||||
}
|
||||
|
||||
WHD_EMAC &WHD_EMAC::get_instance()
|
||||
{
|
||||
return get_instance(WHD_STA_ROLE);
|
||||
}
|
||||
|
||||
WHD_EMAC &WHD_EMAC::get_instance(whd_interface_role_t role)
|
||||
{
|
||||
static WHD_EMAC emac_sta(WHD_STA_ROLE);
|
||||
static WHD_EMAC emac_ap(WHD_AP_ROLE);
|
||||
static WHD_EMAC emac_sta(WHD_STA_ROLE, mac_addr);
|
||||
static WHD_EMAC emac_ap(WHD_AP_ROLE, mac_addr);
|
||||
return role == WHD_AP_ROLE ? emac_ap : emac_sta;
|
||||
}
|
||||
|
||||
|
@ -96,33 +97,51 @@ void WHD_EMAC::power_down()
|
|||
bool WHD_EMAC::power_up()
|
||||
{
|
||||
if (!powered_up) {
|
||||
if (CY_RSLT_SUCCESS != cybsp_wifi_init()) {
|
||||
return false;
|
||||
cy_rslt_t res = CY_RSLT_SUCCESS;
|
||||
if (ap_sta_concur && interface_type == WHD_AP_ROLE) {
|
||||
WHD_EMAC &emac_prime = WHD_EMAC::get_instance(WHD_STA_ROLE);
|
||||
if (NULL_MAC(unicast_addr.octet)) {
|
||||
emac_prime.get_hwaddr(unicast_addr.octet);
|
||||
// Generated mac will set locally administered bit 1 of first byte
|
||||
unicast_addr.octet[0] |= (1 << 1);
|
||||
}
|
||||
// Note: This assumes that the primary interface initializes the
|
||||
// wifi driver and turns on the wifi chip.
|
||||
res = cybsp_wifi_init_secondary(&ifp /* Out */, &unicast_addr);
|
||||
} else {
|
||||
res = cybsp_wifi_init_primary(&ifp /* OUT */);
|
||||
}
|
||||
drvp = *(cybsp_get_wifi_driver());
|
||||
if (WHD_SUCCESS != whd_wifi_on(drvp, &ifp /* OUT */)) {
|
||||
|
||||
if (CY_RSLT_SUCCESS == res) {
|
||||
drvp = cybsp_get_wifi_driver();
|
||||
powered_up = true;
|
||||
ifp->whd_link_update_callback = whd_emac_wifi_link_state_changed;
|
||||
if (link_state && emac_link_state_cb) {
|
||||
emac_link_state_cb(link_state);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
powered_up = true;
|
||||
if (link_state && emac_link_state_cb) {
|
||||
emac_link_state_cb(link_state);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WHD_EMAC::get_hwaddr(uint8_t *addr) const
|
||||
{
|
||||
whd_mac_t mac;
|
||||
whd_result_t res = whd_wifi_get_mac_address(ifp, &mac);
|
||||
MBED_ASSERT(res == WHD_SUCCESS);
|
||||
memcpy(addr, mac.octet, sizeof(mac.octet));
|
||||
if (!NULL_MAC(unicast_addr.octet)) {
|
||||
memcpy(addr, unicast_addr.octet, sizeof(unicast_addr.octet));
|
||||
} else {
|
||||
whd_mac_t mac;
|
||||
whd_result_t res = whd_wifi_get_mac_address(ifp, &mac);
|
||||
MBED_ASSERT(res == WHD_SUCCESS);
|
||||
memcpy(addr, mac.octet, sizeof(mac.octet));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void WHD_EMAC::set_hwaddr(const uint8_t *addr)
|
||||
{
|
||||
/* No-op at this stage */
|
||||
memcpy(unicast_addr.octet, addr, sizeof(unicast_addr.octet));
|
||||
}
|
||||
|
||||
uint8_t WHD_EMAC::get_hwaddr_size() const
|
||||
|
@ -175,7 +194,16 @@ bool WHD_EMAC::link_out(emac_mem_buf_t *buf)
|
|||
|
||||
void WHD_EMAC::get_ifname(char *name, uint8_t size) const
|
||||
{
|
||||
memcpy(name, "whd", size);
|
||||
switch (interface_type) {
|
||||
case WHD_STA_ROLE:
|
||||
memcpy(name, "st", size);
|
||||
break;
|
||||
case WHD_AP_ROLE:
|
||||
memcpy(name, "ap", size);
|
||||
break;
|
||||
default:
|
||||
memcpy(name, "wh", size);
|
||||
}
|
||||
}
|
||||
|
||||
void WHD_EMAC::set_activity_cb(mbed::Callback<void(bool)> cb)
|
||||
|
@ -252,7 +280,7 @@ extern "C"
|
|||
}
|
||||
}
|
||||
|
||||
void whd_emac_wifi_link_state_changed(bool state_up, whd_interface_t ifp)
|
||||
void whd_emac_wifi_link_state_changed(whd_interface_t ifp, whd_bool_t state_up)
|
||||
{
|
||||
WHD_EMAC &emac = WHD_EMAC::get_instance(ifp->role);
|
||||
|
||||
|
|
|
@ -28,12 +28,9 @@
|
|||
|
||||
class WHD_EMAC : public EMAC {
|
||||
public:
|
||||
WHD_EMAC();
|
||||
WHD_EMAC(whd_interface_role_t itype);
|
||||
WHD_EMAC(whd_interface_role_t itype = WHD_STA_ROLE, const uint8_t *mac_addr = NULL);
|
||||
|
||||
static WHD_EMAC &get_instance();
|
||||
|
||||
static WHD_EMAC &get_instance(whd_interface_role_t role);
|
||||
static WHD_EMAC &get_instance(whd_interface_role_t role = WHD_STA_ROLE, const uint8_t *mac_addr = NULL);
|
||||
|
||||
/**
|
||||
* Return maximum transmission unit
|
||||
|
@ -167,16 +164,13 @@ public:
|
|||
EMACMemoryManager *memory_manager;
|
||||
bool powered_up = false;
|
||||
bool link_state = false;
|
||||
bool ap_sta_concur = false;
|
||||
whd_interface_role_t interface_type;
|
||||
whd_driver_t drvp = NULL;
|
||||
whd_interface_t ifp = NULL;
|
||||
whd_mac_t unicast_addr;
|
||||
whd_mac_t multicast_addr;
|
||||
struct whd_resource_source *resource_ops = NULL;
|
||||
whd_buffer_funcs_t *buffer_ops = NULL;
|
||||
whd_netif_funcs_t *netif_ops = NULL;
|
||||
whd_init_config_t *whd_init_config = NULL;
|
||||
mbed::Callback<void(bool)> activity_cb;
|
||||
|
||||
};
|
||||
|
||||
#endif /* WHD_EMAC_H_ */
|
||||
|
|
|
@ -53,13 +53,15 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "cybsp_api_core.h"
|
||||
|
||||
#ifdef MBED
|
||||
#include "cybsp_api_wifi.h"
|
||||
#endif /* MBED */
|
||||
#include "cybsp_types.h"
|
||||
#include "cybsp_core.h"
|
||||
#if defined(CYBSP_WIFI_CAPABLE)
|
||||
#include "cybsp_wifi_sdio.h"
|
||||
#endif
|
||||
#ifndef __MBED__
|
||||
#include "cybsp_retarget.h"
|
||||
#include "cybsp_serial_flash.h"
|
||||
#endif /* __MBED__ */
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include "cybsp_types.h"
|
||||
#include "cybsp_wifi.h"
|
||||
#include "cy_network_buffer.h"
|
||||
#include "cmsis_os2.h"
|
||||
#include "cyabs_rtos.h"
|
||||
#include "whd_types.h"
|
||||
#include "cyhal.h"
|
||||
#include "cybsp_wifi_sdio.h"
|
||||
|
@ -37,11 +37,9 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#define THREAD_STACK_SIZE 5120
|
||||
#define THREAD_PRIORITY osPriorityHigh
|
||||
#define THREAD_PRIORITY CY_RTOS_PRIORITY_HIGH
|
||||
#define COUNTRY WHD_COUNTRY_AUSTRALIA
|
||||
#define DEFAULT_OOB_PIN 0
|
||||
#define WLAN_INTR_PRIORITY 1
|
||||
#define WLAN_POWER_UP_DELAY_MS 250
|
||||
|
||||
#define SDIO_ENUMERATION_TRIES 500
|
||||
#define SDIO_RETRY_DELAY_MS 1
|
||||
|
@ -52,63 +50,39 @@ extern "C" {
|
|||
#endif/* !defined(CY_WIFI_OOB_INTR_PRIORITY) */
|
||||
|
||||
/* Determine whether to use the SDIO oob interrupt.
|
||||
* When CY_SDIO_BUS_NEEDS_OOB_INTR is defined,
|
||||
* use its value to determine enable status; otherwise,
|
||||
* default to enable. Use CY_WIFI_HOST_WAKE_SW_FORCE
|
||||
* to force the enable status.
|
||||
* Use CY_WIFI_HOST_WAKE_SW_FORCE to force the enable status.
|
||||
*/
|
||||
#if !defined(CY_WIFI_HOST_WAKE_SW_FORCE)
|
||||
|
||||
#if !defined(CY_SDIO_BUS_NEEDS_OOB_INTR)
|
||||
#define CY_SDIO_BUS_USE_OOB_INTR (1u)
|
||||
#define CY_SDIO_BUS_USE_OOB_INTR (1u)
|
||||
#else
|
||||
#define CY_SDIO_BUS_USE_OOB_INTR CY_SDIO_BUS_NEEDS_OOB_INTR
|
||||
#endif /* !defined(CY_SDIO_BUS_NEEDS_OOB_INTR) */
|
||||
|
||||
#else
|
||||
|
||||
#define CY_SDIO_BUS_USE_OOB_INTR CY_WIFI_HOST_WAKE_SW_FORCE
|
||||
|
||||
#define CY_SDIO_BUS_USE_OOB_INTR CY_WIFI_HOST_WAKE_SW_FORCE
|
||||
#endif /* defined(CY_WIFI_HOST_WAKE_SW_FORCE) */
|
||||
|
||||
/* Define the host-wake configuration.
|
||||
* Choose the configurator settings over the HAL.
|
||||
*/
|
||||
#if (CY_SDIO_BUS_USE_OOB_INTR != 0)
|
||||
|
||||
/* Prefer configurator declarations over HAL */
|
||||
|
||||
#if defined(CYCFG_WIFI_HOST_WAKE_GPIO)
|
||||
#define CY_WIFI_HOST_WAKE_GPIO CYCFG_WIFI_HOST_WAKE_GPIO
|
||||
/* Setup configuration based on configurator or BSP, where configurator has precedence. */
|
||||
#if defined(CYCFG_WIFI_HOST_WAKE_ENABLED)
|
||||
#define CY_WIFI_HOST_WAKE_GPIO CYCFG_WIFI_HOST_WAKE_GPIO
|
||||
#define CY_WIFI_HOST_WAKE_IRQ_EVENT CYCFG_WIFI_HOST_WAKE_IRQ_EVENT
|
||||
#else
|
||||
/* Setup host-wake pin */
|
||||
#if defined(CYBSP_WIFI_HOST_WAKE)
|
||||
#define CY_WIFI_HOST_WAKE_GPIO CYBSP_WIFI_HOST_WAKE
|
||||
#else
|
||||
#error "CYBSP_WIFI_HOST_WAKE must be defined"
|
||||
#endif
|
||||
/* Setup host-wake irq */
|
||||
#if defined(CYBSP_WIFI_HOST_WAKE_IRQ_EVENT)
|
||||
#define CY_WIFI_HOST_WAKE_IRQ_EVENT CYBSP_WIFI_HOST_WAKE_IRQ_EVENT
|
||||
#else
|
||||
#error "CYBSP_WIFI_HOST_WAKE_IRQ_EVENT must be defined"
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#define CY_WIFI_HOST_WAKE_GPIO CYBSP_WIFI_HOST_WAKE
|
||||
#endif
|
||||
|
||||
#if defined(CYCFG_WIFI_HOST_WAKE_GPIO_DM)
|
||||
#define CY_WIFI_HOST_WAKE_GPIO_DM CYCFG_WIFI_HOST_WAKE_GPIO_DM
|
||||
#else
|
||||
#define CY_WIFI_HOST_WAKE_GPIO_DM CYBSP_WIFI_HOST_WAKE_GPIO_DM
|
||||
#endif
|
||||
|
||||
#if defined(CYCFG_WIFI_HOST_WAKE_IRQ_EVENT)
|
||||
#define CY_WIFI_HOST_WAKE_IRQ_EVENT CYCFG_WIFI_HOST_WAKE_IRQ_EVENT
|
||||
#else
|
||||
#define CY_WIFI_HOST_WAKE_IRQ_EVENT CYBSP_WIFI_HOST_WAKE_IRQ_EVENT
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
/* Dummy macro declarations to appease compiler */
|
||||
#define CY_WIFI_HOST_WAKE_GPIO 0
|
||||
#define CY_WIFI_HOST_WAKE_GPIO_DM 0
|
||||
#define CY_WIFI_HOST_WAKE_IRQ_EVENT 0
|
||||
|
||||
#define CY_WIFI_HOST_WAKE_GPIO CYHAL_NC_PIN_VALUE
|
||||
#define CY_WIFI_HOST_WAKE_IRQ_EVENT 0
|
||||
#endif /* (CY_SDIO_BUS_USE_OOB_INTR != 0) */
|
||||
|
||||
whd_driver_t whd_drv;
|
||||
bool sdio_initialized = false;
|
||||
cyhal_sdio_t sdio_obj;
|
||||
|
||||
static whd_driver_t whd_drv;
|
||||
static whd_buffer_funcs_t buffer_ops =
|
||||
{
|
||||
.whd_host_buffer_get = cy_host_buffer_get,
|
||||
|
@ -142,7 +116,6 @@ static cy_rslt_t sdio_try_send_cmd(const cyhal_sdio_t *sdio_object, cyhal_transf
|
|||
loop_count++;
|
||||
}
|
||||
while(result != CY_RSLT_SUCCESS && loop_count <= SDIO_BUS_LEVEL_MAX_RETRIES);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -179,42 +152,10 @@ static cy_rslt_t cybsp_sdio_enumerate(const cyhal_sdio_t *sdio_object)
|
|||
return result;
|
||||
}
|
||||
|
||||
static cy_rslt_t init_sdio_whd(void)
|
||||
{
|
||||
/* WiFi into reset */
|
||||
cy_rslt_t result = cyhal_gpio_init(CYBSP_WIFI_WL_REG_ON, CYHAL_GPIO_DIR_OUTPUT, CY_GPIO_DM_PULLUP, 0);
|
||||
|
||||
if(result == CY_RSLT_SUCCESS)
|
||||
{
|
||||
/* Init SDIO Host */
|
||||
if (!sdio_initialized)
|
||||
{
|
||||
result = cybsp_sdio_init();
|
||||
}
|
||||
if(result == CY_RSLT_SUCCESS)
|
||||
{
|
||||
/* WiFi out of reset */
|
||||
cyhal_gpio_write(CYBSP_WIFI_WL_REG_ON, true);
|
||||
Cy_SysLib_Delay(WLAN_POWER_UP_DELAY_MS);
|
||||
}
|
||||
else
|
||||
{
|
||||
cyhal_gpio_free(CYBSP_WIFI_WL_REG_ON);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static void deinit_sdio_whd(void)
|
||||
{
|
||||
cyhal_sdio_free(&sdio_obj);
|
||||
cyhal_gpio_free(CYBSP_WIFI_WL_REG_ON);
|
||||
sdio_initialized = false;
|
||||
}
|
||||
|
||||
static cy_rslt_t init_sdio_bus(void)
|
||||
{
|
||||
cy_rslt_t result = cybsp_sdio_enumerate(&sdio_obj);
|
||||
cyhal_sdio_t* sdio_p = cybsp_get_wifi_sdio_obj();
|
||||
cy_rslt_t result = cybsp_sdio_enumerate(sdio_p);
|
||||
if(result == CY_RSLT_SUCCESS)
|
||||
{
|
||||
whd_sdio_config_t whd_sdio_config;
|
||||
|
@ -231,12 +172,12 @@ static cy_rslt_t init_sdio_bus(void)
|
|||
whd_sdio_config.sdio_1bit_mode = WHD_FALSE;
|
||||
whd_sdio_config.high_speed_sdio_clock = WHD_FALSE;
|
||||
whd_sdio_config.oob_config = oob_config;
|
||||
whd_bus_sdio_attach(whd_drv, &whd_sdio_config, &sdio_obj);
|
||||
whd_bus_sdio_attach(whd_drv, &whd_sdio_config, sdio_p);
|
||||
|
||||
/* Increase frequency to 25 MHz for better performance */
|
||||
config.frequencyhal_hz = 25000000;
|
||||
config.block_size = 0;
|
||||
cyhal_sdio_configure(&sdio_obj, &config);
|
||||
cyhal_sdio_configure(sdio_p, &config);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -244,15 +185,19 @@ static cy_rslt_t init_sdio_bus(void)
|
|||
cy_rslt_t cybsp_wifi_init_primary(whd_interface_t* interface)
|
||||
{
|
||||
whd_init_config_t whd_init_config;
|
||||
whd_init_config.thread_stack_size = (uint32_t) THREAD_STACK_SIZE;
|
||||
whd_init_config.thread_stack_size = (uint32_t)THREAD_STACK_SIZE;
|
||||
whd_init_config.thread_stack_start = (uint8_t *)malloc(THREAD_STACK_SIZE);
|
||||
whd_init_config.thread_priority = (uint32_t) THREAD_PRIORITY;
|
||||
whd_init_config.thread_priority = (uint32_t)THREAD_PRIORITY;
|
||||
whd_init_config.country = COUNTRY;
|
||||
|
||||
uint32_t ret = whd_init(&whd_drv, &whd_init_config, &resource_ops, &buffer_ops, &netif_ops);
|
||||
if(ret == WHD_SUCCESS)
|
||||
cy_rslt_t result = whd_init(&whd_drv, &whd_init_config, &resource_ops, &buffer_ops, &netif_ops);
|
||||
if(result == CY_RSLT_SUCCESS)
|
||||
{
|
||||
result = init_sdio_bus();
|
||||
if(result == CY_RSLT_SUCCESS)
|
||||
{
|
||||
result = whd_wifi_on(whd_drv, interface);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue