Subversion Repositories Code-Repo

Rev

Rev 109 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 109 Rev 111
Line 17... Line 17...
17
//       is not enabled.
17
//       is not enabled.
18
 
18
 
19
void interrupt_init() {
19
void interrupt_init() {
20
    // Peripheral interrupts can have their priority set to high or low
20
    // Peripheral interrupts can have their priority set to high or low
21
    // Decide on the priority of the enabled peripheral interrupts (0 is low, 1 is high)
21
    // Decide on the priority of the enabled peripheral interrupts (0 is low, 1 is high)
-
 
22
 
-
 
23
    // High priority interrupts
22
//    INTCON2bits.TMR0IP = 0; // Timer0 interrupt
24
    IPR3bits.RC2IP = 1; // USART2 RX interrupt
23
//    IPR1bits.TMR1IP = 1;    // Timer1 interrupt
25
    IPR1bits.SSPIP = 1; // I2C interrupt
-
 
26
 
-
 
27
    // Low priority interrupts
24
//    IPR1bits.RC1IP = 0;      // USART1 RX interrupt
28
    //    IPR1bits.RC1IP = 0;      // USART1 RX interrupt
-
 
29
    INTCON2bits.TMR0IP = 0; // Timer0 interrupt
25
    IPR3bits.RC2IP = 1;     // USART2 RX interrupt
30
    //    IPR1bits.TMR1IP = 0;    // Timer1 interrupt
26
    IPR1bits.SSPIP = 1;     // I2C interrupt
31
    IPR2bits.TMR3IP = 0; // Timer 3 interrupt
27
//    IPR1bits.ADIP = 0;      // ADC interupt
32
    //    IPR1bits.ADIP = 0;      // ADC interupt
28
//    INTCON2bits.RBIP = 1;   // Port B interrupt
33
    INTCON2bits.RBIP = 0;   // Port B interrupt
29
    INTCON3bits.INT1IP = 1; // INT1 interrupt
34
    INTCON3bits.INT1IP = 0; // INT1 interrupt
-
 
35
    
30
    // I2C interupts must be specifically enabled
36
    // Enable I2C interrupt
31
    PIE1bits.SSPIE = 1;
37
    PIE1bits.SSPIE = 1;
-
 
38
    // Enable Port B interrupt
-
 
39
    INTCONbits.RBIE = 1;
32
}
40
}
33
 
41
 
34
void interrupt_enable() {
42
void interrupt_enable() {
35
    // Peripheral interrupts can have their priority set to high or low.
43
    // Peripheral interrupts can have their priority set to high or low.
36
    // Enable both high-priority interrupts and low-priority interrupts
44
    // Enable both high-priority interrupts and low-priority interrupts
37
    RCONbits.IPEN = 1;
45
    RCONbits.IPEN = 1;
38
    INTCONbits.GIEH = 1;
46
    INTCONbits.GIEH = 1;
39
    INTCONbits.GIEL = 0;
47
    INTCONbits.GIEL = 1;
40
}
48
}
41
 
49
 
42
int interrupt_in_high_interrupt_routine() {
50
int interrupt_in_high_interrupt_routine() {
43
    return (!INTCONbits.GIEH);
51
    return (!INTCONbits.GIEH);
44
}
52
}
Line 68... Line 76...
68
// Set up the interrupt vectors
76
// Set up the interrupt vectors
69
void InterruptHandlerHigh();
77
void InterruptHandlerHigh();
70
void InterruptHandlerLow();
78
void InterruptHandlerLow();
71
 
79
 
72
#pragma code InterruptVectorLow = 0x18
80
#pragma code InterruptVectorLow = 0x18
-
 
81
 
73
void InterruptVectorLow(void) {
82
void InterruptVectorLow(void) {
74
    _asm
83
    _asm
75
    goto InterruptHandlerLow //jump to interrupt routine
84
    goto InterruptHandlerLow //jump to interrupt routine
76
    _endasm
85
            _endasm
77
}
86
}
78
 
87
 
79
#pragma code InterruptVectorHigh = 0x08
88
#pragma code InterruptVectorHigh = 0x08
-
 
89
 
80
void InterruptVectorHigh(void) {
90
void InterruptVectorHigh(void) {
81
    _asm
91
    _asm
82
    goto InterruptHandlerHigh //jump to interrupt routine
92
    goto InterruptHandlerHigh //jump to interrupt routine
83
    _endasm
93
            _endasm
84
}
94
}
85
 
95
 
86
//----------------------------------------------------------------------------
96
//----------------------------------------------------------------------------
87
// High priority interrupt routine
97
// High priority interrupt routine
88
// this parcels out interrupts to individual handlers
98
// this parcels out interrupts to individual handlers
89
 
99
 
90
#pragma code
100
#pragma code
91
#pragma interrupt InterruptHandlerHigh
101
#pragma interrupt InterruptHandlerHigh
-
 
102
 
92
void InterruptHandlerHigh() {
103
void InterruptHandlerHigh() {
93
    // We need to check the interrupt flag of each enabled high-priority interrupt to
104
    // We need to check the interrupt flag of each enabled high-priority interrupt to
94
    //  see which device generated this interrupt.  Then we can call the correct handler.
105
    //  see which device generated this interrupt.  Then we can call the correct handler.
95
    
-
 
96
    // Check to see if we have an I2C interrupt
-
 
97
    if (PIR1bits.SSPIF) {
-
 
98
        // Nofity the xbee to stop sending serial data
-
 
99
        xbee_set_RTS(1);
-
 
100
        
-
 
101
        // Call the handler
-
 
102
        i2c_interrupt_handler();
-
 
103
 
-
 
104
        // Clear the interrupt flag
-
 
105
        PIR1bits.SSPIF = 0;
-
 
106
 
-
 
107
        // Notify xbee to resume sending serial data
-
 
108
        xbee_set_RTS(0);
-
 
109
    }
-
 
110
 
106
 
111
    // Check to see if we have an interrupt on USART2 RX
107
    // Check to see if we have an interrupt on USART2 RX
112
    if (PIR3bits.RC2IF) {
108
    if (PIR3bits.RC2IF) {
-
 
109
        DBG_PRINT_INT("INT: UART2 RX\r\n");
113
        // Call the interrupt handler
110
        // Call the interrupt handler
114
        uart_recv_interrupt_handler();
111
        uart_recv_interrupt_handler();
115
 
112
 
116
        // Clear the interrupt flag
113
        // Clear the interrupt flag
117
        PIR3bits.RC2IF = 0;
114
        PIR3bits.RC2IF = 0;
118
    }
115
    }
119
 
116
 
120
#ifdef _MASTER
-
 
121
    // Check to see if we have an interrupt on INT1
117
//    // Nofity the xbee to stop sending serial data
122
    if (INTCON3bits.INT1IF) {
-
 
123
        int1_interrupt_handler();
118
//    xbee_set_RTS(1);
124
 
-
 
125
        INTCON3bits.INT1IF = 0;
-
 
126
    }
-
 
127
#endif
-
 
128
 
119
 
129
    // Check to see if we have an interrupt on any port B inputs <4:7>
120
    // Check to see if we have an I2C interrupt
130
    if (INTCONbits.RBIF) {
121
    if (PIR1bits.SSPIF) {
-
 
122
        DBG_PRINT_INT("INT: I2C\r\n");
-
 
123
        // Call the handler
131
        port_b_int_interrupt_handler();
124
        i2c_interrupt_handler();
132
 
125
 
-
 
126
        // Clear the interrupt flag
133
        INTCONbits.RBIF = 0;
127
        PIR1bits.SSPIF = 0;
134
    }
128
    }
135
    
-
 
136
//    // Check to see if we have an interrupt on timer 1
-
 
137
//    if (PIR1bits.TMR1IF) {
-
 
138
//        // Clear the interrupt flag
-
 
139
//        PIR1bits.TMR1IF = 0;
-
 
140
//
129
 
141
//        // Call the interrupt handler
130
//     //Notify xbee to resume sending serial data
142
//        timer1_interrupt_handler();
131
//    xbee_set_RTS(0);
143
//    }
-
 
144
 
132
 
145
    // The *last* thing I do here is check to see if we can
133
    // The *last* thing I do here is check to see if we can
146
    // allow the processor to go to sleep
134
    // allow the processor to go to sleep
147
    // This code *DEPENDS* on the code in messages.c being
135
    // This code *DEPENDS* on the code in messages.c being
148
    // initialized using "init_queues()" -- if you aren't using
136
    // initialized using "init_queues()" -- if you aren't using
149
    // this, then you shouldn't have this call here
137
    // this, then you shouldn't have this call here
150
//    MQ_sleep_high_interrupt_if_okay();
138
    //    MQ_sleep_high_interrupt_if_okay();
151
}
139
}
152
 
140
 
153
//----------------------------------------------------------------------------
141
//----------------------------------------------------------------------------
154
// Low priority interrupt routine
142
// Low priority interrupt routine
155
// this parcels out interrupts to individual handlers
143
// this parcels out interrupts to individual handlers
156
#pragma code
144
#pragma code
157
#pragma interruptlow InterruptHandlerLow
145
#pragma interruptlow InterruptHandlerLow
158
// This works the same way as the "High" interrupt handler
146
// This works the same way as the "High" interrupt handler
-
 
147
 
159
void InterruptHandlerLow() {
148
void InterruptHandlerLow() {
-
 
149
    // Check to see if we have an interrupt on INT1
-
 
150
    if (INTCON3bits.INT1IF) {
-
 
151
        DBG_PRINT_INT("INT: INT1\r\n");
-
 
152
        int1_interrupt_handler();
160
 
153
 
161
//    // Check to see if we have an interrupt on timer 0
-
 
162
//    if (INTCONbits.TMR0IF) {
-
 
163
//        // Clear this interrupt flag
-
 
164
//        INTCONbits.TMR0IF = 0;
154
        INTCON3bits.INT1IF = 0;
165
//
-
 
166
//        // Call the handler
-
 
167
//        timer0_interrupt_handler();
-
 
168
//    }
155
    }
169
 
156
 
-
 
157
    // Check to see if we have an interrupt on any port B inputs <4:7>
-
 
158
    if (INTCONbits.RBIF) {
-
 
159
        DBG_PRINT_INT("INT: Port B\r\n");
-
 
160
        port_b_int_interrupt_handler();
-
 
161
 
-
 
162
        INTCONbits.RBIF = 0;
-
 
163
    }
-
 
164
    
170
//    // Check to see if we have an interrupt on USART1 RX
165
    // Check to see if we have an interrupt on timer 0
171
//    if (PIR1bits.RC1IF) {
166
    if (INTCONbits.TMR0IF) {
-
 
167
        DBG_PRINT_INT("INT: Timer 0\r\n");
-
 
168
        // Call the handler
-
 
169
        timer0_interrupt_handler();
-
 
170
 
172
//        // Clear the interrupt flag
171
        // Clear this interrupt flag
173
//        PIR1bits.RC1IF = 0;
172
        INTCONbits.TMR0IF = 0;
-
 
173
    }
174
//
174
 
-
 
175
//    // Check to see if we have an interrupt on timer 1
-
 
176
//    if (PIR1bits.TMR1IF) {
175
//        // Call the interrupt handler
177
//        // Call the interrupt handler
176
//        uart_recv_interrupt_handler();
178
//        timer1_interrupt_handler();
-
 
179
//
-
 
180
//        // Clear the interrupt flag
-
 
181
//        PIR1bits.TMR1IF = 0;
177
//    }
182
//    }
-
 
183
 
-
 
184
    // Check to see if we have an interrupt on timer 3
-
 
185
    if (PIR2bits.TMR3IF) {
-
 
186
        DBG_PRINT_INT("INT: Timer 3\r\n");
-
 
187
        timer3_interrupt_handler();
-
 
188
 
-
 
189
        PIR2bits.TMR3IF = 0;
-
 
190
    }
178
    
191
    
179
//    // Check to see if we have an interrupt on ADC
192
//        // Check to see if we have an interrupt on USART1 RX
180
//    if (PIR1bits.ADIF) {
193
//        if (PIR1bits.RC1IF) {
181
//        // Clear the interrupt flag
194
//            // Call the interrupt handler
182
//        PIR1bits.ADIF = 0;
195
//            uart_recv_interrupt_handler();
183
//
196
//
-
 
197
//            // Clear the interrupt flag
-
 
198
//            PIR1bits.RC1IF = 0;
-
 
199
//        }
-
 
200
 
-
 
201
//        // Check to see if we have an interrupt on ADC
-
 
202
//        if (PIR1bits.ADIF) {
184
//        // Call the interrupt handler
203
//            // Call the interrupt handler
185
//        adc_interrupt_handler();
204
//            adc_interrupt_handler();
-
 
205
//
-
 
206
//            // Clear the interrupt flag
-
 
207
//            PIR1bits.ADIF = 0;
186
//    }
208
//        }
187
}
209
}
188
 
210