spi.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /** @file spi.h
  2. * @brief SPI Driver Definition File
  3. * @date 29.May.2013
  4. * @version 03.05.02
  5. *
  6. * (c) Texas Instruments 2009-2013, All rights reserved.
  7. */
  8. #ifndef __SPI_H__
  9. #define __SPI_H__
  10. #include "reg_spi.h"
  11. /** @enum chipSelect
  12. * @brief Transfer Group Chip Select
  13. */
  14. enum spiChipSelect
  15. {
  16. SPI_CS_NONE = 0xFFU,
  17. SPI_CS_0 = 0xFEU,
  18. SPI_CS_1 = 0xFDU,
  19. SPI_CS_2 = 0xFBU,
  20. SPI_CS_3 = 0xF7U,
  21. SPI_CS_4 = 0xEFU,
  22. SPI_CS_5 = 0xDFU,
  23. SPI_CS_6 = 0xBFU,
  24. SPI_CS_7 = 0x7FU
  25. };
  26. /** @enum spiPinSelect
  27. * @brief spi Pin Select
  28. */
  29. enum spiPinSelect
  30. {
  31. SPI_PIN_CS0 = 0U,
  32. SPI_PIN_CS1 = 1U,
  33. SPI_PIN_CS2 = 2U,
  34. SPI_PIN_CS3 = 3U,
  35. SPI_PIN_CS4 = 4U,
  36. SPI_PIN_CS5 = 5U,
  37. SPI_PIN_CS6 = 6U,
  38. SPI_PIN_CS7 = 7U,
  39. SPI_PIN_ENA = 8U,
  40. SPI_PIN_CLK = 9U,
  41. SPI_PIN_SIMO = 10U,
  42. SPI_PIN_SOMI = 11U,
  43. SPI_PIN_SIMO_1 = 17U,
  44. SPI_PIN_SIMO_2 = 18U,
  45. SPI_PIN_SIMO_3 = 19U,
  46. SPI_PIN_SIMO_4 = 20U,
  47. SPI_PIN_SIMO_5 = 21U,
  48. SPI_PIN_SIMO_6 = 22U,
  49. SPI_PIN_SIMO_7 = 23U,
  50. SPI_PIN_SOMI_1 = 25U,
  51. SPI_PIN_SOMI_2 = 26U,
  52. SPI_PIN_SOMI_3 = 27U,
  53. SPI_PIN_SOMI_4 = 28U,
  54. SPI_PIN_SOMI_5 = 29U,
  55. SPI_PIN_SOMI_6 = 30U,
  56. SPI_PIN_SOMI_7 = 31U
  57. };
  58. /** @enum dataformat
  59. * @brief SPI dataformat register select
  60. */
  61. typedef enum dataformat
  62. {
  63. SPI_FMT_0 = 0U,
  64. SPI_FMT_1 = 1U,
  65. SPI_FMT_2 = 2U,
  66. SPI_FMT_3 = 3U
  67. }SPIDATAFMT_t;
  68. /** @struct spiDAT1RegConfig
  69. * @brief SPI data register configuration
  70. */
  71. typedef struct spiDAT1RegConfig
  72. {
  73. boolean CS_HOLD;
  74. boolean WDEL;
  75. SPIDATAFMT_t DFSEL;
  76. uint8 CSNR;
  77. }spiDAT1_t;
  78. /** @enum SpiTxRxDataStatus
  79. * @brief SPI Data Status
  80. */
  81. typedef enum SpiTxRxDataStatus
  82. {
  83. SPI_READY = 0U,
  84. SPI_PENDING = 1U,
  85. SPI_COMPLETED = 2U
  86. }SpiDataStatus_t;
  87. /* USER CODE BEGIN (0) */
  88. /* USER CODE END */
  89. /**
  90. * @defgroup SPI SPI
  91. * @brief Serial Peripheral Interface Module.
  92. *
  93. * SPI is a high-speed synchronous serial input/output port that allows a serial bit stream of
  94. * programmed length (2 to 16 bits) to be shifted in and out of the device at a programmed bit-transfer rate.
  95. *
  96. * Related Files
  97. * - reg_spi.h
  98. * - spi.h
  99. * - spi.c
  100. * @addtogroup SPI
  101. * @{
  102. */
  103. /* SPI Interface Functions */
  104. void spiInit(void);
  105. void spiSetFunctional(spiBASE_t *spi, uint32 port);
  106. void spiEnableNotification(spiBASE_t *spi, uint32 flags);
  107. void spiDisableNotification(spiBASE_t *spi, uint32 flags);
  108. uint32 spiTransmitData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint16 * srcbuff);
  109. void spiSendData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint16 * srcbuff);
  110. uint32 spiReceiveData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint16 * destbuff);
  111. void spiGetData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint16 * destbuff);
  112. uint32 spiTransmitAndReceiveData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint16 * srcbuff, uint16 * destbuff);
  113. void spiSendAndGetData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint16 * srcbuff, uint16 * destbuff);
  114. void spiEnableLoopback(spiBASE_t *spi, loopBackType_t Loopbacktype);
  115. void spiDisableLoopback(spiBASE_t *spi);
  116. SpiDataStatus_t SpiTxStatus(spiBASE_t *spi);
  117. SpiDataStatus_t SpiRxStatus(spiBASE_t *spi);
  118. /** @fn void spiNotification(spiBASE_t *spi, uint32 flags)
  119. * @brief Interrupt callback
  120. * @param[in] spi - Spi module base address
  121. * @param[in] flags - Copy of error interrupt flags
  122. *
  123. * This is a callback that is provided by the application and is called upon
  124. * an interrupt. The parameter passed to the callback is a copy of the
  125. * interrupt flag register.
  126. */
  127. void spiNotification(spiBASE_t *spi, uint32 flags);
  128. /** @fn void spiEndNotification(spiBASE_t *spi)
  129. * @brief Interrupt callback for End of TX or RX data length.
  130. * @param[in] spi - Spi module base address
  131. *
  132. * This is a callback that is provided by the application and is called upon
  133. * an interrupt at the End of TX or RX data length.
  134. */
  135. void spiEndNotification(spiBASE_t *spi);
  136. /**@}*/
  137. /* USER CODE BEGIN (1) */
  138. /* USER CODE END */
  139. #endif