25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

190 satır
5.8 KiB

  1. /**
  2. *
  3. * \file
  4. *
  5. * \brief This module contains WINC3400 bus wrapper APIs declarations.
  6. *
  7. * Copyright (c) 2017-2018 Microchip Technology Inc. and its subsidiaries.
  8. *
  9. * \asf_license_start
  10. *
  11. * \page License
  12. *
  13. * Subject to your compliance with these terms, you may use Microchip
  14. * software and any derivatives exclusively with Microchip products.
  15. * It is your responsibility to comply with third party license terms applicable
  16. * to your use of third party software (including open source software) that
  17. * may accompany Microchip software.
  18. *
  19. * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
  20. * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
  21. * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
  22. * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
  23. * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
  24. * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
  25. * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
  26. * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
  27. * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
  28. * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
  29. * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
  30. *
  31. * \asf_license_stop
  32. *
  33. */
  34. #ifndef _NM_BUS_WRAPPER_H_
  35. #define _NM_BUS_WRAPPER_H_
  36. #include "common/include/nm_common.h"
  37. /**
  38. BUS Type
  39. **/
  40. #define NM_BUS_TYPE_I2C ((uint8)0)
  41. #define NM_BUS_TYPE_SPI ((uint8)1)
  42. #define NM_BUS_TYPE_UART ((uint8)2)
  43. /**
  44. IOCTL commands
  45. **/
  46. #define NM_BUS_IOCTL_R ((uint8)0) /*!< Read only ==> I2C/UART. Parameter:tstrNmI2cDefault/tstrNmUartDefault */
  47. #define NM_BUS_IOCTL_W ((uint8)1) /*!< Write only ==> I2C/UART. Parameter type tstrNmI2cDefault/tstrNmUartDefault*/
  48. #define NM_BUS_IOCTL_W_SPECIAL ((uint8)2) /*!< Write two buffers within the same transaction
  49. (same start/stop conditions) ==> I2C only. Parameter:tstrNmI2cSpecial */
  50. #define NM_BUS_IOCTL_RW ((uint8)3) /*!< Read/Write at the same time ==> SPI only. Parameter:tstrNmSpiRw */
  51. #define NM_BUS_IOCTL_WR_RESTART ((uint8)4) /*!< Write buffer then made restart condition then read ==> I2C only. parameter:tstrNmI2cSpecial */
  52. /**
  53. * @struct tstrNmBusCapabilities
  54. * @brief Structure holding bus capabilities information
  55. * @sa NM_BUS_TYPE_I2C, NM_BUS_TYPE_SPI
  56. */
  57. typedef struct
  58. {
  59. uint16 u16MaxTrxSz; /*!< Maximum transfer size. Must be >= 16 bytes*/
  60. } tstrNmBusCapabilities;
  61. /**
  62. * @struct tstrNmI2cDefault
  63. * @brief Structure holding I2C default operation parameters
  64. * @sa NM_BUS_IOCTL_R, NM_BUS_IOCTL_W
  65. */
  66. typedef struct
  67. {
  68. uint8 u8SlaveAdr;
  69. uint8 *pu8Buf; /*!< Operation buffer */
  70. uint16 u16Sz; /*!< Operation size */
  71. } tstrNmI2cDefault;
  72. /**
  73. * @struct tstrNmI2cSpecial
  74. * @brief Structure holding I2C special operation parameters
  75. * @sa NM_BUS_IOCTL_W_SPECIAL
  76. */
  77. typedef struct
  78. {
  79. uint8 u8SlaveAdr;
  80. uint8 *pu8Buf1; /*!< pointer to the 1st buffer */
  81. uint8 *pu8Buf2; /*!< pointer to the 2nd buffer */
  82. uint16 u16Sz1; /*!< 1st buffer size */
  83. uint16 u16Sz2; /*!< 2nd buffer size */
  84. } tstrNmI2cSpecial;
  85. /**
  86. * @struct tstrNmSpiRw
  87. * @brief Structure holding SPI R/W parameters
  88. * @sa NM_BUS_IOCTL_RW
  89. */
  90. typedef struct
  91. {
  92. uint8 *pu8InBuf; /*!< pointer to input buffer.
  93. Can be set to null and in this case zeros should be sent at MOSI */
  94. uint8 *pu8OutBuf; /*!< pointer to output buffer.
  95. Can be set to null and in this case data from MISO can be ignored */
  96. uint16 u16Sz; /*!< Transfere size */
  97. } tstrNmSpiRw;
  98. /**
  99. * @struct tstrNmUartDefault
  100. * @brief Structure holding UART default operation parameters
  101. * @sa NM_BUS_IOCTL_R, NM_BUS_IOCTL_W
  102. */
  103. typedef struct
  104. {
  105. uint8 *pu8Buf; /*!< Operation buffer */
  106. uint16 u16Sz; /*!< Operation size */
  107. } tstrNmUartDefault;
  108. /*!< Bus capabilities. This structure must be declared at platform specific bus wrapper */
  109. extern tstrNmBusCapabilities egstrNmBusCapabilities;
  110. #ifdef __cplusplus
  111. extern "C" {
  112. #endif
  113. /**
  114. * @fn nm_bus_init
  115. * @brief Initialize the bus wrapper
  116. * @param [in] req_com_port
  117. * Used to choose com port assigned to device like edbg
  118. * @param [in] req_serial_number
  119. * Used to choose peripheral, eg if 2 aardvark's are connected to pc.
  120. * Pass 0 to select first/only or if using UART.
  121. * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure
  122. */
  123. sint8 nm_bus_init(uint8 *req_com_port, uint32 req_serial_number);
  124. /**
  125. * @fn nm_bus_ioctl
  126. * @brief send/receive from the bus
  127. * @param [in] u8Cmd
  128. * IOCTL command for the operation
  129. * @param [in] pvParameter
  130. * Arbitrary parameter depending on IOCTL
  131. * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure
  132. * @note For SPI only, it's important to be able to send/receive at the same time
  133. */
  134. sint8 nm_bus_ioctl(uint8 u8Cmd, void* pvParameter);
  135. /**
  136. * @fn nm_bus_deinit
  137. * @brief De-initialize the bus wrapper
  138. * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure
  139. */
  140. sint8 nm_bus_deinit(void);
  141. /*
  142. * @fn nm_bus_reinit
  143. * @brief re-initialize the bus wrapper
  144. * @param [in] void *config
  145. * re-init configuration data
  146. * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure
  147. */
  148. sint8 nm_bus_reinit(void *);
  149. /*
  150. * @fn nm_bus_get_chip_type
  151. * @brief get chip type
  152. * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure
  153. */
  154. #ifdef CONF_WINC_USE_UART
  155. uint8 nm_bus_get_chip_type(void);
  156. uint8 nm_bus_get_sb_type(void);
  157. #endif
  158. /*
  159. * @fn spi_rw
  160. * @brief Process SPI Read/Write operation
  161. * @param pu8Mosi TX Data buffer
  162. * @param pu8Miso RX Data buffer
  163. * @param u16Sz Transfer length
  164. * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure
  165. */
  166. #ifdef CONF_WINC_USE_SPI
  167. sint8 nm_spi_rw(uint8* pu8Mosi, uint8* pu8Miso, uint16 u16Sz);
  168. #endif
  169. #ifdef __cplusplus
  170. }
  171. #endif
  172. #endif /*_NM_BUS_WRAPPER_H_*/