1 //*****************************************************************************
2 //
3 // pwm.h - API function protoypes for Pulse Width Modulation (PWM) ports
4 //
5 // Copyright (c) 2005-2012 Texas Instruments Incorporated.  All rights reserved.
6 // Software License Agreement
7 //
8 //   Redistribution and use in source and binary forms, with or without
9 //   modification, are permitted provided that the following conditions
10 //   are met:
11 //
12 //   Redistributions of source code must retain the above copyright
13 //   notice, this list of conditions and the following disclaimer.
14 //
15 //   Redistributions in binary form must reproduce the above copyright
16 //   notice, this list of conditions and the following disclaimer in the
17 //   documentation and/or other materials provided with the
18 //   distribution.
19 //
20 //   Neither the name of Texas Instruments Incorporated nor the names of
21 //   its contributors may be used to endorse or promote products derived
22 //   from this software without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 //
36 // This is part of revision 9453 of the Stellaris Peripheral Driver Library.
37 //
38 //*****************************************************************************
39 
40 #ifndef __PWM_H__
41 #define __PWM_H__
42 
43 //*****************************************************************************
44 //
45 // If building with a C++ compiler, make all of the definitions in this header
46 // have a C binding.
47 //
48 //*****************************************************************************
49 #ifdef __cplusplus
50 extern "C"
51 {
52 #endif
53 
54 //*****************************************************************************
55 //
56 // The following defines are passed to PWMGenConfigure() as the ulConfig
57 // parameter and specify the configuration of the PWM generator.
58 //
59 //*****************************************************************************
60 #define PWM_GEN_MODE_DOWN       0x00000000  // Down count mode
61 #define PWM_GEN_MODE_UP_DOWN    0x00000002  // Up/Down count mode
62 #define PWM_GEN_MODE_SYNC       0x00000038  // Synchronous updates
63 #define PWM_GEN_MODE_NO_SYNC    0x00000000  // Immediate updates
64 #define PWM_GEN_MODE_DBG_RUN    0x00000004  // Continue running in debug mode
65 #define PWM_GEN_MODE_DBG_STOP   0x00000000  // Stop running in debug mode
66 #define PWM_GEN_MODE_FAULT_LATCHED \
67                                 0x00040000  // Fault is latched
68 #define PWM_GEN_MODE_FAULT_UNLATCHED \
69                                 0x00000000  // Fault is not latched
70 #define PWM_GEN_MODE_FAULT_MINPER \
71                                 0x00020000  // Enable min fault period
72 #define PWM_GEN_MODE_FAULT_NO_MINPER \
73                                 0x00000000  // Disable min fault period
74 #define PWM_GEN_MODE_FAULT_EXT  0x00010000  // Enable extended fault support
75 #define PWM_GEN_MODE_FAULT_LEGACY \
76                                 0x00000000  // Disable extended fault support
77 #define PWM_GEN_MODE_DB_NO_SYNC 0x00000000  // Deadband updates occur
78                                             // immediately
79 #define PWM_GEN_MODE_DB_SYNC_LOCAL \
80                                 0x0000A800  // Deadband updates locally
81                                             // synchronized
82 #define PWM_GEN_MODE_DB_SYNC_GLOBAL \
83                                 0x0000FC00  // Deadband updates globally
84                                             // synchronized
85 #define PWM_GEN_MODE_GEN_NO_SYNC \
86                                 0x00000000  // Generator mode updates occur
87                                             // immediately
88 #define PWM_GEN_MODE_GEN_SYNC_LOCAL \
89                                 0x00000280  // Generator mode updates locally
90                                             // synchronized
91 #define PWM_GEN_MODE_GEN_SYNC_GLOBAL \
92                                 0x000003C0  // Generator mode updates globally
93                                             // synchronized
94 
95 //*****************************************************************************
96 //
97 // Defines for enabling, disabling, and clearing PWM generator interrupts and
98 // triggers.
99 //
100 //*****************************************************************************
101 #define PWM_INT_CNT_ZERO        0x00000001  // Int if COUNT = 0
102 #define PWM_INT_CNT_LOAD        0x00000002  // Int if COUNT = LOAD
103 #define PWM_INT_CNT_AU          0x00000004  // Int if COUNT = CMPA U
104 #define PWM_INT_CNT_AD          0x00000008  // Int if COUNT = CMPA D
105 #define PWM_INT_CNT_BU          0x00000010  // Int if COUNT = CMPA U
106 #define PWM_INT_CNT_BD          0x00000020  // Int if COUNT = CMPA D
107 #define PWM_TR_CNT_ZERO         0x00000100  // Trig if COUNT = 0
108 #define PWM_TR_CNT_LOAD         0x00000200  // Trig if COUNT = LOAD
109 #define PWM_TR_CNT_AU           0x00000400  // Trig if COUNT = CMPA U
110 #define PWM_TR_CNT_AD           0x00000800  // Trig if COUNT = CMPA D
111 #define PWM_TR_CNT_BU           0x00001000  // Trig if COUNT = CMPA U
112 #define PWM_TR_CNT_BD           0x00002000  // Trig if COUNT = CMPA D
113 
114 //*****************************************************************************
115 //
116 // Defines for enabling, disabling, and clearing PWM interrupts.
117 //
118 //*****************************************************************************
119 #define PWM_INT_GEN_0           0x00000001  // Generator 0 interrupt
120 #define PWM_INT_GEN_1           0x00000002  // Generator 1 interrupt
121 #define PWM_INT_GEN_2           0x00000004  // Generator 2 interrupt
122 #define PWM_INT_GEN_3           0x00000008  // Generator 3 interrupt
123 #ifndef DEPRECATED
124 #define PWM_INT_FAULT           0x00010000  // Fault interrupt
125 #endif
126 #define PWM_INT_FAULT0          0x00010000  // Fault0 interrupt
127 #define PWM_INT_FAULT1          0x00020000  // Fault1 interrupt
128 #define PWM_INT_FAULT2          0x00040000  // Fault2 interrupt
129 #define PWM_INT_FAULT3          0x00080000  // Fault3 interrupt
130 #define PWM_INT_FAULT_M         0x000F0000  // Fault interrupt source mask
131 
132 //*****************************************************************************
133 //
134 // Defines to identify the generators within a module.
135 //
136 //*****************************************************************************
137 #define PWM_GEN_0               0x00000040  // Offset address of Gen0
138 #define PWM_GEN_1               0x00000080  // Offset address of Gen1
139 #define PWM_GEN_2               0x000000C0  // Offset address of Gen2
140 #define PWM_GEN_3               0x00000100  // Offset address of Gen3
141 
142 #define PWM_GEN_0_BIT           0x00000001  // Bit-wise ID for Gen0
143 #define PWM_GEN_1_BIT           0x00000002  // Bit-wise ID for Gen1
144 #define PWM_GEN_2_BIT           0x00000004  // Bit-wise ID for Gen2
145 #define PWM_GEN_3_BIT           0x00000008  // Bit-wise ID for Gen3
146 
147 #define PWM_GEN_EXT_0           0x00000800  // Offset of Gen0 ext address range
148 #define PWM_GEN_EXT_1           0x00000880  // Offset of Gen1 ext address range
149 #define PWM_GEN_EXT_2           0x00000900  // Offset of Gen2 ext address range
150 #define PWM_GEN_EXT_3           0x00000980  // Offset of Gen3 ext address range
151 
152 //*****************************************************************************
153 //
154 // Defines to identify the outputs within a module.
155 //
156 //*****************************************************************************
157 #define PWM_OUT_0               0x00000040  // Encoded offset address of PWM0
158 #define PWM_OUT_1               0x00000041  // Encoded offset address of PWM1
159 #define PWM_OUT_2               0x00000082  // Encoded offset address of PWM2
160 #define PWM_OUT_3               0x00000083  // Encoded offset address of PWM3
161 #define PWM_OUT_4               0x000000C4  // Encoded offset address of PWM4
162 #define PWM_OUT_5               0x000000C5  // Encoded offset address of PWM5
163 #define PWM_OUT_6               0x00000106  // Encoded offset address of PWM6
164 #define PWM_OUT_7               0x00000107  // Encoded offset address of PWM7
165 
166 #define PWM_OUT_0_BIT           0x00000001  // Bit-wise ID for PWM0
167 #define PWM_OUT_1_BIT           0x00000002  // Bit-wise ID for PWM1
168 #define PWM_OUT_2_BIT           0x00000004  // Bit-wise ID for PWM2
169 #define PWM_OUT_3_BIT           0x00000008  // Bit-wise ID for PWM3
170 #define PWM_OUT_4_BIT           0x00000010  // Bit-wise ID for PWM4
171 #define PWM_OUT_5_BIT           0x00000020  // Bit-wise ID for PWM5
172 #define PWM_OUT_6_BIT           0x00000040  // Bit-wise ID for PWM6
173 #define PWM_OUT_7_BIT           0x00000080  // Bit-wise ID for PWM7
174 
175 //*****************************************************************************
176 //
177 // Defines to identify each of the possible fault trigger conditions in
178 // PWM_FAULT_GROUP_0.
179 //
180 //*****************************************************************************
181 #define PWM_FAULT_GROUP_0       0
182 
183 #define PWM_FAULT_FAULT0        0x00000001
184 #define PWM_FAULT_FAULT1        0x00000002
185 #define PWM_FAULT_FAULT2        0x00000004
186 #define PWM_FAULT_FAULT3        0x00000008
187 #define PWM_FAULT_ACMP0         0x00010000
188 #define PWM_FAULT_ACMP1         0x00020000
189 #define PWM_FAULT_ACMP2         0x00040000
190 
191 //*****************************************************************************
192 //
193 // Defines to identify each of the possible fault trigger conditions in
194 // PWM_FAULT_GROUP_1.
195 //
196 //*****************************************************************************
197 #define PWM_FAULT_GROUP_1       1
198 
199 #define PWM_FAULT_DCMP0         0x00000001
200 #define PWM_FAULT_DCMP1         0x00000002
201 #define PWM_FAULT_DCMP2         0x00000004
202 #define PWM_FAULT_DCMP3         0x00000008
203 #define PWM_FAULT_DCMP4         0x00000010
204 #define PWM_FAULT_DCMP5         0x00000020
205 #define PWM_FAULT_DCMP6         0x00000040
206 #define PWM_FAULT_DCMP7         0x00000080
207 
208 //*****************************************************************************
209 //
210 // Defines to identify the sense of each of the external FAULTn signals
211 //
212 //*****************************************************************************
213 #define PWM_FAULT0_SENSE_HIGH   0x00000000
214 #define PWM_FAULT0_SENSE_LOW    0x00000001
215 #define PWM_FAULT1_SENSE_HIGH   0x00000000
216 #define PWM_FAULT1_SENSE_LOW    0x00000002
217 #define PWM_FAULT2_SENSE_HIGH   0x00000000
218 #define PWM_FAULT2_SENSE_LOW    0x00000004
219 #define PWM_FAULT3_SENSE_HIGH   0x00000000
220 #define PWM_FAULT3_SENSE_LOW    0x00000008
221 
222 //*****************************************************************************
223 //
224 // API Function prototypes
225 //
226 //*****************************************************************************
227 extern void PWMGenConfigure(unsigned long ulBase, unsigned long ulGen,
228                             unsigned long ulConfig);
229 extern void PWMGenPeriodSet(unsigned long ulBase, unsigned long ulGen,
230                             unsigned long ulPeriod);
231 extern unsigned long PWMGenPeriodGet(unsigned long ulBase,
232                                      unsigned long ulGen);
233 extern void PWMGenEnable(unsigned long ulBase, unsigned long ulGen);
234 extern void PWMGenDisable(unsigned long ulBase, unsigned long ulGen);
235 extern void PWMPulseWidthSet(unsigned long ulBase, unsigned long ulPWMOut,
236                              unsigned long ulWidth);
237 extern unsigned long PWMPulseWidthGet(unsigned long ulBase,
238                                       unsigned long ulPWMOut);
239 extern void PWMDeadBandEnable(unsigned long ulBase, unsigned long ulGen,
240                               unsigned short usRise, unsigned short usFall);
241 extern void PWMDeadBandDisable(unsigned long ulBase, unsigned long ulGen);
242 extern void PWMSyncUpdate(unsigned long ulBase, unsigned long ulGenBits);
243 extern void PWMSyncTimeBase(unsigned long ulBase, unsigned long ulGenBits);
244 extern void PWMOutputState(unsigned long ulBase, unsigned long ulPWMOutBits,
245                            tBoolean bEnable);
246 extern void PWMOutputInvert(unsigned long ulBase, unsigned long ulPWMOutBits,
247                             tBoolean bInvert);
248 extern void PWMOutputFaultLevel(unsigned long ulBase,
249                                 unsigned long ulPWMOutBits,
250                                 tBoolean bDriveHigh);
251 extern void PWMOutputFault(unsigned long ulBase, unsigned long ulPWMOutBits,
252                            tBoolean bFaultSuppress);
253 extern void PWMGenIntRegister(unsigned long ulBase, unsigned long ulGen,
254                               void (*pfnIntHandler)(void));
255 extern void PWMGenIntUnregister(unsigned long ulBase, unsigned long ulGen);
256 extern void PWMFaultIntRegister(unsigned long ulBase,
257                                 void (*pfnIntHandler)(void));
258 extern void PWMFaultIntUnregister(unsigned long ulBase);
259 extern void PWMGenIntTrigEnable(unsigned long ulBase, unsigned long ulGen,
260                                 unsigned long ulIntTrig);
261 extern void PWMGenIntTrigDisable(unsigned long ulBase, unsigned long ulGen,
262                                  unsigned long ulIntTrig);
263 extern unsigned long PWMGenIntStatus(unsigned long ulBase, unsigned long ulGen,
264                                      tBoolean bMasked);
265 extern void PWMGenIntClear(unsigned long ulBase, unsigned long ulGen,
266                            unsigned long ulInts);
267 extern void PWMIntEnable(unsigned long ulBase, unsigned long ulGenFault);
268 extern void PWMIntDisable(unsigned long ulBase, unsigned long ulGenFault);
269 extern void PWMFaultIntClear(unsigned long ulBase);
270 extern unsigned long PWMIntStatus(unsigned long ulBase, tBoolean bMasked);
271 extern void PWMFaultIntClearExt(unsigned long ulBase,
272                                 unsigned long ulFaultInts);
273 extern void PWMGenFaultConfigure(unsigned long ulBase, unsigned long ulGen,
274                                  unsigned long ulMinFaultPeriod,
275                                  unsigned long ulFaultSenses);
276 extern void PWMGenFaultTriggerSet(unsigned long ulBase, unsigned long ulGen,
277                                   unsigned long ulGroup,
278                                   unsigned long ulFaultTriggers);
279 extern unsigned long PWMGenFaultTriggerGet(unsigned long ulBase,
280                                            unsigned long ulGen,
281                                            unsigned long ulGroup);
282 extern unsigned long PWMGenFaultStatus(unsigned long ulBase,
283                                        unsigned long ulGen,
284                                        unsigned long ulGroup);
285 extern void PWMGenFaultClear(unsigned long ulBase, unsigned long ulGen,
286                              unsigned long ulGroup,
287                              unsigned long ulFaultTriggers);
288 
289 //*****************************************************************************
290 //
291 // Mark the end of the C bindings section for C++ compilers.
292 //
293 //*****************************************************************************
294 #ifdef __cplusplus
295 }
296 #endif
297 
298 #endif // __PWM_H__
299