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