1 /*******************************************************************************
\r
2 * (c) Copyright 2007-2015 Microsemi SoC Products Group. All rights reserved.
\r
4 * CoreTimer public API.
\r
6 * SVN $Revision: 7967 $
\r
7 * SVN $Date: 2015-10-09 18:48:26 +0530 (Fri, 09 Oct 2015) $
\r
9 #ifndef CORE_TIMER_H_
\r
10 #define CORE_TIMER_H_
\r
12 #include "cpu_types.h"
\r
14 /***************************************************************************//**
\r
15 * The following definitions are used to select the CoreTimer driver operating
\r
16 * mode. They allow selecting continuous or one-shot mode.
\r
17 * 1. Continuous Mode
\r
18 * In continuous mode the timer's counter is decremented from the load value
\r
19 * until it reaches zero. The timer counter is automatically reloaded, with the
\r
20 * load value, upon reaching zero. An interrupt is generated every time the
\r
21 * counter reaches zero if interrupt is enabled.
\r
22 * This mode is typically used to generate an interrupt at constant time
\r
24 * 2. One-shot mode:
\r
25 * In one-shot mode, the counter decrements from the load value and until it
\r
26 * reaches zero. An interrupt can be generated, if enabled, when the counter
\r
27 * reaches zero. The timer's counter must be reloaded to begin counting down
\r
30 #define TMR_CONTINUOUS_MODE 0
\r
31 #define TMR_ONE_SHOT_MODE 1
\r
33 /***************************************************************************//**
\r
34 * The following definitions are used to configure the CoreTimer prescaler.
\r
35 * The prescaler is used to divide down the clock used to decrement the
\r
36 * CoreTimer counter. It can be configure to divide the clock by 2, 4, 8,
\r
37 * 16, 32, 64, 128, 256, 512, or 1024.
\r
39 #define PRESCALER_DIV_2 0
\r
40 #define PRESCALER_DIV_4 1
\r
41 #define PRESCALER_DIV_8 2
\r
42 #define PRESCALER_DIV_16 3
\r
43 #define PRESCALER_DIV_32 4
\r
44 #define PRESCALER_DIV_64 5
\r
45 #define PRESCALER_DIV_128 6
\r
46 #define PRESCALER_DIV_256 7
\r
47 #define PRESCALER_DIV_512 8
\r
48 #define PRESCALER_DIV_1024 9
\r
50 /***************************************************************************//**
\r
51 * There should be one instance of this structure for each instance of CoreTimer
\r
52 * in your system. The function TMR_init() initializes this structure. It is
\r
53 * used to identify the various CoreTimer hardware instances in your system.
\r
54 * An initialized timer instance structure should be passed as first parameter to
\r
55 * CoreTimer driver functions to identify which CoreTimer instance should perform
\r
56 * the requested operation.
\r
57 * Software using this driver should only need to create one single instance of
\r
58 * this data structure for each hardware timer instance in the system.
\r
60 typedef struct __timer_instance_t
\r
62 addr_t base_address;
\r
65 /***************************************************************************//**
\r
66 * The function TMR_init() initializes the data structures and sets relevant
\r
67 * CoreTimer registers. This function will prepare the Timer for use in a given
\r
68 * hardware/software configuration. It should be called before any other Timer
\r
70 * The timer will not start counting down immediately after this function is
\r
71 * called. It is necessary to call TMR_start() to start the timer decrementing.
\r
72 * The CoreTimer interrupt is disabled as part of this function.
\r
74 * @param this_timer Pointer to a timer_instance_t structure holding all
\r
75 * relevant data associated with the target timer hardware
\r
76 * instance. This pointer will be used to identify the
\r
77 * target CoreTimer hardware instance in subsequent calls
\r
78 * to the CoreTimer functions.
\r
79 * @param address Base address in the processor's memory map of the
\r
80 * registers of the CoreTimer instance being initialized.
\r
81 * @param mode This parameter is used to select the operating mode of
\r
82 * the timer driver. This can be either TMR_CONTINUOUS_MODE
\r
83 * or TMR_ONE_SHOT_MODE.
\r
84 * @param prescale This parameter is used to select the prescaler divider
\r
85 * used to divide down the clock used to decrement the
\r
86 * timer
\92s counter. This can be set using one of the
\r
87 * PRESCALER_DIV_<n> definitions, where <n> is the
\r
88 * divider
\92s value.
\r
89 * @param load_value This parameter is used to set the timer
\92s load value
\r
90 * from which the CoreTimer counter will decrement.
\r
91 * In Continuous mode, this value will be used to reload
\r
92 * the timer
\92s counter whenever it reaches zero.
\r
97 timer_instance_t * this_timer,
\r
101 uint32_t load_value
\r
104 /***************************************************************************//**
\r
105 * The function TMR_start() enables the timer to start counting down.
\r
106 * This function only needs to be called once after the timer has been
\r
107 * initialized through a call to TMR_init(). It does not need to be called after
\r
108 * each call to TMR_reload() when the timer is used in one-shot mode.
\r
110 * @param this_timer Pointer to a timer_instance_t structure holding all
\r
111 * relevant data associated with the target timer hardware
\r
112 * instance. This pointer is used to identify the target
\r
113 * CoreTimer hardware instance.
\r
118 timer_instance_t * this_timer
\r
121 /***************************************************************************//**
\r
122 * The function TMR_stop() stops the timer counting down. It can be used to
\r
123 * stop interrupts from being generated when continuous mode is used and
\r
124 * interrupts must be paused from being generated.
\r
126 * @param this_timer Pointer to a timer_instance_t structure holding all
\r
127 * relevant data associated with the target timer hardware
\r
128 * instance. This pointer is used to identify the target
\r
129 * CoreTimer hardware instance.
\r
134 timer_instance_t * this_timer
\r
137 /***************************************************************************//**
\r
138 * The function TMR_enable_int() enables the timer interrupt. A call to this
\r
139 * function will allow the interrupt signal coming out of CoreTimer to be
\r
142 * @param this_timer Pointer to a timer_instance_t structure holding all
\r
143 * relevant data associated with the target timer hardware
\r
144 * instance. This pointer is used to identify the target
\r
145 * CoreTimer hardware instance.
\r
150 timer_instance_t * this_timer
\r
153 /***************************************************************************//**
\r
154 * The function TMR_clear_int() clears the timer interrupt. This function should
\r
155 * be called within the interrupt handler servicing interrupts from the timer.
\r
156 * Failure to clear the timer interrupt will result in the interrupt signal
\r
157 * generating from CoreTimer to remain asserted. This assertion may cause the
\r
158 * interrupt service routine to be continuously called, causing the system to
\r
161 * @param this_timer Pointer to a timer_instance_t structure holding all
\r
162 * relevant data associated with the target timer hardware
\r
163 * instance. This pointer is used to identify the target
\r
164 * CoreTimer hardware instance.
\r
169 timer_instance_t * this_timer
\r
172 /***************************************************************************//**
\r
173 * The TMR_current_value() function returns the current value of the counter.
\r
175 * @param this_timer Pointer to a timer_instance_t structure holding all
\r
176 * relevant data associated with the target timer hardware
\r
177 * instance. This pointer is used to identify the target
\r
178 * CoreTimer hardware instance.
\r
180 * @return Returns the current value of the timer counter value.
\r
185 timer_instance_t * this_timer
\r
188 /***************************************************************************//**
\r
189 * The TMR_reload() function is used in one-shot mode. It reloads the timer
\r
190 * counter with the values passed as parameter. This will result in an interrupt
\r
191 * being generated when the timer counter reaches 0 if interrupt is enabled.
\r
193 * @param this_timer Pointer to a timer_instance_t structure holding all
\r
194 * relevant data associated with the target timer hardware
\r
195 * instance. This pointer is used to identify the target
\r
196 * CoreTimer hardware instance.
\r
197 * @param load_value This parameter sets the value from which the CoreTimer
\r
198 * counter will decrement.
\r
202 timer_instance_t * this_timer,
\r
203 uint32_t load_value
\r
206 #endif /* CORE_TIMER_H_ */
\r