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.
 
 
 
 

174 rivejä
5.8 KiB

  1. /**
  2. *
  3. * \file
  4. *
  5. * \brief This module contains NMC1000 bus wrapper APIs declarations.
  6. *
  7. * Copyright (c) 2015 - 2017 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. #ifndef _NM_BUS_WRAPPER_H_
  42. #define _NM_BUS_WRAPPER_H_
  43. #include "common/include/nm_common.h"
  44. /**
  45. BUS Type
  46. **/
  47. #define NM_BUS_TYPE_I2C ((uint8)0)
  48. #define NM_BUS_TYPE_SPI ((uint8)1)
  49. #define NM_BUS_TYPE_UART ((uint8)2)
  50. /**
  51. IOCTL commands
  52. **/
  53. #define NM_BUS_IOCTL_R ((uint8)0) /*!< Read only ==> I2C/UART. Parameter:tstrNmI2cDefault/tstrNmUartDefault */
  54. #define NM_BUS_IOCTL_W ((uint8)1) /*!< Write only ==> I2C/UART. Parameter type tstrNmI2cDefault/tstrNmUartDefault*/
  55. #define NM_BUS_IOCTL_W_SPECIAL \
  56. ((uint8)2) /*!< Write two buffers within the same transaction \
  57. (same start/stop conditions) ==> I2C only. Parameter:tstrNmI2cSpecial */
  58. #define NM_BUS_IOCTL_RW ((uint8)3) /*!< Read/Write at the same time ==> SPI only. Parameter:tstrNmSpiRw */
  59. #define NM_BUS_IOCTL_WR_RESTART \
  60. ((uint8)4) /*!< Write buffer then made restart condition then read ==> I2C only. parameter:tstrNmI2cSpecial */
  61. /**
  62. * @struct tstrNmBusCapabilities
  63. * @brief Structure holding bus capabilities information
  64. * @sa NM_BUS_TYPE_I2C, NM_BUS_TYPE_SPI
  65. */
  66. typedef struct {
  67. uint16 u16MaxTrxSz; /*!< Maximum transfer size. Must be >= 16 bytes*/
  68. } tstrNmBusCapabilities;
  69. /**
  70. * @struct tstrNmI2cDefault
  71. * @brief Structure holding I2C default operation parameters
  72. * @sa NM_BUS_IOCTL_R, NM_BUS_IOCTL_W
  73. */
  74. typedef struct {
  75. uint8 u8SlaveAdr;
  76. uint8 *pu8Buf; /*!< Operation buffer */
  77. uint16 u16Sz; /*!< Operation size */
  78. } tstrNmI2cDefault;
  79. /**
  80. * @struct tstrNmI2cSpecial
  81. * @brief Structure holding I2C special operation parameters
  82. * @sa NM_BUS_IOCTL_W_SPECIAL
  83. */
  84. typedef struct {
  85. uint8 u8SlaveAdr;
  86. uint8 *pu8Buf1; /*!< pointer to the 1st buffer */
  87. uint8 *pu8Buf2; /*!< pointer to the 2nd buffer */
  88. uint16 u16Sz1; /*!< 1st buffer size */
  89. uint16 u16Sz2; /*!< 2nd buffer size */
  90. } tstrNmI2cSpecial;
  91. /**
  92. * @struct tstrNmSpiRw
  93. * @brief Structure holding SPI R/W parameters
  94. * @sa NM_BUS_IOCTL_RW
  95. */
  96. typedef struct {
  97. uint8 *pu8InBuf; /*!< pointer to input buffer.
  98. Can be set to null and in this case zeros should be sent at MOSI */
  99. uint8 *pu8OutBuf; /*!< pointer to output buffer.
  100. Can be set to null and in this case data from MISO can be ignored */
  101. uint16 u16Sz; /*!< Transfere size */
  102. } tstrNmSpiRw;
  103. /**
  104. * @struct tstrNmUartDefault
  105. * @brief Structure holding UART default operation parameters
  106. * @sa NM_BUS_IOCTL_R, NM_BUS_IOCTL_W
  107. */
  108. typedef struct {
  109. uint8 *pu8Buf; /*!< Operation buffer */
  110. uint16 u16Sz; /*!< Operation size */
  111. } tstrNmUartDefault;
  112. /*!< Bus capabilities. This structure must be declared at platform specific bus wrapper */
  113. extern tstrNmBusCapabilities egstrNmBusCapabilities;
  114. #ifdef __cplusplus
  115. extern "C" {
  116. #endif
  117. /**
  118. * @fn nm_bus_init
  119. * @brief Initialize the bus wrapper
  120. * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure
  121. */
  122. sint8 nm_bus_init(void *);
  123. /**
  124. * @fn nm_bus_ioctl
  125. * @brief send/receive from the bus
  126. * @param [in] u8Cmd
  127. * IOCTL command for the operation
  128. * @param [in] pvParameter
  129. * Arbitrary parameter depending on IOCTL
  130. * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure
  131. * @note For SPI only, it's important to be able to send/receive at the same time
  132. */
  133. sint8 nm_bus_ioctl(uint8 u8Cmd, void *pvParameter);
  134. /**
  135. * @fn nm_bus_deinit
  136. * @brief De-initialize the bus wrapper
  137. * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure
  138. */
  139. sint8 nm_bus_deinit(void);
  140. /*
  141. * @fn nm_bus_reinit
  142. * @brief re-initialize the bus wrapper
  143. * @param [in] void *config
  144. * re-init configuration data
  145. * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure
  146. */
  147. sint8 nm_bus_reinit(void *);
  148. /*
  149. * @fn nm_bus_get_chip_type
  150. * @brief get chip type
  151. * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure
  152. */
  153. #ifdef CONF_WINC_USE_UART
  154. uint8 nm_bus_get_chip_type(void);
  155. sint8 nm_bus_break(void);
  156. #endif
  157. #ifdef __cplusplus
  158. }
  159. #endif
  160. #endif /*_NM_BUS_WRAPPER_H_*/