]> git.sur5r.net Git - freertos/blob - Demo/CORTEX_A2F200_IAR_and_Keil/MicroSemi_Code/drivers/mss_timer/mss_timer.h
Add in the Microsemi timer driver to provide a time base for the run time stats.
[freertos] / Demo / CORTEX_A2F200_IAR_and_Keil / MicroSemi_Code / drivers / mss_timer / mss_timer.h
1 /*******************************************************************************\r
2  * (c) Copyright 2009 Actel Corporation.  All rights reserved.\r
3  * \r
4  * SmartFusion microcontroller subsystem (MSS) timer driver API.\r
5  *\r
6  * SVN $Revision: 2661 $\r
7  * SVN $Date: 2010-04-19 17:14:26 +0100 (Mon, 19 Apr 2010) $\r
8  */\r
9 /*=========================================================================*//**\r
10   @mainpage SmartFusion MSS Timer Bare Metal Driver.\r
11 \r
12   @section intro_sec Introduction\r
13   The SmartFusion Microcontroller Subsystem (MSS) includes a timer hardware\r
14   block which can be used as two independent 32-bits timers or as a single\r
15   64-bits timer in periodic or one-shot mode. \r
16 \r
17   This driver provides a set of functions for controlling the MSS timer as part\r
18   of a bare metal system where no operating system is available. These drivers\r
19   can be adapted for use as part of an operating system but the implementation\r
20   of the adaptation layer between this driver and the operating system's driver\r
21   model is outside the scope of this driver.\r
22   \r
23   @section theory_op Theory of Operation\r
24   The MSS Timer driver uses the SmartFusion "Cortex Microcontroler Software\r
25   Interface Standard - Peripheral Access Layer" (CMSIS-PAL) to access hadware\r
26   registers. You must ensure that the SmartFusion CMSIS-PAL is either included\r
27   in the software toolchain used to build your project or is included in your\r
28   project. The most up-to-date SmartFusion CMSIS-PAL files can be obtained using\r
29   the Actel Firmware Catalog.\r
30   The SmartFusion MSS Timer can be used in one of two mutually exclusive modes;\r
31   either as a single 64-bits timer or as two independent 32-bits timers. The MSS\r
32   Timer can be used in either periodic mode or one-shot mode. A timer configured\r
33   for periodic mode operations will generate an interrupt and reload its\r
34   down-counter when it reaches 0. The timer will then continue decrementing from\r
35   its reload value without waiting for the interrupt to be cleared. A timer\r
36   configured for one-shot mode will only generate an interrupt once when its\r
37   down-counter reaches 0. It must be explitcitly reloaded to start decrementing\r
38   again.\r
39   \r
40   The MSS Timer driver functions are grouped into the following categories:\r
41     - Initialization and Configuration\r
42     - Timer control\r
43     - Interrupt control\r
44   \r
45   The MSS Timer driver provides three initialization functions:\r
46     - MSS_TIM1_init()\r
47     - MSS_TIM2_init()\r
48     - MSS_TIM64_init()\r
49   The MSS Timer driver is initialized through calls to these functions and at\r
50   least one of them must be called before any other MSS Timer driver functions\r
51   can be called.\r
52   You should only use the MSS_TIM1_init() and MSS_TIM2_init() functions if you\r
53   intend to use the timer in 32-bits mode. Use the MSS_TIM64_init() function is\r
54   you intend to use the MSS Timer as a single 64-bits timer. The initialization\r
55   functions take a single parameter specifying the operating mode of the timer\r
56   being initialized.\r
57   \r
58   Once initialized a timer can be controlled using the following functions:\r
59     - MSS_TIM1_load_immediate()\r
60     - MSS_TIM1_load_background()\r
61     - MSS_TIM1_get_current_value()\r
62     - MSS_TIM1_start()\r
63     - MSS_TIM1_stop()\r
64     - MSS_TIM2_load_immediate()\r
65     - MSS_TIM2_load_background()\r
66     - MSS_TIM2_get_current_value()\r
67     - MSS_TIM2_start()\r
68     - MSS_TIM2_stop()\r
69     - MSS_TIM64_load_immediate()\r
70     - MSS_TIM64_load_background()\r
71     - MSS_TIM64_get_current_value()\r
72     - MSS_TIM64_start()\r
73     - MSS_TIM64_stop()\r
74   \r
75   Timer interrupts are controlled using the following functions:\r
76     - MSS_TIM1_enable_irq()\r
77     - MSS_TIM1_disable_irq()\r
78     - MSS_TIM1_clear_irq()\r
79     - MSS_TIM2_enable_irq()\r
80     - MSS_TIM2_disable_irq()\r
81     - MSS_TIM2_clear_irq()\r
82     - MSS_TIM64_enable_irq()\r
83     - MSS_TIM64_disable_irq()\r
84     - MSS_TIM64_clear_irq()\r
85   \r
86   The function prototypes for the timer interrupt handlers are:\r
87     - void Timer1_IRQHandler( void )\r
88     - void Timer2_IRQHandler( void )\r
89   Entries for these interrupt handlers are provided in the SmartFusion CMSIS-PAL\r
90   vector table. To add a Timer 1 interrupt handler, you must implement a\r
91   Timer1_IRQHandler( ) function as part of your application code. To add a\r
92   Timer 2 interrupt handler, you must implement a Timer2_IRQHandler( ) function\r
93   as part of your application code. When using the MSS Timer as a 64-bit timer,\r
94   you must implement a Timer1_IRQHandler( ) function as part of your\r
95   application code. The Timer 2 interrupt is not used when the MSS Timer is\r
96   configured as a 64-bit timer.\r
97   \r
98  *//*=========================================================================*/\r
99 #ifndef MSS_TIMER_H_\r
100 #define MSS_TIMER_H_\r
101 \r
102 \r
103 #include "../../CMSIS/a2fxxxm3.h"\r
104 \r
105 #ifdef __cplusplus\r
106 extern "C" {\r
107 #endif \r
108 \r
109 /*-------------------------------------------------------------------------*//**\r
110  * Timer mode selection. This enumeration is used to select between the two\r
111  * possible timer modes of operation: periodic and one-shot mode. It is used as\r
112  * an argument to the MSS_TIM1_init(), MSS_TIM2_init() and MSS_TIM64_init()\r
113  * functions.\r
114  * MSS_TIMER_PERIODIC_MODE:\r
115  *  In periodic mode the timer generates interrupts at constant intervals. On \r
116  *  reaching zero, the timer's counter is reloaded with a value held in a\r
117  *  register and begins counting down again.\r
118  * MSS_TIMER_ONE_SHOT_MODE:\r
119  *  The timer generates a single interrupt in this mode. On reaching zero, the\r
120  *  timer's counter halts until reprogrammed by the user.\r
121  */\r
122 typedef enum __mss_timer_mode_t\r
123 {\r
124     MSS_TIMER_PERIODIC_MODE = 0,\r
125     MSS_TIMER_ONE_SHOT_MODE = 1\r
126 } mss_timer_mode_t;\r
127 \r
128 /*-------------------------------------------------------------------------*//**\r
129   The MSS_TIM1_init() function initializes the SmartFusion MSS Timer block for\r
130   use as a 32-bit timer and selects the operating mode for Timer 1. This function\r
131   takes the MSS Timer block out of reset in case this hasn\92t been done already,\r
132   stops Timer 1, disables its interrupt and sets the Timer 1 operating mode.\r
133   Please note that the SmartFusion MSS Timer block cannot be used both as a\r
134   64-bit and 32-bit timer. Calling MSS_TIM1_init() will overwrite any previous\r
135   configuration of the MSS Timer as a 64-bit timer.\r
136 \r
137  \r
138   @param mode\r
139     The mode parameter specifies whether the timer will operate in periodic or\r
140     one-shot mode. Allowed values for this parameter are:\r
141         - MSS_TIMER_PERIODIC_MODE\r
142         - MSS_TIMER_ONE_SHOT_MODE\r
143  */\r
144 static __INLINE void MSS_TIM1_init( mss_timer_mode_t mode )\r
145 {\r
146     NVIC_DisableIRQ( Timer1_IRQn );             /* Disable timer 1 irq in the Cortex-M3 NVIC */  \r
147     \r
148     SYSREG->SOFT_RST_CR &= ~SYSREG_TIMER_SOFTRESET_MASK; /* Take timer block out of reset */\r
149     \r
150     TIMER->TIM64_MODE = 0U;                     /* switch to 32 bits mode */\r
151     \r
152     TIMER_BITBAND->TIM1ENABLE = 0U;             /* disable timer */\r
153     TIMER_BITBAND->TIM1INTEN = 0U;              /* disable interrupt */\r
154     TIMER_BITBAND->TIM1MODE = (uint32_t)mode;   /* set mode (continuous/one-shot) */\r
155     \r
156     TIMER->TIM1_RIS = 1U;                       /* clear timer 1 interrupt */\r
157     NVIC_ClearPendingIRQ( Timer1_IRQn );        /* clear timer 1 interrupt within NVIC */\r
158 }\r
159 \r
160 /*-------------------------------------------------------------------------*//**\r
161   The MSS_TIM1_start() function enables Timer 1 and starts its down-counter\r
162   decrementing from the load_value specified in previous calls to the\r
163   MSS_TIM1_load_immediate() or MSS_TIM1_load_background() functions.\r
164  */\r
165 static __INLINE void MSS_TIM1_start( void )\r
166 {\r
167     TIMER_BITBAND->TIM1ENABLE = 1U;    /* enable timer */\r
168 }\r
169 \r
170 /*-------------------------------------------------------------------------*//**\r
171   The MSS_TIM1_stop() function disables Timer 1 and stops its down-counter\r
172   decrementing.\r
173  */\r
174 static __INLINE void MSS_TIM1_stop( void )\r
175 {\r
176     TIMER_BITBAND->TIM1ENABLE = 0U;    /* disable timer */\r
177 }\r
178 \r
179 /*-------------------------------------------------------------------------*//**\r
180   The MSS_TIM1_get_current_value() returns the current value of the Timer 1\r
181   down-counter.\r
182   \r
183   @return\r
184     This function returns the 32-bits current value of the Timer 1 down-counter.\r
185  */\r
186 static __INLINE uint32_t MSS_TIM1_get_current_value( void )\r
187 {\r
188     return TIMER->TIM1_VAL;\r
189 }\r
190 \r
191 /*-------------------------------------------------------------------------*//**\r
192   The MSS_TIM1_load_immediate() function loads the value passed by the\r
193   load_value parameter into the Timer 1 down-counter. The counter will decrement\r
194   immediately from this value once Timer 1 is enabled. The MSS Timer will\r
195   generate an interrupt when the counter reaches zero if Timer 1 interrupts are\r
196   enabled. This function is intended to be used when Timer 1 is configured for\r
197   one-shot mode to time a single delay.\r
198  \r
199   @param load_value\r
200     The load_value parameter specifies the value from which the Timer 1 down-counter\r
201     will start decrementing from.\r
202  */\r
203 static __INLINE void MSS_TIM1_load_immediate( uint32_t load_value )\r
204 {\r
205     TIMER->TIM1_LOADVAL = load_value;\r
206 }\r
207 \r
208 /*-------------------------------------------------------------------------*//**\r
209   The MSS_TIM1_load_background() function is used to specify the value that will\r
210   be reloaded into the Timer 1 down-counter the next time the counter reaches\r
211   zero. This function is typically used when Timer 1 is configured for periodic\r
212   mode operation to select or change the delay period between the interrupts\r
213   generated by Timer 1.\r
214  \r
215   @param load_value\r
216     The load_value parameter specifies the value that will be loaded into the\r
217     Timer 1 down-counter the next time the down-counter reaches zero. The Timer\r
218     1 down-counter will start decrementing from this value after the current\r
219     count expires.\r
220  */\r
221 static __INLINE void MSS_TIM1_load_background( uint32_t load_value )\r
222 {\r
223     TIMER->TIM1_BGLOADVAL = load_value;\r
224 }\r
225 \r
226 /*-------------------------------------------------------------------------*//**\r
227   The MSS_TIM1_enable_irq() function is used to enable interrupt generation for\r
228   Timer 1. This function also enables the interrupt in the Cortex-M3 interrupt\r
229   controller. The Timer1_IRQHandler() function will be called when a Timer 1\r
230   interrupt occurs.\r
231   Note: Note:   A Timer1_IRQHandler() default implementation is defined, with\r
232   weak linkage, in the SmartFusion CMSIS-PAL. You must provide your own\r
233   implementation of the Timer1_IRQHandler() function, that will override the\r
234   default implementation, to suit your application.\r
235 \r
236  */\r
237 static __INLINE void MSS_TIM1_enable_irq( void )\r
238 {\r
239     TIMER_BITBAND->TIM1INTEN = 1U;\r
240     NVIC_EnableIRQ( Timer1_IRQn );\r
241 }\r
242 \r
243 /*-------------------------------------------------------------------------*//**\r
244   The MSS_TIM1_disable_irq() function is used to disable interrupt generation\r
245   for Timer 1. This function also disables the interrupt in the Cortex-M3\r
246   interrupt controller.\r
247  */\r
248 static __INLINE void MSS_TIM1_disable_irq( void )\r
249 {\r
250     TIMER_BITBAND->TIM1INTEN = 0U;\r
251     NVIC_DisableIRQ( Timer1_IRQn );\r
252 }\r
253 \r
254 /*-------------------------------------------------------------------------*//**\r
255   The MSS_TIM1_clear_irq() function is used to clear a pending interrupt from\r
256   Timer 1. This function also clears the interrupt in the Cortex-M3 interrupt\r
257   controller.\r
258   Note: You must call the MSS_TIM1_clear_irq() function as part of your\r
259   implementation of the Timer1_IRQHandler() Timer 1 interrupt service routine\r
260   (ISR) in order to prevent the same interrupt event retriggering a call to the\r
261   ISR.\r
262 \r
263  */\r
264 static __INLINE void MSS_TIM1_clear_irq( void )\r
265 {\r
266     TIMER->TIM1_RIS = 1U;\r
267     NVIC_ClearPendingIRQ( Timer1_IRQn );\r
268 }\r
269 \r
270 /*-------------------------------------------------------------------------*//**\r
271   The MSS_TIM2_init() function initializes the SmartFusion MSS Timer block for\r
272   use as a 32-bit timer and selects the operating mode for Timer 2. This function\r
273   takes the MSS Timer block out of reset in case this hasn\92t been done already,\r
274   stops Timer 2, disables its interrupt and sets the Timer 2 operating mode.\r
275   Note: Please note that the SmartFusion MSS Timer block cannot be used both as\r
276   a 64-bit and 32-bit timer. Calling MSS_TIM2_init() will overwrite any previous\r
277   configuration of the MSS Timer as a 64-bit timer.\r
278   \r
279   @param mode\r
280     The mode parameter specifies whether the timer will operate in periodic or\r
281     one-shot mode. Allowed values for this parameter are:\r
282         - MSS_TIMER_PERIODIC_MODE\r
283         - MSS_TIMER_ONE_SHOT_MODE \r
284  */\r
285 static __INLINE void MSS_TIM2_init( mss_timer_mode_t mode )\r
286 {\r
287     NVIC_DisableIRQ( Timer2_IRQn );             /* Disable timer 2 irq in the Cortex-M3 NVIC */  \r
288     \r
289     SYSREG->SOFT_RST_CR &= ~SYSREG_TIMER_SOFTRESET_MASK; /* Take timer block out of reset */\r
290     \r
291     TIMER->TIM64_MODE = 0U;                     /* switch to 32 bits mode */\r
292     \r
293     TIMER_BITBAND->TIM2ENABLE = 0U;             /* disable timer */\r
294     TIMER_BITBAND->TIM2INTEN = 0U;              /* disable interrupt */\r
295     TIMER_BITBAND->TIM2MODE = (uint32_t)mode;   /* set mode (continuous/one-shot) */\r
296     \r
297     TIMER->TIM2_RIS = 1U;                       /* clear timer 2 interrupt */\r
298     NVIC_ClearPendingIRQ( Timer2_IRQn );        /* clear timer 2 interrupt within NVIC */\r
299 }\r
300 \r
301 /*-------------------------------------------------------------------------*//**\r
302   The MSS_TIM2_start() function enables Timer 2 and  starts its down-counter\r
303   decrementing from the load_value specified in previous calls to the\r
304   MSS_TIM2_load_immediate() or MSS_TIM2_load_background() functions.\r
305  */\r
306 static __INLINE void MSS_TIM2_start( void )\r
307 {\r
308     TIMER_BITBAND->TIM2ENABLE = 1U;    /* enable timer */\r
309 }\r
310 \r
311 /*-------------------------------------------------------------------------*//**\r
312   The MSS_TIM2_stop() function disables Timer 2 and stops its down-counter\r
313   decrementing.\r
314  */\r
315 static __INLINE void MSS_TIM2_stop( void )\r
316 {\r
317     TIMER_BITBAND->TIM2ENABLE = 0U;    /* disable timer */\r
318 }\r
319 \r
320 /*-------------------------------------------------------------------------*//**\r
321   The MSS_TIM2_get_current_value() returns the current value of the Timer 2\r
322   down-counter.\r
323  */\r
324 static __INLINE uint32_t MSS_TIM2_get_current_value( void )\r
325 {\r
326     return TIMER->TIM2_VAL;\r
327 }\r
328 \r
329 /*-------------------------------------------------------------------------*//**\r
330   The MSS_TIM2_load_immediate() function loads the value passed by the\r
331   load_value parameter into the Timer 2 down-counter. The counter will decrement\r
332   immediately from this value once Timer 2 is enabled. The MSS Timer will\r
333   generate an interrupt when the counter reaches zero if Timer 2 interrupts are\r
334   enabled. This function is intended to be used when Timer 2 is configured for\r
335   one-shot mode to time a single delay.\r
336   \r
337   @param load_value\r
338     The load_value parameter specifies the value from which the Timer 2\r
339     down-counter will start decrementing. \r
340  */\r
341 static __INLINE void MSS_TIM2_load_immediate( uint32_t load_value )\r
342 {\r
343     TIMER->TIM2_LOADVAL = load_value;\r
344 }\r
345 \r
346 /*-------------------------------------------------------------------------*//**\r
347   The MSS_TIM2_load_background() function is used to specify the value that will\r
348   be reloaded into the Timer 2 down-counter the next time the counter reaches\r
349   zero. This function is typically used when Timer 2 is configured for periodic\r
350   mode operation to select or change the delay period between the interrupts\r
351   generated by Timer 2.\r
352   \r
353   @param load_value\r
354     The load_value parameter specifies the value that will be loaded into the\r
355     Timer 2 down-counter the next time the down-counter reaches zero. The Timer\r
356     2 down-counter will start decrementing from this value after the current\r
357     count expires.\r
358  */\r
359 static __INLINE void MSS_TIM2_load_background( uint32_t load_value )\r
360 {\r
361     TIMER->TIM2_BGLOADVAL = load_value;\r
362 }\r
363 \r
364 /*-------------------------------------------------------------------------*//**\r
365   The MSS_TIM2_enable_irq() function is used to enable interrupt generation for\r
366   Timer 2. This function also enables the interrupt in the Cortex-M3 interrupt\r
367   controller. The Timer2_IRQHandler() function will be called when a Timer 2\r
368   interrupt occurs.\r
369   Note: A Timer2_IRQHandler() default implementation is defined, with weak\r
370   linkage, in the SmartFusion CMSIS-PAL. You must provide your own implementation\r
371   of the Timer2_IRQHandler() function, that will override the default\r
372   implementation, to suit your application.\r
373  */\r
374 static __INLINE void MSS_TIM2_enable_irq( void )\r
375 {\r
376     TIMER_BITBAND->TIM2INTEN = 1U;\r
377     NVIC_EnableIRQ( Timer2_IRQn );\r
378 }\r
379 \r
380 /*-------------------------------------------------------------------------*//**\r
381   The MSS_TIM2_disable_irq() function is used to disable interrupt generation\r
382   for Timer 2. This function also disables the interrupt in the Cortex-M3\r
383   interrupt controller.\r
384  */\r
385 static __INLINE void MSS_TIM2_disable_irq( void )\r
386 {\r
387     TIMER_BITBAND->TIM2INTEN = 0U;\r
388     NVIC_DisableIRQ( Timer2_IRQn );\r
389 }\r
390 \r
391 /*-------------------------------------------------------------------------*//**\r
392   The MSS_TIM2_clear_irq() function is used to clear a pending interrupt from\r
393   Timer 2. This function also clears the interrupt in the Cortex-M3 interrupt\r
394   controller.\r
395   Note: You must call the MSS_TIM2_clear_irq() function as part of your\r
396   implementation of the Timer2_IRQHandler() Timer 2 interrupt service routine\r
397   (ISR) in order to prevent the same interrupt event retriggering a call to the\r
398   ISR.\r
399  */\r
400 static __INLINE void MSS_TIM2_clear_irq( void )\r
401 {\r
402     TIMER->TIM2_RIS = 1U;\r
403     NVIC_ClearPendingIRQ( Timer2_IRQn );\r
404 }\r
405 \r
406 /*-------------------------------------------------------------------------*//**\r
407   The MSS_TIM64_init() function initializes the SmartFusion MSS Timer block for\r
408   use as a single 64-bit timer and selects the operating mode of the timer. This\r
409   function takes the MSS Timer block out of reset in case this hasn\92t been done\r
410   already, stops the timer, disables its interrupts and sets the timer's\r
411   operating mode.\r
412   Note: Please note that the SmartFusion MSS Timer block cannot be used both as\r
413   a 64-bit and 32-bit timer. Calling MSS_TIM64_init() will overwrite any previous\r
414   configuration of the MSS Timer as a 32-bit timer.\r
415 \r
416   @param mode\r
417     The mode parameter specifies whether the timer will operate in periodic or\r
418     one-shot mode. Allowed values for this parameter are:\r
419         - MSS_TIMER_PERIODIC_MODE\r
420         - MSS_TIMER_ONE_SHOT_MODE \r
421  */\r
422 static __INLINE void MSS_TIM64_init( mss_timer_mode_t mode )\r
423 {\r
424     NVIC_DisableIRQ( Timer1_IRQn );         /* disable timer 1 interrupt within NVIC */\r
425     NVIC_DisableIRQ( Timer2_IRQn );         /* disable timer 2 interrupt within NVIC */\r
426     \r
427     SYSREG->SOFT_RST_CR &= ~SYSREG_TIMER_SOFTRESET_MASK; /* Take timer block out of reset */\r
428     \r
429     TIMER->TIM64_MODE = 1U;                     /* switch to 64 bits mode */\r
430     \r
431     TIMER_BITBAND->TIM64ENABLE = 0U;            /* disable timer */\r
432     TIMER_BITBAND->TIM64INTEN = 0U;             /* disable interrupt */\r
433     TIMER_BITBAND->TIM64MODE = (uint32_t)mode;  /* set mode (continuous/one-shot) */\r
434     \r
435     TIMER->TIM1_RIS = 1U;                   /* clear timer 1 interrupt */\r
436     TIMER->TIM2_RIS = 1U;                   /* clear timer 2 interrupt */\r
437     NVIC_ClearPendingIRQ( Timer1_IRQn );    /* clear timer 1 interrupt within NVIC */\r
438     NVIC_ClearPendingIRQ( Timer2_IRQn );    /* clear timer 2 interrupt within NVIC */\r
439 }\r
440 \r
441 /*-------------------------------------------------------------------------*//**\r
442   The MSS_TIM64_start() function enables the 64-bit timer and starts its\r
443   down-counter decrementing from the load_value specified in previous calls to\r
444   the MSS_TIM64_load_immediate() or MSS_TIM64_load_background() functions.\r
445  */\r
446 static __INLINE void MSS_TIM64_start( void )\r
447 {\r
448     TIMER_BITBAND->TIM64ENABLE = 1U;    /* enable timer */\r
449 }\r
450 \r
451 /*-------------------------------------------------------------------------*//**\r
452   The MSS_TIM64_stop() function disables the 64-bit timer and stops its\r
453   down-counter decrementing.\r
454  */\r
455 static __INLINE void MSS_TIM64_stop( void )\r
456 {\r
457     TIMER_BITBAND->TIM64ENABLE = 0U;    /* disable timer */\r
458 }\r
459 \r
460 /*-------------------------------------------------------------------------*//**\r
461   The MSS_TIM64_get_current_value() is used to read the current value of the\r
462   64-bit timer down-counter. \r
463  \r
464   @param load_value_u\r
465     The load_value_u parameter is a pointer to a 32-bit variable where the upper\r
466     32 bits of the current value of the 64-bit timer down-counter will be copied.\r
467     \r
468   @param load_value_l\r
469     The load_value_l parameter is a pointer to a 32-bit variable where the lower\r
470     32 bits of the current value of the 64-bit timer down-counter will be copied.\r
471     \r
472   Example:\r
473   @code\r
474     uint32_t current_value_u = 0;\r
475     uint32_t current_value_l = 0;\r
476     MSS_TIM64_get_current_value( &current_value_u, &current_value_l );\r
477   @endcode\r
478  */\r
479 static __INLINE void MSS_TIM64_get_current_value\r
480 (\r
481     uint32_t * load_value_u,\r
482     uint32_t * load_value_l\r
483 )\r
484 {\r
485     *load_value_l = TIMER->TIM64_VAL_L;\r
486     *load_value_u = TIMER->TIM64_VAL_U;\r
487 }\r
488 \r
489 /*-------------------------------------------------------------------------*//**\r
490   The MSS_TIM64_load_immediate() function loads the values passed by the\r
491   load_value_u and load_value_l parameters into the 64-bit timer down-counter.\r
492   The counter will decrement immediately from the concatenated 64-bit value once\r
493   the 64-bit timer is enabled. The MSS Timer will generate an interrupt when the\r
494   counter reaches zero if 64-bit timer interrupts are enabled. This function is\r
495   intended to be used when the 64-bit timer is configured for one-shot mode to\r
496   time a single delay.\r
497  \r
498   @param load_value_u\r
499     The load_value_u parameter specifies the upper 32 bits of the 64-bit timer\r
500     load value from which the 64-bit timer down-counter will start decrementing.\r
501     \r
502   @param load_value_l\r
503     The load_value_l parameter specifies the lower 32 bits of the 64-bit timer\r
504     load value from which the 64-bit timer down-counter will start decrementing.\r
505  */\r
506 static __INLINE void MSS_TIM64_load_immediate\r
507 (\r
508     uint32_t load_value_u,\r
509     uint32_t load_value_l\r
510 )\r
511 {\r
512     TIMER->TIM64_LOADVAL_U = load_value_u;\r
513     TIMER->TIM64_LOADVAL_L = load_value_l;\r
514 }\r
515 \r
516 /*-------------------------------------------------------------------------*//**\r
517   The MSS_TIM64_load_background() function is used to specify the 64-bit value\r
518   that will be reloaded into the 64-bit timer down-counter the next time the\r
519   counter reaches zero. This function is typically used when the 64-bit timer is\r
520   configured for periodic mode operation to select or change the delay period\r
521   between the interrupts generated by the 64-bit timer.\r
522  \r
523   @param load_value_u\r
524     The load_value_u parameter specifies the upper 32 bits of the 64-bit timer\r
525     load value. The concatenated 64-bit value formed from load_value_u and\r
526     load_value_l will be loaded into the 64-bit timer down-counter the next\r
527     time the down-counter reaches zero. The 64-bit timer down-counter will start\r
528     decrementing from the concatenated 64-bit value after the current count\r
529     expires.\r
530     \r
531   @param load_value_l\r
532     The load_value_l parameter specifies the lower 32 bits of the 64-bit timer\r
533     load value. The concatenated 64-bit value formed from load_value_u and\r
534     load_value_l will be loaded into the 64-bit timer down-counter the next time\r
535     the down-counter reaches zero. The 64-bit timer down-counter will start\r
536     decrementing from the concatenated 64-bit value after the current count\r
537     expires.\r
538  \r
539  */\r
540 static __INLINE void MSS_TIM64_load_background\r
541 (\r
542     uint32_t load_value_u,\r
543     uint32_t load_value_l\r
544 )\r
545 {\r
546     TIMER->TIM64_BGLOADVAL_U = load_value_u;\r
547     TIMER->TIM64_BGLOADVAL_L = load_value_l;\r
548 }\r
549 \r
550 /*-------------------------------------------------------------------------*//**\r
551   The MSS_TIM64_enable_irq() function is used to enable interrupt generation for\r
552   the 64-bit timer. This function also enables the interrupt in the Cortex-M3\r
553   interrupt controller. The Timer1_IRQHandler() function will be called when a\r
554   64-bit timer interrupt occurs.\r
555   Note: A Timer1_IRQHandler() default implementation is defined, with weak\r
556   linkage, in the SmartFusion CMSIS-PAL. You must provide your own\r
557   implementation of the Timer1_IRQHandler() function, that will override the\r
558   default implementation, to suit your application.\r
559   Note: The MSS_TIM64_enable_irq() function enables and uses Timer 1 interrupts\r
560   for the 64-bit timer. Timer 2 interrupts remain disabled.\r
561  */\r
562 static __INLINE void MSS_TIM64_enable_irq( void )\r
563 {\r
564     TIMER_BITBAND->TIM64INTEN = 1U;\r
565     NVIC_EnableIRQ( Timer1_IRQn );\r
566 }\r
567 \r
568 /*-------------------------------------------------------------------------*//**\r
569   The MSS_TIM64_disable_irq() function is used to disable interrupt generation\r
570   for the 64-bit timer. This function also disables the interrupt in the\r
571   Cortex-M3 interrupt controller.\r
572  */\r
573 static __INLINE void MSS_TIM64_disable_irq( void )\r
574 {\r
575     TIMER_BITBAND->TIM64INTEN = 0U;\r
576     NVIC_DisableIRQ( Timer1_IRQn );\r
577 }\r
578 \r
579 /*-------------------------------------------------------------------------*//**\r
580   The MSS_TIM64_clear_irq() function is used to clear a pending interrupt from\r
581   the 64-bit timer. This function also clears the interrupt in the Cortex-M3\r
582   interrupt controller.\r
583   Note: You must call the MSS_TIM64_clear_irq() function as part of your\r
584   implementation of the Timer1_IRQHandler() 64-bit timer interrupt service\r
585   routine (ISR) in order to prevent the same interrupt event retriggering a\r
586   call to the ISR.\r
587  */\r
588 static __INLINE void MSS_TIM64_clear_irq( void )\r
589 {\r
590     TIMER->TIM64_RIS = 1U;\r
591     NVIC_ClearPendingIRQ( Timer1_IRQn );\r
592 }\r
593 \r
594 #ifdef __cplusplus\r
595 }\r
596 #endif\r
597 \r
598 #endif /*MSS_TIMER_H_*/\r