Skip to content

Update CYSBSYSKIT_01 #12828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -246,14 +254,27 @@ 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) {
return NSAPI_ERROR_TIMEOUT;
}

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*/


/** @file scl_common.h
* Defines common data types used in SCL
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
44 changes: 21 additions & 23 deletions targets/TARGET_Cypress/TARGET_PSOC6/COMPONENT_SCL/src/IPC/scl_ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*/


/** @file
* Provides SCL functionality to communicate with Network Processor
*/
Expand All @@ -40,6 +41,7 @@
#define DELAY_TIME (1000)
#define SEMAPHORE_MAXCOUNT (1)
#define SEMAPHORE_INITCOUNT (0)
#define INTIAL_VALUE (0)
/******************************************************
** Function Declarations
*******************************************************/
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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)) {
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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: {
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ extern "C"
/******************************************************
* Constants
******************************************************/
/**
* Size of the SDIO block
*/
#define SDIO_BLOCK_SIZE (64U)

/******************************************************
* Macros
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -98,15 +98,15 @@ 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;
}
scl_retval = scl_send_data(SCL_TX_WIFI_GET_BSSID, (char *)&scl_bssid_t, TIMER_DEFAULT_VALUE);
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;
}
}
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

void init_cycfg_all(void)
{
init_cycfg_routing();
init_cycfg_pins();
init_cycfg_system();
init_cycfg_routing();
init_cycfg_peripherals();
init_cycfg_pins();
}
Loading