]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_MPU_CEC_MEC_17xx_51xx_Keil_GCC/peripheral_library/basic_timer/btimer.h
Change name of the CEC and MEC directory to CORTEX_MPU_CEC_MEC_17xx_51xx_Keil_GCC...
[freertos] / FreeRTOS / Demo / CORTEX_MPU_CEC_MEC_17xx_51xx_Keil_GCC / peripheral_library / basic_timer / btimer.h
1 /*****************************************************************************\r
2 * © 2015 Microchip Technology Inc. and its subsidiaries.\r
3 * You may use this software and any derivatives exclusively with\r
4 * Microchip products.\r
5 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS".\r
6 * NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,\r
7 * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,\r
8 * AND FITNESS FOR A PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP\r
9 * PRODUCTS, COMBINATION WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.\r
10 * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,\r
11 * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND\r
12 * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS\r
13 * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE.\r
14 * TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL\r
15 * CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF\r
16 * FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.\r
17 * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE\r
18 * OF THESE TERMS.\r
19 ******************************************************************************\r
20 \r
21 Version Control Information (Perforce)\r
22 ******************************************************************************\r
23 $Revision: #1 $ \r
24 $DateTime: 2016/09/22 08:03:49 $ \r
25 $Author: pramans $\r
26 Last Change:    Updated with unit testing feedbacks\r
27 ******************************************************************************/\r
28 /** @file btimer.h\r
29 * \brief Basic Timer Peripheral Header file\r
30 * \author jvasanth\r
31\r
32 * This file is the header file for Basic Timer Peripheral \r
33 ******************************************************************************/\r
34 \r
35 /** @defgroup Basic_Timer\r
36  *  @{\r
37  */\r
38 \r
39 #ifndef _BTIMER_H\r
40 #define _BTIMER_H\r
41 \r
42 /******************************************************************************/\r
43 /**  Logical Timer ID for APIs.\r
44  * This is the timer IDs passed to Basic Timer API function calls \r
45  *******************************************************************************/\r
46 enum _PID_BTIMER_\r
47 {\r
48         PID_BTIMER_0,\r
49         PID_BTIMER_1,\r
50         PID_BTIMER_2,\r
51         PID_BTIMER_3,\r
52         PID_BTIMER_4,\r
53         PID_BTIMER_5,\r
54         PID_BTIMER_MAX  \r
55 };\r
56 \r
57 /* ---------------------------------------------------------------------- */\r
58 /*                    Logical flags for Timer Control                     */\r
59 /* ---------------------------------------------------------------------- */\r
60 //This is for tmr_cntl parameter in btimer_init function\r
61 #define BTIMER_AUTO_RESTART                                  (0x08u)\r
62 #define BTIMER_ONE_SHOT                                      (0u)\r
63 #define BTIMER_COUNT_UP                                      (0x04u)\r
64 #define BTIMER_COUNT_DOWN                                    (0u)\r
65 #define BTIMER_INT_EN                                        (0x01u)\r
66 #define BTIMER_NO_INT                                        (0u)\r
67 /* ---------------------------------------------------------------------- */\r
68 \r
69 \r
70 //Timer Block Hardware Bits and Masks\r
71 #define BTIMER_CNTL_HALT                   (0x80UL)\r
72 #define BTIMER_CNTL_RELOAD                 (0x40UL)\r
73 #define BTIMER_CNTL_START                  (0x20UL)\r
74 #define BTIMER_CNTL_SOFT_RESET             (0x10UL)\r
75 #define BTIMER_CNTL_AUTO_RESTART           (0x08UL)\r
76 #define BTIMER_CNTL_COUNT_UP               (0x04UL)\r
77 #define BTIMER_CNTL_ENABLE                 (0x01UL)\r
78 \r
79 #define BTIMER_CNTL_HALT_BIT               (7U)\r
80 #define BTIMER_CNTL_RELOAD_BIT             (6U)\r
81 #define BTIMER_CNTL_START_BIT              (5U)\r
82 #define BTIMER_CNTRL_SOFT_RESET_BIT        (4U)\r
83 #define BTIMER_CNTL_AUTO_RESTART_BIT       (3U)\r
84 #define BTIMER_CNTL_COUNT_DIR_BIT          (2U)\r
85 #define BTIMER_CNTL_ENABLE_BIT             (0U)\r
86 \r
87 #define BTIMER_GIRQ                                                                                                     MEC_GIRQ23_ID\r
88 #define BTIMER_MAX_INSTANCE                                                                     PID_BTIMER_MAX\r
89 \r
90 \r
91 /* ---------------------------------------------------------------------- */\r
92 /*            API - Basic Timer Intitialization function                  */\r
93 /* ---------------------------------------------------------------------- */\r
94 \r
95 /** Initialize specified timer\r
96  * @param btimer_id Basic Timer ID\r
97  * @param tmr_cntl Logical flags for Timer Control\r
98  * @param initial_count Initial Count\r
99  * @param preload_count Preload Count\r
100  * @note Performs a soft reset of the timer before configuration \r
101  */\r
102 void btimer_init(uint8_t btimer_id, \r
103                uint16_t tmr_cntl,\r
104                uint16_t prescaler,\r
105                uint32_t initial_count,\r
106                uint32_t preload_count);\r
107 \r
108 /* ---------------------------------------------------------------------- */\r
109 /*  API -   Functions to program and read the Basic Timer Counter         */\r
110 /* ---------------------------------------------------------------------- */\r
111 /** Program timer's counter register.\r
112  * @param btimer_id Basic Timer ID\r
113  * @param count new counter value \r
114  * @note Timer hardware may implement a 16-bit or 32-bit \r
115  *       hardware counter. If the timer is 16-bit only the lower\r
116  *       16-bits of the count paramter are used.\r
117  */\r
118 void btimer_count_set(uint8_t btimer_id, uint32_t count);\r
119 \r
120 /** Return current value of timer's count register.\r
121  * @param btimer_id Basic Timer ID. \r
122  * @return uint32_t timer count may be 32 or 16 bits depending \r
123  *         upon the hardware.  Timers 0-3 are 16-bit\r
124  *         and Timers 4-5 are 32-bit.\r
125  */\r
126 uint32_t btimer_count_get(uint8_t btimer_id);\r
127 \r
128 /* ---------------------------------------------------------------------- */\r
129 /*  API -   Function to reload counter from Preload Register              */\r
130 /* ---------------------------------------------------------------------- */\r
131 /** Force timer to reload counter from preload \r
132  * register.  \r
133  * @param btimer_id Basic Timer ID. \r
134  * @note Hardware will only reload counter if timer is running. \r
135  */\r
136 void btimer_reload(uint8_t btimer_id);\r
137 \r
138 /* ---------------------------------------------------------------------- */\r
139 /*  API -    Functions for stopping and starting the basic Timer          */\r
140 /* ---------------------------------------------------------------------- */\r
141 /** Start timer counting.\r
142  * @param btimer_id Basic Timer ID.\r
143  */\r
144 void btimer_start(uint8_t btimer_id);\r
145 \r
146 /** Stop timer. \r
147  * @param btimer_id Basic Timer ID. \r
148  * @note When a stopped timer is started again it will reload \r
149  *       the count register from preload value.\r
150  */\r
151 void btimer_stop(uint8_t btimer_id);\r
152 \r
153 /** Return state of timer's START bit. \r
154  * @param btimer_id Basic Timer ID. \r
155  * @return uint8_t 0(timer not started), 1 (timer started)\r
156  */\r
157 uint8_t btimer_is_started(uint8_t btimer_id);\r
158 \r
159 /* ---------------------------------------------------------------------- */\r
160 /*  API -         Function to perform basic timer soft reset              */\r
161 /* ---------------------------------------------------------------------- */\r
162 /** Peform soft reset of specified timer. \r
163  * @param btimer_id Basic Timer ID \r
164  * @note Soft reset set all registers to POR values.\r
165  * Spins 256 times waiting on hardware to clear reset bit. \r
166  */\r
167 void btimer_reset(uint8_t btimer_id);\r
168 \r
169 /* ---------------------------------------------------------------------- */\r
170 /*   API -        Functions to halt/unhalt the timer counting             */\r
171 /* ---------------------------------------------------------------------- */\r
172 /** Halt timer counting with no reload on unhalt.   \r
173  * @param btimer_id Basic Timer ID. \r
174  * @note A halted timer will not reload the count register when \r
175  *       unhalted, it will continue counting from the current\r
176  *       count value.\r
177  */\r
178 void btimer_halt(uint8_t btimer_id);\r
179 \r
180 /** Unhalt timer counting. \r
181  * @param btimer_id Basic Timer ID.\r
182  */\r
183 void btimer_unhalt(uint8_t btimer_id);\r
184 \r
185 /* ---------------------------------------------------------------------- */\r
186 /*   API -        Functions for Basic Timer interrupt                     */\r
187 /* ---------------------------------------------------------------------- */\r
188 /** Enable specified timer's interrupt from the block. \r
189  * @param btimer_id Basic Timer ID.\r
190  * @param ien Non-zero enable interrupt in timer block, 0 \r
191  *            disable.\r
192  */\r
193 void btimer_interrupt_enable(uint8_t btimer_id, uint8_t ien);\r
194 \r
195 /** Read Timer interrupt status and clear if set \r
196  * @param btimer_id Basic Timer ID. \r
197  * @return uint8_t 1 (Timer interrupt status set) else 0. \r
198  * @note If timer interrupt status is set then clear it before \r
199  *       returning.\r
200  */\r
201 uint8_t btimer_interrupt_status_get_clr(uint8_t btimer_id);\r
202 \r
203 /* ---------------------------------------------------------------------- */\r
204 /*  API -         Functions for Basic Timer GIRQ                          */\r
205 /* ---------------------------------------------------------------------- */\r
206 /** Enables GIRQ enable bit for the timer \r
207  * @param btimer_id Basic Timer ID.\r
208  */\r
209 void btimer_girq_enable_set(uint8_t btimer_id);\r
210 \r
211 /** Clears GIRQ enable bit for the timer \r
212  * @param btimer_id Basic Timer ID.\r
213  */\r
214 void btimer_girq_enable_clr(uint8_t btimer_id);\r
215 \r
216 /** Returns GIRQ source bit for the timer \r
217  * @param btimer_id Basic Timer ID.\r
218  * @return uint8_t 0(src bit not set), Non-zero (src bit set)\r
219  */\r
220 uint8_t btimer_girq_src_get(uint8_t btimer_id);\r
221 \r
222 /** Clears GIRQ source bit for the timer \r
223  * @param btimer_id Basic Timer ID.\r
224  */\r
225 void btimer_girq_src_clr(uint8_t btimer_id);\r
226 \r
227 /** Returns GIRQ result bit for the timer \r
228  * @param btimer_id Basic Timer ID.\r
229  * @return uint8_t 0(result bit not set), Non-zero (result bit set)\r
230  */\r
231 uint8_t btimer_girq_result_get(uint8_t btimer_id);\r
232 \r
233 /* ---------------------------------------------------------------------- */\r
234 /*  API -         Functions for Basic Timer Sleep                         */\r
235 /* ---------------------------------------------------------------------- */\r
236 /** Enable/Disable clock gating on idle of a timer  \r
237  * @param btimer_id Basic Timer ID.\r
238  * @param sleep_en 1 = Sleep enable, 0 = Sleep disable\r
239  */\r
240 void btimer_sleep(uint8_t btimer_id, uint8_t sleep_en);\r
241 \r
242 /** Returns clk required status for the timer block\r
243  * @param btimer_id Basic Timer ID.\r
244  * @return Non-zero if clk required, else 0\r
245  */\r
246 uint32_t btimer_clk_reqd_sts_get(uint8_t btimer_id);\r
247 \r
248 /** Enable/Disable reset on sleep for the timer block \r
249  * @param btimer_id Basic Timer ID.\r
250  * @param reset_en 1 to enable, 0 to disable\r
251  */\r
252 void btimer_reset_on_sleep(uint8_t btimer_id, uint8_t reset_en);\r
253 \r
254 /* ---------------------------------------------------------------------- */\r
255 /* Peripheral Function - Functions to set and read Timer Counter Register */\r
256 /* ---------------------------------------------------------------------- */\r
257 /** Sets timer counter\r
258  * @param btimer_id Basic Timer ID\r
259  * @param count - 32-bit counter  \r
260  */\r
261 void p_btimer_count_set(uint8_t btimer_id, uint32_t count);\r
262 \r
263 /** Read the timer counter\r
264  * @param btimer_id Basic Timer ID\r
265  * @return count        - 32-bit counter  \r
266  */\r
267 uint32_t p_btimer_count_get(uint8_t btimer_id);\r
268 \r
269 \r
270 /* ---------------------------------------------------------------------- */\r
271 /* Peripheral Function - Function to program the Preload                  */\r
272 /* ---------------------------------------------------------------------- */\r
273 /** Sets preload for the counter\r
274  * @param btimer_id Basic Timer ID\r
275  * @param preload_count - 32-bit pre-load value \r
276  */\r
277 void p_btimer_preload_set(uint8_t btimer_id, uint32_t preload_count);\r
278 \r
279 /* ---------------------------------------------------------------------- */\r
280 /* Peripheral Functions - Functions for basic timer interrupts            */\r
281 /* ---------------------------------------------------------------------- */\r
282 /** Reads the interrupt status bit in the timer block\r
283  * @param btimer_id Basic Timer ID \r
284  * @return status - 1 if interrupt status set, else 0\r
285  */\r
286 uint8_t p_btimer_int_status_get(uint8_t btimer_id);\r
287 \r
288 /** Clears interrupt status bit in the timer block\r
289  * @param btimer_id Basic Timer ID \r
290  */\r
291 void p_btimer_int_status_clr(uint8_t btimer_id);\r
292 \r
293 /** Sets interrupt enable bit in the timer block\r
294  * @param btimer_id Basic Timer ID  \r
295  */\r
296 void p_btimer_int_enable_set(uint8_t btimer_id);\r
297 \r
298 /** Clears interrupt enable bit for the timer block\r
299  * @param btimer_id Basic Timer ID  \r
300  */\r
301 void p_btimer_int_enable_clr(uint8_t btimer_id);\r
302 \r
303 /* ---------------------------------------------------------------------- */\r
304 /* Peripheral Functions - Functions for Control Register                  */\r
305 /* ---------------------------------------------------------------------- */\r
306 /** Writes the control register 32-bits\r
307  * @param btimer_id Basic Timer ID\r
308  * @param value - 32-bit value to program\r
309  */\r
310 void p_btimer_ctrl_write(uint8_t btimer_id, uint32_t value);\r
311 \r
312 /** Reads the control register \r
313  * @param btimer_id Basic Timer ID\r
314  * @return uint32_t     - 32-bit value\r
315  */\r
316 uint32_t p_btimer_ctrl_read(uint8_t btimer_id);\r
317 \r
318 /** Clears enable bit in the control register\r
319  * @param btimer_id Basic Timer ID\r
320  */\r
321 void p_btimer_ctrl_enable_set(uint8_t btimer_id);\r
322 \r
323 /** Clears enable bit in the control register\r
324  * @param btimer_id Basic Timer ID\r
325  */\r
326 void p_btimer_ctrl_enable_clr(uint8_t btimer_id);\r
327 \r
328 /** Sets counter direction bit in the control register\r
329  * @param btimer_id Basic Timer ID\r
330  */\r
331 void p_btimer_ctrl_counter_dir_set(uint8_t btimer_id);\r
332 \r
333 /** Clears counter direction bit in the control register\r
334  * @param btimer_id Basic Timer ID\r
335  */\r
336 void p_btimer_ctrl_counter_dir_clr(uint8_t btimer_id);\r
337 \r
338 /** Sets auto restart bit in the control register\r
339  * @param btimer_id Basic Timer ID\r
340  */\r
341 void p_btimer_ctrl_auto_restart_set(uint8_t btimer_id);\r
342 \r
343 /** Clears auto resetart bit in the control register\r
344  * @param btimer_id Basic Timer ID\r
345  */\r
346 void p_btimer_ctrl_auto_restart_clr(uint8_t btimer_id);\r
347 \r
348 /** Sets soft reset bit in the control register\r
349  * @param btimer_id Basic Timer ID \r
350  */\r
351 void p_btimer_ctrl_soft_reset_set(uint8_t btimer_id);\r
352 \r
353 /** Read Soft Reset bit \r
354  * @param btimer_id Basic Timer ID\r
355  * @return 0 if soft reset status bit cleared; else non-zero value\r
356  */\r
357 uint8_t p_btimer_ctrl_soft_reset_sts_get(uint8_t btimer_id);\r
358 \r
359 /** Sets start bit in the control register\r
360  * @param btimer_id Basic Timer ID \r
361  */\r
362 void p_btimer_ctrl_start_set(uint8_t btimer_id);\r
363 \r
364 /** Read start bit in the control register\r
365  * @param btimer_id Basic Timer ID \r
366  * @return 0 if start bit not set; else non-zero value\r
367  */\r
368 uint8_t p_btimer_ctrl_start_get(uint8_t btimer_id);\r
369 \r
370 /** Clears start bit in the control register\r
371  * @param btimer_id Basic Timer ID \r
372  */\r
373 void p_btimer_ctrl_start_clr(uint8_t btimer_id);\r
374 \r
375 /** Sets reload bit in the control register\r
376  * @param btimer_id Basic Timer ID \r
377  */\r
378 void p_btimer_ctrl_reload_set(uint8_t btimer_id);\r
379 \r
380 /** Clears reload bit in the control register\r
381  * @param btimer_id Basic Timer ID \r
382  */\r
383 void p_btimer_ctrl_reload_clr(uint8_t btimer_id);\r
384 \r
385 /** Sets halt bit in the control register\r
386  * @param btimer_id Basic Timer ID \r
387  */\r
388 void p_btimer_ctrl_halt_set(uint8_t btimer_id);\r
389 \r
390 /** Clears halt bit in the control register\r
391  * @param btimer_id Basic Timer ID \r
392  */\r
393 \r
394 void p_btimer_ctrl_halt_clr(uint8_t btimer_id);\r
395 \r
396 /** Sets prescale value\r
397  * @param btimer_id Basic Timer ID\r
398  * @param prescaler     - 16-bit pre-scale value \r
399  */\r
400 void p_btimer_ctrl_prescale_set(uint8_t btimer_id, uint16_t prescaler);\r
401 \r
402 \r
403 #endif // #ifndef _BTIMER_H\r
404 \r
405 /* end btimer_perphl.c */\r
406 \r
407 /**   @} //Peripherals Basic_Timer\r
408  */\r
409 \r