spimss.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /**
  2. * @file spimss.h
  3. * @brief Serial Peripheral Interface (SPIMSS) function prototypes and data types.
  4. */
  5. /* ****************************************************************************
  6. * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a
  9. * copy of this software and associated documentation files (the "Software"),
  10. * to deal in the Software without restriction, including without limitation
  11. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  12. * and/or sell copies of the Software, and to permit persons to whom the
  13. * Software is furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included
  16. * in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  21. * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
  22. * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  23. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  24. * OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. * Except as contained in this notice, the name of Maxim Integrated
  27. * Products, Inc. shall not be used except as stated in the Maxim Integrated
  28. * Products, Inc. Branding Policy.
  29. *
  30. * The mere transfer of this software does not imply any licenses
  31. * of trade secrets, proprietary technology, copyrights, patents,
  32. * trademarks, maskwork rights, or any other form of intellectual
  33. * property whatsoever. Maxim Integrated Products, Inc. retains all
  34. * ownership rights.
  35. *
  36. * $Date: 2018-12-18 15:37:22 -0600 (Tue, 18 Dec 2018) $
  37. * $Revision: 40072 $
  38. *
  39. *************************************************************************** */
  40. /* Define to prevent redundant inclusion */
  41. #ifndef _SPIMSS_H_
  42. #define _SPIMSS_H_
  43. /* **** Includes **** */
  44. #include "mxc_config.h"
  45. #include "mxc_sys.h"
  46. #include "spimss_regs.h"
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  50. /**
  51. * @defgroup spimss SPIMSS
  52. * @ingroup spi
  53. * @{
  54. */
  55. /* **** Definitions **** */
  56. /**
  57. * @brief Enumeration type for setting the number data lines to use for communication.
  58. */
  59. typedef enum { // ONLY FOR COMPATIBILITY FOR CONSOLIDATION WITH SPY17, NOT USED OR NEEDED
  60. DUMMY_1, /**< NOT USED */
  61. DUMMY_2, /**< NOT USED */
  62. DUMMY_3, /**< NOT USED */
  63. } spimss_width_t;
  64. /**
  65. * @brief Structure type representing a SPI Master Transaction request.
  66. */
  67. typedef struct spimss_req spimss_req_t;
  68. /**
  69. * @brief Callback function type used in asynchronous SPI Master communication requests.
  70. * @details The function declaration for the SPI Master callback is:
  71. * @code
  72. * void callback(spi_req_t * req, int error_code);
  73. * @endcode
  74. * | | |
  75. * | -----: | :----------------------------------------- |
  76. * | \p req | Pointer to a #spi_req object representing the active SPI Master active transaction. |
  77. * | \p error_code | An error code if the active transaction had a failure or #E_NO_ERROR if successful. |
  78. * @note Callback will execute in interrupt context
  79. * @addtogroup spi_async
  80. */
  81. typedef void (*spimss_callback_fn)(spimss_req_t * req, int error_code);
  82. /**
  83. * @brief Structure definition for an SPI Master Transaction request.
  84. * @note When using this structure for an asynchronous operation, the
  85. * structure must remain allocated until the callback is completed.
  86. * @addtogroup spi_async
  87. */
  88. struct spimss_req {
  89. uint8_t ssel; /**< Not Used*/
  90. uint8_t deass; /**< Not Used*/
  91. const void *tx_data; /**< Pointer to a buffer to transmit data from. NULL if undesired. */
  92. void *rx_data; /**< Pointer to a buffer to store data received. NULL if undesired.*/
  93. spimss_width_t width; /**< Not Used */
  94. unsigned len; /**< Number of transfer units to send from the \p tx_data buffer. */
  95. unsigned bits; /**< Number of bits in transfer unit (e.g. 8 for byte, 16 for short) */
  96. unsigned rx_num; /**< Number of bytes actually read into the \p rx_data buffer. */
  97. unsigned tx_num; /**< Number of bytes actually sent from the \p tx_data buffer */
  98. spimss_callback_fn callback; /**< Callback function if desired, NULL otherwise */
  99. };
  100. /* **** Function Prototypes **** */
  101. /**
  102. * @brief Initialize the spi.
  103. * @param spi Pointer to spi module to initialize.
  104. * @param mode SPI mode for clock phase and polarity.
  105. * @param freq Desired clock frequency.
  106. * @param sys_cfg System configuration object
  107. *
  108. * @return \c #E_NO_ERROR if successful, appropriate error otherwise
  109. */
  110. int SPIMSS_Init(mxc_spimss_regs_t *spi, unsigned mode, unsigned freq, const sys_cfg_spimss_t* sys_cfg);
  111. /**
  112. * @brief Shutdown SPI module.
  113. * @param spi Pointer to SPI regs.
  114. *
  115. * @return \c #E_NO_ERROR if successful, appropriate error otherwise
  116. */
  117. int SPIMSS_Shutdown(mxc_spimss_regs_t *spi);
  118. /**
  119. * @brief Execute a master transaction.
  120. * @param spi Pointer to spi module.
  121. * @param req Pointer to spi request
  122. *
  123. * @return \c #E_NO_ERROR if successful, @ref
  124. * MXC_Error_Codes "error" if unsuccessful.
  125. */
  126. int SPIMSS_MasterTrans(mxc_spimss_regs_t *spi, spimss_req_t *req);
  127. /**
  128. * @brief Execute SPI transaction based on interrupt handler
  129. * @param spi The spi
  130. *
  131. */
  132. void SPIMSS_Handler(mxc_spimss_regs_t *spi);
  133. /**
  134. * @brief Execute a slave transaction.
  135. * @param spi Pointer to spi module.
  136. * @param req Pointer to spi request
  137. *
  138. * @return \c #E_NO_ERROR if successful, @ref
  139. * MXC_Error_Codes "error" if unsuccessful.
  140. */
  141. int SPIMSS_SlaveTrans(mxc_spimss_regs_t *spi, spimss_req_t *req);
  142. /**
  143. * @brief Asynchronously read/write SPI Master data
  144. *
  145. * @param spi Pointer to spi module
  146. * @param req Pointer to spi request
  147. *
  148. * @return \c #E_NO_ERROR if successful, @ref
  149. * MXC_Error_Codes "error" if unsuccessful.
  150. */
  151. int SPIMSS_MasterTransAsync(mxc_spimss_regs_t *spi, spimss_req_t *req);
  152. /**
  153. * @brief Asynchronously read/write SPI Slave data
  154. *
  155. * @param spi Pointer to spi module
  156. * @param req Pointer to spi request
  157. *
  158. * @return \c #E_NO_ERROR if successful, @ref
  159. * MXC_Error_Codes "error" if unsuccessful.
  160. */
  161. int SPIMSS_SlaveTransAsync(mxc_spimss_regs_t *spi, spimss_req_t *req);
  162. /**
  163. * @brief Aborts an Asynchronous request
  164. *
  165. * @param req Pointer to spi request
  166. * @return \c #E_NO_ERROR if successful, @ref
  167. * MXC_Error_Codes "error" if unsuccessful.
  168. */
  169. int SPIMSS_AbortAsync(spimss_req_t *req);
  170. /**@} end of group spimss */
  171. #ifdef __cplusplus
  172. }
  173. #endif
  174. #endif /* _SPIMSS_H_ */