diff --git a/features/netsocket/emac-drivers/TARGET_Cypress/COMPONENT_SCL/interface/SclSTAInterface.cpp b/features/netsocket/emac-drivers/TARGET_Cypress/COMPONENT_SCL/interface/SclSTAInterface.cpp index 5a17077efb..1fefdee079 100644 --- a/features/netsocket/emac-drivers/TARGET_Cypress/COMPONENT_SCL/interface/SclSTAInterface.cpp +++ b/features/netsocket/emac-drivers/TARGET_Cypress/COMPONENT_SCL/interface/SclSTAInterface.cpp @@ -32,14 +32,16 @@ /** @file * Provides SCL interface functions to be used with WiFiInterface or NetworkInterface Objects */ +#define MIN_SSID_LENGTH (0) +#define MIN_PASSWORD_LENGTH (0) -struct scl_tx_nw_credentials { +struct scl_tx_net_credentials { nsapi_security_t network_security_type; int ssid_len; int pass_len; const char *network_ssid; const char *network_passphrase; -} scl_tx_nw_credentials_t; +} scl_tx_network_credentials; network_params_t network_parameter; @@ -177,20 +179,24 @@ nsapi_error_t SclSTAInterface::connect() nsapi_error_t interface_status; uint32_t connection_status = 0; - scl_tx_nw_credentials_t.network_ssid = _ssid; - if (strlen(_ssid) < MAX_SSID_LENGTH) { - scl_tx_nw_credentials_t.ssid_len = strlen(_ssid); + scl_tx_network_credentials.network_ssid = _ssid; + if ((strlen(_ssid) < MAX_SSID_LENGTH) && (strlen(_ssid) > MIN_SSID_LENGTH)) { + scl_tx_network_credentials.ssid_len = strlen(_ssid); + } else { + return NSAPI_ERROR_PARAMETER; } - scl_tx_nw_credentials_t.network_passphrase = _pass; - if (strlen(_pass) < MAX_PASSWORD_LENGTH) { - scl_tx_nw_credentials_t.pass_len = strlen(_pass); + scl_tx_network_credentials.network_passphrase = _pass; + if (((strlen(_pass) < MAX_PASSWORD_LENGTH) && (strlen(_pass) > MIN_PASSWORD_LENGTH)) || (_security == NSAPI_SECURITY_NONE)) { + scl_tx_network_credentials.pass_len = strlen(_pass); + } else { + return NSAPI_ERROR_PARAMETER; } - scl_tx_nw_credentials_t.network_security_type = _security; + scl_tx_network_credentials.network_security_type = _security; - ret_val = scl_send_data(SCL_TX_CONNECT, (char *)&scl_tx_nw_credentials_t, TIMER_DEFAULT_VALUE); + ret_val = scl_send_data(SCL_TX_CONNECT, (char *)&scl_tx_network_credentials, TIMER_DEFAULT_VALUE); if (ret_val == SCL_SUCCESS) { - SCL_LOG(("wifi provisioning in progress")); + SCL_LOG(("wifi provisioning in progress\r\n")); } network_parameter.connection_status = NSAPI_STATUS_DISCONNECTED; @@ -230,7 +236,9 @@ nsapi_error_t SclSTAInterface::connect() network_parameter.gateway, DEFAULT_STACK); - scl_send_data(SCL_TX_CONNECTION_STATUS, (char *)&connection_status, TIMER_DEFAULT_VALUE); + if (interface_status == NSAPI_ERROR_OK) { + scl_send_data(SCL_TX_CONNECTION_STATUS, (char *)&connection_status, TIMER_DEFAULT_VALUE); + } return interface_status; } @@ -246,6 +254,8 @@ nsapi_error_t SclSTAInterface::disconnect() { scl_result_t ret_val; nsapi_error_t disconnect_status; + uint32_t delay_timeout = 0; + ret_val = scl_send_data(SCL_TX_DISCONNECT, (char *)&disconnect_status, TIMER_DEFAULT_VALUE); if (ret_val == SCL_ERROR) { @@ -253,7 +263,18 @@ nsapi_error_t SclSTAInterface::disconnect() } if (!_interface) { - return NSAPI_STATUS_DISCONNECTED; + return NSAPI_ERROR_NO_CONNECTION; + } + + // block till disconnected from network + while ((network_parameter.connection_status != NSAPI_STATUS_DISCONNECTED) && delay_timeout < NW_DISCONNECT_TIMEOUT) { + ret_val = scl_get_nw_parameters(&network_parameter); + wait_us(NW_DELAY_TIME_US); + delay_timeout++; + } + + if (delay_timeout >= NW_DISCONNECT_TIMEOUT) { + return NSAPI_ERROR_TIMEOUT; } // bring down diff --git a/features/netsocket/emac-drivers/TARGET_Cypress/COMPONENT_SCL/interface/scl_emac.cpp b/features/netsocket/emac-drivers/TARGET_Cypress/COMPONENT_SCL/interface/scl_emac.cpp index d7a276858e..24c340821d 100644 --- a/features/netsocket/emac-drivers/TARGET_Cypress/COMPONENT_SCL/interface/scl_emac.cpp +++ b/features/netsocket/emac-drivers/TARGET_Cypress/COMPONENT_SCL/interface/scl_emac.cpp @@ -89,8 +89,11 @@ void SCL_EMAC::power_down() bool SCL_EMAC::power_up() { if (!powered_up) { - if (scl_wifi_on() != true) { - SCL_LOG(("returning False in scl_wifi_on()\n")); +#ifdef MBED_TEST_MODE + scl_init(); +#endif + if (!scl_wifi_on()) { + SCL_LOG(("WiFi failed to turn on\r\n")); return false; } powered_up = true; @@ -109,10 +112,9 @@ bool SCL_EMAC::get_hwaddr(uint8_t *addr) const memcpy(addr, mac.octet, sizeof(mac.octet)); return true; } else { - SCL_LOG(("return False in SCL_EMAC::gethwaddr\n")); + SCL_LOG(("Unable to get MAC address\r\n")); return false; } - } void SCL_EMAC::set_hwaddr(const uint8_t *addr) @@ -150,7 +152,8 @@ bool SCL_EMAC::link_out(emac_mem_buf_t *buf) if (buf == NULL) { return false; } - retval = scl_network_send_ethernet_data(scl_tx_data); + + retval = scl_network_send_ethernet_data(scl_tx_data); //Buffer is copied on Network Processor if (retval != SCL_SUCCESS) { return false; } diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/COMPONENT_SCL/inc/scl_common.h b/targets/TARGET_Cypress/TARGET_PSOC6/COMPONENT_SCL/inc/scl_common.h index 42e0b1c02d..6231462fb1 100644 --- a/targets/TARGET_Cypress/TARGET_PSOC6/COMPONENT_SCL/inc/scl_common.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/COMPONENT_SCL/inc/scl_common.h @@ -15,6 +15,7 @@ * limitations under the License. */ + /** @file scl_common.h * Defines common data types used in SCL */ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/COMPONENT_SCL/inc/scl_ipc.h b/targets/TARGET_Cypress/TARGET_PSOC6/COMPONENT_SCL/inc/scl_ipc.h index a9d3e23700..455968748d 100644 --- a/targets/TARGET_Cypress/TARGET_PSOC6/COMPONENT_SCL/inc/scl_ipc.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/COMPONENT_SCL/inc/scl_ipc.h @@ -53,6 +53,10 @@ extern "C" * Default timeout value (in seconds) for Wi-Fi connection */ #define NW_CONNECT_TIMEOUT (30) +/** + * Default timeout value (in seconds) for Wi-Fi disconnection + */ +#define NW_DISCONNECT_TIMEOUT (30) /** * Default interval (in micro seconds) for polling the Network Processor */ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/COMPONENT_SCL/src/IPC/scl_ipc.c b/targets/TARGET_Cypress/TARGET_PSOC6/COMPONENT_SCL/src/IPC/scl_ipc.c index f3d462f558..66143d0418 100644 --- a/targets/TARGET_Cypress/TARGET_PSOC6/COMPONENT_SCL/src/IPC/scl_ipc.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/COMPONENT_SCL/src/IPC/scl_ipc.c @@ -15,6 +15,7 @@ * limitations under the License. */ + /** @file * Provides SCL functionality to communicate with Network Processor */ @@ -40,6 +41,7 @@ #define DELAY_TIME (1000) #define SEMAPHORE_MAXCOUNT (1) #define SEMAPHORE_INITCOUNT (0) +#define INTIAL_VALUE (0) /****************************************************** ** Function Declarations *******************************************************/ @@ -55,13 +57,13 @@ scl_result_t scl_init(void); * Variables Definitions *****************************************************/ /* Structure of SCL thread info - * scl_thread_quit_flag: flag used to determine if thread is to be quit * scl_inited: flag used to determine if thread is started - * scl_thread: variable for thread handle + * scl_thread_quit_flag: flag used to determine if thread is to be quit * scl_thread_stack_start: pointer to start of thread stack + * scl_thread: variable for thread handle + * scl_rx_ready: semaphore for blocking the thread * scl_thread_stack_size: size of thread stack * scl_thread_priority: priority of thread - * scl_rx_ready: semaphore for blocking the thread */ struct scl_thread_info_t { volatile scl_bool_t scl_inited; @@ -113,9 +115,10 @@ static void scl_config(void) */ static scl_result_t scl_thread_init(void) { - cy_rslt_t retval, tmp = 0; + cy_rslt_t retval = CY_RSLT_SUCCESS; + cy_rslt_t tmp = INTIAL_VALUE; memset(&g_scl_thread_info, 0, sizeof(g_scl_thread_info)); - g_scl_thread_info.scl_thread_stack_start = (uint8_t *) malloc(SCL_THREAD_STACK_SIZE);; + g_scl_thread_info.scl_thread_stack_start = (uint8_t *) malloc(SCL_THREAD_STACK_SIZE); g_scl_thread_info.scl_thread_stack_size = (uint32_t) SCL_THREAD_STACK_SIZE; g_scl_thread_info.scl_thread_priority = (cy_thread_priority_t) SCL_THREAD_PRIORITY; @@ -141,7 +144,7 @@ static scl_result_t scl_thread_init(void) scl_result_t scl_init(void) { scl_result_t retval = SCL_SUCCESS; - uint32_t configuration_parameters = 0; + uint32_t configuration_parameters = INTIAL_VALUE; #ifdef MBED_CONF_TARGET_NP_CLOUD_DISABLE configuration_parameters = (MBED_CONF_TARGET_NP_CLOUD_DISABLE << 1); #else @@ -152,12 +155,12 @@ scl_result_t scl_init(void) #else configuration_parameters |= false; #endif - //SCL_LOG("configuration_parameters = %lu\n", configuration_parameters); + //SCL_LOG("configuration_parameters = %lu\r\n", configuration_parameters); scl_config(); if (g_scl_thread_info.scl_inited != SCL_TRUE) { retval = scl_thread_init(); if (retval != SCL_SUCCESS) { - SCL_LOG(("Thread init failed\n")); + SCL_LOG(("Thread init failed\r\n")); return SCL_ERROR; } else { retval = scl_send_data(SCL_TX_CONFIG_PARAMETERS, (char *) &configuration_parameters, TIMER_DEFAULT_VALUE); @@ -173,7 +176,7 @@ scl_result_t scl_send_data(int index, char *buffer, uint32_t timeout) IPC_STRUCT_Type *scl_send = NULL; uint32_t delay_timeout; - SCL_LOG(("scl_send_data index = %d\n", index)); + SCL_LOG(("scl_send_data index = %d\r\n", index)); scl_send = Cy_IPC_Drv_GetIpcBaseAddress(SCL_TX_CHANNEL); CHECK_BUFFER_NULL(buffer); if (!(REG_IPC_STRUCT_LOCK_STATUS(scl_send) & SCL_LOCK_ACQUIRE_STATUS)) { @@ -198,7 +201,7 @@ scl_result_t scl_send_data(int index, char *buffer, uint32_t timeout) return SCL_SUCCESS; } } else { - SCL_LOG(("unable to acquire lock\n")); + SCL_LOG(("unable to acquire lock\r\n")); return SCL_ERROR; } } @@ -230,27 +233,22 @@ static void scl_rx_handler(void) uint32_t index; IPC_STRUCT_Type *scl_receive = NULL; scl_buffer_t cp_buffer; - scl_buffer_t scl_buffer; uint32_t rx_ipc_size; - struct rx_ipc_info { - uint32_t size; - int *buf_alloc; - }*rx_cp = NULL; - + int *rx_cp_buffer; SCL_LOG(("Starting CP Rx thread\r\n")); scl_receive = Cy_IPC_Drv_GetIpcBaseAddress(SCL_RX_CHANNEL); while (SCL_TRUE) { cy_rtos_get_semaphore(&g_scl_thread_info.scl_rx_ready, CY_RTOS_NEVER_TIMEOUT, SCL_FALSE); index = (uint32_t)REG_IPC_STRUCT_DATA0(scl_receive); - SCL_LOG(("scl_rx_handler index = %lu\n", index)); + SCL_LOG(("scl_rx_handler index = %lu\r\n", index)); switch (index) { case SCL_RX_DATA: { - rx_cp = (struct rx_ipc_info *) REG_IPC_STRUCT_DATA1(scl_receive); - scl_buffer = rx_cp->buf_alloc; + SCL_LOG(("on CP the rxd address = %lx\r\n", REG_IPC_STRUCT_DATA1(scl_receive))); + rx_cp_buffer = (int *) REG_IPC_STRUCT_DATA1(scl_receive); + SCL_LOG(("rx_cp_buffer = %p \r\n", rx_cp_buffer)); REG_IPC_STRUCT_RELEASE(scl_receive) = SCL_RELEASE; - SCL_LOG(("scl_buffer = %p\n", scl_buffer)); - scl_network_process_ethernet_data(scl_buffer); + scl_network_process_ethernet_data(rx_cp_buffer); break; } case SCL_RX_TEST_MSG: { @@ -273,11 +271,11 @@ static void scl_rx_handler(void) } else { scl_emac_wifi_link_state_changed(false); } - SCL_LOG(("connection status = %d\n", connection_status)); + SCL_LOG(("connection status = %d\r\n", connection_status)); break; } default: { - SCL_LOG(("incorrect IPC from Network Processor\n")); + SCL_LOG(("incorrect IPC from Network Processor\r\n")); REG_IPC_STRUCT_RELEASE(scl_receive) = SCL_RELEASE; break; } diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/COMPONENT_SCL/src/include/scl_buffer_api.h b/targets/TARGET_Cypress/TARGET_PSOC6/COMPONENT_SCL/src/include/scl_buffer_api.h index 7a188ce9d2..87ce4e91bb 100644 --- a/targets/TARGET_Cypress/TARGET_PSOC6/COMPONENT_SCL/src/include/scl_buffer_api.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/COMPONENT_SCL/src/include/scl_buffer_api.h @@ -36,10 +36,6 @@ extern "C" /****************************************************** * Constants ******************************************************/ -/** - * Size of the SDIO block - */ -#define SDIO_BLOCK_SIZE (64U) /****************************************************** * Macros diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/COMPONENT_SCL/src/scl_buffer_api.c b/targets/TARGET_Cypress/TARGET_PSOC6/COMPONENT_SCL/src/scl_buffer_api.c index ec4d33a412..509828bee9 100644 --- a/targets/TARGET_Cypress/TARGET_PSOC6/COMPONENT_SCL/src/scl_buffer_api.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/COMPONENT_SCL/src/scl_buffer_api.c @@ -45,10 +45,9 @@ scl_result_t scl_host_buffer_get(scl_buffer_t *buffer, scl_buffer_dir_t directio if ((direction == SCL_NETWORK_TX) && (size <= PBUF_POOL_BUFSIZE)) { p = pbuf_alloc(PBUF_RAW, size, PBUF_POOL); } else { - p = pbuf_alloc(PBUF_RAW, size + SDIO_BLOCK_SIZE, PBUF_RAM); + p = pbuf_alloc(PBUF_RAW, size, PBUF_RAM); if (p != NULL) { p->len = size; - p->tot_len -= SDIO_BLOCK_SIZE; } } if (p != NULL) { diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/COMPONENT_SCL/src/scl_wifi_api.c b/targets/TARGET_Cypress/TARGET_PSOC6/COMPONENT_SCL/src/scl_wifi_api.c index 92b7e43d8d..f6fc3dc2ad 100644 --- a/targets/TARGET_Cypress/TARGET_PSOC6/COMPONENT_SCL/src/scl_wifi_api.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/COMPONENT_SCL/src/scl_wifi_api.c @@ -38,7 +38,7 @@ scl_result_t scl_wifi_is_ready_to_transceive(void) result = scl_send_data(SCL_TX_TRANSCEIVE_READY, (char *)&retval, TIMER_DEFAULT_VALUE); if (result == SCL_ERROR) { - SCL_LOG(("Ready to tranceive error\n")); + SCL_LOG(("Ready to tranceive error\r\n")); return SCL_ERROR; } else { return retval; @@ -51,7 +51,7 @@ bool scl_wifi_on(void) scl_result_t result = SCL_SUCCESS; result = scl_send_data(SCL_TX_WIFI_ON, (char *)&retval, WIFI_ON_TIMEOUT); if (result == SCL_ERROR) { - SCL_LOG(("wifi_on Error\n")); + SCL_LOG(("wifi_on Error\r\n")); return false; } else { return retval; @@ -66,7 +66,7 @@ scl_result_t scl_wifi_set_up(void) if (result == SCL_SUCCESS) { return retval; } else { - SCL_LOG(("Wifi set up error\n")); + SCL_LOG(("Wifi set up error\r\n")); return SCL_ERROR; } } @@ -85,7 +85,7 @@ scl_result_t scl_wifi_get_mac_address(scl_mac_t *mac) if (scl_retval == SCL_SUCCESS) { return scl_mac_data.retval; } else { - SCL_LOG(("Get MAC address error\n")); + SCL_LOG(("Get MAC address error\r\n")); return SCL_ERROR; } } @@ -98,7 +98,7 @@ scl_result_t scl_wifi_get_bssid(scl_mac_t *bssid) } scl_bssid_t; scl_result_t scl_retval = SCL_SUCCESS; scl_bssid_t.bssid = bssid; - scl_bssid_t.retval = 0; + scl_bssid_t.retval = SCL_SUCCESS; if (bssid == NULL) { return SCL_BADARG; } @@ -106,7 +106,7 @@ scl_result_t scl_wifi_get_bssid(scl_mac_t *bssid) if (scl_retval == SCL_SUCCESS) { return scl_bssid_t.retval; } else { - SCL_LOG(("get bssid error\n")); + SCL_LOG(("get bssid error\r\n")); return SCL_ERROR; } } @@ -115,14 +115,14 @@ scl_result_t scl_wifi_register_multicast_address(scl_mac_t *mac) { scl_mac scl_mac_t; scl_mac_t.mac = mac; - scl_mac_t.retval = 0; + scl_mac_t.retval = SCL_SUCCESS; scl_result_t scl_retval = SCL_SUCCESS; if (mac == NULL) { return SCL_BADARG; } scl_retval = scl_send_data(SCL_TX_REGISTER_MULTICAST_ADDRESS, (char *)&scl_mac_t, TIMER_DEFAULT_VALUE); if (scl_retval != SCL_SUCCESS) { - SCL_LOG(("Register Multicast Address IPC Error")); + SCL_LOG(("Register Multicast Address IPC Error\r\n")); return SCL_ERROR; } return (scl_mac_t.retval); @@ -154,7 +154,7 @@ scl_result_t scl_wifi_get_rssi(int32_t *rssi) if (scl_retval == SCL_SUCCESS) { return tx_param_t.retval; } else { - SCL_LOG(("get rssi error\n")); + SCL_LOG(("get rssi error\r\n")); return SCL_ERROR; } }