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