MotorWare f2806x Driver API Documentation
cap.h
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2015, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #ifndef _CAP_H_
33 #define _CAP_H_
34 
41 
42 // **************************************************************************
43 // the includes
44 
45 // drivers
46 #include "sw/modules/types/src/types.h"
47 
48 
49 // modules
50 
51 
56 
57 
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 
63 
64 // **************************************************************************
65 // the defines
66 
67 
70 #define CAP1_BASE_ADDR (0x00006A00)
71 
74 #define CAP2_BASE_ADDR (0x00006A20)
75 
78 #define CAP3_BASE_ADDR (0x00006A40)
79 
80 
83 #define CAP_ECCTL1_FREESOFT_BITS (3 << 14)
84 
87 #define CAP_ECCTL1_PRESCALE_BITS (31 << 9)
88 
91 #define CAP_ECCTL1_CAPLDEN_BITS (1 << 8)
92 
95 #define CAP_ECCTL1_CTRRST4_BITS (1 << 7)
96 
99 #define CAP_ECCTL1_CAP4POL_BITS (1 << 6)
100 
103 #define CAP_ECCTL1_CTRRST3_BITS (1 << 5)
104 
107 #define CAP_ECCTL1_CAP3POL_BITS (1 << 4)
108 
111 #define CAP_ECCTL1_CTRRST2_BITS (1 << 3)
112 
115 #define CAP_ECCTL1_CAP2POL_BITS (1 << 2)
116 
119 #define CAP_ECCTL1_CTRRST1_BITS (1 << 1)
120 
123 #define CAP_ECCTL1_CAP1POL_BITS (1 << 0)
124 
125 
128 #define CAP_ECCTL2_APWMPOL_BITS (1 << 10)
129 
132 #define CAP_ECCTL2_CAPAPWM_BITS (1 << 9)
133 
136 #define CAP_ECCTL2_SWSYNC_BITS (1 << 8)
137 
140 #define CAP_ECCTL2_SYNCOSEL_BITS (3 << 6)
141 
144 #define CAP_ECCTL2_SYNCIEN_BITS (1 << 5)
145 
148 #define CAP_ECCTL2_TSCTRSTOP_BITS (1 << 4)
149 
152 #define CAP_ECCTL2_REARM_BITS (1 << 3)
153 
156 #define CAP_ECCTL2_STOP_WRAP_BITS (3 << 1)
157 
160 #define CAP_ECCTL2_CONTONESHOT_BITS (1 << 0)
161 
162 
165 #define CAP_ECCxxx_CTRCOMP_BITS (1 << 7)
166 
169 #define CAP_ECCxxx_CTRPRD_BITS (1 << 6)
170 
173 #define CAP_ECCxxx_CTROVF_BITS (1 << 5)
174 
177 #define CAP_ECCxxx_CEVT4_BITS (1 << 4)
178 
181 #define CAP_ECCxxx_CEVT3_BITS (1 << 3)
182 
185 #define CAP_ECCxxx_CEVT2_BITS (1 << 2)
186 
189 #define CAP_ECCxxx_CEVT1_BITS (1 << 1)
190 
193 #define CAP_ECCxxx_INT_BITS (1 << 0)
194 
195 
196 
197 
198 // **************************************************************************
199 // the typedefs
200 
203 typedef enum
204 {
205  CAP_Int_Type_CTR_CMP = (1 << 7),
206  CAP_Int_Type_CTR_PRD = (1 << 6),
207  CAP_Int_Type_CTR_OVF = (1 << 5),
208  CAP_Int_Type_CEVT4 = (1 << 4),
209  CAP_Int_Type_CEVT3 = (1 << 3),
210  CAP_Int_Type_CEVT2 = (1 << 2),
211  CAP_Int_Type_CEVT1 = (1 << 1),
212  CAP_Int_Type_Global = (1 << 0),
215 
218 typedef enum
219 {
220  CAP_Prescale_By_1 = (0 << 9),
221  CAP_Prescale_By_2 = (1 << 9),
222  CAP_Prescale_By_4 = (2 << 9),
223  CAP_Prescale_By_6 = (3 << 9),
224  CAP_Prescale_By_8 = (4 << 9),
225  CAP_Prescale_By_10 = (5 << 9),
226  CAP_Prescale_By_12 = (6 << 9),
227  CAP_Prescale_By_14 = (7 << 9),
228  CAP_Prescale_By_16 = (8 << 9),
229  CAP_Prescale_By_18 = (9 << 9),
230  CAP_Prescale_By_20 = (10 << 9),
231  CAP_Prescale_By_22 = (11 << 9),
232  CAP_Prescale_By_24 = (12 << 9),
233  CAP_Prescale_By_26 = (13 << 9),
234  CAP_Prescale_By_28 = (14 << 9),
235  CAP_Prescale_By_30 = (15 << 9),
236  CAP_Prescale_By_32 = (16 << 9),
237  CAP_Prescale_By_34 = (17 << 9),
238  CAP_Prescale_By_36 = (18 << 9),
239  CAP_Prescale_By_38 = (19 << 9),
240  CAP_Prescale_By_40 = (20 << 9),
241  CAP_Prescale_By_42 = (21 << 9),
242  CAP_Prescale_By_44 = (22 << 9),
243  CAP_Prescale_By_46 = (23 << 9),
244  CAP_Prescale_By_48 = (24 << 9),
245  CAP_Prescale_By_50 = (25 << 9),
246  CAP_Prescale_By_52 = (26 << 9),
247  CAP_Prescale_By_54 = (27 << 9),
248  CAP_Prescale_By_56 = (28 << 9),
249  CAP_Prescale_By_58 = (29 << 9),
250  CAP_Prescale_By_60 = (30 << 9),
251  CAP_Prescale_By_62 = (31 << 9)
253 
256 typedef enum
257 {
258  CAP_RunMode_HardStop = (0 << 14),
261 } CAP_RunMode_e;
262 
265 typedef enum
266 {
267  CAP_Stop_Wrap_CEVT1 = (0 << 1),
268  CAP_Stop_Wrap_CEVT2 = (1 << 1),
269  CAP_Stop_Wrap_CEVT3 = (2 << 1),
272 
275 typedef enum
276 {
281 } CAP_Event_e;
282 
285 typedef enum
286 {
290 
291 
294 typedef enum
295 {
298 } CAP_Reset_e;
299 
302 typedef enum
303 {
304  CAP_SyncOut_SyncIn = (0 << 6),
305  CAP_SyncOut_CTRPRD = (1 << 6),
307 } CAP_SyncOut_e;
308 
309 
312 typedef struct _CAP_Obj_
313 {
314  volatile uint32_t TSCTR;
315  volatile uint32_t CTRPHS;
316  volatile uint32_t CAP1;
317  volatile uint32_t CAP2;
318  volatile uint32_t CAP3;
319  volatile uint32_t CAP4;
320  volatile uint16_t Rsvd_1[8];
321  volatile uint16_t ECCTL1;
322  volatile uint16_t ECCTL2;
323  volatile uint16_t ECEINT;
324  volatile uint16_t ECEFLG;
325  volatile uint16_t ECECLR;
326  volatile uint16_t ECEFRC;
327 
328 } CAP_Obj;
329 
330 
333 typedef struct _CAP_Obj_ *CAP_Handle;
334 
335 
336 // **************************************************************************
337 // the globals
338 
339 
340 // **************************************************************************
341 // the function prototypes
342 
343 
344 
347 extern void CAP_setModeCap(CAP_Handle capHandle);
348 
351 extern void CAP_setModeApwm(CAP_Handle capHandle);
352 
356 static inline void CAP_clearInt(CAP_Handle capHandle, const CAP_Int_Type_e intType)
357 {
358  CAP_Obj *cap = (CAP_Obj *)capHandle;
359 
360  cap->ECECLR |= intType;
361 
362  return;
363 }
364 
367 extern void CAP_disableCaptureLoad(CAP_Handle capHandle);
368 
372 extern void CAP_disableInt(CAP_Handle capHandle, const CAP_Int_Type_e intType);
373 
376 extern void CAP_disableSyncIn(CAP_Handle capHandle);
377 
380 extern void CAP_disableTimestampCounter(CAP_Handle capHandle);
381 
384 extern void CAP_enableCaptureLoad(CAP_Handle capHandle);
385 
389 extern void CAP_enableInt(CAP_Handle capHandle, const CAP_Int_Type_e intType);
390 
393 extern void CAP_enableSyncIn(CAP_Handle capHandle);
394 
397 extern void CAP_enableTimestampCounter(CAP_Handle capHandle);
398 
401 static inline uint32_t CAP_getCap1(CAP_Handle capHandle)
402 {
403  CAP_Obj *cap = (CAP_Obj *)capHandle;
404 
405  return (cap->CAP1);
406 } // end of CAP_getCap1() function
407 
410 static inline uint32_t CAP_getCap2(CAP_Handle capHandle)
411 {
412  CAP_Obj *cap = (CAP_Obj *)capHandle;
413 
414  return (cap->CAP2);
415 } // end of CAP_getCap2() function
416 
419 static inline uint32_t CAP_getCap3(CAP_Handle capHandle)
420 {
421  CAP_Obj *cap = (CAP_Obj *)capHandle;
422 
423  return (cap->CAP3);
424 } // end of CAP_getCap3() function
425 
428 static inline uint32_t CAP_getCap4(CAP_Handle capHandle)
429 {
430  CAP_Obj *cap = (CAP_Obj *)capHandle;
431 
432  return (cap->CAP4);
433 } // end of CAP_getCap4() function
434 
437 static inline void CAP_rearm(CAP_Handle capHandle)
438 {
439  CAP_Obj *cap = (CAP_Obj *)capHandle;
440 
442 
443  return;
444 } // end of CAP_rearm() function
445 
450 extern void CAP_setCapEvtPolarity(CAP_Handle capHandle, const CAP_Event_e event, const CAP_Polarity_e polarity);
451 
456 extern void CAP_setCapEvtReset(CAP_Handle capHandle, const CAP_Event_e event, const CAP_Reset_e reset);
457 
460 extern void CAP_setCapContinuous(CAP_Handle capHandle);
461 
464 extern void CAP_setCapOneShot(CAP_Handle capHandle);
465 
469 static inline void CAP_setApwmPeriod(CAP_Handle capHandle, const uint32_t period)
470 {
471  CAP_Obj *cap = (CAP_Obj *)capHandle;
472 
473  cap->CAP1 = period;
474 
475  return;
476 } // end of CAP_setApwmPeriod() function
477 
481 static inline void CAP_setApwmCompare(CAP_Handle capHandle, const uint32_t compare)
482 {
483  CAP_Obj *cap = (CAP_Obj *)capHandle;
484 
485  cap->CAP2 = compare;
486 
487  return;
488 } // end of CAP_setApwmCompare() function
489 
493 static inline void CAP_setApwmShadowPeriod(CAP_Handle capHandle, const uint32_t shadowPeriod)
494 {
495  CAP_Obj *cap = (CAP_Obj *)capHandle;
496 
497  cap->CAP3 = shadowPeriod;
498 
499  return;
500 } // end of CAP_setApwmShadowPeriod() function
501 
505 extern void CAP_setStopWrap(CAP_Handle capHandle, const CAP_Stop_Wrap_e stopWrap);
506 
510 extern void CAP_setSyncOut(CAP_Handle capHandle, const CAP_SyncOut_e syncOut);
511 
516 extern CAP_Handle CAP_init(void *pMemory,const size_t numBytes);
517 
518 
519 
520 #ifdef __cplusplus
521 }
522 #endif // extern "C"
523 
525 #endif // end of _CAP_H_ definition
526 
Sync In used for Sync Out.
Definition: cap.h:304
Denotes All interrupts.
Definition: cap.h:213
void CAP_setModeApwm(CAP_Handle capHandle)
Sets capture peripheral up for APWM mode.
Definition: cap.c:213
volatile uint32_t CAP4
Capture 4 Register.
Definition: cap.h:319
volatile uint32_t CAP1
Capture 1 Register.
Definition: cap.h:316
Divide by 62.
Definition: cap.h:251
void CAP_disableInt(CAP_Handle capHandle, const CAP_Int_Type_e intType)
Disables capture (CAP) interrupt source.
Definition: cap.c:91
void CAP_setModeCap(CAP_Handle capHandle)
Sets capture peripheral up for capture mode.
Definition: cap.c:202
Divide by 38.
Definition: cap.h:239
CTR = PRD used for Sync Out.
Definition: cap.h:305
void CAP_enableSyncIn(CAP_Handle capHandle)
Enables counter synchronization.
Definition: cap.c:133
Divide by 22.
Definition: cap.h:231
volatile uint16_t ECEINT
Capture Interrupt Enable Register.
Definition: cap.h:323
static uint32_t CAP_getCap3(CAP_Handle capHandle)
Gets the CAP3 register value.
Definition: cap.h:419
Divide by 26.
Definition: cap.h:233
Defines the capture (CAP) object.
Definition: cap.h:312
Divide by 1.
Definition: cap.h:220
Disables Sync Out.
Definition: cap.h:306
Divide by 42.
Definition: cap.h:241
Divide by 50.
Definition: cap.h:245
Divide by 14.
Definition: cap.h:227
void CAP_disableSyncIn(CAP_Handle capHandle)
Disables counter synchronization.
Definition: cap.c:80
static void CAP_clearInt(CAP_Handle capHandle, const CAP_Int_Type_e intType)
Clears capture (CAP) interrupt flag.
Definition: cap.h:356
volatile uint32_t CAP2
Capture 2 Register.
Definition: cap.h:317
Divide by 20.
Definition: cap.h:230
CAP_Prescale_e
Enumeration to define the capture (CAP) prescaler values.
Definition: cap.h:218
struct _CAP_Obj_ * CAP_Handle
Defines the capture (CAP) handle.
Definition: cap.h:333
struct _CAP_Obj_ CAP_Obj
Defines the capture (CAP) object.
Denotes CTR = PRD interrupt.
Definition: cap.h:206
Denotes CEVT2 interrupt.
Definition: cap.h:210
static void CAP_setApwmShadowPeriod(CAP_Handle capHandle, const uint32_t shadowPeriod)
Sets the APWM shadow period.
Definition: cap.h:493
volatile uint32_t CAP3
Capture 3 Register.
Definition: cap.h:318
Denotes CEVT3 interrupt.
Definition: cap.h:209
Enable counter reset on capture event.
Definition: cap.h:297
volatile uint16_t ECEFRC
Capture Interrupt Force Register.
Definition: cap.h:326
void CAP_setCapEvtReset(CAP_Handle capHandle, const CAP_Event_e event, const CAP_Reset_e reset)
Sets the capture event counter reset configuration.
Definition: cap.c:167
Divide by 6.
Definition: cap.h:223
Divide by 30.
Definition: cap.h:235
Divide by 4.
Definition: cap.h:222
Divide by 34.
Definition: cap.h:237
Divide by 54.
Definition: cap.h:247
CAP_Int_Type_e
Enumeration to define the capture (CAP) interrupts.
Definition: cap.h:203
volatile uint32_t TSCTR
Time-stamp Counter.
Definition: cap.h:314
volatile uint32_t CTRPHS
Counter Phase Offset Value Register.
Definition: cap.h:315
void CAP_setSyncOut(CAP_Handle capHandle, const CAP_SyncOut_e syncOut)
Set the sync out mode.
Definition: cap.c:238
Divide by 18.
Definition: cap.h:229
void CAP_enableCaptureLoad(CAP_Handle capHandle)
Enables loading of CAP1-4 on capture event.
Definition: cap.c:112
Disable counter reset on capture event.
Definition: cap.h:296
Divide by 10.
Definition: cap.h:225
Divide by 40.
Definition: cap.h:240
volatile uint16_t ECEFLG
Capture Interrupt Flag Register.
Definition: cap.h:324
Divide by 52.
Definition: cap.h:246
Divide by 12.
Definition: cap.h:226
Stop/Wrap after Capture Event 2.
Definition: cap.h:268
volatile uint16_t ECCTL1
Capture Control Register 1.
Definition: cap.h:321
Denotes CTR = CMP interrupt.
Definition: cap.h:205
void CAP_disableCaptureLoad(CAP_Handle capHandle)
Disables loading of CAP1-4 on capture event.
Definition: cap.c:70
Capture Event 1.
Definition: cap.h:277
void CAP_setCapEvtPolarity(CAP_Handle capHandle, const CAP_Event_e event, const CAP_Polarity_e polarity)
Sets the capture event polarity.
Definition: cap.c:154
Stop/Wrap after Capture Event 1.
Definition: cap.h:267
void CAP_setStopWrap(CAP_Handle capHandle, const CAP_Stop_Wrap_e stopWrap)
Set the stop/wrap mode.
Definition: cap.c:224
Divide by 24.
Definition: cap.h:232
Divide by 56.
Definition: cap.h:248
Divide by 16.
Definition: cap.h:228
CAP_Stop_Wrap_e
Enumeration to define the capture (CAP) Stop/Wrap modes.
Definition: cap.h:265
Capture Event 4.
Definition: cap.h:280
Divide by 28.
Definition: cap.h:234
static uint32_t CAP_getCap1(CAP_Handle capHandle)
Gets the CAP1 register value.
Definition: cap.h:401
void CAP_enableTimestampCounter(CAP_Handle capHandle)
Enables Time Stamp counter to running.
Definition: cap.c:144
Divide by 8.
Definition: cap.h:224
CAP_SyncOut_e
Enumeration to define the Sync Out options.
Definition: cap.h:302
static uint32_t CAP_getCap2(CAP_Handle capHandle)
Gets the CAP2 register value.
Definition: cap.h:410
Divide by 32.
Definition: cap.h:236
static void CAP_setApwmCompare(CAP_Handle capHandle, const uint32_t compare)
Sets the APWM compare value.
Definition: cap.h:481
#define CAP_ECCTL2_REARM_BITS
Defines the location of the REARM bits in the ECCTL2 register.
Definition: cap.h:152
Divide by 36.
Definition: cap.h:238
Divide by 58.
Definition: cap.h:249
CAP_Polarity_e
Enumeration to define the capture (CAP) event polarities.
Definition: cap.h:285
Divide by 46.
Definition: cap.h:243
Capture Event 2.
Definition: cap.h:278
Denotes CEVT1 interrupt.
Definition: cap.h:211
Divide by 60.
Definition: cap.h:250
void CAP_disableTimestampCounter(CAP_Handle capHandle)
Disables Time Stamp counter from running.
Definition: cap.c:102
CAP_Reset_e
Enumeration to define the capture (CAP) event resets.
Definition: cap.h:294
static void CAP_rearm(CAP_Handle capHandle)
(Re-)Arm the capture module
Definition: cap.h:437
CAP_RunMode_e
Enumeration to define the pulse width modulation (PWM) run modes.
Definition: cap.h:256
Denotes CEVT4 interrupt.
Definition: cap.h:208
volatile uint16_t ECCTL2
Capture Control Register 2.
Definition: cap.h:322
Divide by 2.
Definition: cap.h:221
static uint32_t CAP_getCap4(CAP_Handle capHandle)
Gets the CAP4 register value.
Definition: cap.h:428
Rising Edge Triggered.
Definition: cap.h:287
Divide by 48.
Definition: cap.h:244
Falling Edge Triggered.
Definition: cap.h:288
static void CAP_setApwmPeriod(CAP_Handle capHandle, const uint32_t period)
Sets the APWM period.
Definition: cap.h:469
Denotes CTROVF interrupt.
Definition: cap.h:207
Capture Event 3.
Definition: cap.h:279
CAP_Handle CAP_init(void *pMemory, const size_t numBytes)
Initializes the capture (CAP) object handle.
Definition: cap.c:56
Divide by 44.
Definition: cap.h:242
Stop/Wrap after Capture Event 3.
Definition: cap.h:269
void CAP_enableInt(CAP_Handle capHandle, const CAP_Int_Type_e intType)
Enables capture (CAP) interrupt source.
Definition: cap.c:122
volatile uint16_t ECECLR
Capture Interrupt Clear Register.
Definition: cap.h:325
Stop/Wrap after Capture Event 4.
Definition: cap.h:270
CAP_Event_e
Enumeration to define the capture (CAP) events.
Definition: cap.h:275
volatile uint16_t Rsvd_1[8]
Reserved.
Definition: cap.h:320
Denotes Capture global interrupt.
Definition: cap.h:212
void CAP_setCapContinuous(CAP_Handle capHandle)
Sets up for continuous Capture.
Definition: cap.c:180
void CAP_setCapOneShot(CAP_Handle capHandle)
Sets up for one-shot Capture.
Definition: cap.c:191