1 /*
2  *  Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
3  *
4  *  Redistribution and use in source and binary forms, with or without
5  *  modification, are permitted provided that the following conditions
6  *  are met:
7  *
8  *    Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *
11  *    Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the
14  *    distribution.
15  *
16  *    Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
33 //*****************************************************************************
34 //
35 //  timer.h
36 //
37 //  Prototypes for the timer module
38 //
39 //*****************************************************************************
40 
41 #ifndef __TIMER_H__
42 #define __TIMER_H__
43 
44 //*****************************************************************************
45 //
46 // If building with a C++ compiler, make all of the definitions in this header
47 // have a C binding.
48 //
49 //*****************************************************************************
50 #ifdef __cplusplus
51 extern "C"
52 {
53 #endif
54 
55 //*****************************************************************************
56 //
57 // Values that can be passed to TimerConfigure as the ulConfig parameter.
58 //
59 //*****************************************************************************
60 
61 #define TIMER_CFG_ONE_SHOT       0x00000021  // Full-width one-shot timer
62 #define TIMER_CFG_ONE_SHOT_UP    0x00000031  // Full-width one-shot up-count
63                                              // timer
64 #define TIMER_CFG_PERIODIC       0x00000022  // Full-width periodic timer
65 #define TIMER_CFG_PERIODIC_UP    0x00000032  // Full-width periodic up-count
66                                              // timer
67 #define TIMER_CFG_SPLIT_PAIR     0x04000000  // Two half-width timers
68 
69 #define TIMER_CFG_A_ONE_SHOT     0x00000021  // Timer A one-shot timer
70 #define TIMER_CFG_A_ONE_SHOT_UP  0x00000031  // Timer A one-shot up-count timer
71 #define TIMER_CFG_A_PERIODIC     0x00000022  // Timer A periodic timer
72 #define TIMER_CFG_A_PERIODIC_UP  0x00000032  // Timer A periodic up-count timer
73 #define TIMER_CFG_A_CAP_COUNT    0x00000003  // Timer A event counter
74 #define TIMER_CFG_A_CAP_COUNT_UP 0x00000013  // Timer A event up-counter
75 #define TIMER_CFG_A_CAP_TIME     0x00000007  // Timer A event timer
76 #define TIMER_CFG_A_CAP_TIME_UP  0x00000017  // Timer A event up-count timer
77 #define TIMER_CFG_A_PWM          0x0000000A  // Timer A PWM output
78 #define TIMER_CFG_B_ONE_SHOT     0x00002100  // Timer B one-shot timer
79 #define TIMER_CFG_B_ONE_SHOT_UP  0x00003100  // Timer B one-shot up-count timer
80 #define TIMER_CFG_B_PERIODIC     0x00002200  // Timer B periodic timer
81 #define TIMER_CFG_B_PERIODIC_UP  0x00003200  // Timer B periodic up-count timer
82 #define TIMER_CFG_B_CAP_COUNT    0x00000300  // Timer B event counter
83 #define TIMER_CFG_B_CAP_COUNT_UP 0x00001300  // Timer B event up-counter
84 #define TIMER_CFG_B_CAP_TIME     0x00000700  // Timer B event timer
85 #define TIMER_CFG_B_CAP_TIME_UP  0x00001700  // Timer B event up-count timer
86 #define TIMER_CFG_B_PWM          0x00000A00  // Timer B PWM output
87 
88 //*****************************************************************************
89 //
90 // Values that can be passed to TimerIntEnable, TimerIntDisable, and
91 // TimerIntClear as the ulIntFlags parameter, and returned from TimerIntStatus.
92 //
93 //*****************************************************************************
94 
95 #define TIMER_TIMB_DMA          0x00002000  // TimerB DMA Done interrupt
96 #define TIMER_TIMB_MATCH        0x00000800  // TimerB match interrupt
97 #define TIMER_CAPB_EVENT        0x00000400  // CaptureB event interrupt
98 #define TIMER_CAPB_MATCH        0x00000200  // CaptureB match interrupt
99 #define TIMER_TIMB_TIMEOUT      0x00000100  // TimerB time out interrupt
100 #define TIMER_TIMA_DMA          0x00000020  // TimerA DMA Done interrupt
101 #define TIMER_TIMA_MATCH        0x00000010  // TimerA match interrupt
102 #define TIMER_CAPA_EVENT        0x00000004  // CaptureA event interrupt
103 #define TIMER_CAPA_MATCH        0x00000002  // CaptureA match interrupt
104 #define TIMER_TIMA_TIMEOUT      0x00000001  // TimerA time out interrupt
105 
106 //*****************************************************************************
107 //
108 // Values that can be passed to TimerControlEvent as the ulEvent parameter.
109 //
110 //*****************************************************************************
111 #define TIMER_EVENT_POS_EDGE    0x00000000  // Count positive edges
112 #define TIMER_EVENT_NEG_EDGE    0x00000404  // Count negative edges
113 #define TIMER_EVENT_BOTH_EDGES  0x00000C0C  // Count both edges
114 
115 //*****************************************************************************
116 //
117 // Values that can be passed to most of the timer APIs as the ulTimer
118 // parameter.
119 //
120 //*****************************************************************************
121 #define TIMER_A                 0x000000ff  // Timer A
122 #define TIMER_B                 0x0000ff00  // Timer B
123 #define TIMER_BOTH              0x0000ffff  // Timer Both
124 
125 
126 //*****************************************************************************
127 //
128 // Values that can be passed to TimerSynchronize as the ulTimers parameter.
129 //
130 //*****************************************************************************
131 #define TIMER_0A_SYNC           0x00000001  // Synchronize Timer 0A
132 #define TIMER_0B_SYNC           0x00000002  // Synchronize Timer 0B
133 #define TIMER_1A_SYNC           0x00000004  // Synchronize Timer 1A
134 #define TIMER_1B_SYNC           0x00000008  // Synchronize Timer 1B
135 #define TIMER_2A_SYNC           0x00000010  // Synchronize Timer 2A
136 #define TIMER_2B_SYNC           0x00000020  // Synchronize Timer 2B
137 #define TIMER_3A_SYNC           0x00000040  // Synchronize Timer 3A
138 #define TIMER_3B_SYNC           0x00000080  // Synchronize Timer 3B
139 
140 //*****************************************************************************
141 //
142 // Values that can be passed to TimerDMAEventSet() or returned from
143 // TimerDMAEventGet().
144 //
145 //*****************************************************************************
146 #define TIMER_DMA_MODEMATCH_B   0x00000800
147 #define TIMER_DMA_CAPEVENT_B    0x00000400
148 #define TIMER_DMA_CAPMATCH_B    0x00000200
149 #define TIMER_DMA_TIMEOUT_B     0x00000100
150 #define TIMER_DMA_MODEMATCH_A   0x00000010
151 #define TIMER_DMA_CAPEVENT_A    0x00000004
152 #define TIMER_DMA_CAPMATCH_A    0x00000002
153 #define TIMER_DMA_TIMEOUT_A     0x00000001
154 
155 
156 //*****************************************************************************
157 //
158 // Prototypes for the APIs.
159 //
160 //*****************************************************************************
161 extern void TimerEnable(unsigned long ulBase, unsigned long ulTimer);
162 extern void TimerDisable(unsigned long ulBase, unsigned long ulTimer);
163 extern void TimerConfigure(unsigned long ulBase, unsigned long ulConfig);
164 extern void TimerControlLevel(unsigned long ulBase, unsigned long ulTimer,
165                               tBoolean bInvert);
166 extern void TimerControlEvent(unsigned long ulBase, unsigned long ulTimer,
167                               unsigned long ulEvent);
168 extern void TimerControlStall(unsigned long ulBase, unsigned long ulTimer,
169                               tBoolean bStall);
170 extern void TimerPrescaleSet(unsigned long ulBase, unsigned long ulTimer,
171                              unsigned long ulValue);
172 extern unsigned long TimerPrescaleGet(unsigned long ulBase,
173                                       unsigned long ulTimer);
174 extern void TimerPrescaleMatchSet(unsigned long ulBase, unsigned long ulTimer,
175                                   unsigned long ulValue);
176 extern unsigned long TimerPrescaleMatchGet(unsigned long ulBase,
177                                            unsigned long ulTimer);
178 extern void TimerLoadSet(unsigned long ulBase, unsigned long ulTimer,
179                          unsigned long ulValue);
180 extern unsigned long TimerLoadGet(unsigned long ulBase, unsigned long ulTimer);
181 
182 extern unsigned long TimerValueGet(unsigned long ulBase,
183                                    unsigned long ulTimer);
184 extern void TimerValueSet(unsigned long ulBase, unsigned long ulTimer,
185               unsigned long ulValue);
186 
187 extern void TimerMatchSet(unsigned long ulBase, unsigned long ulTimer,
188                           unsigned long ulValue);
189 extern unsigned long TimerMatchGet(unsigned long ulBase,
190                                    unsigned long ulTimer);
191 extern void TimerIntRegister(unsigned long ulBase, unsigned long ulTimer,
192                              void (*pfnHandler)(void));
193 extern void TimerIntUnregister(unsigned long ulBase, unsigned long ulTimer);
194 extern void TimerIntEnable(unsigned long ulBase, unsigned long ulIntFlags);
195 extern void TimerIntDisable(unsigned long ulBase, unsigned long ulIntFlags);
196 extern unsigned long TimerIntStatus(unsigned long ulBase, tBoolean bMasked);
197 extern void TimerIntClear(unsigned long ulBase, unsigned long ulIntFlags);
198 extern void TimerDMAEventSet(unsigned long ulBase, unsigned long ulDMAEvent);
199 extern unsigned long TimerDMAEventGet(unsigned long ulBase);
200 
201 
202 //*****************************************************************************
203 //
204 // Mark the end of the C bindings section for C++ compilers.
205 //
206 //*****************************************************************************
207 #ifdef __cplusplus
208 }
209 #endif
210 
211 #endif // __TIMER_H__
212