Subversion Repositories Code-Repo

Rev

Rev 120 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 120 Rev 121
Line 1... Line 1...
1
#include "maindefs.h"
1
#include "maindefs.h"
2
#include "uart.h"
2
#include "uart.h"
3
#include "i2c.h"
3
#include "i2c.h"
-
 
4
#include "spi.h"
4
#include "interrupts.h"
5
#include "interrupts.h"
5
 
6
 
6
//----------------------------------------------------------------------------
7
//----------------------------------------------------------------------------
7
// Note: This code for processing interrupts is configured to allow for high and
8
// Note: This code for processing interrupts is configured to allow for high and
8
//       low priority interrupts.  The high priority interrupt can interrupt the
9
//       low priority interrupts.  The high priority interrupt can interrupt the
Line 16... Line 17...
16
    // Decide on the priority of the enabled peripheral interrupts (0 is low, 1 is high)
17
    // Decide on the priority of the enabled peripheral interrupts (0 is low, 1 is high)
17
 
18
 
18
    // High priority interrupts
19
    // High priority interrupts
19
    IPR1bits.RC1IP = 1;     // USART1 RX interrupt
20
    IPR1bits.RC1IP = 1;     // USART1 RX interrupt
20
    IPR1bits.TX1IP = 1;     // USART1 TX interrupt
21
    IPR1bits.TX1IP = 1;     // USART1 TX interrupt
21
//    IPR3bits.RC2IP = 1; // USART2 RX interrupt
22
//    IPR3bits.RC2IP = 1;     // USART2 RX interrupt
22
    IPR1bits.SSPIP = 1; // I2C interrupt
23
    IPR1bits.SSPIP = 1;     // I2C interrupt
-
 
24
    IPR3bits.SSP2IP = 1;    // MSSP2 (SPI2) interrupt
23
 
25
 
24
    // Low priority interrupts
26
    // Low priority interrupts
25
    
27
    
26
//    INTCON2bits.TMR0IP = 0; // Timer0 interrupt
28
//    INTCON2bits.TMR0IP = 0; // Timer0 interrupt
27
//    IPR1bits.TMR1IP = 0;    // Timer1 interrupt
29
//    IPR1bits.TMR1IP = 0;    // Timer1 interrupt
Line 99... Line 101...
99
 
101
 
100
void InterruptHandlerHigh() {
102
void InterruptHandlerHigh() {
101
    // We need to check the interrupt flag of each enabled high-priority interrupt to
103
    // We need to check the interrupt flag of each enabled high-priority interrupt to
102
    //  see which device generated this interrupt.  Then we can call the correct handler.
104
    //  see which device generated this interrupt.  Then we can call the correct handler.
103
 
105
 
-
 
106
    // Check to see if we have an SPI2 interrupt
-
 
107
    if (PIR3bits.SSP2IF) {
-
 
108
        // Call the handler
-
 
109
        SPI2_Recv_Interrupt_Handler();
-
 
110
 
-
 
111
        // Clear the interrupt flag
-
 
112
        PIR3bits.SSP2IF = 0;
-
 
113
 
-
 
114
        return;
-
 
115
    }
-
 
116
 
-
 
117
    // Check to see if we have an I2C interrupt
-
 
118
    if (PIR1bits.SSPIF) {
-
 
119
        // Call the handler
-
 
120
        I2C_Interrupt_Handler();
-
 
121
 
-
 
122
        // Clear the interrupt flag
-
 
123
        PIR1bits.SSPIF = 0;
-
 
124
 
-
 
125
        return;
-
 
126
    }
-
 
127
    
104
    // Check to see if we have an interrupt on USART1 RX
128
    // Check to see if we have an interrupt on USART1 RX
105
    if (PIR1bits.RC1IF) {
129
    if (PIR1bits.RC1IF) {
106
        // Call the interrupt handler
130
        // Call the interrupt handler
107
        UART1_Recv_Interrupt_Handler();
131
        UART1_Recv_Interrupt_Handler();
108
 
132
 
Line 110... Line 134...
110
        PIR1bits.RC1IF = 0;
134
        PIR1bits.RC1IF = 0;
111
 
135
 
112
        return;
136
        return;
113
    }
137
    }
114
 
138
 
-
 
139
#ifndef _DEBUG  // Disable UART1 TX interrupt for debug mode (using printf)
115
    // Check to see if we have an interrupt on USART1 TX
140
    // Check to see if we have an interrupt on USART1 TX
116
    if (PIR1bits.TX1IF) {
141
    if (PIR1bits.TX1IF) {
117
        // Call the interrupt handler
142
        // Call the interrupt handler
118
        UART1_Send_Interrupt_Handler();
143
        UART1_Send_Interrupt_Handler();
119
        
144
        
120
        // Clear the interrupt flag
145
        // Clear the interrupt flag
121
        PIR1bits.TX1IF = 0;
146
        PIR1bits.TX1IF = 0;
122
 
147
 
123
        return;
148
        return;
124
    }
149
    }
-
 
150
#endif
125
    
151
    
126
//    // Check to see if we have an interrupt on USART2 RX
152
//    // Check to see if we have an interrupt on USART2 RX
127
//    if (PIR3bits.RC2IF) {
153
//    if (PIR3bits.RC2IF) {
128
//        DBG_PRINT_INT("INT: UART2 RX\r\n");
154
//        DBG_PRINT_INT("INT: UART2 RX\r\n");
129
//        // Call the interrupt handler
155
//        // Call the interrupt handler
130
//        uart_2_recv_interrupt_handler();
156
//        uart_2_recv_interrupt_handler();
131
//
157
//
132
//        // Clear the interrupt flag
158
//        // Clear the interrupt flag
133
//        PIR3bits.RC2IF = 0;
159
//        PIR3bits.RC2IF = 0;
134
//    }
160
//    }
135
    
-
 
136
    // Check to see if we have an I2C interrupt
-
 
137
    if (PIR1bits.SSPIF) {
-
 
138
        // Call the handler
-
 
139
        I2C_Interrupt_Handler();
-
 
140
 
-
 
141
        // Clear the interrupt flag
-
 
142
        PIR1bits.SSPIF = 0;
-
 
143
 
-
 
144
        return;
-
 
145
    }
-
 
146
}
161
}
147
 
162
 
148
//----------------------------------------------------------------------------
163
//----------------------------------------------------------------------------
149
// Low priority interrupt routine
164
// Low priority interrupt routine
150
// this parcels out interrupts to individual handlers
165
// this parcels out interrupts to individual handlers