2 * Altera - Module Description
\r
5 /******************************************************************************
\r
7 * Copyright 2013 Altera Corporation. All Rights Reserved.
\r
9 * Redistribution and use in source and binary forms, with or without
\r
10 * modification, are permitted provided that the following conditions are met:
\r
12 * 1. Redistributions of source code must retain the above copyright notice,
\r
13 * this list of conditions and the following disclaimer.
\r
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
16 * this list of conditions and the following disclaimer in the documentation
\r
17 * and/or other materials provided with the distribution.
\r
19 * 3. The name of the author may not be used to endorse or promote products
\r
20 * derived from this software without specific prior written permission.
\r
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY EXPRESS OR
\r
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED. IN NO
\r
25 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
\r
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
\r
27 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
\r
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
\r
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
\r
30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
\r
33 ******************************************************************************/
\r
35 #ifndef __ALT_GBLTMR_H__
\r
36 #define __ALT_GBLTMR_H__
\r
39 #include <stdbool.h>
\r
45 #endif /* __cplusplus */
\r
48 /******************************************************************************/
\r
49 /*! \addtogroup GBLTMR_MGR The Global Timer Manager API
\r
51 * This functional group handles setting and reading various parameters of the
\r
52 * global 64-bit incrementing counter. There is one 64-bit continuously
\r
53 * incrementing counter for all CPU cores and it is clocked by PERIPHCLK.
\r
54 * This section manages the comparator value, compare enable,
\r
55 * auto-increment value, auto-increment enable, and interrupt enable for the
\r
56 * CPU that this code is running on (referenced as \b CPU_GLOBAL_TMR).
\r
59 /******************************************************************************/
\r
60 /*! Uninitialize the Global timer module
\r
63 ALT_STATUS_CODE alt_globaltmr_uninit(void);
\r
65 /******************************************************************************/
\r
66 /*! Initialize the Global timer module
\r
69 ALT_STATUS_CODE alt_globaltmr_init(void);
\r
71 /******************************************************************************/
\r
73 * Stops the global timer counter compare function for this CPU and disables
\r
74 * its interrupt. It does
\r
75 * not stop the global timer itself. This function is identical to calling
\r
76 * \b alt_gpt_tmr_stop() with a tmr_id of \b CPU_GLOBAL_TMR.
\r
80 * \retval ALT_E_SUCCESS The operation was successful.
\r
81 * \retval ALT_E_ERROR The operation failed.
\r
83 ALT_STATUS_CODE alt_globaltmr_stop(void);
\r
85 /******************************************************************************/
\r
87 * Starts the global timer compare function for this CPU, enables its interrupt
\r
88 * function and, if free-running mode is selected also enables its
\r
89 * auto-increment function. If the global timer is not yet running, it starts
\r
90 * the timer. This function is identical to calling \b alt_gpt_tmr_start()
\r
91 * with a tmr_id of \b CPU_GLOBAL_TMR.
\r
95 * \retval ALT_E_SUCCESS The operation was successful.
\r
96 * \retval ALT_E_ERROR The operation failed.
\r
98 ALT_STATUS_CODE alt_globaltmr_start(void);
\r
100 /******************************************************************************/
\r
102 * Returns the current counter value of the 64-bit global timer.
\r
106 * Location used to return the most significant 32-bit word of
\r
107 * the current global timer count.
\r
109 * Location used to return the least significant 32-bit word
\r
110 * of the current global timer count.
\r
113 * \retval ALT_E_SUCCESS The operation was successful.
\r
114 * \retval ALT_E_ERROR The operation failed.
\r
115 * \retval ALT_E_BAD_ARG Invalid input argument.
\r
117 ALT_STATUS_CODE alt_globaltmr_get(uint32_t* highword, uint32_t* lowword);
\r
119 /******************************************************************************/
\r
121 * Returns the current counter value of the 64-bit global timer. This function
\r
122 * is identical to alt_globaltmr_get() except that the value is returned as a
\r
123 * 64-bit unsigned integer rather than as two 32-bit words.
\r
128 * The current value of the 64-bit counter.
\r
130 uint64_t alt_globaltmr_get64(void);
\r
132 /******************************************************************************/
\r
134 * Returns the 32 low-order bits of the global timer. This
\r
135 * is identical to calling \b alt_gpt_counter_get() with a tmr_id equal
\r
136 * to \b CPU_GLOBAL_TMR. Use alt_globaltmr_get() or alt_globaltmr_get64() to
\r
137 * obtain the full 64-bit timer value.
\r
141 * \retval uint32_t The current 32-bit counter value.
\r
143 uint32_t alt_globaltmr_counter_get_low32(void);
\r
145 /******************************************************************************/
\r
147 * Returns the 32 higher-order bits of the global timer. Use alt_globaltmr_get()
\r
148 * or alt_globaltmr_get64() to obtain the full 64-bit timer value.
\r
152 * \retval uint32_t The current 32-bit counter value.
\r
154 uint32_t alt_globaltmr_counter_get_hi32(void);
\r
156 /******************************************************************************/
\r
158 * Sets the value of the 64-bit global timer comparator for this CPU. The
\r
159 * global timer increments its count and when it reaches this value or above,
\r
160 * it triggers the following actions. If the interrupt is enabled, it forwards
\r
161 * an interrupt request to the core. If free-run mode is selected, it adds the
\r
162 * auto-increment value to the value of the global counter and the resulting
\r
163 * sum is saved as the new comparator value.
\r
167 * The 32 MSBits of the new comparator value.
\r
169 * The 32 LSBits of the new comparator value.
\r
171 * \retval ALT_E_SUCCESS The operation was successful.
\r
172 * \retval ALT_E_ERROR The operation failed.
\r
173 * \retval ALT_E_BAD_ARG Invalid input argument.
\r
175 ALT_STATUS_CODE alt_globaltmr_comp_set(uint32_t highword, uint32_t loword);
\r
177 /******************************************************************************/
\r
179 * Sets the value of the 64-bit global timer comparator for this CPU. The
\r
180 * global timer increments its count and when it reaches this value or above,
\r
181 * it triggers the following actions. If the interrupt is enabled, it forwards
\r
182 * an interrupt request to the core. If free-run mode is selected, it adds the
\r
183 * auto-increment value to the value of the global counter and the resulting
\r
184 * sum is saved as the new comparator value.
\r
188 * The new comparator value to set.
\r
190 * \retval ALT_E_SUCCESS The operation was successful.
\r
191 * \retval ALT_E_ERROR The operation failed.
\r
192 * \retval ALT_E_BAD_ARG Invalid input argument.
\r
194 ALT_STATUS_CODE alt_globaltmr_comp_set64(uint64_t compval);
\r
196 /******************************************************************************/
\r
198 * Returns the current 64-bit global timer comparator value for this CPU. The
\r
199 * global timer increments its count and when it reaches this value or above,
\r
200 * it triggers the following actions. If the interrupt is enabled, it forwards
\r
201 * an interrupt request to the core. If free-run mode is selected, it adds the
\r
202 * auto-increment value to the value of the global counter and the resulting
\r
203 * sum is saved as the new comparator value. This value will increase by the
\r
204 * auto-increment value each time the global timer reaches the comparator
\r
209 * Pointer to location to store the 32 MSBits of the comparator value.
\r
211 * Pointer to location to store the 32 LSBits of the comparator value.
\r
213 * \retval ALT_E_SUCCESS The operation was successful.
\r
214 * \retval ALT_E_ERROR The operation failed.
\r
215 * \retval ALT_E_BAD_ARG Invalid input argument.
\r
217 ALT_STATUS_CODE alt_globaltmr_comp_get(uint32_t *highword, uint32_t *lowword);
\r
219 /******************************************************************************/
\r
221 * Returns the current 64-bit global timer comparator value for this CPU. The
\r
222 * global timer increments its count and when it reaches this value or above,
\r
223 * it triggers the following actions. If the interrupt is enabled, it forwards
\r
224 * an interrupt request to the core. If free-run mode is selected, it adds the
\r
225 * auto-increment value to the value of the global counter and the resulting
\r
226 * sum is saved as the new comparator value. This value will increase by the
\r
227 * auto-increment value each time the global timer reaches the comparator
\r
228 * value. This function is identical to alt_globaltmr_comp_get() except that the
\r
229 * value is returned in a 64-bit unsigned integer rather than as two 32-bit
\r
234 * The 64-bit value of the global timer comparator.
\r
236 uint64_t alt_globaltmr_comp_get64(void);
\r
239 /******************************************************************************/
\r
241 * Enables the comparison function of the global timer for this CPU.
\r
244 * \retval ALT_E_SUCCESS The operation was successful.
\r
245 * \retval ALT_E_ERROR The operation failed.
\r
246 * \retval ALT_E_BAD_ARG Invalid input argument.
\r
248 ALT_STATUS_CODE alt_globaltmr_comp_mode_start(void);
\r
250 /******************************************************************************/
\r
252 * Disables the comparison function of the global timer for this CPU.
\r
255 * \retval ALT_E_SUCCESS The operation was successful.
\r
256 * \retval ALT_E_ERROR The operation failed.
\r
257 * \retval ALT_E_BAD_ARG Invalid input argument.
\r
259 ALT_STATUS_CODE alt_globaltmr_comp_mode_stop(void);
\r
261 /******************************************************************************/
\r
263 * Returns the comparison mode selection of the global
\r
264 * timer for this CPU.
\r
267 * \retval FALSE Comparison mode is not enabled.
\r
268 * \retval TRUE Comparison mode is enabled.
\r
270 bool alt_globaltmr_is_comp_mode(void);
\r
273 /******************************************************************************/
\r
275 * Returns the clock prescaler value of the global timer.
\r
278 * \retval uint32_t The prescaler value. Valid range is 0-255.
\r
279 * Actual clock divisor ratio is this number plus one.
\r
281 uint32_t alt_globaltmr_prescaler_get(void);
\r
284 /******************************************************************************/
\r
286 * Sets the clock prescaler value of the global timer.
\r
290 * The 8-bit prescaler value to load. Valid range is 0-255.
\r
291 * Actual clock divisor ratio is this number plus one.
\r
293 * \retval ALT_E_SUCCESS The operation was successful.
\r
294 * \retval ALT_E_ERROR The operation failed.
\r
295 * \retval ALT_E_BAD_ARG Invalid input argument.
\r
297 ALT_STATUS_CODE alt_globaltmr_prescaler_set(uint32_t val);
\r
299 /******************************************************************************/
\r
301 * Sets a 32-bit global timer auto-increment value in the global
\r
302 * timer block for this CPU. The global timer continually increments its count
\r
303 * and when it reaches the value set in the comparator register or above, if
\r
304 * both comparison and free-run modes are selected, it adds the value set by this
\r
305 * function to the comparator value and saves it as the new comparator value.
\r
306 * This count then sets the time delay until the next global timer compare
\r
307 * value is reached.
\r
311 * Auto-increment value to set.
\r
313 * \retval ALT_E_SUCCESS The operation was successful.
\r
314 * \retval ALT_E_ERROR The operation failed.
\r
315 * \retval ALT_E_BAD_ARG Invalid input argument.
\r
317 ALT_STATUS_CODE alt_globaltmr_autoinc_set(uint32_t inc);
\r
319 /******************************************************************************/
\r
321 * Returns the global timer auto-increment value for this CPU. When the global
\r
322 * timer reaches the comparator value, if both comparison and free-run modes
\r
323 * are selected this value is added to the previous comparator value and saved
\r
324 * as the new comparator value.
\r
328 * The current comparator auto-increment value.
\r
330 uint32_t alt_globaltmr_autoinc_get(void);
\r
332 /******************************************************************************/
\r
334 * Enables the auto-increment function of the global timer for this CPU.
\r
337 * \retval ALT_E_SUCCESS The operation was successful.
\r
338 * \retval ALT_E_ERROR The operation failed.
\r
339 * \retval ALT_E_BAD_ARG Invalid input argument.
\r
341 ALT_STATUS_CODE alt_globaltmr_autoinc_mode_start(void);
\r
343 /******************************************************************************/
\r
345 * Disables the auto-increment function of the global timer for this CPU.
\r
348 * \retval ALT_E_SUCCESS The operation was successful.
\r
349 * \retval ALT_E_ERROR The operation failed.
\r
350 * \retval ALT_E_BAD_ARG Invalid input argument.
\r
352 ALT_STATUS_CODE alt_globaltmr_autoinc_mode_stop(void);
\r
354 /******************************************************************************/
\r
356 * Returns the auto-increment selection of the global timer for this CPU.
\r
359 * \retval FALSE Auto-increment mode is not enabled.
\r
360 * \retval TRUE Auto-increment mode is enabled.
\r
362 bool alt_globaltmr_is_autoinc_mode(void);
\r
364 /******************************************************************************/
\r
366 * Returns the maximum counter value available for \b CPU_GLOBAL_TMR. \n
\r
367 * The value returned does not factor in the value of the clock prescaler.
\r
372 * \retval uint32_t The maximum counter value available for this timer.
\r
373 * \retval 0 An error occurred.
\r
376 uint32_t alt_globaltmr_maxcounter_get(void);
\r
378 /******************************************************************************/
\r
380 * Disables the interrupt from the global timer module. Identical to calling
\r
381 * alt_gpt_int_disable() with tmr_id of \b CPU_GLOBAL_TMR.
\r
384 * \retval ALT_E_SUCCESS The operation was successful.
\r
385 * \retval ALT_E_ERROR The operation failed.
\r
386 * \retval ALT_E_BAD_ARG Invalid input argument.
\r
388 ALT_STATUS_CODE alt_globaltmr_int_disable(void);
\r
390 /******************************************************************************/
\r
395 * Enables the interrupt of the global timer
\r
396 * module. Identical to calling alt_gpt_int_enable() with tmr_id of
\r
397 * \b CPU_GLOBAL_TMR. If global timer is not already running, this function
\r
398 * returns an error.
\r
401 * \retval ALT_E_SUCCESS The operation was successful.
\r
402 * \retval ALT_E_ERROR The operation failed.
\r
404 ALT_STATUS_CODE alt_globaltmr_int_enable(void);
\r
409 * Enables the interrupt of the global timer
\r
410 * module. Identical to calling alt_gpt_int_enable() with tmr_id of
\r
411 * \b CPU_GLOBAL_TMR. If global timer is not already running, this function
\r
412 * attempts to start it.
\r
416 * \retval ALT_E_SUCCESS The operation was successful.
\r
417 * \retval ALT_E_ERROR The operation failed.
\r
419 ALT_STATUS_CODE alt_globaltmr_int_enable(void);
\r
423 /******************************************************************************/
\r
425 * Return \b TRUE if the interrupt of the global timer module is enabled
\r
426 * and \b FALSE if the interrupt is disabled or masked. Identical to calling
\r
427 * alt_gpt_int_is_enabled() with tmr_id of
\r
428 * \b CPU_GLOBAL_TMR.
\r
430 * \internal - note that there's more to this than just enabling the
\r
431 * interrupt and clearing the status.
\r
435 * \retval TRUE The timer interrupt is currently enabled.
\r
436 * \retval FALSE The timer interrupt is currently disabled.
\r
438 bool alt_globaltmr_int_is_enabled(void);
\r
440 /******************************************************************************/
\r
442 * Clear the pending interrupt status of the global timer module. Identical to
\r
443 * calling alt_gpt_int_clear_pending() with tmr_id of
\r
444 * \b CPU_GLOBAL_TMR.
\r
447 * \retval ALT_E_SUCCESS The operation was successful.
\r
448 * \retval ALT_E_ERROR The operation failed.
\r
449 * \retval ALT_E_BAD_ARG Invalid input argument.
\r
451 ALT_STATUS_CODE alt_globaltmr_int_clear_pending(void);
\r
453 /******************************************************************************/
\r
455 * Read the state (pending or not) of the interrupt of the global timer
\r
456 * module without changing the interrupt state. Identical to
\r
457 * calling alt_gpt_int_is_pending() with tmr_id of
\r
458 * \b CPU_GLOBAL_TMR.
\r
462 * \retval TRUE The timer interrupt is currently pending.
\r
463 * \retval FALSE The timer interrupt is not currently pending.
\r
465 bool alt_globaltmr_int_is_pending(void);
\r
467 /******************************************************************************/
\r
469 * Read the state of the interrupt of the global timer
\r
470 * module and if the interrupt is set, clear it. Identical to
\r
471 * calling alt_gpt_int_is_pending_and_clear() with tmr_id of
\r
472 * \b CPU_GLOBAL_TMR.
\r
476 * \retval TRUE The timer interrupt was pending.
\r
477 * \retval FALSE The timer interrupt was not pending.
\r
479 bool alt_globaltmr_int_if_pending_clear(void);
\r
487 #endif /* __cplusplus */
\r
488 #endif /* __ALT_GBLTMR_H__ */
\r