00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #ifndef ESOS_PIC24_IRQ_H
00045 #define ESOS_PIC24_IRQ_H
00046
00047 #include "esos.h"
00048 #include "esos_irq.h"
00049 #include "esos_pic24.h"
00050
00051
00075 #define ESOS_USER_INTERRUPT(desc) __xESOS_USER_ISR(desc)
00076 #define __xESOS_USER_ISR(attrib, ivt, ifsr, ifsb, ipcr, ipcb) void _ISRFAST attrib (void)
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00093 #define ESOS_USER_IRQ_LEVEL1 6
00094
00099 #define ESOS_USER_IRQ_LEVEL2 4
00100
00105 #define ESOS_USER_IRQ_LEVEL3 3
00106
00111 #define ESOS_USER_IRQ_LEVEL4 2
00112
00113 #define __ESOS_USER_IRQ_UNREGISTERED 0
00114
00115 #define __ESOS_DISABLE_USER_IRQS_LEVEL ESOS_USER_IRQ_LEVEL2
00116
00117 #define __ESOS_ENABLE_USER_IRQS_LEVEL __ESOS_USER_IRQ_UNREGISTERED
00118
00119
00120
00121
00122 #if defined(__PIC24HJ32GP202__) || defined(__DOXYGEN__)
00123
00138 #define ESOS_IRQ_PIC24_AD1 _ADC1Interrupt, 0x002E, 0, 13, 3, 4 // AD1 Conversion complete
00139
00153 #define ESOS_IRQ_PIC24_SPI1 _SPI1Interrupt, 0x0028, 0, 10, 2, 8 // SPI1 event
00154
00168 #define ESOS_IRQ_PIC24_SPI1E _SPI1ErrInterrupt, 0x0026, 0, 9, 2, 4 // SPI1 (exception) fault event
00169
00183 #define ESOS_IRQ_PIC24_T3 _T3Interrupt, 0x0024, 0, 8, 2, 0 // Timer 3
00184
00198 #define ESOS_IRQ_PIC24_T2 _T2Interrupt, 0x0022, 0, 7, 1, 12 // Timer 2
00199
00213 #define ESOS_IRQ_PIC24_OC2 _OC2Interrupt, 0x0020, 0, 6, 1, 8 // Output compare channel 2
00214
00228 #define ESOS_IRQ_PIC24_IC2 _IC2Interrupt, 0x001E, 0, 5, 1, 4 // Input capture channel 2
00229
00243 #define ESOS_IRQ_PIC24_OC1 _OC1Interrupt, 0x0018, 0, 2, 0, 8 // Output compare channel 1
00244
00259 #define ESOS_IRQ_PIC24_IC1 _IC1Interrupt, 0x0016, 0, 1, 0, 4 // Input capture channel 1
00260
00274 #define ESOS_IRQ_PIC24_INT0 _INT0Interrupt, 0x0014, 0, 0, 0, 0 // external interrupt 0
00275
00289 #define ESOS_IRQ_PIC24_INT2 _INT2Interrupt, 0x004E, 1, 13, 7, 4 // external interrupt 2
00290
00305 #define ESOS_IRQ_PIC24_IC8 _IC8Interrupt, 0x0042, 1, 7, 5, 12 // Input capture channel 8
00306
00320 #define ESOS_IRQ_PIC24_IC7 _IC7Interrupt, 0x0040, 1, 6, 5, 8 // Input capture channel 7
00321
00335 #define ESOS_IRQ_PIC24_INT1 _INT1Interrupt, 0x003C, 1, 4, 5, 0 // external interrupt 1
00336
00350 #define ESOS_IRQ_PIC24_CN _CNInterrupt, 0x003A, 1, 3, 4, 12 // input change notification
00351
00365 #define ESOS_IRQ_PIC24_MI2C1 _MI2C1Interrupt, 0x0036, 1, 1, 4, 4 // I2C1 Master event
00366
00380 #define ESOS_IRQ_PIC24_SI2C1 _SI2C1Interrupt, 0x0034, 1, 0, 4, 0 // I2C1 slave event
00381
00382
00383
00384
00385 #if !defined(_ESOS_PIC24_RS232_H) || defined(__DOXYGEN__)
00386
00401 #define ESOS_IRQ_PIC24_U1TX _U1TXInterrupt, 0x002C, 0, 12, 3, 0 // UART1 TX event
00402
00417 #define ESOS_IRQ_PIC24_U1RX _U1RXInterrupt, 0x002A, 0, 11, 2, 12 // UART1 RX event
00418
00434 #define ESOS_IRQ_PIC24_U1E _U1ErrInterrupt, 0x0096, 4, 1, 16, 4 // UART1 Error event
00435
00436 #endif // end of UART1 constants
00437
00438 #endif // __PIC24HJ32GP202__
00439
00440
00441
00442
00443
00444 #define __GET_IRQ_ATTRIB(Q) __xGET_IRQ_ATTRIB(Q)
00445 #define __GET_IVTQ(Q) __xGET_IVT(Q)
00446 #define __GET_IFS_NUM(Q) __xGET_IFS_NUM(Q)
00447 #define __GET_IFS_BITNUM(Q) __xGET_IFS_BITNUM(Q)
00448 #define __GET_IEC_NUM(Q) __xGET_IFS_NUM(Q)
00449 #define __GET_IEC_BITNUM(Q) __xGET_IFS_BITNUM(Q)
00450 #define __GET_IPC_NUM(Q) __xGET_IPC_NUM(Q)
00451 #define __GET_IPC_BITNUM(Q) __xGET_IPC_BITNUM(Q)
00452
00453 #define __xGET_IRQ_ATTRIB(attrib, ivt, ifsr, ifsb, ipcr, ipcb) attrib
00454 #define __xGET_IVT(attrib, ivt, ifsr, ifsb, ipcr, ipcb) ivt
00455 #define __xGET_IFS_NUM(attrib, ivt, ifsr, ifsb, ipcr, ipcb) ifsr
00456 #define __xGET_IFS_BITNUM(attrib, ivt, ifsr, ifsb, ipcr, ipcb) ifsb
00457 #define __xGET_IEC_NUM(attrib, ivt, ifsr, ifsb, ipcr, ipcb) ifsr
00458 #define __xGET_IEC_BITNUM(attrib, ivt, ifsr, ifsb, ipcr, ipcb) ifsb
00459 #define __xGET_IPC_NUM(attrib, ivt, ifsr, ifsb, ipcr, ipcb) ipcr
00460 #define __xGET_IPC_BITNUM(attrib, ivt, ifsr, ifsb, ipcr, ipcb) ipcb
00461
00462
00463
00464 #define __GET_IPL_FROM_IPCX(Q) ((*(&IPC0+(__xGET_IPC_NUM(Q))) >> __xGET_IPC_BITNUM(Q))&0x7)
00465
00466
00467
00468 #define __IS_IPL_FROM_IPCX(Q, val) ((__GET_IPL_FROM_IPCX(Q))==(val))
00469
00470
00471 #define __PUT_IPL_INTO_IPCX(ipc,ipcb,ipl) \
00472 do { \
00473 BIT_CLEAR_MASK( *(&IPC0+(ipc)), 0x07<<ipcb) + (ipl<<ipcb); \
00474 *(&IPC0+ipc) += (ipl<<ipcb); \
00475 }while(0)
00476
00493 #define ESOS_UNREGISTER_PIC24_USER_INTERRUPT(desc) __xUNREGISTER_PIC24_USER_INTERRUPT(desc)
00494 #define __xUNREGISTER_PIC24_USER_INTERRUPT(attrib, ivt, ifsr, ifsb, ipcr, ipcb) \
00495 do{ \
00496 __xDISABLE_PIC24_USER_INTERRUPT(attrib, ivt, ifsr, ifsb, ipcr, ipcb); \
00497 __PUT_IPL_INTO_IPCX(ipcr,ipcb, __ESOS_USER_IRQ_UNREGISTERED); \
00498 }while(0)
00499
00500
00520 #define ESOS_REGISTER_PIC24_USER_INTERRUPT(desc, ipl, p2f) __xREGISTER_PIC24_USER_INTERRUPT(desc, ipl, p2f)
00521 #define __xREGISTER_PIC24_USER_INTERRUPT(attrib, ivt, ifsr, ifsb, ipcr, ipcb, ipl, p2f) \
00522 do { \
00523 __xDISABLE_PIC24_USER_INTERRUPT(attrib, ivt, ifsr, ifsb, ipcr, ipcb); \
00524 __PUT_IPL_INTO_IPCX(ipcr, ipcb, ipl); \
00525 }while(0)
00526
00542 #define ESOS_DISABLE_ALL_PIC24_USER_INTERRUPTS() SET_CPU_IPL(__ESOS_DISABLE_USER_IRQS_LEVEL)
00543
00558 #define ESOS_ENABLE_ALL_PIC24_USER_INTERRUPTS() SET_CPU_IPL(__ESOS_ENABLE_USER_IRQS_LEVEL)
00559
00578 #define ESOS_IS_PIC24_USER_INTERRUPT_ENABLED(desc) __xIS_PIC24_USER_INTERRUPT_ENABLED(desc)
00579 #define __xIS_PIC24_USER_INTERRUPT_ENABLED(attrib, ivt, ifsr, ifsb, ipcr, ipcb) IS_BIT_SET(*(&IEC0+ifsr),ifsb)
00580
00599 #define ESOS_DOES_PIC24_USER_INTERRUPT_NEED_SERVICING(desc) __xDOES_PIC24_USER_INTERRUPT_NEED_SERVICING(desc)
00600 #define __xDOES_PIC24_USER_INTERRUPT_NEED_SERVICING(attrib, ivt, ifsr, ifsb, ipcr, ipcb) IS_BIT_SET(*(&IFS0+ifsr), ifsb)
00601
00618 #define ESOS_MARK_PIC24_USER_INTERRUPT_SERVICED(desc) __xMARK_PIC24_USER_INTERRUPT_SERVICED(desc)
00619 #define __xMARK_PIC24_USER_INTERRUPT_SERVICED(attrib, ivt, ifsr, ifsb, ipcr, ipcb) BIT_CLEAR(*(&IFS0+ifsr),ifsb)
00620
00637 #define ESOS_ENABLE_PIC24_USER_INTERRUPT(desc) __xENABLE_PIC24_USER_INTERRUPT(desc)
00638 #define __xENABLE_PIC24_USER_INTERRUPT(attrib, ivt, ifsr, ifsb, ipcr, ipcb) BIT_SET(*(&IEC0+ifsr), ifsb)
00639
00656 #define ESOS_DISABLE_PIC24_USER_INTERRUPT(desc) __xDISABLE_PIC24_USER_INTERRUPT(desc)
00657 #define __xDISABLE_PIC24_USER_INTERRUPT(attrib, ivt, ifsr, ifsb, ipcr, ipcb) BIT_CLEAR(*(&IEC0+ifsr), ifsb)
00658
00659 #endif // ESOS_PIC24_IRQ_H
00660
00661