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.
 
 
 
 
 
 

188 lines
4.2 KiB

  1. /*!
  2. * \file rtc-board.h
  3. *
  4. * \brief Target board RTC timer and low power modes management
  5. *
  6. * \copyright Revised BSD License, see section \ref LICENSE.
  7. *
  8. * \code
  9. * ______ _
  10. * / _____) _ | |
  11. * ( (____ _____ ____ _| |_ _____ ____| |__
  12. * \____ \| ___ | (_ _) ___ |/ ___) _ \
  13. * _____) ) ____| | | || |_| ____( (___| | | |
  14. * (______/|_____)_|_|_| \__)_____)\____)_| |_|
  15. * (C)2013-2017 Semtech
  16. *
  17. * \endcode
  18. *
  19. * \author Miguel Luis ( Semtech )
  20. *
  21. * \author Gregory Cristian ( Semtech )
  22. */
  23. #ifndef __RTC_BOARD_H__
  24. #define __RTC_BOARD_H__
  25. #ifdef __cplusplus
  26. extern "C"
  27. {
  28. #endif
  29. #include <stdint.h>
  30. #include <stdbool.h>
  31. #include "timer.h"
  32. /*!
  33. * \brief Temperature coefficient of the clock source
  34. */
  35. #define RTC_TEMP_COEFFICIENT ( -0.035f )
  36. /*!
  37. * \brief Temperature coefficient deviation of the clock source
  38. */
  39. #define RTC_TEMP_DEV_COEFFICIENT ( 0.0035f )
  40. /*!
  41. * \brief Turnover temperature of the clock source
  42. */
  43. #define RTC_TEMP_TURNOVER ( 25.0f )
  44. /*!
  45. * \brief Turnover temperature deviation of the clock source
  46. */
  47. #define RTC_TEMP_DEV_TURNOVER ( 5.0f )
  48. /*!
  49. * \brief Initializes the RTC timer
  50. *
  51. * \remark The timer is based on the RTC
  52. */
  53. void RtcInit( void );
  54. /*!
  55. * \brief Returns the minimum timeout value
  56. *
  57. * \retval minTimeout Minimum timeout value in in ticks
  58. */
  59. uint32_t RtcGetMinimumTimeout( void );
  60. /*!
  61. * \brief converts time in ms to time in ticks
  62. *
  63. * \param[IN] milliseconds Time in milliseconds
  64. * \retval returns time in timer ticks
  65. */
  66. uint32_t RtcMs2Tick( TimerTime_t milliseconds );
  67. /*!
  68. * \brief converts time in ticks to time in ms
  69. *
  70. * \param[IN] time in timer ticks
  71. * \retval returns time in milliseconds
  72. */
  73. TimerTime_t RtcTick2Ms( uint32_t tick );
  74. /*!
  75. * \brief Performs a delay of milliseconds by polling RTC
  76. *
  77. * \param[IN] milliseconds Delay in ms
  78. */
  79. void RtcDelayMs( TimerTime_t milliseconds );
  80. /*!
  81. * \brief Sets the alarm
  82. *
  83. * \note The alarm is set at now (read in this funtion) + timeout
  84. *
  85. * \param timeout [IN] Duration of the Timer ticks
  86. */
  87. void RtcSetAlarm( uint32_t timeout );
  88. /*!
  89. * \brief Stops the Alarm
  90. */
  91. void RtcStopAlarm( void );
  92. /*!
  93. * \brief Starts wake up alarm
  94. *
  95. * \note Alarm in RtcTimerContext.Time + timeout
  96. *
  97. * \param [IN] timeout Timeout value in ticks
  98. */
  99. void RtcStartAlarm( uint32_t timeout );
  100. /*!
  101. * \brief Sets the RTC timer reference
  102. *
  103. * \retval value Timer reference value in ticks
  104. */
  105. uint32_t RtcSetTimerContext( void );
  106. /*!
  107. * \brief Gets the RTC timer reference
  108. *
  109. * \retval value Timer value in ticks
  110. */
  111. uint32_t RtcGetTimerContext( void );
  112. /*!
  113. * \brief Gets the system time with the number of seconds elapsed since epoch
  114. *
  115. * \param [OUT] milliseconds Number of milliseconds elapsed since epoch
  116. * \retval seconds Number of seconds elapsed since epoch
  117. */
  118. uint32_t RtcGetCalendarTime( uint16_t *milliseconds );
  119. /*!
  120. * \brief Get the RTC timer value
  121. *
  122. * \retval RTC Timer value
  123. */
  124. uint32_t RtcGetTimerValue( void );
  125. /*!
  126. * \brief Get the RTC timer elapsed time since the last Alarm was set
  127. *
  128. * \retval RTC Elapsed time since the last alarm in ticks.
  129. */
  130. uint32_t RtcGetTimerElapsedTime( void );
  131. /*!
  132. * \brief Writes data0 and data1 to the RTC backup registers
  133. *
  134. * \param [IN] data0 1st Data to be written
  135. * \param [IN] data1 2nd Data to be written
  136. */
  137. void RtcBkupWrite( uint32_t data0, uint32_t data1 );
  138. /*!
  139. * \brief Reads data0 and data1 from the RTC backup registers
  140. *
  141. * \param [OUT] data0 1st Data to be read
  142. * \param [OUT] data1 2nd Data to be read
  143. */
  144. void RtcBkupRead( uint32_t* data0, uint32_t* data1 );
  145. /*!
  146. * \brief Processes pending timer events
  147. */
  148. void RtcProcess( void );
  149. /*!
  150. * \brief Computes the temperature compensation for a period of time on a
  151. * specific temperature.
  152. *
  153. * \param [IN] period Time period to compensate in milliseconds
  154. * \param [IN] temperature Current temperature
  155. *
  156. * \retval Compensated time period
  157. */
  158. TimerTime_t RtcTempCompensation( TimerTime_t period, float temperature );
  159. #ifdef __cplusplus
  160. }
  161. #endif
  162. #endif // __RTC_BOARD_H__