4.2.1 Configuring Board Support Package
Perform the following changes in the Board Support Package (BSP).
- Add the following code in the
“wifi_PIC24F_WINC15x0\wifi_PIC24F_WINC15x0.X\
\winc1500\bsp\include\nm_bsp_internal.h”.
#ifdef _PIC24_ #include "bsp/include/nm_bsp_PIC24.h" #endif
- Modify the following set of functions
in the
nm_bus_wrapper_PIC24.c
file based on the PIC24 MCU BSP.nm_bsp_init
– This function is used to initialize the BSP to prepare the ATWINC before it starts working.nm_bsp_deinit
– This function is used to de-initialize the BSP.nm_bsp_reset
– This function is used to reset the ATWINC board by setting the CHIP_EN and RESET_N signals low, and, after a specific delay, the function sets the CHIP_EN high, then sets RESET_N high.nm_bsp_sleep
– This function is used to set the host to sleep for the specified duration.nm_bsp_register_isr
– This function is used to register the host interface interrupt service routine.nm_bsp_interrupt_ctrl
– This function is used to enable/disable the interrupt.The following is the modified
nm_bus_wrapper_PIC24.c
file source code.#include "../mcc_generated_files/mcc.h" #include <stdio.h> #include "bsp/include/nm_bsp.h" #include "common/include/nm_common.h" #include "bus_wrapper/include/nm_bus_wrapper.h" #include "conf_winc.h" #define NM_BUS_MAX_TRX_SZ 256 tstrNmBusCapabilities egstrNmBusCapabilities = { NM_BUS_MAX_TRX_SZ }; #ifdef CONF_WINC_USE_SPI static sint8 spi_rw(uint8* pu8Mosi, uint8* pu8Miso, uint16 u16Sz) { uint8 u8Dummy = 0; uint8 u8SkipMosi = 0, u8SkipMiso = 0; uint16_t txd_data = 0; uint16_t rxd_data = 0; if (!pu8Mosi) { pu8Mosi = &u8Dummy; u8SkipMosi = 1; } else if(!pu8Miso) { pu8Miso = &u8Dummy; u8SkipMiso = 1; } else { return M2M_ERR_BUS_FAIL; } //spi_select_slave(&master, &slave_inst, true); WINC_SPI_SELECT_SLAVE; while (u16Sz) { txd_data = *pu8Mosi; rxd_data = WINC_SPI_TRANSCEIVE(txd_data); *pu8Miso = rxd_data; u16Sz--; if (!u8SkipMiso) pu8Miso++; if (!u8SkipMosi) pu8Mosi++; } WINC_SPI_UNSELECT_SLAVE; return M2M_SUCCESS; } #endif /** @fn nm_bus_init * @brief Initialize the bus wrapper * @return M2M_SUCCESS in case of success and M2M_ERR_BUS_FAIL in case of failure */ sint8 nm_bus_init(void *pvinit) { sint8 result = M2M_SUCCESS; // Make sure that the slave is unselected. WINC_SPI_UNSELECT_SLAVE; // SPI Should already be enabled via MCC init code nm_bsp_reset(); nm_bsp_sleep(1); return result; } /* * @fn nm_bus_ioctl * @brief send/receive from the bus * @param[IN] u8Cmd * IOCTL command for the operation * @param[IN] pvParameter * Arbitrary parameter depenging on IOCTL * @return M2M_SUCCESS in case of success and M2M_ERR_BUS_FAIL in case of failure * @note For SPI only, it's important to be able to send/receive at the same time */ sint8 nm_bus_ioctl(uint8 u8Cmd, void* pvParameter) { sint8 s8Ret = 0; switch(u8Cmd) { #ifdef defined CONF_WINC_USE_SPI case NM_BUS_IOCTL_RW: { tstrNmSpiRw *pstrParam = (tstrNmSpiRw *)pvParameter; s8Ret = spi_rw(pstrParam->pu8InBuf, pstrParam->pu8OutBuf, pstrParam->u16Sz); } break; #endif default: s8Ret = -1; M2M_ERR("invalide ioclt cmd\n"); break; } return s8Ret; } /* * @fn nm_bus_deinit * @brief De-initialize the bus wrapper */ sint8 nm_bus_deinit(void) { sint8 result = M2M_SUCCESS; return result; } /* * @fn nm_bus_reinit * @brief re-initialize the bus wrapper * @param [in] void *config * re-init configuration data * @return M2M_SUCCESS in case of success and M2M_ERR_BUS_FAIL in case of failure * @author Dina El Sissy * @date 19 Sept 2012 * @version 1.0 */ sint8 nm_bus_reinit(void* config) { return M2M_SUCCESS; }