ccl.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. /**
  2. * \file
  3. *
  4. * \brief SAM Configurable Custom Logic (CCL) Driver
  5. *
  6. * Copyright (C) 2014-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 CCL_H_INCLUDED
  47. #define CCL_H_INCLUDED
  48. /**
  49. * \defgroup asfdoc_sam0_ccl_group SAM Configurable Custom Logic (CCL) Driver
  50. *
  51. * This driver for Atmel&reg; | SMART ARM&reg;-based microcontrollers provides an interface for the configuration
  52. * and management of the device's Configurable Custom Logic functionality.
  53. *
  54. * The following peripheral is used by this module:
  55. * - CCL (Configurable Custom Logic)
  56. *
  57. * The following devices can use this module:
  58. * - Atmel | SMART SAM L21/L22
  59. * - Atmel | SMART SAM C20/C21
  60. *
  61. * The outline of this documentation is as follows:
  62. * - \ref asfdoc_sam0_ccl_prerequisites
  63. * - \ref asfdoc_sam0_ccl_module_overview
  64. * - \ref asfdoc_sam0_ccl_special_considerations
  65. * - \ref asfdoc_sam0_ccl_extra_info
  66. * - \ref asfdoc_sam0_ccl_examples
  67. * - \ref asfdoc_sam0_ccl_api_overview
  68. *
  69. *
  70. * \section asfdoc_sam0_ccl_prerequisites Prerequisites
  71. *
  72. * There are no prerequisites for this module.
  73. *
  74. *
  75. * \section asfdoc_sam0_ccl_module_overview Module Overview
  76. *
  77. * This driver provides an interface for the Configurable Custom Logic
  78. * functions on the device.
  79. *
  80. * The Configurable Custom Logic (CCL) contains programmable logic
  81. * which can be connected to the device pins, events, or internal peripherals.
  82. *
  83. * Each LUT consists of three inputs, a truth table and optional synchronizer,
  84. * filter and edge detector. Each LUT can generate an output as a user programmable
  85. * logic expression with three inputs.
  86. *
  87. * The output can be combinatorially generated from the inputs, or filtered to remove spike.
  88. * An optional sequential module can be enabled. The inputs of sequential module are
  89. * individually controlled by two independent, adjacent LUT(LUT0/LUT1, LUT2/LUT3 etc.) outputs,
  90. * enabling complex waveform generation.
  91. *
  92. * \section asfdoc_sam0_ccl_special_considerations Special Considerations
  93. *
  94. * There are no special considerations for this module.
  95. *
  96. *
  97. * \section asfdoc_sam0_ccl_extra_info Extra Information
  98. *
  99. * For extra information, see \ref asfdoc_sam0_ccl_extra. This includes:
  100. * - \ref asfdoc_sam0_ccl_extra_acronyms
  101. * - \ref asfdoc_sam0_ccl_extra_dependencies
  102. * - \ref asfdoc_sam0_ccl_extra_errata
  103. * - \ref asfdoc_sam0_ccl_extra_history
  104. *
  105. *
  106. * \section asfdoc_sam0_ccl_examples Examples
  107. *
  108. * For a list of examples related to this driver, see
  109. * \ref asfdoc_sam0_ccl_exqsg.
  110. *
  111. *
  112. * \section asfdoc_sam0_ccl_api_overview API Overview
  113. * @{
  114. */
  115. #include <compiler.h>
  116. #include <system.h>
  117. #ifdef __cplusplus
  118. extern "C" {
  119. #endif
  120. /**
  121. * \brief CCL LUT(look up table) ID number enum.
  122. */
  123. enum ccl_lut_id {
  124. /** CCL LUT 0 */
  125. CCL_LUT_0 = 0,
  126. /** CCL LUT 1 */
  127. CCL_LUT_1 = 1,
  128. /** CCL LUT 2 */
  129. CCL_LUT_2 = 2,
  130. /** CCL LUT 3 */
  131. CCL_LUT_3 = 3,
  132. };
  133. /**
  134. * \brief CCL sequential module ID number enum.
  135. */
  136. enum ccl_seq_id {
  137. /** CCL SEQ 0 */
  138. CCL_SEQ_0 = 0,
  139. /** CCL SEQ 1 */
  140. CCL_SEQ_1 = 1,
  141. };
  142. /**
  143. * \brief Sequential selection enum.
  144. *
  145. * Enum for the sequential selection configuration.
  146. */
  147. enum ccl_seq_selection {
  148. /** Sequential logic is disabled */
  149. CCL_SEQ_DISABLED = CCL_SEQCTRL_SEQSEL_DISABLE,
  150. /** D flip flop */
  151. CCL_SEQ_D_FLIP_FLOP = CCL_SEQCTRL_SEQSEL_DFF,
  152. /** JK flip flop */
  153. CCL_SEQ_JK_FLIP_FLOP = CCL_SEQCTRL_SEQSEL_JK,
  154. /** D latch */
  155. CCL_SEQ_D_LATCH = CCL_SEQCTRL_SEQSEL_LATCH,
  156. /** RS latch */
  157. CCL_SEQ_RS_LATCH = CCL_SEQCTRL_SEQSEL_RS,
  158. };
  159. /**
  160. * \brief LUT Input source selection configuration enum.
  161. *
  162. * Enum for the LUT Input source selection.
  163. */
  164. enum ccl_lut_input_src_sel {
  165. /** Masked input */
  166. CCL_LUT_INPUT_SRC_MASK = 0,
  167. /** Feedback input source */
  168. CCL_LUT_INPUT_SRC_FEEDBACK = 1,
  169. /** Linked LUT input source */
  170. CCL_LUT_INPUT_SRC_LINK = 2,
  171. /** Event input source */
  172. CCL_LUT_INPUT_SRC_EVENT = 3,
  173. /** I/O pin input source */
  174. CCL_LUT_INPUT_SRC_IO = 4,
  175. /** AC input source */
  176. CCL_LUT_INPUT_SRC_AC = 5,
  177. /** TC input source */
  178. CCL_LUT_INPUT_SRC_TC = 6,
  179. /** Alternative TC input source */
  180. CCL_LUT_INPUT_SRC_ALTTC = 7,
  181. /** TCC input source */
  182. CCL_LUT_INPUT_SRC_TCC = 8,
  183. /** SERCOM input source */
  184. CCL_LUT_INPUT_SRC_SERCOM = 9,
  185. };
  186. /**
  187. * \brief Select the LUT output filter options enum.
  188. *
  189. * Enum for the LUT output filter options.
  190. */
  191. enum ccl_lut_filter_sel {
  192. /** Filter disabled */
  193. CCL_LUT_FILTER_DISABLE = CCL_LUTCTRL_FILTSEL_DISABLE,
  194. /** Synchronizer enabled */
  195. CCL_LUT_FILTER_SYNC = CCL_LUTCTRL_FILTSEL_SYNCH,
  196. /** Filter enabled */
  197. CCL_LUT_FILTER_ENABLE = CCL_LUTCTRL_FILTSEL_FILTER,
  198. };
  199. /**
  200. * \brief CCL module configuration structure.
  201. *
  202. * Configuration structure for CCL module.
  203. */
  204. struct ccl_config {
  205. /** GCLK generator used to clock the peripheral */
  206. enum gclk_generator clock_source;
  207. /** If \c true, the GCLK_CCL clock will not stop in standby sleep mode */
  208. bool run_in_standby;
  209. };
  210. /**
  211. * \brief CCL LUT 0 to 3 configuration structure.
  212. *
  213. * Configuration structure for CCL LUT 0 to 3.
  214. */
  215. struct ccl_lut_config {
  216. /** The value of truth logic as a function of inputs IN[2:0] */
  217. uint8_t truth_table_value;
  218. /** If \c true, LUT event output is enabled */
  219. bool event_output_enable;
  220. /** If \c true, LUT incoming event is enabled */
  221. bool event_input_enable;
  222. /** If \c true, incoming event is inverted */
  223. bool event_input_inverted_enable;
  224. /** Selection of the input0 source */
  225. enum ccl_lut_input_src_sel input0_src_sel;
  226. /** Selection of the input1 source */
  227. enum ccl_lut_input_src_sel input1_src_sel;
  228. /** Selection of the input2 source */
  229. enum ccl_lut_input_src_sel input2_src_sel;
  230. /** If \c true, Edge detector is enabled */
  231. bool edge_selection_enable;
  232. /** Selection of the LUT output filter options */
  233. enum ccl_lut_filter_sel filter_sel;
  234. };
  235. /**
  236. * \name Initialize and Reset CCL Module
  237. * @{
  238. */
  239. /**
  240. * \brief Initializes CCL module.
  241. *
  242. * Resets all registers in the MODULE to their initial state,
  243. * and then enable the module.
  244. */
  245. void ccl_init(struct ccl_config *const config);
  246. /**
  247. * \brief Initializes all members of a CCL configuration structure
  248. * to safe defaults.
  249. *
  250. * Initializes all members of a given Configurable Custom Logic configuration
  251. * structure to safe and known default values. This function should be called on
  252. * all new instances of these configuration structures before being modified
  253. * by the user application.
  254. *
  255. * The default configuration is as follows:
  256. * \li GCLK_CLL will be stopped in standby sleep mode
  257. * \li Generator 0 is the default GCLK generator
  258. *
  259. * \param[out] config Configuration structure to initialize to default values
  260. */
  261. static inline void ccl_get_config_defaults(
  262. struct ccl_config *const config)
  263. {
  264. /* Sanity check arguments */
  265. Assert(config);
  266. config->clock_source = GCLK_GENERATOR_0;
  267. /* Default configuration values */
  268. config->run_in_standby = false;
  269. }
  270. /**
  271. * \brief Resets CCL module.
  272. *
  273. * Resets all registers in the MODULE to their initial state,
  274. * and the CCL will be disabled.
  275. */
  276. static inline void ccl_module_reset(void)
  277. {
  278. /* Reset CCL. */
  279. CCL->CTRL.reg |= CCL_CTRL_SWRST;
  280. while((CCL->CTRL.reg & CCL_CTRL_SWRST));
  281. }
  282. /** @} */
  283. /**
  284. * \name Enable and Disable CCL Module
  285. * @{
  286. */
  287. /**
  288. * \brief Enables CCL module.
  289. *
  290. * Enable the peripheral.
  291. *
  292. */
  293. static inline void ccl_module_enable(void)
  294. {
  295. /* Enable CCL. */
  296. CCL->CTRL.reg |= CCL_CTRL_ENABLE;
  297. }
  298. /**
  299. * \brief Disables CCL module.
  300. *
  301. * Disables the peripheral.
  302. */
  303. static inline void ccl_module_disable(void)
  304. {
  305. /* Disable CCL. */
  306. CCL->CTRL.reg &= ~CCL_CTRL_ENABLE;
  307. }
  308. /** @} */
  309. /**
  310. * \name Configure LUT
  311. * @{
  312. */
  313. /**
  314. * \brief Writes sequential selection to the hardware module.
  315. *
  316. * Writes a given sequential selection configuration to the hardware module.
  317. *
  318. * \note This function can only be used when the CCL module is disabled.
  319. *
  320. * \param[in] seq_selection Enum for the sequential selection configuration
  321. * \param[in] number SEQ unit number to config
  322. */
  323. enum status_code ccl_seq_config(const enum ccl_seq_id number,
  324. const enum ccl_seq_selection seq_selection);
  325. /**
  326. * \brief Initializes all members of LUT configuration
  327. * structure to safe defaults.
  328. *
  329. * Initializes all members of LUT configuration
  330. * structure to safe defaults. This function should be called on all new
  331. * instances of these configuration structures before being modified by the
  332. * user application.
  333. *
  334. * The default configuration is as follows:
  335. * \li Truth table value is 0x00
  336. * \li LUT event output is disabled
  337. * \li LUT incoming event is disabled
  338. * \li LUT incoming event is not inverted
  339. * \li The input IN[2:0] source is masked
  340. * \li The edge detector is disabled
  341. * \li The LUT output filter is disabled
  342. *
  343. * \param[out] config LUT configuration structure to initialize to
  344. * default values
  345. */
  346. void ccl_lut_get_config_defaults(struct ccl_lut_config *const config);
  347. /** \brief Writes LUT configuration to the hardware module.
  348. *
  349. * Writes a given LUT configuration to the hardware module.
  350. *
  351. * \note This function can only be used when the CCL module is disabled.
  352. *
  353. * \param[in] config Pointer to the LUT configuration struct
  354. * \param[in] number LUT number to config
  355. */
  356. enum status_code ccl_lut_set_config(const enum ccl_lut_id number,
  357. struct ccl_lut_config *const config);
  358. /** @} */
  359. /**
  360. * \name Enable and Disable LUT
  361. * @{
  362. */
  363. /**
  364. * \brief Enables an LUT that was previously configured.
  365. *
  366. * Enables an LUT that was previously configured via a call to
  367. * \ref ccl_lut_set_config function.
  368. *
  369. * \param[in] number LUT number to enable
  370. */
  371. void ccl_lut_enable(const enum ccl_lut_id number);
  372. /**
  373. * \brief Disables an LUT that was previously enabled.
  374. *
  375. * Disables an LUT that was previously enabled via a call to
  376. * \ref ccl_lut_enable().
  377. *
  378. * \param[in] number LUT number to enable
  379. */
  380. void ccl_lut_disable(const enum ccl_lut_id number);
  381. /** @} */
  382. #ifdef __cplusplus
  383. }
  384. #endif
  385. /** @} */
  386. /**
  387. * \page asfdoc_sam0_ccl_extra Extra Information for CCL Driver
  388. *
  389. * \section asfdoc_sam0_ccl_extra_acronyms Acronyms
  390. * Below is a table listing the acronyms used in this module, along with their
  391. * intended meanings.
  392. *
  393. * <table>
  394. * <tr>
  395. * <th>Acronym</th>
  396. * <th>Description</th>
  397. * </tr>
  398. * <tr>
  399. * <td>CCL</td>
  400. * <td>Configurable Custom Logic</td>
  401. * </tr>
  402. * </table>
  403. *
  404. *
  405. * \section asfdoc_sam0_ccl_extra_dependencies Dependencies
  406. * This driver has no dependencies.
  407. *
  408. *
  409. * \section asfdoc_sam0_ccl_extra_errata Errata
  410. * There are no errata related to this driver.
  411. *
  412. *
  413. * \section asfdoc_sam0_ccl_extra_history Module History
  414. * An overview of the module history is presented in the table below, with
  415. * details on the enhancements and fixes made to the module since its first
  416. * release. The current version of this corresponds to the newest version in
  417. * the table.
  418. *
  419. * <table>
  420. * <tr>
  421. * <th>Changelog</th>
  422. * </tr>
  423. * <tr>
  424. * <td>Initial Release</td>
  425. * </tr>
  426. * </table>
  427. */
  428. /**
  429. * \page asfdoc_sam0_ccl_exqsg Examples for CCL Driver
  430. *
  431. * This is a list of the available Quick Start guides (QSGs) and example
  432. * applications for \ref asfdoc_sam0_ccl_group. QSGs are simple examples with
  433. * step-by-step instructions to configure and use this driver in a selection of
  434. * use cases. Note that a QSG can be compiled as a standalone application or be
  435. * added to the user application.
  436. *
  437. * - \subpage asfdoc_sam0_ccl_basic_use_case
  438. *
  439. * \page asfdoc_sam0_ccl_document_revision_history Document Revision History
  440. *
  441. * <table>
  442. * <tr>
  443. * <th>Doc. Rev.</td>
  444. * <th>Date</td>
  445. * <th>Comments</td>
  446. * </tr>
  447. * <tr>
  448. * <td>42448B</td>
  449. * <td>08/2015</td>
  450. * <td>Add support for SAM L22</td>
  451. * </tr>
  452. * <tr>
  453. * <td>42448A</td>
  454. * <td>06/2015</td>
  455. * <td>Initial document release</td>
  456. * </tr>
  457. * </table>
  458. */
  459. #endif /* CCL_H_INCLUDED */