Subversion Repositories Code-Repo

Rev

Rev 275 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#include "defines.h"
#include "INTERRUPTS.h"
#include "I2C1.h"
#include "I2C2.h"
#include "IO.h"
#include "CPS.h"

void Interrupt_Init() {

}

void Interrupt_Enable() {
    // Enable global and peripheral interrupts
    INTCONbits.PEIE = 1;
    INTCONbits.GIE = 1;
}

void Interrupt_Disable() {
    INTCONbits.PEIE = 0;
    INTCONbits.GIE = 0;
}

void interrupt InterruptHandler(void) {
    uint8_t tmr0_rollover = 0;
    // We need to check the interrupt flag of each enabled high-priority interrupt to
    //  see which device generated this interrupt.  Then we can call the correct handler.

//    // Check to see if we have an SPI2 interrupt
//    if (PIR3bits.SSP2IF) {
//        // Call the handler
//        SPI2_Recv_Interrupt_Handler();
//
//        // Clear the interrupt flag
//        PIR3bits.SSP2IF = 0;
//
//        return;
//    }


    // Check to see if we have an interrupt on Timer 0 (CPS)
    if (INTCONbits.TMR0IF) {
        CPS_Timer_0_Interrupt_Handler();
        INTCONbits.TMR0IF = 0;
        return;
    }
    
    // Check to see if we have an I2C1 interrupt
    if (PIR1bits.SSP1IF) {
        // Call the handler
        I2C1_Interrupt_Handler();

        // Clear the interrupt flag
        PIR1bits.SSP1IF = 0;

        if (INTCONbits.TMR0IF) {
            tmr0_rollover = 1;
        }
    }

    // Check to see if we have an I2C2 interrupt
    if (PIR4bits.SSP2IF) {
        // Call the handler
        I2C2_Interrupt_Handler();

        // Clear the interrupt flag
        PIR4bits.SSP2IF = 0;

        if (INTCONbits.TMR0IF) {
            tmr0_rollover = 1;
        }
    }


    // If Timer 0 rolls over while servicing another interrupt handler,
    //  reset the timers as the sample will be inaccurate.
    if (tmr0_rollover) {
        INTCONbits.TMR0IF = 0;
        CPS_Reset();
    }

//    // Check to see if we have an IO interrupt
//    if (INTCONbits.IOCIF) {
//        // Call the handler
//        IO_Interrupt();
//
//        return;
//    }

//    // Check to see if we have an interrupt on USART1 RX
//    if (PIR1bits.RC1IF) {
//        // Call the interrupt handler
//        UART1_Recv_Interrupt_Handler();
//
//        // Clear the interrupt flag
//        PIR1bits.RC1IF = 0;
//
//        return;
//    }

//    // Check to see if we have an interrupt on USART1 TX
//    if (PIR1bits.TX1IF) {
//        // Call the interrupt handler
//        UART1_Send_Interrupt_Handler();
//
//        // Clear the interrupt flag
//        PIR1bits.TX1IF = 0;
//
//        return;
//    }

//    // Check to see if we have an interrupt on USART2 RX
//    if (PIR3bits.RC2IF) {
//        DBG_PRINT_INT("INT: UART2 RX\r\n");
//        // Call the interrupt handler
//        uart_2_recv_interrupt_handler();
//
//        // Clear the interrupt flag
//        PIR3bits.RC2IF = 0;
//    }
}