1 //*****************************************************************************
2 //
3 // pwm.c - API for the PWM modules
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 //*****************************************************************************
41 //
42 //! \addtogroup pwm_api
43 //! @{
44 //
45 //*****************************************************************************
46
47 #include "inc/hw_ints.h"
48 #include "inc/hw_memmap.h"
49 #include "inc/hw_pwm.h"
50 #include "inc/hw_sysctl.h"
51 #include "inc/hw_types.h"
52 #include "driverlib/debug.h"
53 #include "driverlib/interrupt.h"
54 #include "driverlib/pwm.h"
55
56 //*****************************************************************************
57 //
58 // Misc macros for manipulating the encoded generator and output defines used
59 // by the API.
60 //
61 //*****************************************************************************
62 #define PWM_GEN_BADDR(_mod_, _gen_) \
63 ((_mod_) + (_gen_))
64 #define PWM_GEN_EXT_BADDR(_mod_, _gen_) \
65 ((_mod_) + PWM_GEN_EXT_0 + \
66 ((_gen_) - PWM_GEN_0) * 2)
67 #define PWM_OUT_BADDR(_mod_, _out_) \
68 ((_mod_) + ((_out_) & 0xFFFFFFC0))
69 #define PWM_IS_OUTPUT_ODD(_out_) \
70 ((_out_) & 0x00000001)
71
72 //*****************************************************************************
73 //
74 //! \internal
75 //! Checks a PWM generator number.
76 //!
77 //! \param ulGen is the generator number.
78 //!
79 //! This function determines if a PWM generator number is valid.
80 //!
81 //! \return Returnes \b true if the generator number is valid and \b false
82 //! otherwise.
83 //
84 //*****************************************************************************
85 #ifdef DEBUG
86 static tBoolean
PWMGenValid(unsigned long ulGen)87 PWMGenValid(unsigned long ulGen)
88 {
89 return((ulGen == PWM_GEN_0) || (ulGen == PWM_GEN_1) ||
90 (ulGen == PWM_GEN_2) || (ulGen == PWM_GEN_3));
91 }
92 #endif
93
94 //*****************************************************************************
95 //
96 //! \internal
97 //! Checks a PWM output number.
98 //!
99 //! \param ulPWMOut is the output number.
100 //!
101 //! This function determines if a PWM output number is valid.
102 //!
103 //! \return Returns \b true if the output number is valid and \b false
104 //! otherwise.
105 //
106 //*****************************************************************************
107 #ifdef DEBUG
108 static tBoolean
PWMOutValid(unsigned long ulPWMOut)109 PWMOutValid(unsigned long ulPWMOut)
110 {
111 return((ulPWMOut == PWM_OUT_0) || (ulPWMOut == PWM_OUT_1) ||
112 (ulPWMOut == PWM_OUT_2) || (ulPWMOut == PWM_OUT_3) ||
113 (ulPWMOut == PWM_OUT_4) || (ulPWMOut == PWM_OUT_5) ||
114 (ulPWMOut == PWM_OUT_6) || (ulPWMOut == PWM_OUT_7));
115 }
116 #endif
117
118 //*****************************************************************************
119 //
120 //! Configures a PWM generator.
121 //!
122 //! \param ulBase is the base address of the PWM module.
123 //! \param ulGen is the PWM generator to configure. This parameter must be one
124 //! of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
125 //! \param ulConfig is the configuration for the PWM generator.
126 //!
127 //! This function is used to set the mode of operation for a PWM generator.
128 //! The counting mode, synchronization mode, and debug behavior are all
129 //! configured. After configuration, the generator is left in the disabled
130 //! state.
131 //!
132 //! A PWM generator can count in two different modes: count down mode or count
133 //! up/down mode. In count down mode, it counts from a value down to zero,
134 //! and then resets to the preset value, producing left-aligned PWM
135 //! signals (that is, the rising edge of the two PWM signals produced by the
136 //! generator occur at the same time). In count up/down mode, it counts up
137 //! from zero to the preset value, counts back down to zero, and then repeats
138 //! the process, producing center-aligned PWM signals (that is,
139 //! the middle of the high/low period of the PWM signals produced by the
140 //! generator occurs at the same time).
141 //!
142 //! When the PWM generator parameters (period and pulse width) are modified,
143 //! their effect on the output PWM signals can be delayed. In synchronous
144 //! mode, the parameter updates are not applied until a synchronization event
145 //! occurs. This mode allows multiple parameters to be modified and take
146 //! effect simultaneously, instead of one at a time. Additionally, parameters
147 //! to multiple PWM generators in synchronous mode can be updated
148 //! simultaneously, allowing them to be treated as if they were a unified
149 //! generator. In non-synchronous mode, the parameter updates are not delayed
150 //! until a synchronization event. In either mode, the parameter updates only
151 //! occur when the counter is at zero to help prevent oddly formed PWM signals
152 //! during the update (that is, a PWM pulse that is too short or too long).
153 //!
154 //! The PWM generator can either pause or continue running when the processor
155 //! is stopped via the debugger. If configured to pause, it continues to
156 //! count until it reaches zero, at which point it pauses until the
157 //! processor is restarted. If configured to continue running, it keeps
158 //! counting as if nothing had happened.
159 //!
160 //! The \e ulConfig parameter contains the desired configuration. It is the
161 //! logical OR of the following:
162 //!
163 //! - \b PWM_GEN_MODE_DOWN or \b PWM_GEN_MODE_UP_DOWN to specify the counting
164 //! mode
165 //! - \b PWM_GEN_MODE_SYNC or \b PWM_GEN_MODE_NO_SYNC to specify the counter
166 //! load and comparator update synchronization mode
167 //! - \b PWM_GEN_MODE_DBG_RUN or \b PWM_GEN_MODE_DBG_STOP to specify the debug
168 //! behavior
169 //! - \b PWM_GEN_MODE_GEN_NO_SYNC, \b PWM_GEN_MODE_GEN_SYNC_LOCAL, or
170 //! \b PWM_GEN_MODE_GEN_SYNC_GLOBAL to specify the update synchronization
171 //! mode for generator counting mode changes
172 //! - \b PWM_GEN_MODE_DB_NO_SYNC, \b PWM_GEN_MODE_DB_SYNC_LOCAL, or
173 //! \b PWM_GEN_MODE_DB_SYNC_GLOBAL to specify the deadband parameter
174 //! synchronization mode
175 //! - \b PWM_GEN_MODE_FAULT_LATCHED or \b PWM_GEN_MODE_FAULT_UNLATCHED to
176 //! specify whether fault conditions are latched or not
177 //! - \b PWM_GEN_MODE_FAULT_MINPER or \b PWM_GEN_MODE_FAULT_NO_MINPER to
178 //! specify whether minimum fault period support is required
179 //! - \b PWM_GEN_MODE_FAULT_EXT or \b PWM_GEN_MODE_FAULT_LEGACY to specify
180 //! whether extended fault source selection support is enabled or not
181 //!
182 //! Setting \b PWM_GEN_MODE_FAULT_MINPER allows an application to set the
183 //! minimum duration of a PWM fault signal. Faults are signaled for at
184 //! least this time even if the external fault pin deasserts earlier. Care
185 //! should be taken when using this mode because during the fault signal
186 //! period, the fault interrupt from the PWM generator remains asserted. The
187 //! fault interrupt handler may, therefore, reenter immediately if it exits
188 //! prior to expiration of the fault timer.
189 //!
190 //! \note Changes to the counter mode affect the period of the PWM signals
191 //! produced. PWMGenPeriodSet() and PWMPulseWidthSet() should be called after
192 //! any changes to the counter mode of a generator.
193 //!
194 //! \return None.
195 //
196 //*****************************************************************************
197 void
PWMGenConfigure(unsigned long ulBase,unsigned long ulGen,unsigned long ulConfig)198 PWMGenConfigure(unsigned long ulBase, unsigned long ulGen,
199 unsigned long ulConfig)
200 {
201 //
202 // Check the arguments.
203 //
204 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
205 ASSERT(PWMGenValid(ulGen));
206
207 //
208 // Compute the generator's base address.
209 //
210 ulGen = PWM_GEN_BADDR(ulBase, ulGen);
211
212 //
213 // Change the global configuration of the generator.
214 //
215 HWREG(ulGen + PWM_O_X_CTL) = ((HWREG(ulGen + PWM_O_X_CTL) &
216 ~(PWM_X_CTL_MODE | PWM_X_CTL_DEBUG |
217 PWM_X_CTL_LATCH | PWM_X_CTL_MINFLTPER |
218 PWM_X_CTL_FLTSRC | PWM_X_CTL_DBFALLUPD_M |
219 PWM_X_CTL_DBRISEUPD_M |
220 PWM_X_CTL_DBCTLUPD_M |
221 PWM_X_CTL_GENBUPD_M |
222 PWM_X_CTL_GENAUPD_M |
223 PWM_X_CTL_LOADUPD | PWM_X_CTL_CMPAUPD |
224 PWM_X_CTL_CMPBUPD)) | ulConfig);
225
226 //
227 // Set the individual PWM generator controls.
228 //
229 if(ulConfig & PWM_X_CTL_MODE)
230 {
231 //
232 // In up/down count mode, set the signal high on up count comparison
233 // and low on down count comparison (that is, center align the
234 // signals).
235 //
236 HWREG(ulGen + PWM_O_X_GENA) = (PWM_X_GENA_ACTCMPAU_ONE |
237 PWM_X_GENA_ACTCMPAD_ZERO);
238 HWREG(ulGen + PWM_O_X_GENB) = (PWM_X_GENB_ACTCMPBU_ONE |
239 PWM_X_GENB_ACTCMPBD_ZERO);
240 }
241 else
242 {
243 //
244 // In down count mode, set the signal high on load and low on count
245 // comparison (that is, left align the signals).
246 //
247 HWREG(ulGen + PWM_O_X_GENA) = (PWM_X_GENA_ACTLOAD_ONE |
248 PWM_X_GENA_ACTCMPAD_ZERO);
249 HWREG(ulGen + PWM_O_X_GENB) = (PWM_X_GENB_ACTLOAD_ONE |
250 PWM_X_GENB_ACTCMPBD_ZERO);
251 }
252 }
253
254 //*****************************************************************************
255 //
256 //! Sets the period of a PWM generator.
257 //!
258 //! \param ulBase is the base address of the PWM module.
259 //! \param ulGen is the PWM generator to be modified. This parameter must be
260 //! one of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
261 //! \param ulPeriod specifies the period of PWM generator output, measured
262 //! in clock ticks.
263 //!
264 //! This function sets the period of the specified PWM generator block, where
265 //! the period of the generator block is defined as the number of PWM clock
266 //! ticks between pulses on the generator block zero signal.
267 //!
268 //! \note Any subsequent calls made to this function before an update occurs
269 //! cause the previous values to be overwritten.
270 //!
271 //! \return None.
272 //
273 //*****************************************************************************
274 void
PWMGenPeriodSet(unsigned long ulBase,unsigned long ulGen,unsigned long ulPeriod)275 PWMGenPeriodSet(unsigned long ulBase, unsigned long ulGen,
276 unsigned long ulPeriod)
277 {
278 //
279 // Check the arguments.
280 //
281 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
282 ASSERT(PWMGenValid(ulGen));
283
284 //
285 // Compute the generator's base address.
286 //
287 ulGen = PWM_GEN_BADDR(ulBase, ulGen);
288
289 //
290 // Set the reload register based on the mode.
291 //
292 if(HWREG(ulGen + PWM_O_X_CTL) & PWM_X_CTL_MODE)
293 {
294 //
295 // In up/down count mode, set the reload register to half the requested
296 // period.
297 //
298 ASSERT((ulPeriod / 2) < 65536);
299 HWREG(ulGen + PWM_O_X_LOAD) = ulPeriod / 2;
300 }
301 else
302 {
303 //
304 // In down count mode, set the reload register to the requested period
305 // minus one.
306 //
307 ASSERT((ulPeriod <= 65536) && (ulPeriod != 0));
308 HWREG(ulGen + PWM_O_X_LOAD) = ulPeriod - 1;
309 }
310 }
311
312 //*****************************************************************************
313 //
314 //! Gets the period of a PWM generator block.
315 //!
316 //! \param ulBase is the base address of the PWM module.
317 //! \param ulGen is the PWM generator to query. This parameter must be one of
318 //! \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
319 //!
320 //! This function gets the period of the specified PWM generator block. The
321 //! period of the generator block is defined as the number of PWM clock ticks
322 //! between pulses on the generator block zero signal.
323 //!
324 //! If the update of the counter for the specified PWM generator has yet
325 //! to be completed, the value returned may not be the active period. The
326 //! value returned is the programmed period, measured in PWM clock ticks.
327 //!
328 //! \return Returns the programmed period of the specified generator block
329 //! in PWM clock ticks.
330 //
331 //*****************************************************************************
332 unsigned long
PWMGenPeriodGet(unsigned long ulBase,unsigned long ulGen)333 PWMGenPeriodGet(unsigned long ulBase, unsigned long ulGen)
334 {
335 //
336 // Check the arguments.
337 //
338 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
339 ASSERT(PWMGenValid(ulGen));
340
341 //
342 // Compute the generator's base address.
343 //
344 ulGen = PWM_GEN_BADDR(ulBase, ulGen);
345
346 //
347 // Figure out the counter mode.
348 //
349 if(HWREG(ulGen + PWM_O_X_CTL) & PWM_X_CTL_MODE)
350 {
351 //
352 // The period is twice the reload register value.
353 //
354 return(HWREG(ulGen + PWM_O_X_LOAD) * 2);
355 }
356 else
357 {
358 //
359 // The period is the reload register value plus one.
360 //
361 return(HWREG(ulGen + PWM_O_X_LOAD) + 1);
362 }
363 }
364
365 //*****************************************************************************
366 //
367 //! Enables the timer/counter for a PWM generator block.
368 //!
369 //! \param ulBase is the base address of the PWM module.
370 //! \param ulGen is the PWM generator to be enabled. This parameter must be
371 //! one of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
372 //!
373 //! This function allows the PWM clock to drive the timer/counter for the
374 //! specified generator block.
375 //!
376 //! \return None.
377 //
378 //*****************************************************************************
379 void
PWMGenEnable(unsigned long ulBase,unsigned long ulGen)380 PWMGenEnable(unsigned long ulBase, unsigned long ulGen)
381 {
382 //
383 // Check the arguments.
384 //
385 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
386 ASSERT(PWMGenValid(ulGen));
387
388 //
389 // Enable the PWM generator.
390 //
391 HWREG(PWM_GEN_BADDR(ulBase, ulGen) + PWM_O_X_CTL) |= PWM_X_CTL_ENABLE;
392 }
393
394 //*****************************************************************************
395 //
396 //! Disables the timer/counter for a PWM generator block.
397 //!
398 //! \param ulBase is the base address of the PWM module.
399 //! \param ulGen is the PWM generator to be disabled. This parameter must be
400 //! one of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
401 //!
402 //! This function blocks the PWM clock from driving the timer/counter for the
403 //! specified generator block.
404 //!
405 //! \return None.
406 //
407 //*****************************************************************************
408 void
PWMGenDisable(unsigned long ulBase,unsigned long ulGen)409 PWMGenDisable(unsigned long ulBase, unsigned long ulGen)
410 {
411 //
412 // Check the arguments.
413 //
414 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
415 ASSERT(PWMGenValid(ulGen));
416
417 //
418 // Disable the PWM generator.
419 //
420 HWREG(PWM_GEN_BADDR(ulBase, + ulGen) + PWM_O_X_CTL) &= ~(PWM_X_CTL_ENABLE);
421 }
422
423 //*****************************************************************************
424 //
425 //! Sets the pulse width for the specified PWM output.
426 //!
427 //! \param ulBase is the base address of the PWM module.
428 //! \param ulPWMOut is the PWM output to modify. This parameter must be one
429 //! of \b PWM_OUT_0, \b PWM_OUT_1, \b PWM_OUT_2, \b PWM_OUT_3, \b PWM_OUT_4,
430 //! \b PWM_OUT_5, \b PWM_OUT_6, or \b PWM_OUT_7.
431 //! \param ulWidth specifies the width of the positive portion of the pulse.
432 //!
433 //! This function sets the pulse width for the specified PWM output, where the
434 //! pulse width is defined as the number of PWM clock ticks.
435 //!
436 //! \note Any subsequent calls made to this function before an update occurs
437 //! cause the previous values to be overwritten.
438 //!
439 //! \return None.
440 //
441 //*****************************************************************************
442 void
PWMPulseWidthSet(unsigned long ulBase,unsigned long ulPWMOut,unsigned long ulWidth)443 PWMPulseWidthSet(unsigned long ulBase, unsigned long ulPWMOut,
444 unsigned long ulWidth)
445 {
446 unsigned long ulGenBase, ulReg;
447
448 //
449 // Check the arguments.
450 //
451 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
452 ASSERT(PWMOutValid(ulPWMOut));
453
454 //
455 // Compute the generator's base address.
456 //
457 ulGenBase = PWM_OUT_BADDR(ulBase, ulPWMOut);
458
459 //
460 // If the counter is in up/down count mode, divide the width by two.
461 //
462 if(HWREG(ulGenBase + PWM_O_X_CTL) & PWM_X_CTL_MODE)
463 {
464 ulWidth /= 2;
465 }
466
467 //
468 // Get the period.
469 //
470 ulReg = HWREG(ulGenBase + PWM_O_X_LOAD);
471
472 //
473 // Make sure the width is not too large.
474 //
475 ASSERT(ulWidth < ulReg);
476
477 //
478 // Compute the compare value.
479 //
480 ulReg = ulReg - ulWidth;
481
482 //
483 // Write to the appropriate registers.
484 //
485 if(PWM_IS_OUTPUT_ODD(ulPWMOut))
486 {
487 HWREG(ulGenBase + PWM_O_X_CMPB) = ulReg;
488 }
489 else
490 {
491 HWREG(ulGenBase + PWM_O_X_CMPA) = ulReg;
492 }
493 }
494
495 //*****************************************************************************
496 //
497 //! Gets the pulse width of a PWM output.
498 //!
499 //! \param ulBase is the base address of the PWM module.
500 //! \param ulPWMOut is the PWM output to query. This parameter must be one of
501 //! \b PWM_OUT_0, \b PWM_OUT_1, \b PWM_OUT_2, \b PWM_OUT_3, \b PWM_OUT_4,
502 //! \b PWM_OUT_5, \b PWM_OUT_6, or \b PWM_OUT_7.
503 //!
504 //! This function gets the currently programmed pulse width for the specified
505 //! PWM output. If the update of the comparator for the specified output has
506 //! yet to be completed, the value returned may not be the active pulse width.
507 //! The value returned is the programmed pulse width, measured in PWM clock
508 //! ticks.
509 //!
510 //! \return Returns the width of the pulse in PWM clock ticks.
511 //
512 //*****************************************************************************
513 unsigned long
PWMPulseWidthGet(unsigned long ulBase,unsigned long ulPWMOut)514 PWMPulseWidthGet(unsigned long ulBase, unsigned long ulPWMOut)
515 {
516 unsigned long ulGenBase, ulReg, ulLoad;
517
518 //
519 // Check the arguments.
520 //
521 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
522 ASSERT(PWMOutValid(ulPWMOut));
523
524 //
525 // Compute the generator's base address.
526 //
527 ulGenBase = PWM_OUT_BADDR(ulBase, ulPWMOut);
528
529 //
530 // Then compute the pulse width. If mode is UpDown, set
531 // width = (load - compare) * 2. Otherwise, set width = load - compare.
532 //
533 ulLoad = HWREG(ulGenBase + PWM_O_X_LOAD);
534 if(PWM_IS_OUTPUT_ODD(ulPWMOut))
535 {
536 ulReg = HWREG(ulGenBase + PWM_O_X_CMPB);
537 }
538 else
539 {
540 ulReg = HWREG(ulGenBase + PWM_O_X_CMPA);
541 }
542 ulReg = ulLoad - ulReg;
543
544 //
545 // If in up/down count mode, double the pulse width.
546 //
547 if(HWREG(ulGenBase + PWM_O_X_CTL) & PWM_X_CTL_MODE)
548 {
549 ulReg = ulReg * 2;
550 }
551
552 //
553 // Return the pulse width.
554 //
555 return(ulReg);
556 }
557
558 //*****************************************************************************
559 //
560 //! Enables the PWM dead band output and sets the dead band delays.
561 //!
562 //! \param ulBase is the base address of the PWM module.
563 //! \param ulGen is the PWM generator to modify. This parameter must be one
564 //! of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
565 //! \param usRise specifies the width of delay from the rising edge.
566 //! \param usFall specifies the width of delay from the falling edge.
567 //!
568 //! This function sets the dead bands for the specified PWM generator,
569 //! where the dead bands are defined as the number of \b PWM clock ticks
570 //! from the rising or falling edge of the generator's \b OutA signal.
571 //! Note that this function causes the coupling of \b OutB to \b OutA.
572 //!
573 //! \return None.
574 //
575 //****************************************************************************
576 void
PWMDeadBandEnable(unsigned long ulBase,unsigned long ulGen,unsigned short usRise,unsigned short usFall)577 PWMDeadBandEnable(unsigned long ulBase, unsigned long ulGen,
578 unsigned short usRise, unsigned short usFall)
579 {
580 //
581 // Check the arguments.
582 //
583 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
584 ASSERT(PWMGenValid(ulGen));
585 ASSERT(usRise < 4096);
586 ASSERT(usFall < 4096);
587
588 //
589 // Compute the generator's base address.
590 //
591 ulGen = PWM_GEN_BADDR(ulBase, ulGen);
592
593 //
594 // Write the dead band delay values.
595 //
596 HWREG(ulGen + PWM_O_X_DBRISE) = usRise;
597 HWREG(ulGen + PWM_O_X_DBFALL) = usFall;
598
599 //
600 // Enable the deadband functionality.
601 //
602 HWREG(ulGen + PWM_O_X_DBCTL) |= PWM_X_DBCTL_ENABLE;
603 }
604
605 //*****************************************************************************
606 //
607 //! Disables the PWM dead band output.
608 //!
609 //! \param ulBase is the base address of the PWM module.
610 //! \param ulGen is the PWM generator to modify. This parameter must be one of
611 //! \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
612 //!
613 //! This function disables the dead band mode for the specified PWM generator.
614 //! Doing so decouples the \b OutA and \b OutB signals.
615 //!
616 //! \return None.
617 //
618 //*****************************************************************************
619 void
PWMDeadBandDisable(unsigned long ulBase,unsigned long ulGen)620 PWMDeadBandDisable(unsigned long ulBase, unsigned long ulGen)
621 {
622 //
623 // Check the arguments.
624 //
625 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
626 ASSERT(PWMGenValid(ulGen));
627
628 //
629 // Disable the deadband functionality.
630 //
631 HWREG(PWM_GEN_BADDR(ulBase, ulGen) + PWM_O_X_DBCTL) &=
632 ~(PWM_X_DBCTL_ENABLE);
633 }
634
635 //*****************************************************************************
636 //
637 //! Synchronizes all pending updates.
638 //!
639 //! \param ulBase is the base address of the PWM module.
640 //! \param ulGenBits are the PWM generator blocks to be updated. This
641 //! parameter must be the logical OR of any of \b PWM_GEN_0_BIT,
642 //! \b PWM_GEN_1_BIT, \b PWM_GEN_2_BIT, or \b PWM_GEN_3_BIT.
643 //!
644 //! For the selected PWM generators, this function causes all queued updates to
645 //! the period or pulse width to be applied the next time the corresponding
646 //! counter becomes zero.
647 //!
648 //! \return None.
649 //
650 //*****************************************************************************
651 void
PWMSyncUpdate(unsigned long ulBase,unsigned long ulGenBits)652 PWMSyncUpdate(unsigned long ulBase, unsigned long ulGenBits)
653 {
654 //
655 // Check the arguments.
656 //
657 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
658 ASSERT(!(ulGenBits & ~(PWM_GEN_0_BIT | PWM_GEN_1_BIT | PWM_GEN_2_BIT |
659 PWM_GEN_3_BIT)));
660
661 //
662 // Synchronize pending PWM register changes.
663 //
664 HWREG(ulBase + PWM_O_CTL) = ulGenBits;
665 }
666
667 //*****************************************************************************
668 //
669 //! Synchronizes the counters in one or multiple PWM generator blocks.
670 //!
671 //! \param ulBase is the base address of the PWM module.
672 //! \param ulGenBits are the PWM generator blocks to be synchronized. This
673 //! parameter must be the logical OR of any of \b PWM_GEN_0_BIT,
674 //! \b PWM_GEN_1_BIT, \b PWM_GEN_2_BIT, or \b PWM_GEN_3_BIT.
675 //!
676 //! For the selected PWM module, this function synchronizes the time base
677 //! of the generator blocks by causing the specified generator counters to be
678 //! reset to zero.
679 //!
680 //! \return None.
681 //
682 //*****************************************************************************
683 void
PWMSyncTimeBase(unsigned long ulBase,unsigned long ulGenBits)684 PWMSyncTimeBase(unsigned long ulBase, unsigned long ulGenBits)
685 {
686 //
687 // Check the arguments.
688 //
689 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
690 ASSERT(!(ulGenBits & ~(PWM_GEN_0_BIT | PWM_GEN_1_BIT | PWM_GEN_2_BIT |
691 PWM_GEN_3_BIT)));
692
693 //
694 // Synchronize the counters in the specified generators by writing to the
695 // module's synchronization register.
696 //
697 HWREG(ulBase + PWM_O_SYNC) = ulGenBits;
698 }
699
700 //*****************************************************************************
701 //
702 //! Enables or disables PWM outputs.
703 //!
704 //! \param ulBase is the base address of the PWM module.
705 //! \param ulPWMOutBits are the PWM outputs to be modified. This parameter
706 //! must be the logical OR of any of \b PWM_OUT_0_BIT, \b PWM_OUT_1_BIT,
707 //! \b PWM_OUT_2_BIT, \b PWM_OUT_3_BIT, \b PWM_OUT_4_BIT, \b PWM_OUT_5_BIT,
708 //! \b PWM_OUT_6_BIT, or \b PWM_OUT_7_BIT.
709 //! \param bEnable determines if the signal is enabled or disabled.
710 //!
711 //! This function enables or disables the selected PWM outputs. The
712 //! outputs are selected using the parameter \e ulPWMOutBits. The parameter
713 //! \e bEnable determines the state of the selected outputs. If \e bEnable is
714 //! \b true, then the selected PWM outputs are enabled, or placed in the active
715 //! state. If \e bEnable is \b false, then the selected outputs are disabled
716 //! or placed in the inactive state.
717 //!
718 //! \return None.
719 //
720 //*****************************************************************************
721 void
PWMOutputState(unsigned long ulBase,unsigned long ulPWMOutBits,tBoolean bEnable)722 PWMOutputState(unsigned long ulBase, unsigned long ulPWMOutBits,
723 tBoolean bEnable)
724 {
725 //
726 // Check the arguments.
727 //
728 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
729 ASSERT(!(ulPWMOutBits & ~(PWM_OUT_0_BIT | PWM_OUT_1_BIT | PWM_OUT_2_BIT |
730 PWM_OUT_3_BIT | PWM_OUT_4_BIT | PWM_OUT_5_BIT |
731 PWM_OUT_6_BIT | PWM_OUT_7_BIT)));
732
733 //
734 // Read the module's ENABLE output control register and set or clear the
735 // requested bits.
736 //
737 if(bEnable == true)
738 {
739 HWREG(ulBase + PWM_O_ENABLE) |= ulPWMOutBits;
740 }
741 else
742 {
743 HWREG(ulBase + PWM_O_ENABLE) &= ~(ulPWMOutBits);
744 }
745 }
746
747 //*****************************************************************************
748 //
749 //! Selects the inversion mode for PWM outputs.
750 //!
751 //! \param ulBase is the base address of the PWM module.
752 //! \param ulPWMOutBits are the PWM outputs to be modified. This parameter
753 //! must be the logical OR of any of \b PWM_OUT_0_BIT, \b PWM_OUT_1_BIT,
754 //! \b PWM_OUT_2_BIT, \b PWM_OUT_3_BIT, \b PWM_OUT_4_BIT, \b PWM_OUT_5_BIT,
755 //! \b PWM_OUT_6_BIT, or \b PWM_OUT_7_BIT.
756 //! \param bInvert determines if the signal is inverted or passed through.
757 //!
758 //! This function is used to select the inversion mode for the selected PWM
759 //! outputs. The outputs are selected using the parameter \e ulPWMOutBits.
760 //! The parameter \e bInvert determines the inversion mode for the selected
761 //! outputs. If \e bInvert is \b true, this function causes the specified
762 //! PWM output signals to be inverted or made active low. If \e bInvert is
763 //! \b false, the specified outputs are passed through as is or made active
764 //! high.
765 //!
766 //! \return None.
767 //
768 //*****************************************************************************
769 void
PWMOutputInvert(unsigned long ulBase,unsigned long ulPWMOutBits,tBoolean bInvert)770 PWMOutputInvert(unsigned long ulBase, unsigned long ulPWMOutBits,
771 tBoolean bInvert)
772 {
773 //
774 // Check the arguments.
775 //
776 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
777 ASSERT(!(ulPWMOutBits & ~(PWM_OUT_0_BIT | PWM_OUT_1_BIT | PWM_OUT_2_BIT |
778 PWM_OUT_3_BIT | PWM_OUT_4_BIT | PWM_OUT_5_BIT |
779 PWM_OUT_6_BIT | PWM_OUT_7_BIT)));
780
781 //
782 // Read the module's INVERT output control register and set or clear the
783 // requested bits.
784 //
785 if(bInvert == true)
786 {
787 HWREG(ulBase + PWM_O_INVERT) |= ulPWMOutBits;
788 }
789 else
790 {
791 HWREG(ulBase + PWM_O_INVERT) &= ~(ulPWMOutBits);
792 }
793 }
794
795 //*****************************************************************************
796 //
797 //! Specifies the level of PWM outputs suppressed in response to a fault
798 //! condition.
799 //!
800 //! \param ulBase is the base address of the PWM module.
801 //! \param ulPWMOutBits are the PWM outputs to be modified. This parameter
802 //! must be the logical OR of any of \b PWM_OUT_0_BIT, \b PWM_OUT_1_BIT,
803 //! \b PWM_OUT_2_BIT, \b PWM_OUT_3_BIT, \b PWM_OUT_4_BIT, \b PWM_OUT_5_BIT,
804 //! \b PWM_OUT_6_BIT, or \b PWM_OUT_7_BIT.
805 //! \param bDriveHigh determines if the signal is driven high or low during an
806 //! active fault condition.
807 //!
808 //! This function determines whether a PWM output pin that is suppressed in
809 //! response to a fault condition is driven high or low. The affected outputs
810 //! are selected using the parameter \e ulPWMOutBits. The parameter
811 //! \e bDriveHigh determines the output level for the pins identified by
812 //! \e ulPWMOutBits. If \e bDriveHigh is \b true then the selected outputs are
813 //! driven high when a fault is detected. If it is \e false, the pins are
814 //! driven low.
815 //!
816 //! In a fault condition, pins which have not been configured to be suppressed
817 //! via a call to PWMOutputFault() are unaffected by this function.
818 //!
819 //! \note This function is available only on devices which support extended
820 //! PWM fault handling.
821 //!
822 //! \return None.
823 //
824 //*****************************************************************************
825 void
PWMOutputFaultLevel(unsigned long ulBase,unsigned long ulPWMOutBits,tBoolean bDriveHigh)826 PWMOutputFaultLevel(unsigned long ulBase, unsigned long ulPWMOutBits,
827 tBoolean bDriveHigh)
828 {
829 //
830 // Check the arguments.
831 //
832 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
833 ASSERT(!(ulPWMOutBits & ~(PWM_OUT_0_BIT | PWM_OUT_1_BIT | PWM_OUT_2_BIT |
834 PWM_OUT_3_BIT | PWM_OUT_4_BIT | PWM_OUT_5_BIT |
835 PWM_OUT_6_BIT | PWM_OUT_7_BIT)));
836
837 //
838 // Read the module's FAULT output control register and set or clear the
839 // requested bits.
840 //
841 if(bDriveHigh == true)
842 {
843 HWREG(ulBase + PWM_O_FAULTVAL) |= ulPWMOutBits;
844 }
845 else
846 {
847 HWREG(ulBase + PWM_O_FAULTVAL) &= ~(ulPWMOutBits);
848 }
849 }
850
851 //*****************************************************************************
852 //
853 //! Specifies the state of PWM outputs in response to a fault condition.
854 //!
855 //! \param ulBase is the base address of the PWM module.
856 //! \param ulPWMOutBits are the PWM outputs to be modified. This parameter
857 //! must be the logical OR of any of \b PWM_OUT_0_BIT, \b PWM_OUT_1_BIT,
858 //! \b PWM_OUT_2_BIT, \b PWM_OUT_3_BIT, \b PWM_OUT_4_BIT, \b PWM_OUT_5_BIT,
859 //! \b PWM_OUT_6_BIT, or \b PWM_OUT_7_BIT.
860 //! \param bFaultSuppress determines if the signal is suppressed or passed
861 //! through during an active fault condition.
862 //!
863 //! This function sets the fault handling characteristics of the selected PWM
864 //! outputs. The outputs are selected using the parameter \e ulPWMOutBits.
865 //! The parameter \e bFaultSuppress determines the fault handling
866 //! characteristics for the selected outputs. If \e bFaultSuppress is \b true,
867 //! then the selected outputs are made inactive. If \e bFaultSuppress is
868 //! \b false, then the selected outputs are unaffected by the detected fault.
869 //!
870 //! On devices supporting extended PWM fault handling, the state the affected
871 //! output pins are driven to can be configured with PWMOutputFaultLevel(). If
872 //! not configured, or if the device does not support extended PWM fault
873 //! handling, affected outputs are driven low on a fault condition.
874 //!
875 //! \return None.
876 //
877 //*****************************************************************************
878 void
PWMOutputFault(unsigned long ulBase,unsigned long ulPWMOutBits,tBoolean bFaultSuppress)879 PWMOutputFault(unsigned long ulBase, unsigned long ulPWMOutBits,
880 tBoolean bFaultSuppress)
881 {
882 //
883 // Check the arguments.
884 //
885 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
886 ASSERT(!(ulPWMOutBits & ~(PWM_OUT_0_BIT | PWM_OUT_1_BIT | PWM_OUT_2_BIT |
887 PWM_OUT_3_BIT | PWM_OUT_4_BIT | PWM_OUT_5_BIT |
888 PWM_OUT_6_BIT | PWM_OUT_7_BIT)));
889
890 //
891 // Read the module's FAULT output control register and set or clear the
892 // requested bits.
893 //
894 if(bFaultSuppress == true)
895 {
896 HWREG(ulBase + PWM_O_FAULT) |= ulPWMOutBits;
897 }
898 else
899 {
900 HWREG(ulBase + PWM_O_FAULT) &= ~(ulPWMOutBits);
901 }
902 }
903
904 //*****************************************************************************
905 //
906 //! Gets the PWM generator interrupt number.
907 //!
908 //! \param ulBase is the base address of the PWM module.
909 //! \param ulGen is the PWM generator in question. This parameter must be one
910 //! of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
911 //!
912 //! This function returns the interrupt number of the corresponding PWM
913 //! generator.
914 //!
915 //! \return Returns the interrupt number.
916 //
917 //*****************************************************************************
918 static unsigned long
PWMGenIntGet(unsigned long ulBase,unsigned long ulGen)919 PWMGenIntGet(unsigned long ulBase, unsigned long ulGen)
920 {
921 //
922 // Determine the generator and PWM module in question.
923 //
924 switch(ulBase + ulGen)
925 {
926 //
927 // The first PWM generator in the first PWM module.
928 //
929 case PWM0_BASE + PWM_GEN_0:
930 {
931 return(INT_PWM0_0);
932 }
933
934 //
935 // The second PWM generator in the first PWM module.
936 //
937 case PWM0_BASE + PWM_GEN_1:
938 {
939 return(INT_PWM0_1);
940 }
941
942 //
943 // The third PWM generator in the first PWM module.
944 //
945 case PWM0_BASE + PWM_GEN_2:
946 {
947 return(INT_PWM0_2);
948 }
949
950 //
951 // The fourth PWM generator in the first PWM module.
952 //
953 case PWM0_BASE + PWM_GEN_3:
954 {
955 return(INT_PWM0_3);
956 }
957
958 //
959 // The first PWM generator in the second PWM module.
960 //
961 case PWM1_BASE + PWM_GEN_0:
962 {
963 return(INT_PWM1_0);
964 }
965
966 //
967 // The first PWM generator in the second PWM module.
968 //
969 case PWM1_BASE + PWM_GEN_1:
970 {
971 return(INT_PWM1_1);
972 }
973
974 //
975 // The first PWM generator in the second PWM module.
976 //
977 case PWM1_BASE + PWM_GEN_2:
978 {
979 return(INT_PWM1_2);
980 }
981
982 //
983 // The first PWM generator in the second PWM module.
984 //
985 case PWM1_BASE + PWM_GEN_3:
986 {
987 return(INT_PWM1_3);
988 }
989
990 //
991 // An unknown PWM module/generator was specified.
992 //
993 default:
994 {
995 return(0);
996 }
997 }
998 }
999
1000 //*****************************************************************************
1001 //
1002 //! Registers an interrupt handler for the specified PWM generator block.
1003 //!
1004 //! \param ulBase is the base address of the PWM module.
1005 //! \param ulGen is the PWM generator in question. This parameter must be one
1006 //! of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
1007 //! \param pfnIntHandler is a pointer to the function to be called when the PWM
1008 //! generator interrupt occurs.
1009 //!
1010 //! This function ensures that the interrupt handler specified by
1011 //! \e pfnIntHandler is called when an interrupt is detected for the specified
1012 //! PWM generator block. This function also enables the corresponding
1013 //! PWM generator interrupt in the interrupt controller; individual generator
1014 //! interrupts and interrupt sources must be enabled with PWMIntEnable() and
1015 //! PWMGenIntTrigEnable().
1016 //!
1017 //! \sa IntRegister() for important information about registering interrupt
1018 //! handlers.
1019 //!
1020 //! \return None.
1021 //
1022 //*****************************************************************************
1023 void
PWMGenIntRegister(unsigned long ulBase,unsigned long ulGen,void (* pfnIntHandler)(void))1024 PWMGenIntRegister(unsigned long ulBase, unsigned long ulGen,
1025 void (*pfnIntHandler)(void))
1026 {
1027 unsigned long ulInt;
1028
1029 //
1030 // Check the arguments.
1031 //
1032 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
1033 ASSERT(PWMGenValid(ulGen));
1034
1035 //
1036 // Get the interrupt number associated with the specified generator.
1037 //
1038 ulInt = PWMGenIntGet(ulBase, ulGen);
1039
1040 //
1041 // Register the interrupt handler.
1042 //
1043 IntRegister(ulInt, pfnIntHandler);
1044
1045 //
1046 // Enable the PWMx interrupt.
1047 //
1048 IntEnable(ulInt);
1049 }
1050
1051 //*****************************************************************************
1052 //
1053 //! Removes an interrupt handler for the specified PWM generator block.
1054 //!
1055 //! \param ulBase is the base address of the PWM module.
1056 //! \param ulGen is the PWM generator in question. This parameter must be one
1057 //! of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
1058 //!
1059 //! This function unregisters the interrupt handler for the specified
1060 //! PWM generator block. This function also disables the corresponding
1061 //! PWM generator interrupt in the interrupt controller; individual generator
1062 //! interrupts and interrupt sources must be disabled with PWMIntDisable() and
1063 //! PWMGenIntTrigDisable().
1064 //!
1065 //! \sa IntRegister() for important information about registering interrupt
1066 //! handlers.
1067 //!
1068 //! \return None.
1069 //
1070 //*****************************************************************************
1071 void
PWMGenIntUnregister(unsigned long ulBase,unsigned long ulGen)1072 PWMGenIntUnregister(unsigned long ulBase, unsigned long ulGen)
1073 {
1074 unsigned long ulInt;
1075
1076 //
1077 // Check the arguments.
1078 //
1079 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
1080 ASSERT(PWMGenValid(ulGen));
1081
1082 //
1083 // Get the interrupt number associated with the specified generator.
1084 //
1085 ulInt = PWMGenIntGet(ulBase, ulGen);
1086
1087 //
1088 // Disable the PWMx interrupt.
1089 //
1090 IntDisable(ulInt);
1091
1092 //
1093 // Unregister the interrupt handler.
1094 //
1095 IntUnregister(ulInt);
1096 }
1097
1098 //*****************************************************************************
1099 //
1100 //! Gets the PWM fault interrupt number.
1101 //!
1102 //! \param ulBase is the base address of the PWM module.
1103 //!
1104 //! This function returns the fault interrupt number of the corresponding
1105 //! PWM module.
1106 //!
1107 //! \return Returns the interrupt number.
1108 //
1109 //*****************************************************************************
1110 static unsigned long
PWMFaultIntGet(unsigned long ulBase)1111 PWMFaultIntGet(unsigned long ulBase)
1112 {
1113 //
1114 // Return the fault interrupt number.
1115 //
1116 return((ulBase == PWM0_BASE) ? INT_PWM0_FAULT : INT_PWM1_FAULT);
1117 }
1118
1119 //*****************************************************************************
1120 //
1121 //! Registers an interrupt handler for a fault condition detected in a PWM
1122 //! module.
1123 //!
1124 //! \param ulBase is the base address of the PWM module.
1125 //! \param pfnIntHandler is a pointer to the function to be called when the PWM
1126 //! fault interrupt occurs.
1127 //!
1128 //! This function ensures that the interrupt handler specified by
1129 //! \e pfnIntHandler is called when a fault interrupt is detected for the
1130 //! selected PWM module. This function also enables the PWM fault
1131 //! interrupt in the NVIC; the PWM fault interrupt must also be enabled at the
1132 //! module level using PWMIntEnable().
1133 //!
1134 //! \sa IntRegister() for important information about registering interrupt
1135 //! handlers.
1136 //!
1137 //! \return None.
1138 //
1139 //*****************************************************************************
1140 void
PWMFaultIntRegister(unsigned long ulBase,void (* pfnIntHandler)(void))1141 PWMFaultIntRegister(unsigned long ulBase, void (*pfnIntHandler)(void))
1142 {
1143 unsigned long ulInt;
1144
1145 //
1146 // Check the arguments.
1147 //
1148 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
1149
1150 //
1151 // Get the interrupt number associated with the specified module.
1152 //
1153 ulInt = PWMFaultIntGet(ulBase);
1154
1155 //
1156 // Register the interrupt handler, returning an error if one occurs.
1157 //
1158 IntRegister(ulInt, pfnIntHandler);
1159
1160 //
1161 // Enable the PWM fault interrupt.
1162 //
1163 IntEnable(ulInt);
1164 }
1165
1166 //*****************************************************************************
1167 //
1168 //! Removes the PWM fault condition interrupt handler.
1169 //!
1170 //! \param ulBase is the base address of the PWM module.
1171 //!
1172 //! This function removes the interrupt handler for a PWM fault interrupt
1173 //! from the selected PWM module. This function also disables the PWM
1174 //! fault interrupt in the NVIC; the PWM fault interrupt must also be disabled
1175 //! at the module level using PWMIntDisable().
1176 //!
1177 //! \sa IntRegister() for important information about registering interrupt
1178 //! handlers.
1179 //!
1180 //! \return None.
1181 //
1182 //*****************************************************************************
1183 void
PWMFaultIntUnregister(unsigned long ulBase)1184 PWMFaultIntUnregister(unsigned long ulBase)
1185 {
1186 unsigned long ulInt;
1187
1188 //
1189 // Check the arguments.
1190 //
1191 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
1192
1193 //
1194 // Get the interrupt number associated with the specified module.
1195 //
1196 ulInt = PWMFaultIntGet(ulBase);
1197
1198 //
1199 // Disable the PWM fault interrupt.
1200 //
1201 IntDisable(ulInt);
1202
1203 //
1204 // Unregister the interrupt handler, returning an error if one occurs.
1205 //
1206 IntUnregister(ulInt);
1207 }
1208
1209 //*****************************************************************************
1210 //
1211 //! Enables interrupts and triggers for the specified PWM generator block.
1212 //!
1213 //! \param ulBase is the base address of the PWM module.
1214 //! \param ulGen is the PWM generator to have interrupts and triggers enabled.
1215 //! This parameter must be one of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or
1216 //! \b PWM_GEN_3.
1217 //! \param ulIntTrig specifies the interrupts and triggers to be enabled.
1218 //!
1219 //! This function unmasks the specified interrupt(s) and trigger(s) by setting
1220 //! the specified bits of the interrupt/trigger enable register for the
1221 //! specified PWM generator. The \e ulIntTrig parameter is the logical OR of
1222 //! \b PWM_INT_CNT_ZERO, \b PWM_INT_CNT_LOAD, \b PWM_INT_CNT_AU,
1223 //! \b PWM_INT_CNT_AD, \b PWM_INT_CNT_BU, \b PWM_INT_CNT_BD,
1224 //! \b PWM_TR_CNT_ZERO, \b PWM_TR_CNT_LOAD, \b PWM_TR_CNT_AU, \b PWM_TR_CNT_AD,
1225 //! \b PWM_TR_CNT_BU, or \b PWM_TR_CNT_BD.
1226 //!
1227 //! \return None.
1228 //
1229 //*****************************************************************************
1230 void
PWMGenIntTrigEnable(unsigned long ulBase,unsigned long ulGen,unsigned long ulIntTrig)1231 PWMGenIntTrigEnable(unsigned long ulBase, unsigned long ulGen,
1232 unsigned long ulIntTrig)
1233 {
1234 //
1235 // Check the arguments.
1236 //
1237 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
1238 ASSERT(PWMGenValid(ulGen));
1239 ASSERT((ulIntTrig & ~(PWM_INT_CNT_ZERO | PWM_INT_CNT_LOAD |
1240 PWM_INT_CNT_AU | PWM_INT_CNT_AD | PWM_INT_CNT_BU |
1241 PWM_INT_CNT_BD | PWM_TR_CNT_ZERO | PWM_TR_CNT_LOAD |
1242 PWM_TR_CNT_AU | PWM_TR_CNT_AD | PWM_TR_CNT_BU |
1243 PWM_TR_CNT_BD)) == 0);
1244
1245 //
1246 // Enable the specified interrupts/triggers.
1247 //
1248 HWREG(PWM_GEN_BADDR(ulBase, ulGen) + PWM_O_X_INTEN) |= ulIntTrig;
1249 }
1250
1251 //*****************************************************************************
1252 //
1253 //! Disables interrupts for the specified PWM generator block.
1254 //!
1255 //! \param ulBase is the base address of the PWM module.
1256 //! \param ulGen is the PWM generator to have interrupts and triggers disabled.
1257 //! This parameter must be one of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or
1258 //! \b PWM_GEN_3.
1259 //! \param ulIntTrig specifies the interrupts and triggers to be disabled.
1260 //!
1261 //! This function masks the specified interrupt(s) and trigger(s) by clearing
1262 //! the specified bits of the interrupt/trigger enable register for the
1263 //! specified PWM generator. The \e ulIntTrig parameter is the logical OR of
1264 //! \b PWM_INT_CNT_ZERO, \b PWM_INT_CNT_LOAD, \b PWM_INT_CNT_AU,
1265 //! \b PWM_INT_CNT_AD, \b PWM_INT_CNT_BU, \b PWM_INT_CNT_BD,
1266 //! \b PWM_TR_CNT_ZERO, \b PWM_TR_CNT_LOAD, \b PWM_TR_CNT_AU, \b PWM_TR_CNT_AD,
1267 //! \b PWM_TR_CNT_BU, or \b PWM_TR_CNT_BD.
1268 //!
1269 //! \return None.
1270 //
1271 //*****************************************************************************
1272 void
PWMGenIntTrigDisable(unsigned long ulBase,unsigned long ulGen,unsigned long ulIntTrig)1273 PWMGenIntTrigDisable(unsigned long ulBase, unsigned long ulGen,
1274 unsigned long ulIntTrig)
1275 {
1276 //
1277 // Check the arguments.
1278 //
1279 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
1280 ASSERT(PWMGenValid(ulGen));
1281 ASSERT((ulIntTrig & ~(PWM_INT_CNT_ZERO | PWM_INT_CNT_LOAD |
1282 PWM_INT_CNT_AU | PWM_INT_CNT_AD | PWM_INT_CNT_BU |
1283 PWM_INT_CNT_BD | PWM_TR_CNT_ZERO | PWM_TR_CNT_LOAD |
1284 PWM_TR_CNT_AU | PWM_TR_CNT_AD | PWM_TR_CNT_BU |
1285 PWM_TR_CNT_BD)) == 0);
1286
1287 //
1288 // Disable the specified interrupts/triggers.
1289 //
1290 HWREG(PWM_GEN_BADDR(ulBase, ulGen) + PWM_O_X_INTEN) &= ~(ulIntTrig);
1291 }
1292
1293 //*****************************************************************************
1294 //
1295 //! Gets interrupt status for the specified PWM generator block.
1296 //!
1297 //! \param ulBase is the base address of the PWM module.
1298 //! \param ulGen is the PWM generator to query. This parameter must be one of
1299 //! \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
1300 //! \param bMasked specifies whether masked or raw interrupt status is
1301 //! returned.
1302 //!
1303 //! If \e bMasked is set as \b true, then the masked interrupt status is
1304 //! returned; otherwise, the raw interrupt status is returned.
1305 //!
1306 //! \return Returns the contents of the interrupt status register or the
1307 //! contents of the raw interrupt status register for the specified
1308 //! PWM generator.
1309 //
1310 //*****************************************************************************
1311 unsigned long
PWMGenIntStatus(unsigned long ulBase,unsigned long ulGen,tBoolean bMasked)1312 PWMGenIntStatus(unsigned long ulBase, unsigned long ulGen, tBoolean bMasked)
1313 {
1314 //
1315 // Check the arguments.
1316 //
1317 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
1318 ASSERT(PWMGenValid(ulGen));
1319
1320 //
1321 // Compute the generator's base address.
1322 //
1323 ulGen = PWM_GEN_BADDR(ulBase, ulGen);
1324
1325 //
1326 // Read and return the specified generator's raw or enabled interrupt
1327 // status.
1328 //
1329 if(bMasked == true)
1330 {
1331 return(HWREG(ulGen + PWM_O_X_ISC));
1332 }
1333 else
1334 {
1335 return(HWREG(ulGen + PWM_O_X_RIS));
1336 }
1337 }
1338
1339 //*****************************************************************************
1340 //
1341 //! Clears the specified interrupt(s) for the specified PWM generator block.
1342 //!
1343 //! \param ulBase is the base address of the PWM module.
1344 //! \param ulGen is the PWM generator to query. This parameter must be one of
1345 //! \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
1346 //! \param ulInts specifies the interrupts to be cleared.
1347 //!
1348 //! This funciton clears the specified interrupt(s) by writing a 1 to the
1349 //! specified bits of the interrupt status register for the specified PWM
1350 //! generator. The \e ulInts parameter is the logical OR of
1351 //! \b PWM_INT_CNT_ZERO, \b PWM_INT_CNT_LOAD, \b PWM_INT_CNT_AU,
1352 //! \b PWM_INT_CNT_AD, \b PWM_INT_CNT_BU, or \b PWM_INT_CNT_BD.
1353 //!
1354 //! \note Because there is a write buffer in the Cortex-M processor, it may
1355 //! take several clock cycles before the interrupt source is actually cleared.
1356 //! Therefore, it is recommended that the interrupt source be cleared early in
1357 //! the interrupt handler (as opposed to the very last action) to avoid
1358 //! returning from the interrupt handler before the interrupt source is
1359 //! actually cleared. Failure to do so may result in the interrupt handler
1360 //! being immediately reentered (because the interrupt controller still sees
1361 //! the interrupt source asserted).
1362 //!
1363 //! \return None.
1364 //
1365 //*****************************************************************************
1366 void
PWMGenIntClear(unsigned long ulBase,unsigned long ulGen,unsigned long ulInts)1367 PWMGenIntClear(unsigned long ulBase, unsigned long ulGen, unsigned long ulInts)
1368 {
1369 //
1370 // Check the arguments.
1371 //
1372 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
1373 ASSERT(PWMGenValid(ulGen));
1374 ASSERT((ulInts & ~(PWM_INT_CNT_ZERO | PWM_INT_CNT_LOAD | PWM_INT_CNT_AU |
1375 PWM_INT_CNT_AD | PWM_INT_CNT_BU | PWM_INT_CNT_BD)) ==
1376 0);
1377
1378 //
1379 // Clear the requested interrupts by writing ones to the specified bit
1380 // of the module's interrupt enable register.
1381 //
1382 HWREG(PWM_GEN_BADDR(ulBase, ulGen) + PWM_O_X_ISC) = ulInts;
1383 }
1384
1385 //*****************************************************************************
1386 //
1387 //! Enables generator and fault interrupts for a PWM module.
1388 //!
1389 //! \param ulBase is the base address of the PWM module.
1390 //! \param ulGenFault contains the interrupts to be enabled. This parameter
1391 //! must be a logical OR of any of \b PWM_INT_GEN_0, \b PWM_INT_GEN_1,
1392 //! \b PWM_INT_GEN_2, \b PWM_INT_GEN_3, \b PWM_INT_FAULT0, \b PWM_INT_FAULT1,
1393 //! \b PWM_INT_FAULT2, or \b PWM_INT_FAULT3.
1394 //!
1395 //! This function unmasks the specified interrupt(s) by setting the specified
1396 //! bits of the interrupt enable register for the selected PWM module.
1397 //!
1398 //! \return None.
1399 //
1400 //*****************************************************************************
1401 void
PWMIntEnable(unsigned long ulBase,unsigned long ulGenFault)1402 PWMIntEnable(unsigned long ulBase, unsigned long ulGenFault)
1403 {
1404 //
1405 // Check the arguments.
1406 //
1407 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
1408 ASSERT((ulGenFault & ~(PWM_INT_GEN_0 | PWM_INT_GEN_1 | PWM_INT_GEN_2 |
1409 PWM_INT_GEN_3 | PWM_INT_FAULT0 | PWM_INT_FAULT1 |
1410 PWM_INT_FAULT2 | PWM_INT_FAULT3)) == 0);
1411
1412 //
1413 // Read the module's interrupt enable register and enable interrupts
1414 // for the specified PWM generators.
1415 //
1416 HWREG(ulBase + PWM_O_INTEN) |= ulGenFault;
1417 }
1418
1419 //*****************************************************************************
1420 //
1421 //! Disables generator and fault interrupts for a PWM module.
1422 //!
1423 //! \param ulBase is the base address of the PWM module.
1424 //! \param ulGenFault contains the interrupts to be disabled. This parameter
1425 //! must be a logical OR of any of \b PWM_INT_GEN_0, \b PWM_INT_GEN_1,
1426 //! \b PWM_INT_GEN_2, \b PWM_INT_GEN_3, \b PWM_INT_FAULT0, \b PWM_INT_FAULT1,
1427 //! \b PWM_INT_FAULT2, or \b PWM_INT_FAULT3.
1428 //!
1429 //! This function masks the specified interrupt(s) by clearing the specified
1430 //! bits of the interrupt enable register for the selected PWM module.
1431 //!
1432 //! \return None.
1433 //
1434 //*****************************************************************************
1435 void
PWMIntDisable(unsigned long ulBase,unsigned long ulGenFault)1436 PWMIntDisable(unsigned long ulBase, unsigned long ulGenFault)
1437 {
1438 //
1439 // Check the arguments.
1440 //
1441 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
1442 ASSERT((ulGenFault & ~(PWM_INT_GEN_0 | PWM_INT_GEN_1 | PWM_INT_GEN_2 |
1443 PWM_INT_GEN_3 | PWM_INT_FAULT0 | PWM_INT_FAULT1 |
1444 PWM_INT_FAULT2 | PWM_INT_FAULT3)) == 0);
1445
1446 //
1447 // Read the module's interrupt enable register and disable interrupts
1448 // for the specified PWM generators.
1449 //
1450 HWREG(ulBase + PWM_O_INTEN) &= ~(ulGenFault);
1451 }
1452
1453 //*****************************************************************************
1454 //
1455 //! Clears the fault interrupt for a PWM module.
1456 //!
1457 //! \param ulBase is the base address of the PWM module.
1458 //!
1459 //! This function clears the fault interrupt by writing to the appropriate bit
1460 //! of the interrupt status register for the selected PWM module.
1461 //!
1462 //! This function clears only the FAULT0 interrupt and is retained for
1463 //! backwards compatibility. It is recommended that PWMFaultIntClearExt() be
1464 //! used instead because it supports all fault interrupts supported on devices
1465 //! with and without extended PWM fault handling support.
1466 //!
1467 //! \note Because there is a write buffer in the Cortex-M processor, it may
1468 //! take several clock cycles before the interrupt source is actually cleared.
1469 //! Therefore, it is recommended that the interrupt source be cleared early in
1470 //! the interrupt handler (as opposed to the very last action) to avoid
1471 //! returning from the interrupt handler before the interrupt source is
1472 //! actually cleared. Failure to do so may result in the interrupt handler
1473 //! being immediately reentered (because the interrupt controller still sees
1474 //! the interrupt source asserted).
1475 //!
1476 //! \return None.
1477 //
1478 //*****************************************************************************
1479 void
PWMFaultIntClear(unsigned long ulBase)1480 PWMFaultIntClear(unsigned long ulBase)
1481 {
1482 //
1483 // Check the arguments.
1484 //
1485 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
1486
1487 //
1488 // Write the only writeable bit in the module's interrupt register.
1489 //
1490 HWREG(ulBase + PWM_O_ISC) = PWM_ISC_INTFAULT0;
1491 }
1492
1493 //*****************************************************************************
1494 //
1495 //! Gets the interrupt status for a PWM module.
1496 //!
1497 //! \param ulBase is the base address of the PWM module.
1498 //! \param bMasked specifies whether masked or raw interrupt status is
1499 //! returned.
1500 //!
1501 //! If \e bMasked is set as \b true, then the masked interrupt status is
1502 //! returned; otherwise, the raw interrupt status is returned.
1503 //!
1504 //! \return The current interrupt status, enumerated as a bit field of
1505 //! \b PWM_INT_GEN_0, \b PWM_INT_GEN_1, \b PWM_INT_GEN_2, \b PWM_INT_GEN_3,
1506 //! \b PWM_INT_FAULT0, \b PWM_INT_FAULT1, \b PWM_INT_FAULT2, and
1507 //! \b PWM_INT_FAULT3.
1508 //!
1509 //*****************************************************************************
1510 unsigned long
PWMIntStatus(unsigned long ulBase,tBoolean bMasked)1511 PWMIntStatus(unsigned long ulBase, tBoolean bMasked)
1512 {
1513 //
1514 // Check the arguments.
1515 //
1516 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
1517
1518 //
1519 // Read and return either the module's raw or enabled interrupt status.
1520 //
1521 if(bMasked == true)
1522 {
1523 return(HWREG(ulBase + PWM_O_ISC));
1524 }
1525 else
1526 {
1527 return(HWREG(ulBase + PWM_O_RIS));
1528 }
1529 }
1530
1531 //*****************************************************************************
1532 //
1533 //! Clears the fault interrupt for a PWM module.
1534 //!
1535 //! \param ulBase is the base address of the PWM module.
1536 //! \param ulFaultInts specifies the fault interrupts to clear.
1537 //!
1538 //! This function clears one or more fault interrupts by writing to the
1539 //! appropriate bit of the PWM interrupt status register. The parameter
1540 //! \e ulFaultInts must be the logical OR of any of \b PWM_INT_FAULT0,
1541 //! \b PWM_INT_FAULT1, \b PWM_INT_FAULT2, or \b PWM_INT_FAULT3.
1542 //!
1543 //! When running on a device supporting extended PWM fault handling, the fault
1544 //! interrupts are derived by performing a logical OR of each of the configured
1545 //! fault trigger signals for a given generator. Therefore, these interrupts
1546 //! are not directly related to the four possible FAULTn inputs to the device
1547 //! but indicate that a fault has been signaled to one of the four possible PWM
1548 //! generators. On a device without extended PWM fault handling, the interrupt
1549 //! is directly related to the state of the single FAULT pin.
1550 //!
1551 //! \note Because there is a write buffer in the Cortex-M processor, it may
1552 //! take several clock cycles before the interrupt source is actually cleared.
1553 //! Therefore, it is recommended that the interrupt source be cleared early in
1554 //! the interrupt handler (as opposed to the very last action) to avoid
1555 //! returning from the interrupt handler before the interrupt source is
1556 //! actually cleared. Failure to do so may result in the interrupt handler
1557 //! being immediately reentered (because the interrupt controller still sees
1558 //! the interrupt source asserted).
1559 //!
1560 //! \return None.
1561 //
1562 //*****************************************************************************
1563 void
PWMFaultIntClearExt(unsigned long ulBase,unsigned long ulFaultInts)1564 PWMFaultIntClearExt(unsigned long ulBase, unsigned long ulFaultInts)
1565 {
1566 //
1567 // Check the arguments.
1568 //
1569 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
1570 ASSERT((ulFaultInts & ~(PWM_INT_FAULT0 | PWM_INT_FAULT1 |
1571 PWM_INT_FAULT2 | PWM_INT_FAULT3)) == 0);
1572
1573 //
1574 // Clear the supplied fault bits.
1575 //
1576 HWREG(ulBase + PWM_O_ISC) = ulFaultInts;
1577 }
1578
1579 //*****************************************************************************
1580 //
1581 //! Configures the minimum fault period and fault pin senses for a given
1582 //! PWM generator.
1583 //!
1584 //! \param ulBase is the base address of the PWM module.
1585 //! \param ulGen is the PWM generator for which fault configuration is being
1586 //! set. This function must be one of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2,
1587 //! or \b PWM_GEN_3.
1588 //! \param ulMinFaultPeriod is the minimum fault active period expressed in
1589 //! PWM clock cycles.
1590 //! \param ulFaultSenses indicates which sense of each FAULT input should be
1591 //! considered the ``asserted'' state. Valid values are logical OR
1592 //! combinations of \b PWM_FAULTn_SENSE_HIGH and \b PWM_FAULTn_SENSE_LOW.
1593 //!
1594 //! This function configures the minimum fault period for a given generator
1595 //! along with the sense of each of the 4 possible fault inputs. The minimum
1596 //! fault period is expressed in PWM clock cycles and takes effect only if
1597 //! PWMGenConfigure() is called with flag \b PWM_GEN_MODE_FAULT_PER set in the
1598 //! \e ulConfig parameter. When a fault input is asserted, the minimum fault
1599 //! period timer ensures that it remains asserted for at least the number of
1600 //! clock cycles specified.
1601 //!
1602 //! \note This function is only available on devices supporting extended PWM
1603 //! fault handling.
1604 //!
1605 //! \return None.
1606 //
1607 //*****************************************************************************
1608 void
PWMGenFaultConfigure(unsigned long ulBase,unsigned long ulGen,unsigned long ulMinFaultPeriod,unsigned long ulFaultSenses)1609 PWMGenFaultConfigure(unsigned long ulBase, unsigned long ulGen,
1610 unsigned long ulMinFaultPeriod,
1611 unsigned long ulFaultSenses)
1612 {
1613 //
1614 // Check the arguments.
1615 //
1616 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
1617 ASSERT(PWMGenValid(ulGen));
1618 ASSERT(ulMinFaultPeriod < PWM_X_MINFLTPER_M);
1619 ASSERT((ulFaultSenses & ~(PWM_FAULT0_SENSE_HIGH | PWM_FAULT0_SENSE_LOW |
1620 PWM_FAULT1_SENSE_HIGH | PWM_FAULT1_SENSE_LOW |
1621 PWM_FAULT2_SENSE_HIGH | PWM_FAULT2_SENSE_LOW |
1622 PWM_FAULT3_SENSE_HIGH | PWM_FAULT3_SENSE_LOW)) ==
1623 0);
1624
1625 //
1626 // Write the minimum fault period.
1627 //
1628 HWREG(PWM_GEN_BADDR(ulBase, ulGen) + PWM_O_X_MINFLTPER) = ulMinFaultPeriod;
1629
1630 //
1631 // Write the fault senses.
1632 //
1633 HWREG(PWM_GEN_EXT_BADDR(ulBase, ulGen) + PWM_O_X_FLTSEN) = ulFaultSenses;
1634 }
1635
1636 //*****************************************************************************
1637 //
1638 //! Configures the set of fault triggers for a given PWM generator.
1639 //!
1640 //! \param ulBase is the base address of the PWM module.
1641 //! \param ulGen is the PWM generator for which fault triggers are being set.
1642 //! This parameter must be one of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or
1643 //! \b PWM_GEN_3.
1644 //! \param ulGroup indicates the subset of possible faults that are to be
1645 //! configured. This parameter must be \b PWM_FAULT_GROUP_0 or
1646 //! \b PWM_FAULT_GROUP_1.
1647 //! \param ulFaultTriggers defines the set of inputs that are to contribute
1648 //! towards generation of the fault signal to the given PWM generator. For
1649 //! \b PWM_FAULT_GROUP_0, this is the logical OR of \b PWM_FAULT_FAULT0,
1650 //! \b PWM_FAULT_FAULT1, \b PWM_FAULT_FAULT2, or \b PWM_FAULT_FAULT3. For
1651 //! \b PWM_FAULT_GROUP_1, this is the logical OR of \b PWM_FAULT_DCMP0,
1652 //! \b PWM_FAULT_DCMP1, \b PWM_FAULT_DCMP2, \b PWM_FAULT_DCMP3,
1653 //! \b PWM_FAULT_DCMP4, \b PWM_FAULT_DCMP5, \b PWM_FAULT_DCMP6, or
1654 //! \b PWM_FAULT_DCMP7.
1655 //!
1656 //! This function allows selection of the set of fault inputs that is combined
1657 //! to generate a fault condition to a given PWM generator. By default, all
1658 //! generators use only FAULT0 (for backwards compatibility) but if
1659 //! PWMGenConfigure() is called with flag \b PWM_GEN_MODE_FAULT_SRC in the
1660 //! \e ulConfig parameter, extended fault handling is enabled and this function
1661 //! must be called to configure the fault triggers.
1662 //!
1663 //! The fault signal to the PWM generator is generated by ORing together each
1664 //! of the signals specified in the \e ulFaultTriggers parameter after having
1665 //! adjusted the sense of each FAULTn input based on the configuration
1666 //! previously set using a call to PWMGenFaultConfigure().
1667 //!
1668 //! \note This function is only available on devices supporting extended PWM
1669 //! fault handling.
1670 //!
1671 //! \return None.
1672 //
1673 //*****************************************************************************
1674 void
PWMGenFaultTriggerSet(unsigned long ulBase,unsigned long ulGen,unsigned long ulGroup,unsigned long ulFaultTriggers)1675 PWMGenFaultTriggerSet(unsigned long ulBase, unsigned long ulGen,
1676 unsigned long ulGroup, unsigned long ulFaultTriggers)
1677 {
1678 //
1679 // Check for valid parameters.
1680 //
1681 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
1682 ASSERT(PWMGenValid(ulGen));
1683 ASSERT((ulGroup == PWM_FAULT_GROUP_0) || (ulGroup == PWM_FAULT_GROUP_1));
1684 ASSERT((ulGroup == PWM_FAULT_GROUP_0) &&
1685 ((ulFaultTriggers & ~(PWM_FAULT_FAULT0 | PWM_FAULT_FAULT1 |
1686 PWM_FAULT_FAULT2 | PWM_FAULT_FAULT3)) == 0));
1687 ASSERT((ulGroup == PWM_FAULT_GROUP_1) &&
1688 ((ulFaultTriggers & ~(PWM_FAULT_DCMP0 | PWM_FAULT_DCMP1 |
1689 PWM_FAULT_DCMP2 | PWM_FAULT_DCMP3 |
1690 PWM_FAULT_DCMP4 | PWM_FAULT_DCMP5 |
1691 PWM_FAULT_DCMP6 | PWM_FAULT_DCMP7)) == 0));
1692
1693 //
1694 // Write the fault triggers to the appropriate register.
1695 //
1696 if(ulGroup == PWM_FAULT_GROUP_0)
1697 {
1698 HWREG(PWM_GEN_BADDR(ulBase, ulGen) + PWM_O_X_FLTSRC0) =
1699 ulFaultTriggers;
1700 }
1701 else
1702 {
1703 HWREG(PWM_GEN_BADDR(ulBase, ulGen) + PWM_O_X_FLTSRC1) =
1704 ulFaultTriggers;
1705 }
1706 }
1707
1708 //*****************************************************************************
1709 //
1710 //! Returns the set of fault triggers currently configured for a given PWM
1711 //! generator.
1712 //!
1713 //! \param ulBase is the base address of the PWM module.
1714 //! \param ulGen is the PWM generator for which fault triggers are being
1715 //! queried. This parameter must be one of \b PWM_GEN_0, \b PWM_GEN_1,
1716 //! \b PWM_GEN_2, or \b PWM_GEN_3.
1717 //! \param ulGroup indicates the subset of faults that are being queried. This
1718 //! parameter must be \b PWM_FAULT_GROUP_0 or \b PWM_FAULT_GROUP_1.
1719 //!
1720 //! This function allows an application to query the current set of inputs that
1721 //! contribute to the generation of a fault condition to a given PWM generator.
1722 //!
1723 //! \note This function is only available on devices supporting extended PWM
1724 //! fault handling.
1725 //!
1726 //! \return Returns the current fault triggers configured for the fault group
1727 //! provided. For \b PWM_FAULT_GROUP_0, the returned value is a logical OR of
1728 //! \b PWM_FAULT_FAULT0, \b PWM_FAULT_FAULT1, \b PWM_FAULT_FAULT2, or
1729 //! \b PWM_FAULT_FAULT3. For \b PWM_FAULT_GROUP_1, the return value is the
1730 //! logical OR of \b PWM_FAULT_DCMP0, \b PWM_FAULT_DCMP1,
1731 //! \b PWM_FAULT_DCMP2, \b PWM_FAULT_DCMP3, \b PWM_FAULT_DCMP4,
1732 //! \b PWM_FAULT_DCMP5, \b PWM_FAULT_DCMP6, or \b PWM_FAULT_DCMP7.
1733 //
1734 //*****************************************************************************
1735 unsigned long
PWMGenFaultTriggerGet(unsigned long ulBase,unsigned long ulGen,unsigned long ulGroup)1736 PWMGenFaultTriggerGet(unsigned long ulBase, unsigned long ulGen,
1737 unsigned long ulGroup)
1738 {
1739 //
1740 // Check for valid parameters.
1741 //
1742 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
1743 ASSERT(PWMGenValid(ulGen));
1744 ASSERT((ulGroup == PWM_FAULT_GROUP_0) || (ulGroup == PWM_FAULT_GROUP_1));
1745
1746 //
1747 // Return the current fault triggers.
1748 //
1749 if(ulGroup == PWM_FAULT_GROUP_0)
1750 {
1751 return(HWREG(PWM_GEN_BADDR(ulBase, ulGen) + PWM_O_X_FLTSRC0));
1752 }
1753 else
1754 {
1755 return(HWREG(PWM_GEN_BADDR(ulBase, ulGen) + PWM_O_X_FLTSRC1));
1756 }
1757 }
1758
1759 //*****************************************************************************
1760 //
1761 //! Returns the current state of the fault triggers for a given PWM generator.
1762 //!
1763 //! \param ulBase is the base address of the PWM module.
1764 //! \param ulGen is the PWM generator for which fault trigger states are being
1765 //! queried. This parameter must be one of \b PWM_GEN_0, \b PWM_GEN_1,
1766 //! \b PWM_GEN_2, or \b PWM_GEN_3.
1767 //! \param ulGroup indicates the subset of faults that are being queried. This
1768 //! parameter must be \b PWM_FAULT_GROUP_0 or \b PWM_FAULT_GROUP_1.
1769 //!
1770 //! This function allows an application to query the current state of each of
1771 //! the fault trigger inputs to a given PWM generator. The current state of
1772 //! each fault trigger input is returned unless PWMGenConfigure() has
1773 //! previously been called with flag \b PWM_GEN_MODE_FAULT_LATCHED in the
1774 //! \e ulConfig parameter, in which case the returned status is the latched
1775 //! fault trigger status.
1776 //!
1777 //! If latched faults are configured, the application must call
1778 //! PWMGenFaultClear() to clear each trigger.
1779 //!
1780 //! \note This function is only available on devices supporting extended PWM
1781 //! fault handling.
1782 //!
1783 //! \return Returns the current state of the fault triggers for the given PWM
1784 //! generator. A set bit indicates that the associated trigger is active.
1785 //! For \b PWM_FAULT_GROUP_0, the returned value is a logical OR of
1786 //! \b PWM_FAULT_FAULT0, \b PWM_FAULT_FAULT1, \b PWM_FAULT_FAULT2, or
1787 //! \b PWM_FAULT_FAULT3. For \b PWM_FAULT_GROUP_1, the return value is the
1788 //! logical OR of \b PWM_FAULT_DCMP0, \b PWM_FAULT_DCMP1,
1789 //! \b PWM_FAULT_DCMP2, \b PWM_FAULT_DCMP3, \b PWM_FAULT_DCMP4,
1790 //! \b PWM_FAULT_DCMP5, \b PWM_FAULT_DCMP6, or \b PWM_FAULT_DCMP7.
1791 //
1792 //*****************************************************************************
1793 unsigned long
PWMGenFaultStatus(unsigned long ulBase,unsigned long ulGen,unsigned long ulGroup)1794 PWMGenFaultStatus(unsigned long ulBase, unsigned long ulGen,
1795 unsigned long ulGroup)
1796 {
1797 //
1798 // Check for valid parameters.
1799 //
1800 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
1801 ASSERT(PWMGenValid(ulGen));
1802 ASSERT((ulGroup == PWM_FAULT_GROUP_0) || (ulGroup == PWM_FAULT_GROUP_1));
1803
1804 //
1805 // Return the current fault status.
1806 //
1807 if(ulGroup == PWM_FAULT_GROUP_0)
1808 {
1809 return(HWREG(PWM_GEN_EXT_BADDR(ulBase, ulGen) + PWM_O_X_FLTSTAT0));
1810 }
1811 else
1812 {
1813 return(HWREG(PWM_GEN_EXT_BADDR(ulBase, ulGen) + PWM_O_X_FLTSTAT1));
1814 }
1815 }
1816
1817 //*****************************************************************************
1818 //
1819 //! Clears one or more latched fault triggers for a given PWM generator.
1820 //!
1821 //! \param ulBase is the base address of the PWM module.
1822 //! \param ulGen is the PWM generator for which fault trigger states are being
1823 //! queried. This parameter must be one of \b PWM_GEN_0, \b PWM_GEN_1,
1824 //! \b PWM_GEN_2, or \b PWM_GEN_3.
1825 //! \param ulGroup indicates the subset of faults that are being queried.
1826 //! This parameter must be \b PWM_FAULT_GROUP_0 or \b PWM_FAULT_GROUP_1.
1827 //! \param ulFaultTriggers is the set of fault triggers which are to be
1828 //! cleared.
1829 //!
1830 //! This function allows an application to clear the fault triggers for a
1831 //! given PWM generator. This function is only required if PWMGenConfigure()
1832 //! has previously been called with flag \b PWM_GEN_MODE_FAULT_LATCHED in
1833 //! parameter \e ulConfig.
1834 //!
1835 //! \note This function is only available on devices supporting extended PWM
1836 //! fault handling.
1837 //!
1838 //! \return None.
1839 //
1840 //*****************************************************************************
1841 void
PWMGenFaultClear(unsigned long ulBase,unsigned long ulGen,unsigned long ulGroup,unsigned long ulFaultTriggers)1842 PWMGenFaultClear(unsigned long ulBase, unsigned long ulGen,
1843 unsigned long ulGroup, unsigned long ulFaultTriggers)
1844 {
1845 //
1846 // Check for valid parameters.
1847 //
1848 ASSERT((ulBase == PWM0_BASE) || (ulBase == PWM1_BASE));
1849 ASSERT(PWMGenValid(ulGen));
1850 ASSERT((ulGroup == PWM_FAULT_GROUP_0) || (ulGroup == PWM_FAULT_GROUP_1));
1851 ASSERT((ulGroup == PWM_FAULT_GROUP_0) &&
1852 ((ulFaultTriggers & ~(PWM_FAULT_FAULT0 | PWM_FAULT_FAULT1 |
1853 PWM_FAULT_FAULT2 | PWM_FAULT_FAULT3)) == 0));
1854 ASSERT((ulGroup == PWM_FAULT_GROUP_1) &&
1855 ((ulFaultTriggers & ~(PWM_FAULT_DCMP0 | PWM_FAULT_DCMP1 |
1856 PWM_FAULT_DCMP2 | PWM_FAULT_DCMP3 |
1857 PWM_FAULT_DCMP4 | PWM_FAULT_DCMP5 |
1858 PWM_FAULT_DCMP6 | PWM_FAULT_DCMP7)) == 0));
1859
1860 //
1861 // Clear the given faults.
1862 //
1863 if(ulGroup == PWM_FAULT_GROUP_0)
1864 {
1865 HWREG(PWM_GEN_EXT_BADDR(ulBase, ulGen) + PWM_O_X_FLTSTAT0) =
1866 ulFaultTriggers;
1867 }
1868 else
1869 {
1870 HWREG(PWM_GEN_EXT_BADDR(ulBase, ulGen) + PWM_O_X_FLTSTAT1) =
1871 ulFaultTriggers;
1872 }
1873 }
1874
1875 //*****************************************************************************
1876 //
1877 // Close the Doxygen group.
1878 //! @}
1879 //
1880 //*****************************************************************************
1881