You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

206 lines
4.9 KiB

  1. /**
  2. *
  3. * \file
  4. *
  5. * \brief This module contains NMC1000 bus wrapper APIs implementation.
  6. *
  7. * Copyright (c) 2015 Atmel Corporation. All rights reserved.
  8. *
  9. * \asf_license_start
  10. *
  11. * \page License
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions are met:
  15. *
  16. * 1. Redistributions of source code must retain the above copyright notice,
  17. * this list of conditions and the following disclaimer.
  18. *
  19. * 2. Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. *
  23. * 3. The name of Atmel may not be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  27. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  28. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  29. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  30. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  32. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  34. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  35. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * \asf_license_stop
  39. *
  40. */
  41. #include <stdio.h>
  42. #include "bsp/include/nm_bsp.h"
  43. #include "common/include/nm_common.h"
  44. #include "bus_wrapper/include/nm_bus_wrapper.h"
  45. #include "define.h"
  46. #include "BoardCfg.h"
  47. #include "SPI.h"
  48. //#include "atmel_start.h"
  49. //#include "winc_init.h"
  50. #define NM_BUS_MAX_TRX_SZ 256
  51. tstrNmBusCapabilities egstrNmBusCapabilities = {NM_BUS_MAX_TRX_SZ};
  52. static sint8 spi_rw(uint8 *pu8Mosi, uint8 *pu8Miso, uint16 u16Sz)
  53. {
  54. uint8 u8Dummy = 0;
  55. uint8 u8SkipMosi = 0, u8SkipMiso = 0;
  56. if (!pu8Mosi)
  57. {
  58. pu8Mosi = &u8Dummy;
  59. u8SkipMosi = 1;
  60. }
  61. else if (!pu8Miso)
  62. {
  63. pu8Miso = &u8Dummy;
  64. u8SkipMiso = 1;
  65. }
  66. else
  67. {
  68. return M2M_ERR_BUS_FAIL;
  69. }
  70. if (!u8SkipMiso)
  71. {
  72. while(u16Sz-- != 0)
  73. {
  74. uint8 tmp;
  75. tmp = SPITransaction(0xDE);
  76. *pu8Miso++ = tmp;
  77. }
  78. }
  79. if (!u8SkipMosi)
  80. {
  81. while(u16Sz-- != 0)
  82. {
  83. uint8 tmp;
  84. tmp = SPITransaction(*pu8Mosi++); //assign to tmp for debug purposes only.
  85. }
  86. }
  87. WIFI_SPI_SS_PIN = 1;
  88. /*uint8 u8Dummy = 0;
  89. uint8 u8SkipMosi = 0, u8SkipMiso = 0;
  90. if (!pu8Mosi)
  91. {
  92. pu8Mosi = &u8Dummy;
  93. u8SkipMosi = 1;
  94. }
  95. else if (!pu8Miso)
  96. {
  97. pu8Miso = &u8Dummy;
  98. u8SkipMiso = 1;
  99. }
  100. else
  101. {
  102. return M2M_ERR_BUS_FAIL;
  103. }
  104. gpio_set_pin_level(CONF_WINC_PIN_CHIP_SELECT, false);
  105. if (!u8SkipMiso) {
  106. io_read(io, pu8Miso, u16Sz);
  107. }
  108. if (!u8SkipMosi) {
  109. io_write(io, pu8Mosi, u16Sz);
  110. }
  111. gpio_set_pin_level(CONF_WINC_PIN_CHIP_SELECT, true);*/
  112. return M2M_SUCCESS;
  113. }
  114. /*
  115. * @fn nm_bus_init
  116. * @brief Initialize the bus wrapper
  117. * @return M2M_SUCCESS in case of success and M2M_ERR_BUS_FAIL in case of failure
  118. */
  119. sint8 nm_bus_init(void *pvinit)
  120. {
  121. sint8 result = M2M_SUCCESS;
  122. nm_bsp_reset();
  123. nm_bsp_sleep(1);
  124. return result;
  125. }
  126. //JFM The SPI module has been initialized in InitBoard()
  127. //so the two following lines are not needed.
  128. /* spi_m_sync_get_io_descriptor(spi_instance, &io);
  129. spi_m_sync_enable(spi_instance);/*
  130. nm_bsp_reset();
  131. nm_bsp_sleep(1);
  132. return result;
  133. }
  134. /*
  135. * @fn nm_bus_ioctl
  136. * @brief send/receive from the bus
  137. * @param[IN] u8Cmd
  138. * IOCTL command for the operation
  139. * @param[IN] pvParameter
  140. * Arbitrary parameter depenging on IOCTL
  141. * @return M2M_SUCCESS in case of success and M2M_ERR_BUS_FAIL in case of failure
  142. * @note For SPI only, it's important to be able to send/receive at the same time
  143. */
  144. sint8 nm_bus_ioctl(uint8 u8Cmd, void *pvParameter)
  145. {
  146. sint8 s8Ret = 0;
  147. switch (u8Cmd)
  148. {
  149. case NM_BUS_IOCTL_RW:
  150. {
  151. tstrNmSpiRw *pstrParam = (tstrNmSpiRw *)pvParameter;
  152. s8Ret = spi_rw(pstrParam->pu8InBuf, pstrParam->pu8OutBuf, pstrParam->u16Sz);
  153. break;
  154. }
  155. default:
  156. {
  157. s8Ret = -1;
  158. M2M_ERR("invalide ioclt cmd\n");
  159. break;
  160. }
  161. }
  162. return s8Ret;
  163. }
  164. /*
  165. * @fn nm_bus_deinit
  166. * @brief De-initialize the bus wrapper
  167. */
  168. sint8 nm_bus_deinit(void)
  169. {
  170. sint8 result = 0;
  171. return result;
  172. }
  173. /*
  174. * @fn nm_bus_reinit
  175. * @brief re-initialize the bus wrapper
  176. * @param [in] void *config
  177. * re-init configuration data
  178. * @return M2M_SUCCESS in case of success and M2M_ERR_BUS_FAIL in case of failure
  179. */
  180. sint8 nm_bus_reinit(void *config)
  181. {
  182. return M2M_SUCCESS;
  183. }