events.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. /**
  2. * \file
  3. *
  4. * \brief SAM Event System Driver
  5. *
  6. * Copyright (C) 2012-2016 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 EVENTS_H_INCLUDED
  47. #define EVENTS_H_INCLUDED
  48. #ifdef __cplusplus
  49. extern "C" {
  50. #endif
  51. /**
  52. * \defgroup asfdoc_sam0_events_group SAM Event System (EVENTS) Driver
  53. *
  54. * This driver for Atmel&reg; | SMART ARM&reg;-based microcontrollers provides
  55. * an interface for the configuration and management of the device's peripheral
  56. * event resources and users within the device, including enabling and disabling
  57. * of peripheral source selection and synchronization of clock domains between
  58. * various modules. The following API modes is covered by this manual:
  59. * - Polled API
  60. * \if EVENTS_INTERRUPT_HOOK_MODE
  61. * - Interrupt hook API
  62. * \endif
  63. *
  64. * The following peripheral is used by this module:
  65. * - EVSYS (Event System Management)
  66. *
  67. * The following devices can use this module:
  68. * - Atmel | SMART SAM D20/D21
  69. * - Atmel | SMART SAM R21
  70. * - Atmel | SMART SAM D09/D10/D11
  71. * - Atmel | SMART SAM L21/L22
  72. * - Atmel | SMART SAM DA1
  73. * - Atmel | SMART SAM C20/C21
  74. * - Atmel | SMART SAM HA1
  75. * - Atmel | SMART SAM R30
  76. *
  77. * The outline of this documentation is as follows:
  78. * - \ref asfdoc_sam0_events_prerequisites
  79. * - \ref asfdoc_sam0_events_module_overview
  80. * - \ref asfdoc_sam0_events_special_considerations
  81. * - \ref asfdoc_sam0_events_extra_info
  82. * - \ref asfdoc_sam0_events_examples
  83. * - \ref asfdoc_sam0_events_api_overview
  84. *
  85. *
  86. * \section asfdoc_sam0_events_prerequisites Prerequisites
  87. *
  88. * There are no prerequisites for this module.
  89. *
  90. *
  91. * \section asfdoc_sam0_events_module_overview Module Overview
  92. *
  93. * Peripherals within the SAM devices are capable of generating two types of
  94. * actions in response to given stimulus; set a register flag for later
  95. * intervention by the CPU (using interrupt or polling methods), or generate
  96. * event signals, which can be internally routed directly to other
  97. * peripherals within the device. The use of events allows for direct actions
  98. * to be performed in one peripheral in response to a stimulus in another
  99. * without CPU intervention. This can lower the overall power consumption of the
  100. * system if the CPU is able to remain in sleep modes for longer periods
  101. * (SleepWalking), and lowers the latency of the system response.
  102. *
  103. * The event system is comprised of a number of freely configurable Event
  104. * resources, plus a number of fixed Event Users. Each Event resource can be
  105. * configured to select the input peripheral that will generate the events
  106. * signal, as well as the synchronization path and edge detection mode.
  107. * The fixed-function Event Users, connected to peripherals within the device,
  108. * can then subscribe to an Event resource in a one-to-many relationship in order
  109. * to receive events as they are generated. An overview of the event system
  110. * chain is shown in
  111. * \ref asfdoc_sam0_events_module_overview_fig "the figure below".
  112. *
  113. * \anchor asfdoc_sam0_events_module_overview_fig
  114. * \dot
  115. * digraph overview {
  116. * rankdir=LR;
  117. * node [label="Source\nPeripheral\n(Generator)" shape=ellipse style=filled fillcolor=lightgray] src_peripheral;
  118. * node [label="Event\nResource A" shape=square style=""] event_gen0;
  119. * node [label="Event\nUser X" shape=square style=""] event_user0;
  120. * node [label="Event\nUser Y" shape=square style=""] event_user1;
  121. * node [label="Destination\nPeripheral\n(User)" shape=ellipse style=filled fillcolor=lightgray] dst_peripheral0;
  122. * node [label="Destination\nPeripheral\n(User)" shape=ellipse style=filled fillcolor=lightgray] dst_peripheral1;
  123. *
  124. * src_peripheral -> event_gen0;
  125. * event_gen0 -> event_user0;
  126. * event_gen0 -> event_user1;
  127. * event_user0 -> dst_peripheral0;
  128. * event_user1 -> dst_peripheral1;
  129. * }
  130. * \enddot
  131. *
  132. * There are many different events that can be routed in the device, which can
  133. * then trigger many different actions. For example, an Analog Comparator module
  134. * could be configured to generate an event when the input signal rises above
  135. * the compare threshold, which then triggers a Timer Counter module to capture
  136. * the current count value for later use.
  137. *
  138. * \subsection asfdoc_sam0_events_module_overview_event_channels Event Channels
  139. * The Event module in each device consists of several channels, which can be
  140. * freely linked to an event generator (i.e. a peripheral within the device
  141. * that is capable of generating events). Each channel can be individually
  142. * configured to select the generator peripheral, signal path, and edge detection
  143. * applied to the input event signal, before being passed to any event user(s).
  144. *
  145. * Event channels can support multiple users within the device in a standardized
  146. * manner. When an Event User is linked to an Event Channel, the channel will
  147. * automatically handshake with all attached users to ensure that all modules
  148. * correctly receive and acknowledge the event.
  149. *
  150. * \subsection asfdoc_sam0_events_module_overview_event_users Event Users
  151. * Event Users are able to subscribe to an Event Channel, once it has been
  152. * configured. Each Event User consists of a fixed connection to one of the
  153. * peripherals within the device (for example, an ADC module, or Timer module)
  154. * and is capable of being connected to a single Event Channel.
  155. *
  156. * \subsection asfdoc_sam0_events_module_overview_edge_detection Edge Detection
  157. * For asynchronous events, edge detection on the event input is not possible,
  158. * and the event signal must be passed directly between the event generator and
  159. * event user. For synchronous and re-synchronous events, the input signal from
  160. * the event generator must pass through an edge detection unit, so that only
  161. * the rising, falling, or both edges of the event signal triggers an action in
  162. * the event user.
  163. *
  164. * \subsection asfdoc_sam0_events_module_overview_path_selection Path Selection
  165. * The event system in the SAM devices supports three signal path types from
  166. * the event generator to Event Users: asynchronous, synchronous, and
  167. * re-synchronous events.
  168. *
  169. * \subsubsection asfdoc_sam0_events_module_overview_path_selection_async Asynchronous Paths
  170. * Asynchronous event paths allow for an asynchronous connection between the
  171. * event generator and Event Users, when the source and destination
  172. * peripherals share the same \ref asfdoc_sam0_system_clock_group "Generic Clock"
  173. * channel. In this mode the event is propagated between the source and
  174. * destination directly to reduce the event latency, thus no edge detection is
  175. * possible. The asynchronous event chain is shown in
  176. * \ref asfdoc_sam0_events_module_async_path_fig "the figure below".
  177. *
  178. * \anchor asfdoc_sam0_events_module_async_path_fig
  179. * \dot
  180. * digraph overview {
  181. * rankdir=LR;
  182. * node [label="Source\nPeripheral" shape=ellipse style=filled fillcolor=lightgray] src_peripheral;
  183. * node [label="<f0> EVSYS | <f1> Event\nChannel/User" fillcolor=white style="dashed" shape=record] events_chan;
  184. * node [label="Destination\nPeripheral" shape=ellipse style=filled fillcolor=lightgray] dst_peripheral;
  185. *
  186. * src_peripheral -> events_chan;
  187. * events_chan -> dst_peripheral;
  188. *
  189. * }
  190. * \enddot
  191. * \note Identically shaped borders in the diagram indicate a shared generic clock channel.
  192. *
  193. * \subsubsection asfdoc_sam0_events_module_overview_path_selection_sync Synchronous Paths
  194. * The Synchronous event path should be used when edge detection or interrupts
  195. * from the event channel are required, and the source event generator and the
  196. * event channel shares the same Generic Clock channel. The synchronous event
  197. * chain is shown in
  198. * \ref asfdoc_sam0_events_module_sync_path_fig "the figure below".
  199. *
  200. * Not all peripherals support Synchronous event paths; refer to the device datasheet.
  201. *
  202. * \anchor asfdoc_sam0_events_module_sync_path_fig
  203. * \dot
  204. * digraph overview {
  205. * rankdir=LR;
  206. * node [label="Source\nPeripheral" shape=ellipse style="filled, dashed" fillcolor=lightgray] src_peripheral;
  207. * node [label="<f0> EVSYS | <f1> Event\nChannel/User" fillcolor=white shape=record style="dashed"] events_chan;
  208. * node [label="Destination\nPeripheral" shape=ellipse style="filled, solid" fillcolor=lightgray] dst_peripheral;
  209. *
  210. * src_peripheral -> events_chan;
  211. * events_chan -> dst_peripheral;
  212. *
  213. * }
  214. * \enddot
  215. * \note Identically shaped borders in the diagram indicate a shared generic clock channel.
  216. *
  217. * \subsubsection asfdoc_sam0_events_module_overview_path_selection_resync Re-synchronous Paths
  218. * Re-synchronous event paths are a special form of synchronous events, where
  219. * when edge detection or interrupts from the event channel are required, but
  220. * the event generator and the event channel use different Generic Clock
  221. * channels. The re-synchronous path allows the Event System to synchronize the
  222. * incoming event signal from the Event Generator to the clock of the Event
  223. * System module to avoid missed events, at the cost of a higher latency due to
  224. * the re-synchronization process. The re-synchronous event chain is shown in
  225. * \ref asfdoc_sam0_events_module_resync_path_fig "the figure below".
  226. *
  227. * Not all peripherals support re-synchronous event paths; refer to the device datasheet.
  228. * \anchor asfdoc_sam0_events_module_resync_path_fig
  229. * \dot
  230. * digraph overview {
  231. * rankdir=LR;
  232. * node [label="Source\nPeripheral" shape=ellipse style="filled, dotted" fillcolor=lightgray] src_peripheral;
  233. * node [label="<f0> EVSYS | <f1> Event\nChannel/User" fillcolor=white shape=record style="dashed"] events_chan;
  234. * node [label="Destination\nPeripheral" shape=ellipse style=filled fillcolor=lightgray] dst_peripheral;
  235. *
  236. * src_peripheral -> events_chan;
  237. * events_chan -> dst_peripheral;
  238. *
  239. * }
  240. * \enddot
  241. * \note Identically shaped borders in the diagram indicate a shared generic clock channel.
  242. *
  243. * \subsection asfdoc_sam0_events_module_overview_physical Physical Connection
  244. *
  245. * \ref asfdoc_sam0_events_module_int_connections_fig "The diagram below"
  246. * shows how this module is interconnected within the device.
  247. *
  248. * \anchor asfdoc_sam0_events_module_int_connections_fig
  249. * \dot
  250. * digraph overview {
  251. * rankdir=LR;
  252. * node [label="Source\nPeripherals" shape=ellipse style=filled fillcolor=lightgray] src_peripheral;
  253. *
  254. * subgraph driver {
  255. * node [label="<f0> EVSYS | <f1> Event Channels" fillcolor=white shape=record] events_chan;
  256. * node [label="<f0> EVSYS | <f1> Event Users" fillcolor=white shape=record] events_user;
  257. * }
  258. *
  259. * node [label="Destination\nPeripherals" shape=ellipse style=filled fillcolor=lightgray] dst_peripheral;
  260. *
  261. * src_peripheral -> events_chan:f1 [label="Source\nMUXs"];
  262. * events_chan:f1 -> events_user:f1 [label="Channel\nMUXs"];
  263. * events_user:f1 -> dst_peripheral;
  264. * }
  265. * \enddot
  266. *
  267. * \subsection asfdoc_sam0_events_module_overview_config Configuring Events
  268. * For SAM devices, several steps are required to properly configure an
  269. * event chain, so that hardware peripherals can respond to events generated by
  270. * each other, as listed below.
  271. *
  272. * \subsubsection asfdoc_sam0_events_module_overview_config_src Source Peripheral
  273. * -# The source peripheral (that will generate events) must be configured and
  274. * enabled.
  275. * -# The source peripheral (that will generate events) must have an output
  276. * event enabled.
  277. * \subsubsection asfdoc_sam0_events_module_overview_config_evsys Event System
  278. * -# An event system channel must be allocated and configured with the
  279. * correct source peripheral selected as the channel's event generator.
  280. * -# The event system user must be configured and enabled, and attached to
  281. # event channel previously allocated.
  282. * \subsubsection asfdoc_sam0_events_module_overview_config_dst Destination Peripheral
  283. * -# The destination peripheral (that will receive events) must be configured
  284. * and enabled.
  285. * -# The destination peripheral (that will receive events) must have an input
  286. * event enabled.
  287. *
  288. *
  289. * \section asfdoc_sam0_events_special_considerations Special Considerations
  290. *
  291. * There are no special considerations for this module.
  292. *
  293. *
  294. * \section asfdoc_sam0_events_extra_info Extra Information
  295. *
  296. * For extra information, see \ref asfdoc_sam0_events_extra. This includes:
  297. * - \ref asfdoc_sam0_events_extra_acronyms
  298. * - \ref asfdoc_sam0_events_extra_dependencies
  299. * - \ref asfdoc_sam0_events_extra_errata
  300. * - \ref asfdoc_sam0_events_extra_history
  301. *
  302. *
  303. * \section asfdoc_sam0_events_examples Examples
  304. *
  305. * For a list of examples related to this driver, see
  306. * \ref asfdoc_sam0_events_exqsg.
  307. *
  308. *
  309. * \section asfdoc_sam0_events_api_overview API Overview
  310. * @{
  311. */
  312. #include <compiler.h>
  313. #include "events_common.h"
  314. /**
  315. * \brief Edge detect enum.
  316. *
  317. * Event channel edge detect setting.
  318. *
  319. */
  320. enum events_edge_detect {
  321. /** No event output */
  322. EVENTS_EDGE_DETECT_NONE,
  323. /** Event on rising edge */
  324. EVENTS_EDGE_DETECT_RISING,
  325. /** Event on falling edge */
  326. EVENTS_EDGE_DETECT_FALLING,
  327. /** Event on both edges */
  328. EVENTS_EDGE_DETECT_BOTH,
  329. };
  330. /**
  331. * \brief Path selection enum.
  332. *
  333. * Event channel path selection.
  334. *
  335. */
  336. enum events_path_selection {
  337. /** Select the synchronous path for this event channel */
  338. EVENTS_PATH_SYNCHRONOUS,
  339. /** Select the resynchronizer path for this event channel */
  340. EVENTS_PATH_RESYNCHRONIZED,
  341. /** Select the asynchronous path for this event channel */
  342. EVENTS_PATH_ASYNCHRONOUS,
  343. };
  344. /**
  345. * \brief Events configuration struct.
  346. *
  347. * This event configuration struct is used to configure each of the channels.
  348. *
  349. */
  350. struct events_config {
  351. /** Select edge detection mode */
  352. enum events_edge_detect edge_detect;
  353. /** Select events channel path */
  354. enum events_path_selection path;
  355. /** Set event generator for the channel */
  356. uint8_t generator;
  357. /** Clock source for the event channel */
  358. uint8_t clock_source;
  359. #if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30)
  360. /** Run in standby mode for the channel */
  361. bool run_in_standby;
  362. /** Run On Demand */
  363. bool on_demand;
  364. #endif
  365. };
  366. /**
  367. * \brief No event generator definition.
  368. *
  369. * Use this to disable any peripheral event input to a channel. This can be useful
  370. * if you only want to use a channel for software generated events.
  371. *
  372. */
  373. ///@cond INTERNAL
  374. /**
  375. * \internal
  376. * Status bit offsets in the status register/interrupt register.
  377. *
  378. * @{
  379. */
  380. #if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) || (SAMR30)
  381. # define _EVENTS_START_OFFSET_BUSY_BITS 16
  382. # define _EVENTS_START_OFFSET_USER_READY_BIT 0
  383. # define _EVENTS_START_OFFSET_DETECTION_BIT 16
  384. # define _EVENTS_START_OFFSET_OVERRUN_BIT 0
  385. #else /* SAM D/R */
  386. # define _EVENTS_START_OFFSET_BUSY_BITS 8
  387. # define _EVENTS_START_OFFSET_USER_READY_BIT 0
  388. # define _EVENTS_START_OFFSET_DETECTION_BIT 8
  389. # define _EVENTS_START_OFFSET_OVERRUN_BIT 0
  390. #endif
  391. /** @} */
  392. ///@endcond
  393. /**
  394. * Definition for no generator selection.
  395. */
  396. #define EVSYS_ID_GEN_NONE 0
  397. /**
  398. * \brief Event channel resource.
  399. *
  400. * Event resource structure.
  401. *
  402. * \note The fields in this structure should not be altered by the user application;
  403. * they are reserved for driver internals only.
  404. */
  405. struct events_resource {
  406. #if !defined(__DOXYGEN__)
  407. /** Channel allocated for the event resource */
  408. uint8_t channel;
  409. /** Channel setting in CHANNEL register */
  410. uint32_t channel_reg;
  411. #endif
  412. };
  413. #if EVENTS_INTERRUPT_HOOKS_MODE == true
  414. typedef void (*events_interrupt_hook)(struct events_resource *resource);
  415. /**
  416. * \brief Event hook.
  417. *
  418. * Event hook structure.
  419. *
  420. */
  421. struct events_hook {
  422. /** Event resource */
  423. struct events_resource *resource;
  424. /** Event hook function */
  425. events_interrupt_hook hook_func;
  426. /** Next event hook */
  427. struct events_hook *next;
  428. };
  429. #endif
  430. /**
  431. * \brief Initializes an event configurations struct to defaults.
  432. *
  433. * Initailizes an event configuration struct to predefined safe default settings.
  434. *
  435. * \param[in] config Pointer to an instance of \ref struct events_config
  436. *
  437. */
  438. void events_get_config_defaults(struct events_config *config);
  439. /**
  440. * \brief Allocate an event channel and set configuration.
  441. *
  442. * Allocates an event channel from the event channel pool and sets
  443. * the channel configuration.
  444. *
  445. * \param[out] resource Pointer to a \ref events_resource struct instance
  446. * \param[in] config Pointer to a \ref events_config struct
  447. *
  448. * \return Status of the configuration procedure.
  449. * \retval STATUS_OK Allocation and configuration went successful
  450. * \retval STATUS_ERR_NOT_FOUND No free event channel found
  451. *
  452. */
  453. enum status_code events_allocate(struct events_resource *resource, struct events_config *config);
  454. /**
  455. * \brief Attach user to the event channel.
  456. *
  457. * Attach a user peripheral to the event channel to receive events.
  458. *
  459. * \param[in] resource Pointer to an \ref events_resource struct instance
  460. * \param[in] user_id A number identifying the user peripheral found in the device header file
  461. *
  462. * \return Status of the user attach procedure.
  463. * \retval STATUS_OK No errors detected when attaching the event user
  464. */
  465. enum status_code events_attach_user(struct events_resource *resource, uint8_t user_id);
  466. /**
  467. * \brief Detach a user peripheral from the event channel.
  468. *
  469. * Deattach a user peripheral from the event channels so it does not receive any more events.
  470. *
  471. * \param[in] resource Pointer to an \ref event_resource struct instance
  472. * \param[in] user_id A number identifying the user peripheral found in the device header file
  473. *
  474. * \return Status of the user detach procedure.
  475. * \retval STATUS_OK No errors detected when detaching the event user
  476. */
  477. enum status_code events_detach_user(struct events_resource *resource, uint8_t user_id);
  478. /**
  479. * \brief Check if a channel is busy.
  480. *
  481. * Check if a channel is busy, a channel stays busy until all users connected to the channel
  482. * has handled an event.
  483. *
  484. * \param[in] resource Pointer to a \ref events_resource struct instance
  485. *
  486. * \return Status of the channels busy state.
  487. * \retval true One or more users connected to the channel has not handled the last event
  488. * \retval false All users are ready to handle new events
  489. */
  490. bool events_is_busy(struct events_resource *resource);
  491. /**
  492. * \brief Trigger software event.
  493. *
  494. * Trigger an event by software.
  495. *
  496. * \note Software event works on either a synchronous path or resynchronized path, and
  497. * edge detection must be configured to rising-edge detection.
  498. *
  499. * \param[in] resource Pointer to an \ref events_resource struct
  500. *
  501. * \return Status of the event software procedure.
  502. * \retval STATUS_OK No error was detected when the software tigger signal was issued
  503. * \retval STATUS_ERR_UNSUPPORTED_DEV If the channel path is asynchronous and/or the
  504. * edge detection is not set to RISING
  505. */
  506. enum status_code events_trigger(struct events_resource *resource);
  507. /**
  508. * \brief Check if all users connected to the channel are ready.
  509. *
  510. * Check if all users connected to the channel are ready to handle incoming events.
  511. *
  512. * \param[in] resource Pointer to an \ref events_resource struct
  513. *
  514. * \return The ready status of users connected to an event channel.
  515. * \retval true All the users connected to the event channel are ready to handle incoming events
  516. * \retval false One or more users connected to the event channel are not ready to handle incoming events
  517. */
  518. bool events_is_users_ready(struct events_resource *resource);
  519. /**
  520. * \brief Check if an event is detected on the event channel.
  521. *
  522. * Check if an event has been detected on the channel.
  523. *
  524. * \note This function will clear the event detected interrupt flag.
  525. *
  526. * \param[in] resource Pointer to an \ref events_resource struct
  527. *
  528. * \return Status of the event detection interrupt flag.
  529. * \retval true Event has been detected
  530. * \retval false Event has not been detected
  531. */
  532. bool events_is_detected(struct events_resource *resource);
  533. /**
  534. * \brief Check if there has been an overrun situation on this channel.
  535. *
  536. * \note This function will clear the event overrun detected interrupt flag.
  537. *
  538. * \param[in] resource Pointer to an \ref events_resource struct
  539. *
  540. * \return Status of the event overrun interrupt flag.
  541. * \retval true Event overrun has been detected
  542. * \retval false Event overrun has not been detected
  543. */
  544. bool events_is_overrun(struct events_resource *resource);
  545. /**
  546. * \brief Release allocated channel back the the resource pool.
  547. *
  548. * Release an allocated channel back to the resource pool to make it available for other purposes.
  549. *
  550. * \param[in] resource Pointer to an \ref events_resource struct
  551. *
  552. * \return Status of the channel release procedure.
  553. * \retval STATUS_OK No error was detected when the channel was released
  554. * \retval STATUS_BUSY One or more event users have not processed the last event
  555. * \retval STATUS_ERR_NOT_INITIALIZED Channel not allocated, and can therefore not be released
  556. */
  557. enum status_code events_release(struct events_resource *resource);
  558. /**
  559. * \brief Get the number of free channels.
  560. *
  561. * Get the number of allocatable channels in the events system resource pool.
  562. *
  563. * \return The number of free channels in the event system.
  564. *
  565. */
  566. uint8_t events_get_free_channels(void);
  567. ///@cond INTERNAL
  568. /**
  569. * \internal
  570. * Function to find bit position in the CHSTATUS and INTFLAG register,
  571. * and return bit mask of this position.
  572. *
  573. * @{
  574. */
  575. uint32_t _events_find_bit_position(uint8_t channel, uint8_t start_offset);
  576. /** @} */
  577. ///@endcond
  578. /** @} */
  579. /**
  580. * \page asfdoc_sam0_events_extra Extra Information for EVENTS Driver
  581. *
  582. * \section asfdoc_sam0_events_extra_acronyms Acronyms
  583. * Below is a table listing the acronyms used in this module, along with their
  584. * intended meanings.
  585. *
  586. * <table>
  587. * <tr>
  588. * <th>Acronym</th>
  589. * <th>Description</th>
  590. * </tr>
  591. * <tr>
  592. * <td>CPU</td>
  593. * <td>Central Processing Unit</td>
  594. * </tr>
  595. * <tr>
  596. * <td>MUX</td>
  597. * <td>Multiplexer</td>
  598. * </tr>
  599. * </table>
  600. *
  601. *
  602. * \section asfdoc_sam0_events_extra_dependencies Dependencies
  603. * This driver has the following dependencies:
  604. *
  605. * - \ref asfdoc_sam0_system_clock_group "System Clock Driver"
  606. *
  607. *
  608. * \section asfdoc_sam0_events_extra_errata Errata
  609. * There are no errata related to this driver.
  610. *
  611. *
  612. * \section asfdoc_sam0_events_extra_history Module History
  613. * An overview of the module history is presented in the table below, with
  614. * details on the enhancements and fixes made to the module since its first
  615. * release. The current version of this corresponds to the newest version in
  616. * the table.
  617. *
  618. * <table>
  619. * <tr>
  620. * <th>Changelog</th>
  621. * </tr>
  622. * <tr>
  623. * <td>Fix a bug in internal function _events_find_bit_position()</td>
  624. * </tr>
  625. * <tr>
  626. * <td>Rewrite of events driver</td>
  627. * </tr>
  628. * <tr>
  629. * <td>Initial Release</td>
  630. * </tr>
  631. * </table>
  632. */
  633. /**
  634. * \page asfdoc_sam0_events_exqsg Examples for EVENTS Driver
  635. *
  636. * This is a list of the available Quick Start guides (QSGs) and example
  637. * applications for \ref asfdoc_sam0_events_group. QSGs are simple examples with
  638. * step-by-step instructions to configure and use this driver in a selection of
  639. * use cases. Note that a QSG can be compiled as a standalone application or be
  640. * added to the user application.
  641. *
  642. * - \subpage asfdoc_sam0_events_basic_use_case
  643. * \if EVENTS_INTERRUPT_HOOK_MODE
  644. * - \subpage asfdoc_sam0_events_interrupt_hook_use_case
  645. * \endif
  646. *
  647. * \page asfdoc_sam0_events_document_revision_history Document Revision History
  648. *
  649. * <table>
  650. * <tr>
  651. * <th>Doc. Rev.</td>
  652. * <th>Date</td>
  653. * <th>Comments</td>
  654. * </tr>
  655. * <tr>
  656. * <td>42108G</td>
  657. * <td>12/2015</td>
  658. * <td>Added support for SAM D09 and SAM L22</td>
  659. * </tr>
  660. * <tr>
  661. * <td>42108F</td>
  662. * <td>08/2015</td>
  663. * <td>Added support for SAM L21, SAM DA1, SAMR30 and SAM C20/C21</td>
  664. * </tr>
  665. * <tr>
  666. * <td>42108E</td>
  667. * <td>12/2014</td>
  668. * <td>Added support for interrupt hook mode.
  669. * Added support for SAM R21 and SAM D10/D11.</td>
  670. * </tr>
  671. * <tr>
  672. * <td>42108D</td>
  673. * <td>01/2014</td>
  674. * <td>Update to support SAM D21 and corrected documentation typos</td>
  675. * </tr>
  676. * <tr>
  677. * <td>42108C</td>
  678. * <td>11/2013</td>
  679. * <td>Fixed incorrect documentation for the event signal paths. Added
  680. * configuration steps overview to the documentation.</td>
  681. * </tr>
  682. * <tr>
  683. * <td>42108B</td>
  684. * <td>06/2013</td>
  685. * <td>Corrected documentation typos</td>
  686. * </tr>
  687. * <tr>
  688. * <td>42108A</td>
  689. * <td>06/2013</td>
  690. * <td>Initial release</td>
  691. * </tr>
  692. * </table>
  693. */
  694. #ifdef __cplusplus
  695. }
  696. #endif
  697. #endif /* EVENTS_H_INCLUDED */