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