timer.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /**
  2. * \file
  3. *
  4. * \brief SAM TIMER Driver for SAMB11
  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. /*
  44. * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
  45. */
  46. #ifndef TIMER_H_INCLUDED
  47. #define TIMER_H_INCLUDED
  48. /**
  49. * \defgroup asfdoc_samb_timer_group SAM TIMER
  50. *
  51. * This driver for Atmel&reg; | SMART SAM devices provides an interface for the
  52. * configuration and management of the device's basic Timer functionality.
  53. *
  54. * The following peripherals are used by this module:
  55. * - TIMER
  56. *
  57. * The following devices can use this module:
  58. * - Atmel | SMART SAM B11
  59. *
  60. * The outline of this documentation is as follows:
  61. * - \ref asfdoc_samb_timer_prerequisites
  62. * - \ref asfdoc_samb_timer_module_overview
  63. * - \ref asfdoc_samb_timer_special_considerations
  64. * - \ref asfdoc_samb_timer_extra_info
  65. * - \ref asfdoc_samb_timer_examples
  66. * - \ref asfdoc_samb_timer_api_overview
  67. *
  68. *
  69. * \section asfdoc_samb_timer_prerequisites Prerequisites
  70. *
  71. * There are no prerequisites for this module.
  72. *
  73. *
  74. * \section asfdoc_samb_timer_module_overview Module Overview
  75. * This driver proiveds a basic timer for count, is a 32-bit
  76. * down-counter with the following features:
  77. *
  78. * - You can generate an interrupt request signal, TIMERINT,
  79. * when the counter reaches 0.
  80. * - The interrupt request is held until it is cleared by writing to the INTCLEAR Register.
  81. *
  82. * - You can use the zero to one transition of the external input signal, EXTIN, as a timer enable.
  83. *
  84. * - If the APB timer count reaches 0 and, at the same time, the software clears a previous
  85. * interrupt status, the interrupt status is set to 1.
  86. *
  87. * - The external clock, EXTIN, must be slower than half of the peripheral clock because it is
  88. * sampled by a double flip-flop and then goes through edge-detection logic when the
  89. * external inputs act as a clock.
  90. *
  91. * - A separate clock pin, PCLKG, for the APB register read or write logic that permits the
  92. * clock to peripheral register logic to stop when there is no APB activity.
  93. *
  94. * \section asfdoc_samb_timer_special_considerations Special Considerations
  95. *
  96. * There are no prerequisites for this module.
  97. *
  98. * \section asfdoc_samb_timer_extra_info Extra Information
  99. *
  100. * For extra information, see \ref asfdoc_samb_timer_extra. This includes:
  101. * - \ref asfdoc_samb_timer_extra_acronyms
  102. * - \ref asfdoc_samb_timer_extra_dependencies
  103. * - \ref asfdoc_samb_timer_extra_errata
  104. * - \ref asfdoc_samb_timer_extra_history
  105. *
  106. *
  107. * \section asfdoc_samb_timer_examples Examples
  108. *
  109. * For a list of examples related to this driver, see
  110. * \ref asfdoc_samb_timer_exqsg.
  111. *
  112. *
  113. * \section asfdoc_samb_timer_api_overview API Overview
  114. * @{
  115. */
  116. #include <compiler.h>
  117. #include <system_sam_b.h>
  118. #ifdef __cplusplus
  119. extern "C" {
  120. #endif
  121. /** Type definition for a TIMER module callback function. */
  122. typedef void (*timer_callback_t)(void);
  123. /**
  124. * \brief TIMER configuration structure.
  125. *
  126. * Configuration struct for a TIMER instance. This structure should be
  127. * initialized by the \ref timer_get_config_defaults function before being
  128. * modified by the user application.
  129. */
  130. struct timer_config {
  131. /** Reload value */
  132. uint32_t reload_value;
  133. /** Enable timer interrupt */
  134. bool interrupt_enable;
  135. };
  136. /**
  137. * \name Configuration and Initialization
  138. * @{
  139. */
  140. void timer_get_config_defaults(struct timer_config *config);
  141. void timer_init(const struct timer_config *config);
  142. /** @} */
  143. /**
  144. * \name Get and set value
  145. * @{
  146. */
  147. uint32_t timer_get_value(void);
  148. void timer_set_value(uint32_t value);
  149. /** @} */
  150. /**
  151. * \name Get and Clear status
  152. * @{
  153. */
  154. uint32_t timer_get_interrupt_status(void);
  155. void timer_clear_interrupt_status(void);
  156. /** @} */
  157. /**
  158. * \name Enable and disable module
  159. * @{
  160. */
  161. void timer_enable(void);
  162. void timer_disable(void);
  163. /** @} */
  164. /**
  165. * \name Callback
  166. * @{
  167. */
  168. void timer_register_callback(timer_callback_t fun);
  169. void timer_unregister_callback(void);
  170. /** @} */
  171. /** @}*/
  172. #ifdef __cplusplus
  173. }
  174. #endif
  175. /**
  176. * \page asfdoc_samb_timer_extra Extra Information for TIMER Driver
  177. *
  178. * \section asfdoc_samb_timer_extra_acronyms Acronyms
  179. * Below is a table listing the acronyms used in this module, along with their
  180. * intended meanings.
  181. * <table>
  182. * <tr>
  183. * <th>Acronym</th>
  184. * <th>Description</th>
  185. * </tr>
  186. * <tr>
  187. * <td>TIMER</td>
  188. * <td>Timer</td>
  189. * </tr>
  190. * </table>
  191. *
  192. * \section asfdoc_samb_timer_extra_dependencies Dependencies
  193. * There are no dependencies related to this driver.
  194. *
  195. *
  196. * \section asfdoc_samb_timer_extra_errata Errata
  197. * There are no errata related to this driver.
  198. *
  199. *
  200. * \section asfdoc_samb_timer_extra_history Module History
  201. * An overview of the module history is presented in the table below, with
  202. * details on the enhancements and fixes made to the module since its first
  203. * release. The current version of this corresponds to the newest version in
  204. * the table.
  205. *
  206. * <table>
  207. * <tr>
  208. * <th>Changelog</th>
  209. * </tr>
  210. * <tr>
  211. * <td>Initial Release</td>
  212. * </tr>
  213. * </table>
  214. */
  215. /**
  216. * \page asfdoc_samb_timer_exqsg Examples for TIMER Driver
  217. *
  218. * This is a list of the available Quick Start guides (QSGs) and example
  219. * applications for \ref asfdoc_samb_timer_group. QSGs are simple examples with
  220. * step-by-step instructions to configure and use this driver in a selection of
  221. * use cases. Note that QSGs can be compiled as a standalone application or be
  222. * added to the user application.
  223. *
  224. * - \subpage asfdoc_samb_timer_basic_use_case
  225. *
  226. * \page asfdoc_samb_timer_document_revision_history Document Revision History
  227. *
  228. * <table>
  229. * <tr>
  230. * <th>Doc. Rev.</td>
  231. * <th>Date</td>
  232. * <th>Comments</td>
  233. * </tr>
  234. * <tr>
  235. * <td>A</td>
  236. * <td>09/2015</td>
  237. * <td>Initial release</td>
  238. * </tr>
  239. * </table>
  240. */
  241. #endif