PIC24 Support Libraries
esos_irq.c
1 /*
2  * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
3  * All rights reserved.
4  * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
5  * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
6  * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
7  *
8  * Permission to use, copy, modify, and distribute this software and its
9  * documentation for any purpose, without fee, and without written agreement is
10  * hereby granted, provided that the above copyright notice, the following
11  * two paragraphs and the authors appear in all copies of this software.
12  *
13  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
14  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
15  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
16  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17  *
18  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
19  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
22  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
23  *
24  * Please maintain this header in its entirety when copying/modifying
25  * these files.
26  *
27  *
28  */
29 
30 /************************************************************************
31  * esos_irq.c
32  ************************************************************************
33  * ES_OS file for (hardware independent) IRQ routines
34  */
35 
36 #include "esos_irq.h"
37 
38 void (*__esos_IsrFcns[NUM_USER_IRQS])(void);
39 
40 void esos_InitUserInterrupts(void) {
41  uint8_t i;
42 
43  // initialize the os ISR fcn ptrs to point to a benign ISR
44  for (i=0; i<NUM_USER_IRQS; i++) {
45  esos_UnregisterUserInterrupt(i);
46  }
47  _esos_hw_InitUserInterrupts();
48 } // end osInitInterrupts()
49 
50 void esos_UnregisterUserInterrupt( uint8_t u8IrqIndex ) {
51  // disassociate and unregister the p2f function with the IRQ given
52  // in u8IrqIndex
53  if (u8IrqIndex < NUM_USER_IRQS) {
54  esos_DisableUserInterrupt( u8IrqIndex );
55  __esos_IsrFcns[u8IrqIndex] = _esos_DoNothingIsr;
56  } // end if
57 } // end osUnregisterUserIsr()
58 
59 void esos_RegisterUserInterrupt( uint8_t u8IrqIndex, void (*p2f)(void) ) {
60  // associate and register the p2f function with the IRQ given
61  // in u8IrqIndex
62  if (u8IrqIndex < NUM_USER_IRQS) {
63  __esos_IsrFcns[u8IrqIndex] = p2f;
64  }
65 } // end osRegisterUserIsr()
66 
67 void esos_EnableVerifiedUserInterrupt( uint8_t u8IrqIndex ) {
68  // do ESOS checks on UserInterrupt and if all is well
69  // call the user-provided HW specific routine
70  if ((__esos_IsrFcns[u8IrqIndex] != NULLPTR) && ( __esos_IsrFcns[u8IrqIndex] != _esos_DoNothingIsr))
71  _esos_hw_EnableUserInterrupt( u8IrqIndex );
72 } // end esos_EnableUserInterrupt()
73 
74 void esos_ExecuteUserIsr( uint8_t u8IrqIndex ) {
75  __esos_IsrFcns[u8IrqIndex]();
76 } // esos_ExecuteUserIsr
77 
78 void _esos_DoNothingIsr(void) {
79  _esos_hw_DoNothingIsr();
80 } // end _esos_DoNothingIsr()
#define NULLPTR
Definition: all_generic.h:424
unsigned char uint8_t
An abbreviation for an 8-bit unsigned integer.
Definition: dataXferImpl.h:194