Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
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.
 
 
 
 
 
 

172 lines
6.2 KiB

  1. /**
  2. * \file
  3. *
  4. * \brief SPI related functionality declaration.
  5. *
  6. * Copyright (C) 2015 Atmel Corporation. All rights reserved.
  7. *
  8. * \asf_license_start
  9. *
  10. * \page License
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. *
  18. * 2. Redistributions in binary form must reproduce the above copyright notice,
  19. * this list of conditions and the following disclaimer in the documentation
  20. * and/or other materials provided with the distribution.
  21. *
  22. * 3. The name of Atmel may not be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * 4. This software may only be redistributed and used in connection with an
  26. * Atmel microcontroller product.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  29. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  30. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  31. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  32. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  33. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  34. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  36. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  37. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. * POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. * \asf_license_stop
  41. *
  42. */
  43. #ifndef _HPL_SPI_M_SYNC_H_INCLUDED
  44. #define _HPL_SPI_M_SYNC_H_INCLUDED
  45. #include <hpl_spi.h>
  46. #include <hpl_spi_sync.h>
  47. /**
  48. * \addtogroup hpl_spi HPL SPI
  49. *
  50. *@{
  51. */
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55. /** Uses common SPI async device driver. */
  56. #define _spi_m_sync_dev _spi_sync_dev
  57. /**
  58. * \brief Initialize SPI for access without interrupts
  59. * It will load default hardware configuration and software struct.
  60. * \param[in, out] dev Pointer to the SPI device instance.
  61. * \param[in] hw Pointer to the hardware base.
  62. * \return Operation status.
  63. * \retval ERR_INVALID_ARG Input parameter problem.
  64. * \retval ERR_BUSY SPI hardware not ready (resetting).
  65. * \retval ERR_DENIED SPI has been enabled.
  66. * \retval 0 Operation done successfully.
  67. */
  68. int32_t _spi_m_sync_init(struct _spi_m_sync_dev *dev, void *const hw);
  69. /**
  70. * \brief Deinitialize SPI
  71. * Disable, reset the hardware and the software struct.
  72. * \param[in, out] dev Pointer to the SPI device instance.
  73. * \return Operation status.
  74. * \retval 0 Operation done successfully.
  75. */
  76. int32_t _spi_m_sync_deinit(struct _spi_m_sync_dev *dev);
  77. /**
  78. * \brief Enable SPI for access without interrupts
  79. * \param[in, out] dev Pointer to the SPI device instance.
  80. * \return Operation status.
  81. * \retval ERR_BUSY SPI hardware not ready (resetting).
  82. * \retval 0 Operation done successfully.
  83. */
  84. int32_t _spi_m_sync_enable(struct _spi_m_sync_dev *dev);
  85. /**
  86. * \brief Disable SPI for access without interrupts
  87. * Disable SPI. Deactivate all CS pins if works as master.
  88. * \param[in, out] dev Pointer to the SPI device instance.
  89. * \return Operation status.
  90. * \retval 0 Operation done successfully.
  91. */
  92. int32_t _spi_m_sync_disable(struct _spi_m_sync_dev *dev);
  93. /**
  94. * \brief Set SPI transfer mode
  95. * Set SPI transfer mode (\ref spi_transfer_mode),
  96. * which controls clock polarity and clock phase.
  97. * Mode 0: leading edge is rising edge, data sample on leading edge.
  98. * Mode 1: leading edge is rising edge, data sample on trailing edge.
  99. * Mode 2: leading edge is falling edge, data sample on leading edge.
  100. * Mode 3: leading edge is falling edge, data sample on trailing edge.
  101. * \param[in, out] dev Pointer to the SPI device instance.
  102. * \param[in] mode The SPI transfer mode.
  103. * \return Operation status.
  104. * \retval ERR_BUSY SPI is not ready to accept new setting.
  105. * \retval 0 Operation done successfully.
  106. */
  107. int32_t _spi_m_sync_set_mode(struct _spi_m_sync_dev *dev, const enum spi_transfer_mode mode);
  108. /**
  109. * \brief Set SPI baudrate
  110. * \param[in, out] dev Pointer to the SPI device instance.
  111. * \param[in] baud_val The SPI baudrate value, see \ref _spi_calc_baud_val() on
  112. * how it's generated.
  113. * \return Operation status.
  114. * \retval ERR_BUSY SPI is not ready to accept new setting.
  115. * \retval 0 Operation done successfully.
  116. */
  117. int32_t _spi_m_sync_set_baudrate(struct _spi_m_sync_dev *dev, const uint32_t baud_val);
  118. /**
  119. * \brief Set SPI baudrate
  120. * \param[in, out] dev Pointer to the SPI device instance.
  121. * \param[in] char_size The character size, see \ref spi_char_size.
  122. * \return Operation status.
  123. * \retval ERR_INVALID_ARG The character size is not supported.
  124. * \retval ERR_BUSY SPI is not ready to accept new setting.
  125. * \retval 0 Operation done successfully.
  126. */
  127. int32_t _spi_m_sync_set_char_size(struct _spi_m_sync_dev *dev, const enum spi_char_size char_size);
  128. /**
  129. * \brief Set SPI data order
  130. * \param[in, out] dev Pointer to the SPI device instance.
  131. * \param[in] dord SPI data order (LSB/MSB first).
  132. * \return Operation status.
  133. * \retval ERR_INVALID_ARG The character size is not supported.
  134. * \retval ERR_BUSY SPI is not ready to accept new setting.
  135. * \retval 0 Operation done successfully.
  136. */
  137. int32_t _spi_m_sync_set_data_order(struct _spi_m_sync_dev *dev, const enum spi_data_order dord);
  138. /**
  139. * \brief Transfer the whole message without interrupt
  140. * Transfer the message, it will keep waiting until the message finish or
  141. * error.
  142. * \param[in, out] dev Pointer to the SPI device instance.
  143. * \param[in] msg Pointer to the message instance to process.
  144. * \return Error or number of characters transferred.
  145. * \retval ERR_BUSY SPI hardware is not ready to start transfer (not
  146. * enabled, busy applying settings, ...).
  147. * \retval SPI_ERR_OVERFLOW Overflow error.
  148. * \retval >=0 Number of characters transferred.
  149. */
  150. int32_t _spi_m_sync_trans(struct _spi_m_sync_dev *dev, const struct spi_msg *msg);
  151. #ifdef __cplusplus
  152. }
  153. #endif
  154. /**@}*/
  155. #endif /* ifndef _HPL_SPI_M_SYNC_H_INCLUDED */