MotorWare f2806x Driver API Documentation
pie.c
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--*/
37 
38 // **************************************************************************
39 // the includes
40 
42 
43 
44 // **************************************************************************
45 // the defines
46 
47 
48 // **************************************************************************
49 // the globals
50 
51 
52 // **************************************************************************
53 // the functions
54 
56 {
57  PIE_Obj *pie = (PIE_Obj *)pieHandle;
58  uint_least8_t groupCnt;
59 
60 
61  for(groupCnt=0;groupCnt<12;groupCnt++)
62  {
63  pie->PIEIER_PIEIFR[groupCnt].IFR = 0;
64  }
65 
66  return;
67 } // end of PIE_clearAllFlags() function
68 
69 
71 {
72  PIE_Obj *pie = (PIE_Obj *)pieHandle;
73 
74 
75  // set the bits
76  pie->PIEACK |= 0xFFFF;
77 
78  return;
79 } // end of PIE_clearAllInts() function
80 
81 
82 void PIE_disable(PIE_Handle pieHandle)
83 {
84  PIE_Obj *pie = (PIE_Obj *)pieHandle;
85 
86 
87  // clear the bits
89 
90  return;
91 } // end of PIE_disable() function
92 
94 {
95  PIE_Obj *pie = (PIE_Obj *)pieHandle;
96 
97  // set the value
99 
100  return;
101 } // end of PIE_disableCaptureInt() function
102 
103 
104 void PIE_disableExtInt(PIE_Handle pieHandle, const CPU_ExtIntNumber_e intNumber)
105 {
106  PIE_Obj *pie = (PIE_Obj *)pieHandle;
107 
108 
109  // clear the bits
110  pie->XINTnCR[intNumber] &= (~PIE_XINTnCR_ENABLE_BITS);
111 
112  return;
113 } // end of PIE_disableExtInt() function
114 
115 
117 {
118  PIE_Obj *pie = (PIE_Obj *)pieHandle;
119 
120  uint_least8_t groupCnt;
121 
122  for(groupCnt=0;groupCnt<12;groupCnt++)
123  {
124  pie->PIEIER_PIEIFR[groupCnt].IER = 0;
125  }
126 
127  return;
128 } // end of PIE_disableAllInts() function
129 
130 void PIE_disableInt(PIE_Handle pieHandle, const PIE_GroupNumber_e group, const PIE_InterruptSource_e intSource)
131 {
132  PIE_Obj *pie = (PIE_Obj *)pieHandle;
133 
134  pie->PIEIER_PIEIFR[group].IER &= ~intSource;
135 
136  return;
137 }
138 
139 
140 void PIE_enable(PIE_Handle pieHandle)
141 {
142  PIE_Obj *pie = (PIE_Obj *)pieHandle;
143 
144 
145  // set the bits
147 
148  return;
149 } // end of PIE_enable() function
150 
151 
152 void PIE_enableAdcInt(PIE_Handle pieHandle, const ADC_IntNumber_e intNumber)
153 {
154  PIE_Obj *pie = (PIE_Obj *)pieHandle;
155  uint16_t index;
156  uint16_t setValue;
157 
158 
159  if(intNumber < ADC_IntNumber_9)
160  {
161  index = 9;
162  setValue = 1 << intNumber;
163  }
164  else if(intNumber == ADC_IntNumber_9)
165  {
166  index = 0;
167  setValue = 1 << 5;
168  }
169  else
170  {
171  index = 0;
172  setValue = 1 << ((intNumber & 0x07) - 1) ;
173  }
174 
175  // set the value
176  pie->PIEIER_PIEIFR[index].IER |= setValue;
177 
178  return;
179 } // end of PIE_enableAdcInt() function
180 
182 {
183  PIE_Obj *pie = (PIE_Obj *)pieHandle;
184 
185  // set the value
187 
188  return;
189 } // end of PIE_enableCaptureInt() function
190 
191 
192 void PIE_enableExtInt(PIE_Handle pieHandle, const CPU_ExtIntNumber_e intNumber)
193 {
194  PIE_Obj *pie = (PIE_Obj *)pieHandle;
195  uint16_t index;
196  uint16_t setValue;
197 
198 
199  if(intNumber < CPU_ExtIntNumber_3)
200  {
201  index = 0;
202  setValue = 1 << (intNumber + 3);
203  }
204  else
205  {
206  index = 10;
207  setValue = 1 << 0;
208  }
209 
210 
211  // set the value
212  pie->PIEIER_PIEIFR[index].IER |= setValue;
213 
214 
215  // set the bits
216  pie->XINTnCR[intNumber] |= PIE_XINTnCR_ENABLE_BITS;
217 
218  return;
219 } // end of PIE_enableExtInt() function
220 
221 void PIE_enableInt(PIE_Handle pieHandle, const PIE_GroupNumber_e group, const PIE_InterruptSource_e intSource)
222 {
223  PIE_Obj *pie = (PIE_Obj *)pieHandle;
224 
225  pie->PIEIER_PIEIFR[group].IER |= intSource;
226 
227  return;
228 }
229 
230 
231 void PIE_enablePwmInt(PIE_Handle pieHandle, const PWM_Number_e pwmNumber)
232 {
233  PIE_Obj *pie = (PIE_Obj *)pieHandle;
234  uint16_t index = 2;
235  uint16_t setValue = (1 << pwmNumber);
236 
237 
238  // set the value
239  pie->PIEIER_PIEIFR[index].IER |= setValue;
240 
241  return;
242 } // end of PIE_enablePwmInt() function
243 
244 void PIE_enablePwmTzInt(PIE_Handle pieHandle, const PWM_Number_e pwmNumber)
245 {
246  PIE_Obj *pie = (PIE_Obj *)pieHandle;
247  uint16_t index = 1;
248  uint16_t setValue = (1 << pwmNumber);
249 
250 
251  // set the value
252  pie->PIEIER_PIEIFR[index].IER |= setValue;
253 
254  return;
255 } // end of PIE_enablePwmTzInt() function
256 
258 {
259  PIE_Obj *pie = (PIE_Obj *)pieHandle;
260 
261  // set the value
263 
264  return;
265 } // end of PIE_enableTimer0Int() function
266 
267 
268 void PIE_forceInt(PIE_Handle pieHandle, const PIE_GroupNumber_e group, const PIE_InterruptSource_e intSource)
269 {
270  PIE_Obj *pie = (PIE_Obj *)pieHandle;
271 
272  pie->PIEIER_PIEIFR[group].IFR |= intSource;
273 
274  return;
275 }
276 
277 
278 uint16_t PIE_getExtIntCount(PIE_Handle pieHandle, const CPU_ExtIntNumber_e intNumber)
279 {
280  PIE_Obj *pie = (PIE_Obj *)pieHandle;
281 
282 
283  // get the count value
284  uint16_t count = pie->XINTnCTR[intNumber];
285 
286  return(count);
287 } // end of PIE_getExtIntCount() function
288 
289 
290 uint16_t PIE_getIntEnables(PIE_Handle pieHandle, const PIE_GroupNumber_e group)
291 {
292  PIE_Obj *pie = (PIE_Obj *)pieHandle;
293 
294  return (pie->PIEIER_PIEIFR[group].IER);
295 } // end of PIE_getIntEnables() function
296 
297 
298 uint16_t PIE_getIntFlags(PIE_Handle pieHandle, const PIE_GroupNumber_e group)
299 {
300  PIE_Obj *pie = (PIE_Obj *)pieHandle;
301 
302  return (pie->PIEIER_PIEIFR[group].IFR);
303 } // end of PIE_getIntFlags() function
304 
305 
306 interrupt void PIE_illegalIsr(void)
307 {
308 
309  // The next two lines are placeholders
310  asm(" ESTOP0");
311 
312  // endless hold loop
313  for(;;);
314 
315 } // end of PIE_illegalIsr() function
316 
317 
318 PIE_Handle PIE_init(void *pMemory, const size_t numBytes)
319 {
320  PIE_Handle pieHandle;
321 
322 
323  if(numBytes < sizeof(PIE_Obj))
324  return((PIE_Handle)NULL);
325 
326  // assign the handle
327  pieHandle = (PIE_Handle)pMemory;
328 
329  return(pieHandle);
330 } // end of PIE_init() function
331 
332 
333 
335  const PIE_GroupNumber_e groupNumber,
336  const PIE_SubGroupNumber_e subGroupNumber,
337  const PIE_IntVec_t vector)
338 {
339  PIE_Obj *pie = (PIE_Obj *)pieHandle;
340  PIE_IntVec_t *intPointer;
341 
343 
344  // Point to the beginning of the PIE table
345  intPointer = (PIE_IntVec_t *)&(pie->ADCINT1_HP);
346 
347  // Increment pointer to the correct group
348  intPointer += groupNumber * 8;
349 
350  // Increment point to the correct subgroup
351  intPointer += subGroupNumber;
352 
353  // Set the vector
354  *intPointer = vector;
355 
357 
358  return;
359 } // end of PIE_registerIntHandler() function
360 
361 
363  const PIE_SystemInterrupts_e systemInt,
364  const PIE_IntVec_t vector)
365 {
366  PIE_Obj *pie = (PIE_Obj *)pieHandle;
367  PIE_IntVec_t *intPointer;
368 
370 
371  // Point to the beginning of the system interrupt table
372  intPointer = (PIE_IntVec_t *)&(pie->Reset);
373 
374  // Increment point to the correct interrupt
375  intPointer += systemInt;
376 
377  // Set the vector
378  *intPointer = vector;
379 
381 
382  return;
383 } // end of PIE_registerIntHandler() function
384 
385 
387 {
388  PIE_Obj *pie = (PIE_Obj *)pieHandle;
389  PIE_IntVec_t *addr = (PIE_IntVec_t *)&(pie->INT1);
390  uint16_t regCnt;
391 
393 
394  // initialize the table to PIE_illegalIsr() address
395  for(regCnt=0;regCnt<120;regCnt++)
396  {
397  *addr++ = &PIE_illegalIsr;
398  }
399 
401 
402  return;
403 } // end of PIE_setDefaultIntVectorTable() function
404 
405 
407  const CPU_ExtIntNumber_e intNumber,
408  const PIE_ExtIntPolarity_e polarity)
409 {
410  PIE_Obj *pie = (PIE_Obj *)pieHandle;
411 
412 
413  // clear the bits
414  pie->XINTnCR[intNumber] &= (~PIE_XINTnCR_POLARITY_BITS);
415 
416  // set the bits
417  pie->XINTnCR[intNumber] |= polarity;
418 
419  return;
420 } // end of PIE_setExtIntPolarity() function
421 
422 
424  const PIE_GroupNumber_e groupNumber,
425  const PIE_SubGroupNumber_e subGroupNumber)
426 {
427  PIE_Obj *pie = (PIE_Obj *)pieHandle;
428  PIE_IntVec_t *intPointer;
429 
431 
432  // Point to the beginning of the PIE table
433  intPointer = (PIE_IntVec_t *)&(pie->ADCINT1_HP);
434 
435  // Increment pointer to the correct group
436  intPointer += groupNumber * 8;
437 
438  // Increment point to the correct subgroup
439  intPointer += subGroupNumber;
440 
441  // Set the vector
442  *intPointer = PIE_illegalIsr;
443 
445 
446  return;
447 } // end of PIE_unregisterPieIntHandler() function
448 
449 
451  const PIE_SystemInterrupts_e systemInt)
452 {
453  PIE_Obj *pie = (PIE_Obj *)pieHandle;
454  PIE_IntVec_t *intPointer;
455 
457 
458  // Point to the beginning of the system interrupt table
459  intPointer = (PIE_IntVec_t *)&(pie->Reset);
460 
461  // Increment point to the correct interrupt
462  intPointer += systemInt;
463 
464  // Set the vector
465  *intPointer = PIE_illegalIsr;
466 
468 
469  return;
470 } // end of PIE_unregisterSystemIntHandler() function
471 
472 // end of file
Contains public interface to various functions related to the peripheral interrupt expansion (PIE) ob...
volatile uint16_t IER
the Interrupt Enable Register (IER)
Definition: pie.h:596
#define DISABLE_PROTECTED_REGISTER_WRITE_MODE
Define to disable protected register writes.
Definition: cpu.h:101
void PIE_clearAllFlags(PIE_Handle pieHandle)
Clears all the interrupt flags.
Definition: pie.c:55
void PIE_enableInt(PIE_Handle pieHandle, const PIE_GroupNumber_e group, const PIE_InterruptSource_e intSource)
Enable a specific PIE interrupt.
Definition: pie.c:221
void PIE_enableExtInt(PIE_Handle pieHandle, const CPU_ExtIntNumber_e intNumber)
Enables the prescribed external interrupt.
Definition: pie.c:192
volatile uint16_t IFR
the Interrupt Flag Register (IFR)
Definition: pie.h:597
PIE_ExtIntPolarity_e
Enumeration to define the external interrupt polarity.
Definition: pie.h:408
void PIE_setDefaultIntVectorTable(PIE_Handle pieHandle)
Initializes the vector table with illegal ISR handlers.
Definition: pie.c:386
void PIE_enablePwmInt(PIE_Handle pieHandle, const PWM_Number_e pwmNumber)
Enables the PWM interrupt.
Definition: pie.c:231
void PIE_enableTimer0Int(PIE_Handle pieHandle)
Enables the Cpu Timer 0 interrupt.
Definition: pie.c:257
void PIE_forceInt(PIE_Handle pieHandle, const PIE_GroupNumber_e group, const PIE_InterruptSource_e intSource)
Force a specific PIE interrupt.
Definition: pie.c:268
#define PIE_IERx_INTx7_BITS
Defines the location of the INTx7 bits in the IERx register.
Definition: pie.h:230
Defines the peripheral interrupt expansion (PIE) object.
Definition: pie.h:603
Denotes ADCINT9.
Definition: adc.h:242
volatile PIE_IERIFR_t PIEIER_PIEIFR[12]
PIE Interrupt Enable Register and PIE Interrupt Flag Register.
Definition: pie.h:607
struct _PIE_Obj_ * PIE_Handle
Defines the peripheral interrupt expansion (PIE) handle.
Definition: pie.h:768
uint16_t PIE_getIntEnables(PIE_Handle pieHandle, const PIE_GroupNumber_e group)
Gets PIE interrupt enable values.
Definition: pie.c:290
void PIE_unregisterPieIntHandler(PIE_Handle pieHandle, const PIE_GroupNumber_e groupNumber, const PIE_SubGroupNumber_e subGroupNumber)
Unregisters a handler for a PIE interrupt.
Definition: pie.c:423
void PIE_registerPieIntHandler(PIE_Handle pieHandle, const PIE_GroupNumber_e groupNumber, const PIE_SubGroupNumber_e subGroupNumber, const PIE_IntVec_t vector)
Registers a handler for a PIE interrupt.
Definition: pie.c:334
interrupt void PIE_illegalIsr(void)
Defines an illegal interrupt service routine - if the program pointer references this function...
Definition: pie.c:306
#define ENABLE_PROTECTED_REGISTER_WRITE_MODE
Define to allow protected register writes.
Definition: cpu.h:93
PIE_SystemInterrupts_e
Enumeration to define the system interrupts.
Definition: pie.h:452
void PIE_enableCaptureInt(PIE_Handle pieHandle)
Enables the capture interrupt.
Definition: pie.c:181
interrupt void(* PIE_IntVec_t)(void)
Defines the type for an interrupt vector.
Definition: pie.h:403
ADC_IntNumber_e
Enumeration to define the analog-to-digital converter (ADC) interrupt number.
Definition: adc.h:232
#define PIE_IERx_INTx1_BITS
Defines the location of the INTx1 bits in the IERx register.
Definition: pie.h:206
volatile uint16_t PIECTRL
PIE Control Register.
Definition: pie.h:605
void PIE_disableExtInt(PIE_Handle pieHandle, const CPU_ExtIntNumber_e intNumber)
Definition: pie.c:104
void PIE_disable(PIE_Handle pieHandle)
Disables the peripheral interrupt expansion (PIE)
Definition: pie.c:82
#define PIE_XINTnCR_POLARITY_BITS
Definition: pie.h:394
void PIE_enable(PIE_Handle pieHandle)
Enables the peripheral interrupt expansion (PIE)
Definition: pie.c:140
void PIE_registerSystemIntHandler(PIE_Handle pieHandle, const PIE_SystemInterrupts_e systemInt, const PIE_IntVec_t vector)
Registers a handler for a PIE interrupt.
Definition: pie.c:362
uint16_t PIE_getIntFlags(PIE_Handle pieHandle, const PIE_GroupNumber_e group)
Gets PIE interrupt flag values.
Definition: pie.c:298
void PIE_enablePwmTzInt(PIE_Handle pieHandle, const PWM_Number_e pwmNumber)
Enables the PWM Trip Zone interrupt.
Definition: pie.c:244
#define PIE_PIECTRL_ENPIE_BITS
Defines the location of the ENPIE bits in the PIECTRL register.
Definition: pie.h:337
PIE_GroupNumber_e
Enumeration to define the peripheral interrupt expansion (PIE) group numbers.
Definition: pie.h:418
#define PIE_XINTnCR_ENABLE_BITS
Definition: pie.h:395
uint16_t PIE_getExtIntCount(PIE_Handle pieHandle, const CPU_ExtIntNumber_e intNumber)
Gets the external interrupt count value.
Definition: pie.c:278
volatile PIE_IntVec_t Reset
Reset interrupt vector.
Definition: pie.h:609
void PIE_setExtIntPolarity(PIE_Handle pieHandle, const CPU_ExtIntNumber_e intNumber, const PIE_ExtIntPolarity_e polarity)
Sets the external interrupt polarity.
Definition: pie.c:406
volatile uint16_t XINTnCTR[3]
External Interrupt n Counter Register.
Definition: pie.h:762
Denotes external interrupt number 3.
Definition: cpu.h:408
void PIE_disableAllInts(PIE_Handle pieHandle)
Disables all of the interrupts.
Definition: pie.c:116
CPU_ExtIntNumber_e
Enumeration to define the external interrupt numbers.
Definition: cpu.h:404
PIE_InterruptSource_e
Enumeration to define the peripheral interrupt expansion (PIE) individual interrupt sources...
Definition: pie.h:491
PIE_Handle PIE_init(void *pMemory, const size_t numBytes)
Initializes the peripheral interrupt expansion (PIE) object handle.
Definition: pie.c:318
volatile uint16_t XINTnCR[3]
External Interrupt n Control Register.
Definition: pie.h:760
void PIE_clearAllInts(PIE_Handle pieHandle)
Clears all the interrupts.
Definition: pie.c:70
PIE_SubGroupNumber_e
Enumeration to define the peripheral interrupt expansion (PIE) sub-group numbers. ...
Definition: pie.h:437
void PIE_enableAdcInt(PIE_Handle pieHandle, const ADC_IntNumber_e intNumber)
Enables the specified ADC interrupt.
Definition: pie.c:152
void PIE_unregisterSystemIntHandler(PIE_Handle pieHandle, const PIE_SystemInterrupts_e systemInt)
Unregisters a handler for a PIE interrupt.
Definition: pie.c:450
PWM_Number_e
Enumeration to define the pulse width modulation (PWM) numbers.
Definition: pwm.h:715
volatile PIE_IntVec_t ADCINT1_HP
ADC high priority interrupt.
Definition: pie.h:642
void PIE_disableCaptureInt(PIE_Handle pieHandle)
Disables the capture interrupt.
Definition: pie.c:93
volatile PIE_IntVec_t INT1
INT1 interrupt vector.
Definition: pie.h:610
volatile uint16_t PIEACK
PIE Acknowledge Register.
Definition: pie.h:606
void PIE_disableInt(PIE_Handle pieHandle, const PIE_GroupNumber_e group, const PIE_InterruptSource_e intSource)
Disable a specific PIE interrupt.
Definition: pie.c:130