/**************************************************************************** Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED. This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT be copied by any method or incorporated into another program without the express written consent of Aerospace C.Power. This Information or any portion thereof remains the property of Aerospace C.Power. The Information contained herein is believed to be accurate and Aerospace C.Power assumes no responsibility or liability for its use in any way and conveys no license or title under any patent or copyright and makes no representation or warranty that this Information is free from patent or copyright infringement. ****************************************************************************/ /* common includes */ #include "iot_errno_api.h" #include "iot_module_api.h" #include "iot_config_api.h" #include "iot_utils_api.h" #include "iot_ipc_api.h" #include "iot_io_api.h" #include "iot_dbglog_api.h" #include "iot_swc_api.h" /* swc lib internal includes */ #include "swc_lib_internal.h" #if IOT_SWC_ENABLE swc_lib_global_t *p_swc_lib = NULL; void iot_ipc_swc_func(void *param, iot_ipc_addr_t *addr, iot_pkt_t *pkt) { (void)param; (void)addr; if (p_swc_lib && p_swc_lib->on_recv) { p_swc_lib->on_recv(pkt); } } uint32_t iot_swc_lib_init() { uint32_t ret = 0; iot_ipc_client_t client; if (p_swc_lib) goto out; p_swc_lib = os_mem_malloc(IOT_SWC_LIB_MID, sizeof(*p_swc_lib)); if (p_swc_lib == NULL) { ret = ERR_NOMEM; goto out; } p_swc_lib->lock = os_create_mutex(IOT_SWC_LIB_MID); if (p_swc_lib->lock == NULL) { ret = ERR_NOMEM; goto err; } /* register ipc to communicate with swc stack */ client.addr.f_id = IOT_IPC_FID_SWC; client.addr.c_id = IOT_IPC_CID_SWC_APP; client.recv = iot_ipc_swc_func; client.param = p_swc_lib; p_swc_lib->ipc_h = iot_ipc_register_client(&client); if (p_swc_lib->ipc_h == NULL) { ret = ERR_NOMEM; goto err; } goto out; err: os_mem_free(p_swc_lib); p_swc_lib = NULL; out: return ret; } void iot_swc_lib_deinit() { if (p_swc_lib) { iot_ipc_deregister_client(p_swc_lib->ipc_h); os_delete_mutex(p_swc_lib->lock); os_mem_free(p_swc_lib); p_swc_lib = NULL; } } void iot_swc_init(iot_swc_lib_cb_t cb) { iot_swc_lib_init(); p_swc_lib->on_recv = cb; } #endif