Subversion Repositories Code-Repo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
260 Kevin 1
#include "defines.h"
2
#include "INTERRUPTS.h"
3
#include "I2C1.h"
4
#include "I2C2.h"
273 Kevin 5
#include "IO.h"
277 Kevin 6
#include "CPS.h"
260 Kevin 7
 
8
void Interrupt_Init() {
9
 
10
}
11
 
12
void Interrupt_Enable() {
13
    // Enable global and peripheral interrupts
14
    INTCONbits.PEIE = 1;
15
    INTCONbits.GIE = 1;
16
}
17
 
18
void Interrupt_Disable() {
19
    INTCONbits.PEIE = 0;
20
    INTCONbits.GIE = 0;
21
}
22
 
23
void interrupt InterruptHandler(void) {
277 Kevin 24
    uint8_t tmr0_rollover = 0;
260 Kevin 25
    // We need to check the interrupt flag of each enabled high-priority interrupt to
26
    //  see which device generated this interrupt.  Then we can call the correct handler.
27
 
28
//    // Check to see if we have an SPI2 interrupt
29
//    if (PIR3bits.SSP2IF) {
30
//        // Call the handler
31
//        SPI2_Recv_Interrupt_Handler();
32
//
33
//        // Clear the interrupt flag
34
//        PIR3bits.SSP2IF = 0;
35
//
36
//        return;
37
//    }
38
 
277 Kevin 39
 
40
    // Check to see if we have an interrupt on Timer 0 (CPS)
41
    if (INTCONbits.TMR0IF) {
42
        CPS_Timer_0_Interrupt_Handler();
43
        INTCONbits.TMR0IF = 0;
44
        return;
45
    }
46
 
260 Kevin 47
    // Check to see if we have an I2C1 interrupt
48
    if (PIR1bits.SSP1IF) {
49
        // Call the handler
50
        I2C1_Interrupt_Handler();
51
 
52
        // Clear the interrupt flag
53
        PIR1bits.SSP1IF = 0;
54
 
277 Kevin 55
        if (INTCONbits.TMR0IF) {
56
            tmr0_rollover = 1;
57
        }
260 Kevin 58
    }
59
 
60
    // Check to see if we have an I2C2 interrupt
61
    if (PIR4bits.SSP2IF) {
62
        // Call the handler
63
        I2C2_Interrupt_Handler();
64
 
65
        // Clear the interrupt flag
66
        PIR4bits.SSP2IF = 0;
67
 
277 Kevin 68
        if (INTCONbits.TMR0IF) {
69
            tmr0_rollover = 1;
70
        }
260 Kevin 71
    }
72
 
277 Kevin 73
 
74
    // If Timer 0 rolls over while servicing another interrupt handler,
75
    //  reset the timers as the sample will be inaccurate.
76
    if (tmr0_rollover) {
77
        INTCONbits.TMR0IF = 0;
78
        CPS_Reset();
79
    }
80
 
275 Kevin 81
//    // Check to see if we have an IO interrupt
82
//    if (INTCONbits.IOCIF) {
83
//        // Call the handler
84
//        IO_Interrupt();
85
//
86
//        return;
87
//    }
273 Kevin 88
 
260 Kevin 89
//    // Check to see if we have an interrupt on USART1 RX
90
//    if (PIR1bits.RC1IF) {
91
//        // Call the interrupt handler
92
//        UART1_Recv_Interrupt_Handler();
93
//
94
//        // Clear the interrupt flag
95
//        PIR1bits.RC1IF = 0;
96
//
97
//        return;
98
//    }
99
 
100
//    // Check to see if we have an interrupt on USART1 TX
101
//    if (PIR1bits.TX1IF) {
102
//        // Call the interrupt handler
103
//        UART1_Send_Interrupt_Handler();
104
//
105
//        // Clear the interrupt flag
106
//        PIR1bits.TX1IF = 0;
107
//
108
//        return;
109
//    }
110
 
111
//    // Check to see if we have an interrupt on USART2 RX
112
//    if (PIR3bits.RC2IF) {
113
//        DBG_PRINT_INT("INT: UART2 RX\r\n");
114
//        // Call the interrupt handler
115
//        uart_2_recv_interrupt_handler();
116
//
117
//        // Clear the interrupt flag
118
//        PIR3bits.RC2IF = 0;
119
//    }
120
}