Microchip® Advanced Software Framework

winc3400/wifi_drv/driver/source/m2m_hif.c File Reference

This module contains M2M host interface APIs implementation.

Copyright (c) 2017-2021 Microchip Technology Inc. and its subsidiaries.

#include "common/include/nm_common.h"
#include "driver/source/nmbus.h"
#include "driver/source/nmdrv.h"
#include "bsp/include/nm_bsp.h"
#include "m2m_hif.h"
#include "driver/include/m2m_types.h"
#include "driver/source/nmasic.h"
#include "driver/include/m2m_periph.h"
#include "socket/include/m2m_socket_host_if.h"

Data Structures

struct  tstrHifContext
 

Macros

#define HIF_BLACKLIST_SZ   (sizeof(gau16HifBlacklist)/sizeof(gau16HifBlacklist[0]))
 
#define HIF_OTA_RB_ONLY   0xFFFF
 
#define HIFCODE_IP_RAW_SOCK_OPT   ((M2M_REQ_GROUP_IP << 8) | SOCKET_CMD_RAW_SET_SOCK_OPT)
 
#define HIFCODE_IP_SECURE   ((M2M_REQ_GROUP_IP << 8) | SOCKET_CMD_SECURE)
 
#define HIFCODE_OTA_RB   ((M2M_REQ_GROUP_OTA << 8) | M2M_OTA_REQ_ROLLBACK)
 
#define HIFCODE_OTA_SW   ((M2M_REQ_GROUP_OTA << 8) | M2M_OTA_REQ_SWITCH_FIRMWARE)
 
#define HIFCODE_SSL_WRITECERT   ((M2M_REQ_GROUP_SSL << 8) | M2M_SSL_REQ_WRITE_OWN_CERTS)
 
#define HIFCODE_WIFI_CONN   ((M2M_REQ_GROUP_WIFI << 8) | M2M_WIFI_REQ_CONN)
 
#define HIFCODE_WIFI_CONN_PARAM   ((M2M_REQ_GROUP_WIFI << 8) | M2M_WIFI_IND_CONN_PARAM)
 
#define HIFCODE_WIFI_DELETE_CRED   ((M2M_REQ_GROUP_WIFI << 8) | M2M_WIFI_REQRSP_DELETE_APID)
 
#define HIFCODE_WIFI_ENABLE_AP   ((M2M_REQ_GROUP_WIFI << 8) | M2M_WIFI_REQ_ENABLE_AP)
 
#define HIFCODE_WIFI_PASSIVESCAN   ((M2M_REQ_GROUP_WIFI << 8) | M2M_WIFI_REQ_PASSIVE_SCAN)
 
#define HIFCODE_WIFI_ROAMING   ((M2M_REQ_GROUP_WIFI << 8) | M2M_WIFI_REQ_ROAMING)
 
#define HIFCODE_WIFI_SCAN_SSID_LIST   ((M2M_REQ_GROUP_WIFI << 8) | M2M_WIFI_REQ_SCAN_SSID_LIST)
 
#define HIFCODE_WIFI_SET_STOP_SCAN_OPTION   ((M2M_REQ_GROUP_WIFI << 8) | M2M_WIFI_REQ_SET_STOP_SCAN_OPTION)
 
#define HIFCODE_WIFI_START_PROV_MODE   ((M2M_REQ_GROUP_WIFI << 8) | M2M_WIFI_REQ_START_PROVISION_MODE)
 
#define INTERRUPT_CORTUS_0_3000D0   (0x10a8)
 
#define INTERRUPT_CORTUS_1_3000D0   (0x10ac)
 
#define INTERRUPT_CORTUS_2_3000D0   (0x10b0)
 
#define INTERRUPT_CORTUS_3_3000D0   (0x10b4)
 
#define NEW_HIF_LIST
 
#define NMI_AHB_DATA_MEM_BASE   0x30000
 
#define NMI_AHB_SHARE_MEM_BASE   0xd0000
 
#define WIFI_HOST_RCV_CTRL_0   (0x1070)
 
#define WIFI_HOST_RCV_CTRL_1   (0x1084)
 
#define WIFI_HOST_RCV_CTRL_2   (0x1078)
 
#define WIFI_HOST_RCV_CTRL_3   (0x106c)
 
#define WIFI_HOST_RCV_CTRL_4   (0x150400)
 

Functions

sint8 hif_check_code (uint8 u8Gid, uint8 u8OpCode)
 
        To check that a particular hif message is supported with the current driver/firmware pair.
More...
 
sint8 hif_check_compatibility (uint16 u16HifInfo)
 
        To check the compatibility of an image with the current driver.
More...
 
sint8 hif_chip_sleep (void)
 To make the chip sleep. More...
 
static sint8 hif_chip_sleep_sc (void)
 
sint8 hif_chip_wake (void)
 To Wakeup the chip. More...
 
sint8 hif_deinit (void *arg)
 To Deinitialize HIF layer. More...
 
sint8 hif_enable_access (void)
 
        To enable access to HIF layer, based on HIF level of Firmware.
More...
 
uint8 hif_get_sleep_mode (void)
 Get the sleep mode of the HIF layer. More...
 
sint8 hif_handle_isr (void)
 Handle interrupt received from NMC1500 firmware. More...
 
sint8 hif_init (void *arg)
 To initialize HIF layer. More...
 
static sint8 hif_isr (void)
 Host interface interrupt service routine. More...
 
sint8 hif_receive (uint32 u32Addr, uint8 *pu8Buf, uint16 u16Sz, uint8 isDone)
 
sint8 hif_register_cb (uint8 u8Grp, tpfHifCallBack fn)
 
sint8 hif_send (uint8 u8Gid, uint8 u8Opcode, uint8 *pu8CtrlBuf, uint16 u16CtrlBufSize, uint8 *pu8DataBuf, uint16 u16DataSize, uint16 u16DataOffset)
 Send packet using host interface. More...
 
static sint8 hif_set_rx_done (void)
 
void hif_set_sleep_mode (uint8 u8Pstype)
 Set the sleep mode of the HIF layer. More...
 
void hif_yield (void)
 
    Yields control from interrupt event handler.
More...
 
static void isr (void)
 
static void m2m_hif_cb (uint8 u8OpCode, uint16 u16DataSize, uint32 u32Addr)
 WiFi call back function. More...
 
void os_hook_isr (void)
 Put interrupt request in netif queue for later processing. More...
 

Variables

static uint16 gau16HifBlacklist [] = {NEW_HIF_LIST}
 
volatile tstrHifContext gstrHifCxt
 
static uint8 gu8HifBlOffset = 0
 

#define HIF_BLACKLIST_SZ   (sizeof(gau16HifBlacklist)/sizeof(gau16HifBlacklist[0]))
#define HIF_OTA_RB_ONLY   0xFFFF
#define HIFCODE_IP_RAW_SOCK_OPT   ((M2M_REQ_GROUP_IP << 8) | SOCKET_CMD_RAW_SET_SOCK_OPT)
#define HIFCODE_IP_SECURE   ((M2M_REQ_GROUP_IP << 8) | SOCKET_CMD_SECURE)
#define HIFCODE_OTA_RB   ((M2M_REQ_GROUP_OTA << 8) | M2M_OTA_REQ_ROLLBACK)

Referenced by hif_check_code().

#define HIFCODE_OTA_SW   ((M2M_REQ_GROUP_OTA << 8) | M2M_OTA_REQ_SWITCH_FIRMWARE)

Referenced by hif_check_code().

#define HIFCODE_SSL_WRITECERT   ((M2M_REQ_GROUP_SSL << 8) | M2M_SSL_REQ_WRITE_OWN_CERTS)
#define HIFCODE_WIFI_CONN   ((M2M_REQ_GROUP_WIFI << 8) | M2M_WIFI_REQ_CONN)
#define HIFCODE_WIFI_CONN_PARAM   ((M2M_REQ_GROUP_WIFI << 8) | M2M_WIFI_IND_CONN_PARAM)
#define HIFCODE_WIFI_DELETE_CRED   ((M2M_REQ_GROUP_WIFI << 8) | M2M_WIFI_REQRSP_DELETE_APID)
#define HIFCODE_WIFI_ENABLE_AP   ((M2M_REQ_GROUP_WIFI << 8) | M2M_WIFI_REQ_ENABLE_AP)
#define HIFCODE_WIFI_PASSIVESCAN   ((M2M_REQ_GROUP_WIFI << 8) | M2M_WIFI_REQ_PASSIVE_SCAN)
#define HIFCODE_WIFI_ROAMING   ((M2M_REQ_GROUP_WIFI << 8) | M2M_WIFI_REQ_ROAMING)
#define HIFCODE_WIFI_SCAN_SSID_LIST   ((M2M_REQ_GROUP_WIFI << 8) | M2M_WIFI_REQ_SCAN_SSID_LIST)
#define HIFCODE_WIFI_SET_STOP_SCAN_OPTION   ((M2M_REQ_GROUP_WIFI << 8) | M2M_WIFI_REQ_SET_STOP_SCAN_OPTION)
#define HIFCODE_WIFI_START_PROV_MODE   ((M2M_REQ_GROUP_WIFI << 8) | M2M_WIFI_REQ_START_PROVISION_MODE)
#define INTERRUPT_CORTUS_0_3000D0   (0x10a8)

Referenced by hif_set_rx_done().

#define INTERRUPT_CORTUS_1_3000D0   (0x10ac)

Referenced by hif_send().

#define INTERRUPT_CORTUS_2_3000D0   (0x10b0)

Referenced by hif_send(), and hif_send_optimized().

#define INTERRUPT_CORTUS_3_3000D0   (0x10b4)
#define NEW_HIF_LIST
Value:
#define HIFCODE_IP_RAW_SOCK_OPT
Definition: winc3400/wifi_drv/driver/source/m2m_hif.c:110
#define HIFCODE_WIFI_PASSIVESCAN
Definition: winc3400/wifi_drv/driver/source/m2m_hif.c:104
#define HIFCODE_WIFI_ROAMING
Definition: winc3400/wifi_drv/driver/source/m2m_hif.c:111
#define HIFCODE_WIFI_CONN
Definition: winc3400/wifi_drv/driver/source/m2m_hif.c:105
#define HIFCODE_WIFI_SET_STOP_SCAN_OPTION
Definition: winc3400/wifi_drv/driver/source/m2m_hif.c:114
#define HIFCODE_WIFI_DELETE_CRED
Definition: winc3400/wifi_drv/driver/source/m2m_hif.c:107
#define HIFCODE_WIFI_ENABLE_AP
Definition: winc3400/wifi_drv/driver/source/m2m_hif.c:109
#define HIFCODE_WIFI_CONN_PARAM
Definition: winc3400/wifi_drv/driver/source/m2m_hif.c:106
#define HIFCODE_WIFI_SCAN_SSID_LIST
Definition: winc3400/wifi_drv/driver/source/m2m_hif.c:113
#define HIFCODE_SSL_WRITECERT
Definition: winc3400/wifi_drv/driver/source/m2m_hif.c:103
#define HIFCODE_IP_SECURE
Definition: winc3400/wifi_drv/driver/source/m2m_hif.c:112
#define HIF_OTA_RB_ONLY
Definition: winc3400/wifi_drv/driver/source/m2m_hif.c:95
#define HIFCODE_WIFI_START_PROV_MODE
Definition: winc3400/wifi_drv/driver/source/m2m_hif.c:108
#define NMI_AHB_DATA_MEM_BASE   0x30000
#define NMI_AHB_SHARE_MEM_BASE   0xd0000
#define WIFI_HOST_RCV_CTRL_0   (0x1070)

Referenced by hif_isr(), and hif_set_rx_done().

#define WIFI_HOST_RCV_CTRL_1   (0x1084)

Referenced by hif_isr().

#define WIFI_HOST_RCV_CTRL_2   (0x1078)

Referenced by hif_send().

#define WIFI_HOST_RCV_CTRL_3   (0x106c)

Referenced by hif_send().

#define WIFI_HOST_RCV_CTRL_4   (0x150400)

Referenced by hif_send().

sint8 hif_check_code ( uint8  u8Gid,
uint8  u8OpCode 
)

        To check that a particular hif message is supported with the current driver/firmware pair.

Parameters
[in]u8GidGroup ID.
[in]u8OpcodeOperation ID.
Returns
The function shall return M2M_SUCCESS for success and a negative value otherwise.
Parameters
[in]u8GidGroup ID.
[in]u8OpcodeOperation ID.
Returns
The function shall return ZERO for support and a negative value otherwise.

References gau16HifBlacklist, gu8HifBlOffset, HIF_BLACKLIST_SZ, HIFCODE_OTA_RB, HIFCODE_OTA_SW, M2M_ERR, M2M_ERR_SEND, and M2M_SUCCESS.

Referenced by hif_send().

sint8 hif_check_compatibility ( uint16  u16HifInfo)

        To check the compatibility of an image with the current driver.

Parameters
[in]u16HifInfoHIF info of image to be checked.
Returns
The function shall return ZERO for compatible image and a negative value otherwise.

References M2M_ERR_FW_VER_MISMATCH, M2M_GET_HIF_BLOCK, M2M_GET_HIF_MAJOR, M2M_HIF_BLOCK_VALUE, M2M_HIF_MAJOR_VALUE, and M2M_SUCCESS.

Referenced by hif_enable_access(), and m2m_wifi_check_ota_rb().

sint8 hif_chip_sleep ( void  )

To make the chip sleep.

        To make the chip sleep.
Returns
The function shall return ZERO for successful operation and a negative value otherwise.

References chip_sleep(), gu8ChipMode, gu8ChipSleep, M2M_NO_PS, M2M_SUCCESS, tstrHifContext::u8ChipMode, and tstrHifContext::u8ChipSleep.

static sint8 hif_chip_sleep_sc ( void  )
static
sint8 hif_chip_wake ( void  )

To Wakeup the chip.

    To Wakeup the chip.
Returns
The function shall return ZERO for successful operation and a negative value otherwise.

References chip_wake(), gu8ChipMode, gu8ChipSleep, gu8HifSizeDone, M2M_NO_PS, M2M_SUCCESS, tstrHifContext::u8ChipMode, tstrHifContext::u8ChipSleep, and tstrHifContext::u8HifRXDone.

sint8 hif_deinit ( void *  arg)

To Deinitialize HIF layer.

To De-initialize HIF layer.

        To Deinitialize HIF layer.
Parameters
[in]argPointer to the arguments.
Returns
The function shall return ZERO for successful operation and a negative value otherwise.
Parameters
[in]argPointer to the arguments.
Returns
The function shall return ZERO for successful operation and a negative value otherwise.

References cnt, hif_chip_wake(), M2M_DBG, M2M_DISABLE_PS, m2m_memset(), M2M_SUCCESS, nm_bsp_sleep(), and nm_read_reg().

sint8 hif_enable_access ( void  )

        To enable access to HIF layer, based on HIF level of Firmware.

        This function reads HIF level directly from a register written by Firmware.
Returns
The function shall return ZERO for full match operation and a negative value if operation is restricted.

References gu8HifBlOffset, HIF_BLACKLIST_SZ, hif_check_compatibility(), M2M_ERR, M2M_GET_HIF_MINOR, M2M_SUCCESS, nm_get_hif_info(), and NULL.

Referenced by m2m_wifi_init_start().

uint8 hif_get_sleep_mode ( void  )

Get the sleep mode of the HIF layer.

Returns
The function SHALL return the sleep mode of the HIF layer.

References gu8ChipMode, and tstrHifContext::u8ChipMode.

sint8 hif_handle_isr ( void  )

Handle interrupt received from NMC1500 firmware.

    Handle interrupt received from NMC1500 firmware.
Returns
The function SHALL return 0 for success and a negative value otherwise.

References gu8Interrupt, hif_isr(), M2M_ERR, M2M_SUCCESS, nm_bsp_interrupt_ctrl(), tstrHifContext::u8Interrupt, and tstrHifContext::u8Yield.

sint8 hif_init ( void *  arg)

To initialize HIF layer.

        To initialize HIF layer.
Parameters
[in]argPointer to the arguments.
Returns
The function shall return ZERO for successful operation and a negative value otherwise.
Parameters
[in]pstrInitParamPointer to the init parameters.
Returns
The function shall return ZERO for successful operation and a negative value otherwise.
Parameters
[in]argPointer to the arguments.
Returns
The function shall return ZERO for successful operation and a negative value otherwise.

References hif_chip_sleep(), hif_register_cb(), isr(), m2m_hif_cb(), m2m_memset(), M2M_REQ_GROUP_HIF, M2M_SUCCESS, and nm_bsp_register_isr().

sint8 hif_send ( uint8  u8Gid,
uint8  u8Opcode,
uint8 pu8CtrlBuf,
uint16  u16CtrlBufSize,
uint8 pu8DataBuf,
uint16  u16DataSize,
uint16  u16DataOffset 
)

Send packet using host interface.

Parameters
[in]u8GidGroup ID.
[in]u8OpcodeOperation ID.
[in]pu8CtrlBufPointer to the Control buffer.
[in]u16CtrlBufSizeControl buffer size.
[in]u16DataOffsetPacket Data offset.
[in]pu8DataBufPacket buffer Allocated by the caller.
[in]u16DataSizePacket buffer size (including the HIF header).
Returns
The function shall return ZERO for successful operation and a negative value otherwise.
Parameters
[in]u8GidGroup ID.
[in]u8OpcodeOperation ID.
[in]pu8CtrlBufPointer to the Control buffer.
[in]u16CtrlBufSizeControl buffer size.
[in]u16DataOffsetPacket Data offset.
[in]pu8DataBufPacket buffer Allocated by the caller.
[in]u16DataSizePacket buffer size (including the HIF header).
Returns
The function shall return M2M_SUCCESS for successful operation and a negative value otherwise.

References cnt, hif_check_code(), hif_chip_sleep(), hif_chip_sleep_sc(), hif_chip_wake(), INTERRUPT_CORTUS_1_3000D0, INTERRUPT_CORTUS_2_3000D0, ISNMC3400, M2M_DBG, M2M_ERR, M2M_ERR_MEM_ALLOC, M2M_ERR_SEND, M2M_HIF_HDR_OFFSET, M2M_HIF_MAX_PACKET_SIZE, M2M_INFO, M2M_SUCCESS, NBIT1, NBIT7, NM_BSP_B_L_16, nm_bsp_sleep(), nm_read_reg_with_ret(), nm_write_block(), nm_write_reg(), nmi_get_chipid(), NMI_STATE_REG, NULL, tstrHifHdr::u16Length, tstrHifHdr::u8Gid, tstrHifHdr::u8Opcode, WIFI_HOST_RCV_CTRL_2, WIFI_HOST_RCV_CTRL_3, and WIFI_HOST_RCV_CTRL_4.

void hif_set_sleep_mode ( uint8  u8Pstype)

Set the sleep mode of the HIF layer.

Parameters
[in]u8PstypeSleep mode.
Returns
The function SHALL return 0 for success and a negative value otherwise.

References gu8ChipMode, and tstrHifContext::u8ChipMode.

void hif_yield ( void  )

    Yields control from interrupt event handler.

Yields control from interrupt event handler.

References tstrHifContext::u8Yield.

static void isr ( void  )
static
static void m2m_hif_cb ( uint8  u8OpCode,
uint16  u16DataSize,
uint32  u32Addr 
)
static

WiFi call back function.

Parameters
[in]u8OpCodeHIF Opcode type.
[in]u16DataSizeHIF data length.
[in]u32AddrHIF address.

Referenced by hif_init().

void os_hook_isr ( void  )

Put interrupt request in netif queue for later processing.

References hif_msg_t::id, MSG_RX, NULL, os_hif_task_msg_post_counter_rx, osprintf(), hif_msg_t::payload, hif_msg_t::payload_size, hif_msg_t::pbuf, pdFALSE, pdTRUE, and xQueueSendFromISR.

Referenced by isr().

uint16 gau16HifBlacklist[] = {NEW_HIF_LIST}
static

Referenced by hif_check_code().

volatile tstrHifContext gstrHifCxt
uint8 gu8HifBlOffset = 0
static