// UART 2 interrupt handler
// it is set at priority level 2
void __ISR(_UART2_VECTOR, ipl2) IntUart2Handler(void)
{
	// Is this an RX interrupt?
	if(INTGetFlag(INT_SOURCE_UART_RX(UART2)))
	{
		unsigned char databyte;

		// Clear the RX interrupt Flag
	    INTClearFlag(INT_SOURCE_UART_RX(UART2));

		// Code to be executed on RX interrupt:
		databyte = UARTGetDataByte(UART2);
		databyte++;
		
		// Echo what we just received.
		PutCharacter(databyte);
	}

	// We don't care about TX interrupt
	if ( INTGetFlag(INT_SOURCE_UART_TX(UART2)) )
	{
		// Clear the TX interrupt Flag
		INTClearFlag(INT_SOURCE_UART_TX(UART2));

		// Code to be executed on TX interrupt:

		
	}
}
// UART 2 interrupt handler
// it is set at priority level 2
void __ISR(_UART2_VECTOR, ipl2) IntUart2Handler(void)
{
	// Is this an RX interrupt?
	if(INTGetFlag(INT_SOURCE_UART_RX(UART2)))
	{
		// Clear the RX interrupt Flag
	    INTClearFlag(INT_SOURCE_UART_RX(UART2));

	// Code to be executed on RX interrupt:

		// Echo what we just received.
		PutCharacter(UARTGetDataByte(UART2));
		// Toggle LED to indicate UART activity
		mPORTAToggleBits(BIT_7);

	}

	// We don't care about TX interrupt
	if ( INTGetFlag(INT_SOURCE_UART_TX(UART2)) )
	{
		// Clear the TX interrupt Flag
		INTClearFlag(INT_SOURCE_UART_TX(UART2));

	// Code to be executed on TX interrupt:

		
	}
}
Beispiel #3
0
//******************************************************************************
//Public Function Definitions
//******************************************************************************
void FIFOUART1_initialize()
{
    UARTConfigure(UART1, UART_ENABLE_PINS_TX_RX_ONLY);

    UARTSetLineControl(UART1, UART_DATA_SIZE_8_BITS | //Sets the data transfer size to 8-bits per frame.�
            UART_PARITY_NONE | //Disables parity bit generation.�
            UART_STOP_BITS_1); //1 stop bit per frame (default).�

    UARTSetDataRate(UART1, GetPeripheralClock(), FIFOUART1_BAUD_RATE);



    //Interrupt Stuff
    INTSetVectorPriority(INT_UART_1_VECTOR, INT_PRIORITY_LEVEL_5);
    INTSetVectorSubPriority(INT_UART_1_VECTOR, INT_SUB_PRIORITY_LEVEL_0);

    INTClearFlag(INT_U1RX);
    INTClearFlag(INT_U1TX);

    //configure what triggers UART1 itnerrupts
    UARTSetFifoMode(UART1,
        UART_INTERRUPT_ON_TX_BUFFER_EMPTY | //TX interrupt will occur when the TX buffer is empty.�
        UART_INTERRUPT_ON_RX_NOT_EMPTY); //RX interrupt will occur whenever the RX buffer has any data.�

    //Enable UART1 Rx Interrupt
    INTEnable(INT_U1RX, INT_ENABLED);
    //Enable UART1 Tx Interrupt
    //INTEnable(INT_U1TX, INT_ENABLED);

    UARTEnable(UART1, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));

}
Beispiel #4
0
void MyCyclone_Init(void)
{
    // Configure Reset Pin = GPIO_2[10] = RD7
    mPORTDClearBits(RST_FPGA);
    mPORTDSetPinsDigitalOut(RST_FPGA);

    // Do a Reset
    mPORTDSetBits(RST_FPGA);
    mPORTDClearBits(RST_FPGA);

    // Do Interrupts Initialization
    // Set RD8/INT1 and RD9/INT2 as inputs
    mPORTDSetPinsDigitalIn(BIT_8 | BIT_9);
    // Clear corresponding bits in INTCON for falling edge trigger
    INTCONCLR = _INTCON_INT1EP_MASK | _INTCON_INT2EP_MASK;
    // Set up interrupt prioirty and sub-priority
    INTSetVectorPriority(INT_EXTERNAL_1_VECTOR, My_INT_EXTERNAL_1_PRIORITY);
    INTSetVectorSubPriority(INT_EXTERNAL_1_VECTOR, My_INT_EXTERNAL_1_SUB_PRIORITY);
    INTSetVectorPriority(INT_EXTERNAL_2_VECTOR, My_INT_EXTERNAL_2_PRIORITY);
    INTSetVectorSubPriority(INT_EXTERNAL_2_VECTOR, My_INT_EXTERNAL_2_SUB_PRIORITY);
    // Clear the interrupt flags
    INTClearFlag(INT_INT1);
    INTClearFlag(INT_INT2);
    // Enable INT1 & INT2
    INTEnable(INT_INT1, INT_ENABLED);
    INTEnable(INT_INT2, INT_ENABLED);
    // Enable KEY0 and KEY1 interrupts and IOs of the MyExpansionBoard_IO_v2
    MyCyclone_Write(CYCLONE_CONFIG,CYCLONE_ENABLE_INT_KEY0 | CYCLONE_ENABLE_INT_KEY1 | CYCLONE_ENABLE_IO_AB | CYCLONE_ENABLE_IO_CD);
}
void __ISR(_UART2_VECTOR, ipl2) IntUart2Handler(void)
{
	// Is this an RX interrupt?
	if(INTGetFlag(INT_SOURCE_UART_RX(UART2)))
	{

		// Clear the RX interrupt Flag
	    INTClearFlag(INT_SOURCE_UART_RX(UART2));

		// Code to be executed on RX interrupt:
		COMMAND = UARTGetDataByte(UART2);
		
		// Echo what we just received.
		PutCharacter(COMMAND);
	}

	// We don't care about TX interrupt
	if ( INTGetFlag(INT_SOURCE_UART_TX(UART2)) )
	{
		// Clear the TX interrupt Flag
		INTClearFlag(INT_SOURCE_UART_TX(UART2));

		// Code to be executed on TX interrupt:
			//none
	}
}
Beispiel #6
0
BOOL ConfigSPIComms(void)
{
    SpiChnClose(RPI_SPI_CHANNEL);
    /* do I need to configure this? */
    INTEnable(INT_SOURCE_SPI_RX(RPI_SPI_CHANNEL),INT_DISABLED);
    INTEnable(INT_SOURCE_SPI_TX(RPI_SPI_CHANNEL),INT_DISABLED);
    INTEnable(INT_SOURCE_SPI_ERROR(RPI_SPI_CHANNEL),INT_DISABLED);
    INTEnable(INT_SOURCE_SPI(RPI_SPI_CHANNEL),INT_DISABLED);
    SPI_DATA_IN_DIRECTION = TRIS_IN;
    SPI_DATA_OUT_DIRECTION = TRIS_OUT;
    SPI_CLOCK_IN_DIRECTION = TRIS_IN;
    SPI_SELECT_IN_DIRECTION = TRIS_IN;
    SPI.RXCount=0;
    SPI.TXCount=0;
    SPI.address=0;
    SPI.command=TRISTHIS_SPI_NO_COMMAND;
    SpiChnOpen(RPI_SPI_CHANNEL,
            SPI_OPEN_SLVEN|SPI_OPEN_CKE_REV|SPI_OPEN_MODE8|SPI_OPEN_SSEN,
            0);
    //TODO: Not acting consistently? RPI needs to send -b 8 -H parameters to spidev
    /* configure interrupts                                                   */
    INTSetVectorPriority(INT_VECTOR_SPI(RPI_SPI_CHANNEL), INT_PRIORITY_LEVEL_3);
    INTSetVectorSubPriority(INT_VECTOR_SPI(RPI_SPI_CHANNEL),
            INT_SUB_PRIORITY_LEVEL_1);
    INTClearFlag(INT_SOURCE_SPI_RX(RPI_SPI_CHANNEL));
    INTEnable(INT_SOURCE_SPI_RX(RPI_SPI_CHANNEL),INT_ENABLED);
    INTClearFlag(INT_SOURCE_SPI_TX(RPI_SPI_CHANNEL));
    INTClearFlag(INT_SOURCE_SPI_ERROR(RPI_SPI_CHANNEL));
    INTClearFlag(INT_SOURCE_SPI(RPI_SPI_CHANNEL));
    //INTEnable(INT_SOURCE_SPI(RPI_SPI_CHANNEL),INT_ENABLED);
    /* configure change notice, as I can't figure out any other way to        */
    /* trigger the beginning of the slave select with just the SPI peripheral */
    /* buuut the change notice pins are not on the SS pins, so a white wire is*/
    /* needed                                                                 */
    /* tie chip enable CE0 to pin20/RE5 CE1 */
    SPI_SELECT_CN_DIRECTION=TRIS_IN;
    CNCONbits.w=0;
    CNCONSET=_CNCON_ON_MASK;
    CNENbits.w=0;
    CNENSET=_CNEN_CNEN7_MASK;
    CNTemp=CE_PORT; /* read for change notice */
    RPI_SPI_RX_OVERFLOW_CLEAR;
    SPI1CONbits.STXISEL=0b01;
    SPI.status.w=0;
    INTClearFlag(INT_CN);
    INTSetVectorPriority(INT_CHANGE_NOTICE_VECTOR, INT_PRIORITY_LEVEL_2);
    INTSetVectorSubPriority(INT_CHANGE_NOTICE_VECTOR, INT_SUB_PRIORITY_LEVEL_1);
    return TRUE;
}
Beispiel #7
0
void __ISR(_TIMER_4_VECTOR, IPL2SOFT) tick_timer_isr() {
    INTClearFlag(INT_T4);
    ColourEngine::Tick();
    //toggle(PIO_LED2);

    // Power toggle
    if (_PORT(PIO_BTN1) == HIGH) {
        last_btn1 = HIGH;
    }
    else if (last_btn1 == HIGH) {
        last_btn1 = LOW;
        power = (power == OFF) ? ON : OFF;
        ColourEngine::SetPower(power, 1000);
    }

    // Switch mode
    if (_PORT(PIO_BTN2) == HIGH) {
        last_btn2 = HIGH;
    }
    else if (last_btn2 == HIGH) {
        last_btn2 = LOW;
        if (mode++ == (int)ColourEngine::NUM_MODES-1)
            mode = 0;
        ColourEngine::SetMode(static_cast<ColourEngine::mode_t>(mode), Q15(0.0001));
    }
}
Beispiel #8
0
/**
 * @Function AD_Init
 * @param None
 * @return SUCCESS or ERROR
 * @brief  Initializes the A/D subsystem and enable battery voltage monitoring.
 * @author Max Dunne, 2013.08.10 */
char AD_Init(void)
{

    if (ADActive) {
        return ERROR;
    }
    int pin = 0;
    //ensure that the battery monitor is active
    ActivePins = BAT_VOLTAGE_MONITOR;
    ADActive = TRUE;
    AD_SetPins();
    for (pin = 0; pin < NUM_AD_PINS; pin++) {
        ADValues[pin] = -1;
    }
    INTEnable(INT_AD1, INT_DISABLED);
    INTClearFlag(INT_AD1);
    INTSetVectorPriority(INT_ADC_VECTOR, 1);
    INTSetVectorSubPriority(INT_ADC_VECTOR, 3);
    INTEnable(INT_AD1, INT_ENABLED);
    EnableADC10();
    ADNewData = FALSE;
    //wait for first reading to ensure  battery monitor starts in the right spot
    while (!AD_IsNewDataReady()) {
#ifdef AD_DEBUG_VERBOSE
        PutChar('.');
#endif
    }
    //set the first values for the battery monitor filter
    Filt_BatVoltage = AD_ReadADPin(BAT_VOLTAGE_MONITOR);
    CurFilt_BatVoltage = Filt_BatVoltage;
    PrevFilt_BatVoltage = Filt_BatVoltage;

    return SUCCESS;
}
Beispiel #9
0
void WF_EintInit(void)
{
       /* disable the external interrupt */
    INTEnable(INT_INT1, INT_DISABLED); // disable interrupt

    #if !defined(TCPIP_STACK_USE_EVENT_NOTIFICATION)
    SYS_INT_DynamicRegister(MRFWB0M_INT_SOURCE, WF_NoEventISR, 0);
    // #else the MRF ISR is already hooked by MRF24W_MACEventInit()!
    #endif
    /* configure IO pin as input and External Interrupt pin*/
    /* set the I/O high since we do not have pull-ups */
    
    
    INT1Rbits.INT1R = 0x0d;    //select INT1 pin  = RPE8
    ANSELEbits.ANSE8 = 0;         /* configure IO pin as input and External Interrupt pin*/
    WF_INT_IO   = 1; // PORTEbits.RE8 = 1;         /* configure IO pin as input and External Interrupt pin*/
    WF_INT_TRIS = 1; //TRISEbits.TRISE8 =   1   ; //    ;  /* set the I/O high since we do not have pull-ups */
    WF_INT_EDGE = 0;  //INTCONbits.INT1EP = 0;     /* falling edge triggered */



    /* clear and enable the interrupt */
    INTClearFlag(INT_INT1) ;           // clear status
    INTSetVectorPriority(INT_EXTERNAL_1_VECTOR, 5);   //set security level to 5
    INTSetVectorSubPriority(INT_EXTERNAL_1_VECTOR,1);  //set sub_security level to 1
    // INTEnable(INT_INT1, INT_ENABLED); // Should not enable interrupt here

    //---
}
Beispiel #10
0
//=============================================
// Configure the ADC interrupt handler
//=============================================
void __ISR(_ADC_VECTOR, ADC_INT_PRIORITY) AdcInterruptHandler(void)
{
  oAdcReady = 1;
  
  Adc.Read();               // Read the enabled channels and puts them in Adc.Var.adcReadValues[]
  INTClearFlag(INT_AD1);    // Clear the ADC conversion done interrupt Flag
}
Beispiel #11
0
/**
 * @Function ADCIntHandler
 * @param None
 * @return None
 * @brief  Interrupt Handler for A/D. Reads all used pins into buffer.
 * @note  This function is not to be called by the user
 * @author Max Dunne, 2013.08.25 */
void __ISR(_ADC_VECTOR, ipl1) ADCIntHandler(void)
{
    unsigned char CurPin = 0;
    INTClearFlag(INT_AD1);
    for (CurPin = 0; CurPin <= PinCount; CurPin++) {
        ADValues[CurPin] = ReadADC10(CurPin); //read in new set of values
    }
    //calculate new filtered battery voltage
    Filt_BatVoltage = (Filt_BatVoltage * KEEP_FILT + AD_ReadADPin(BAT_VOLTAGE_MONITOR) * ADD_FILT) >> SHIFT_FILT;

    SampleCount++;
    if (SampleCount > PointsPerBatSamples) {//if sample time has passed
        PrevFilt_BatVoltage = CurFilt_BatVoltage;
        CurFilt_BatVoltage = Filt_BatVoltage;
        SampleCount = 0;
        //check for battery undervoltage check
        if ((CurFilt_BatVoltage <= BAT_VOLTAGE_LOCKOUT) && (PrevFilt_BatVoltage <= BAT_VOLTAGE_LOCKOUT) && (AD_ReadADPin(BAT_VOLTAGE_MONITOR) > BAT_VOLTAGE_NO_BAT)) {
            BOARD_End();
            while (1) {
                printf("Battery is undervoltage with reading %d, Stack is inoperable until charging\r\n", AD_ReadADPin(BAT_VOLTAGE_MONITOR));
                while (!IsTransmitEmpty());
            }
        }
    }
    //if pins are changed add pins
    if (PinsToAdd | PinsToRemove) {
        AD_SetPins();
    }
    ADNewData = TRUE;
}
//*************************************
//*************************************
//********** COMMS TX PACKET **********
//*************************************
//*************************************
//Call with:
//	comms_tx_byte			Check this is zero before loading comms_tx_buffer (confirms last tx is complete)
//	comms_tx_buffer[]		The packet data to send with the command in byte 0:1.  The Length will automatically be added to bytes 2:3 by this function
//	packet_length			The number of data bytes excluding the checksum (which is automatically added by the tx function)
void comms_tx_packet (WORD packet_length)
{

	//Packet format:
	//	CommandH | CommandL | LengthH | LengthL | 0-# Data Bytes | Checksum H | Checksum L

	//Check last tx is complete
	if (comms_tx_byte)
		return;

	if (packet_length > COMMS_TX_BUFFER_LENGTH)
		return;

	//----- START TX -----
	comms_tx_no_of_bytes_to_tx = packet_length;		//no of bytes to tx (excluding checksum)

	//Set the length bytes
	comms_tx_buffer[2] = (BYTE)(packet_length >> 8);
	comms_tx_buffer[3] = (BYTE)(packet_length & 0x00ff);

	//comms_rx_no_of_bytes_to_rx = 0xfffe;		//If you want to reset rx
	//comms_rx_1ms_timeout_timer = ;

	comms_tx_byte = 0;

	comms_tx_chksum = (WORD)comms_tx_buffer[0];
	
	INTClearFlag(INT_SOURCE_UART_TX(COMMS_UART_NAME));
	UARTSendDataByte(COMMS_UART_NAME, comms_tx_buffer[comms_tx_byte++]);	//Manually trigger the first tx
	INTEnable(INT_SOURCE_UART_TX(COMMS_UART_NAME), INT_ENABLED);
}
Beispiel #13
0
void MyMIWI_Init(void) {

    // Configure Pins for MRF24J40MB
    mPORTESetBits(RST_MIWI);
    mPORTESetPinsDigitalOut(RST_MIWI);

    mPORTBSetBits(MIWI_WAKE);
    mPORTBSetPinsDigitalOut(MIWI_WAKE);

    // Configure the INT3 controller for MIWI
    // Set RD10/INT3 as input
    mPORTDSetPinsDigitalIn(BIT_10);
    // Clear corresponding bits in INTCON for falling edge trigger
    INTCONCLR = _INTCON_INT3EP_MASK;
    // Set up interrupt prioirty and sub-priority
    INTSetVectorPriority(INT_EXTERNAL_3_VECTOR, My_INT_EXTERNAL_3_PRIORITY);
    INTSetVectorSubPriority(INT_EXTERNAL_3_VECTOR, My_INT_EXTERNAL_3_SUB_PRIORITY);
    // Clear the interrupt flags
    INTClearFlag(INT_INT3);
    // Enable INT3
    INTEnable(INT_INT3, INT_ENABLED);

    // WARNING : Change in file MRF24J40.c in Microchip Application Library
    // the line : void __ISR(_EXTERNAL_1_VECTOR, ipl4) _INT1Interrupt(void)
    // by       : void __ISR(_EXTERNAL_3_VECTOR, ipl4) _INT3Interrupt(void)
}
Beispiel #14
0
void __ISR(_TIMER_4_VECTOR, IPL7AUTO) TimerBlinkHandler(void)
{
	// check the LED blink flags
	if (V.blink_alt) {
		if (V.blink & 0b00000001) LEDS.out_bits.b0 = !LEDS.out_bits.b0;
		if (V.blink & 0b00000010) LEDS.out_bits.b1 = !LEDS.out_bits.b0;
		if (V.blink & 0b00000100) LEDS.out_bits.b2 = !LEDS.out_bits.b2;
		if (V.blink & 0b00001000) LEDS.out_bits.b3 = !LEDS.out_bits.b2;
		if (V.blink & 0b00010000) LEDS.out_bits.b4 = !LEDS.out_bits.b4;
		if (V.blink & 0b00100000) LEDS.out_bits.b5 = !LEDS.out_bits.b4;
		if (V.blink & 0b01000000) LEDS.out_bits.b6 = !LEDS.out_bits.b6;
		if (V.blink & 0b10000000) LEDS.out_bits.b7 = !LEDS.out_bits.b6;
	} else {
		if (V.blink & 0b00000001) LEDS.out_bits.b0 = !LEDS.out_bits.b0;
		if (V.blink & 0b00000010) LEDS.out_bits.b1 = !LEDS.out_bits.b1;
		if (V.blink & 0b00000100) LEDS.out_bits.b2 = !LEDS.out_bits.b2;
		if (V.blink & 0b00001000) LEDS.out_bits.b3 = !LEDS.out_bits.b3;
		if (V.blink & 0b00010000) LEDS.out_bits.b4 = !LEDS.out_bits.b4;
		if (V.blink & 0b00100000) LEDS.out_bits.b5 = !LEDS.out_bits.b5;
		if (V.blink & 0b01000000) LEDS.out_bits.b6 = !LEDS.out_bits.b6;
		if (V.blink & 0b10000000) LEDS.out_bits.b7 = !LEDS.out_bits.b7;
	}
	Drive_leds();
	V.blink_count++;
	INTClearFlag(INT_T4);
}
Beispiel #15
0
/**
 * This is the ISR for the ADC1 peripheral. It has been enabled to run continuously. Reads all 8
 * samples from the ADC, averages them, and stores them in a module-level variable for use in the
 * main event loop.
 */
void __ISR(_ADC_VECTOR, IPL2AUTO) AdcHandler(void)
{
    // Clear the interrupt flag.
    INTClearFlag(INT_AD1);


}
Beispiel #16
0
/**
 * This is the interrupt for the Timer1 peripheral. It checks for button events and stores them in a
 * module-level variable. Additionally during each call it increments a counter (the value member of
 * a module-level TimerResult struct). This counter is then checked against the top four bits of the
 * ADC result, and if it's greater, then the event member of a module-level TimerResult struct is
 * set to true and the value member is cleared.
 */
void __ISR(_TIMER_1_VECTOR, IPL4AUTO) Timer1Handler(void)
{
    // Clear the interrupt flag.
    INTClearFlag(INT_T1);


}
Beispiel #17
0
//================================================
// Configure the InputCapture 4 interrupt handler
//================================================
void __ISR(_INPUT_CAPTURE_4_VECTOR, IC4_INT_PRIORITY) InputCapture4InterruptHandler(void)
{
  // Get the timer used by this Input Capture
  TimerNum_t numTimer = InputCapture.Var.timerUsed[IC4];

  // Wait for capture data to be ready
  while(!(InputCapture.IsCaptureReady(IC4)));

  // Update values of timer overflows
  InputCapture.Var.previousTimerOverflows[IC4] = InputCapture.Var.currentTimerOverflows[IC4];
  InputCapture.Var.currentTimerOverflows[IC4]  = Timer.ReadOverflows(numTimer);

  // Store the timer value of the capture event
  InputCapture.Var.previousCaptureCountValue[IC4] = InputCapture.Var.currentCaptureCountValue[IC4];
  InputCapture.Var.currentCaptureCountValue [IC4] = InputCapture.ReadCapture(IC4);

  if (!oFirstCapture4)
  {
    oCapture4 = 1;   // Flag that tells that a new Capture event occured
  }
  else
  {
    oFirstCapture4 = 0;
  }

  // Clear the interrupt flag
  INTClearFlag(INT_IC4);
}
Beispiel #18
0
void vUART1_ISR( void )
{
    static portBASE_TYPE
                xHigherPriorityTaskWoken;
    UART_DATA   rx_data;
    static int  i = 0;

    if( INTGetFlag( INT_U1RX ) )
    {
        INTClearFlag( INT_U1RX );
        
        /*----------------------------------------------------------------------
            Rx interrupt functionality
        ----------------------------------------------------------------------*/
        rx_data = UARTGetData( TARGET_UART );
        rx_buffer = rx_data.__data;
        
        xHigherPriorityTaskWoken = xTaskResumeFromISR( rx_task_handle );

        xSemaphoreGiveFromISR( inputByteBuffer, &xHigherPriorityTaskWoken );
        
        // set Rx task to resume
        portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
    }
    else
    {
        if( INTGetFlag( INT_U1TX ) )
        {
            INTClearFlag( INT_U1TX );

            /*------------------------------------------------------------------
                Tx interrupt functionality
            ------------------------------------------------------------------*/
            // transmit tx_buffer
            if( tx_buffer[ i ] != '\0' )
                UARTSendDataByte( TARGET_UART, tx_buffer[ i++ ] );
            else
            {
                i = 0;
                
                xHigherPriorityTaskWoken = pdFALSE;
                xSemaphoreGiveFromISR( outputStringBuffer, &xHigherPriorityTaskWoken );
            }
        }
    }
}
Beispiel #19
0
void __ISR(_TIMER_2_VECTOR, ipl2) Timer2_ISR(void) {
    if (INTGetFlag(INT_T2)){
         millisec++;
         stopDelayCounter++;
         startDelayCounter++;
         INTClearFlag(INT_T2);   // Acknowledge the interrupt source by clearing its flag.
    }
}
Beispiel #20
0
void __ISR(_UART_2_VECTOR, ipl1) UART2_ISR(void){
    if(INTGetFlag(INT_U2RX)){
        GPSData[GPSIndex] = UARTReceiveByte(UART2);
        GPSIndex++;
        newData = 1;
        INTClearFlag(INT_U2RX);
    }
}
Beispiel #21
0
void __attribute__((vector(47), interrupt(ipl4), nomips16)) CAN2InterruptHandler(void)
{

    /* This is the CAN2 Interrupt Handler. Note that there
    * are many events in the CAN2 module that can cause
    * this interrupt. These events are enabled by the
    * CANEnableModuleEvent() function. In this example,
    * only the RX_EVENT is enabled. */


    /* Check if the source of the interrupt is RX_EVENT.
    * This is redundant  since only this event is enabled
    * in this example but this shows one scheme for handling
    * interrupts. */
    if((CANGetModuleEvent(CAN2) & CAN_RX_EVENT) != 0)
    {

        /* Within this, you can check which event caused the
        * interrupt by using the CANGetPendingEventCode() function
        * to get a code representing the highest priority active
        * event.*/

        if(CANGetPendingEventCode(CAN2) == CAN_CHANNEL1_EVENT)
        {
            /* This means that channel 1 caused the event.
            * The CAN_RX_CHANNEL_NOT_EMPTY event is persistent. You
            * could either read the channel in the ISR
            * to clear the event condition or as done
            * here, disable the event source, and set
            * an application flag to indicate that a message
            * has been received. The event can be
            * enabled by the application when it has processed
            * one message.
            *
            * Note that leaving the event enabled would
            * cause the CPU to keep executing the ISR since
            * the CAN_RX_CHANNEL_NOT_EMPTY event is persistent (unless
            * the not empty condition is cleared.)
            * */

            CANEnableChannelEvent(CAN2, CAN_CHANNEL1, CAN_RX_CHANNEL_NOT_EMPTY, FALSE);
            isCAN2MsgReceived = TRUE;
        }
    }

    /* The CAN2 Interrupt flag is  cleared at the end of the
    * interrupt routine. This is because the event
    * that could have caused this interrupt  to occur
    * (CAN_RX_CHANNEL_NOT_EMPTY) is disabled. Attempting to
    * clear the CAN2 interrupt flag when the the CAN_RX_CHANNEL_NOT_EMPTY
    * interrupt is enabled will not have any effect because the
    * base event is still present. */

    INTClearFlag(INT_CAN2);


}
Beispiel #22
0
void __ISR(_EXTERNAL_1_VECTOR, ipl7auto) Ext3Handler_PmodACLInt1(void)
{
 //we have data, signal main loop to collect
    aclDataReady = 1;
    portBASE_TYPE taskWoken;
   // OC1CONbits.ON = 1;
    //xSemaphoreGiveFromISR (sema, &taskWoken);
    INTClearFlag(INT_INT1);
}
Beispiel #23
0
void __ISR(_UART1_VECTOR, IPL2SOFT) IntUart1Handler(void)
{
     if(INTGetFlag(INT_SOURCE_UART_RX(UART1)))
     {
         INTClearFlag(INT_SOURCE_UART_RX(UART1));
         if (uart_rx_count<sizeof(uart_rx_buff)-1)
             uart_rx_count++;
         else
             uart_rx_count=0; // overflow
         
         uart_rx_buff[uart_rx_count]=UARTGetDataByte(UART1);
     }

    if(INTGetFlag(INT_SOURCE_UART_TX(UART1)))
   {
       INTClearFlag(INT_SOURCE_UART_TX(UART1));
    }
}
void handleUartInterrupt(UART_MODULE uart, Buffer* buffer) {
    // Is this an RX interrupt?
    if (INTGetFlag(INT_SOURCE_UART_RX(uart))) {
        if (UARTReceivedDataIsAvailable(uart)) {
            unsigned char c = UARTGetDataByte(uart);
            // BUG2018, BUG2019 (255 / 254 value) when Motor Power is too strong
            if (c != 'ÿ' && c != 'þ') {
                bufferWriteChar(buffer, c);
            }
            // Clear the RX interrupt Flag
            INTClearFlag(INT_SOURCE_UART_RX(uart));
        }
    }
    // We don't care about TX interrupt
    if ( INTGetFlag(INT_SOURCE_UART_TX(uart)) ) {
        INTClearFlag(INT_SOURCE_UART_TX(uart));
    }
}
/****************************************************************************
 * Function:        TCPIPEventClose
 *
 * PreCondition:    None.
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function closes the ethernet event notification.
 *
 * Note:            None
 ******************************************************************************/
void TCPIPEventClose(void)
{

	INTEnable(INT_ETHERNET, INT_DISABLED);		// stop Eth ints
	INTClearFlag(INT_ETHERNET);

	_TcpNotifyFnc=0;
	_TcpEnabledEvents=_TcpPendingEvents=0;
}
// UART interrupt handler, set at priority level 2
void __ISR(_UART_2_VECTOR, ipl2) IntUart2Handler(void)
{
    // Is this an RX interrupt?
    if(INTGetFlag(INT_SOURCE_UART_RX(UART_CMD_MODULE_ID)))
    {
        char rchar = UARTGetDataByte(UART_CMD_MODULE_ID);

        AddKeystroke(&CurrentCommandEngine, rchar);

        // Clear the RX interrupt Flag
        INTClearFlag(INT_SOURCE_UART_RX(UART_CMD_MODULE_ID));
    }

    // We don't care about TX interrupt
    if ( INTGetFlag(INT_SOURCE_UART_TX(UART_CMD_MODULE_ID)) )
    {
        INTClearFlag(INT_SOURCE_UART_TX(UART_CMD_MODULE_ID));
    }
}
/*******************************************************************************
 * FUNCTION: vUART2Init
 *
 * PARAMETERS:
 * ~ void
 *
 * RETURN:
 * ~ void
 *
 * DESCRIPTIONS:
 * Initialize the UART2 module.
 * UART 2 is used by bluetooth module.
 *
 *******************************************************************************/
void vUART2Init(void)
{
    // Configure UART 2.
    UARTConfigure(UART2, UART_ENABLE_HIGH_SPEED | UART_ENABLE_PINS_TX_RX_ONLY);
    UARTSetFifoMode(UART2, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
    UARTSetLineControl(UART2, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
    UARTSetDataRate(UART2, GetPeripheralClock(), BT2_BAUDRATE);
    UARTEnable(UART2, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));

    // Configure the interrupt.
    INTSetVectorPriority(INT_UART_2_VECTOR, INT_PRIORITY_LEVEL_7);

    INTClearFlag(INT_U2TX);
    INTClearFlag(INT_U2RX);
    INTClearFlag(INT_U2E);

    INTEnable(INT_U2RX, INT_ENABLED);
    INTEnable(INT_U2E, INT_ENABLED);
}
void __ISR(_UART_4_VECTOR, ipl1) IntUart4Handler(void)
{
    // Is this an RX interrupt?
    if(INTGetFlag(INT_SOURCE_UART_RX(UART_WIFI_MODULE_ID)))
    {
        const char rchar = UARTGetDataByte(UART_WIFI_MODULE_ID);

        PutcToWifiReceivedBuffer(rchar, &DefaultWifiService);

        // Clear the RX interrupt Flag
        INTClearFlag(INT_SOURCE_UART_RX(UART_WIFI_MODULE_ID));
    }

    // We don't care about TX interrupt
    if ( INTGetFlag(INT_SOURCE_UART_TX(UART_WIFI_MODULE_ID)) )
    {
        INTClearFlag(INT_SOURCE_UART_TX(UART_WIFI_MODULE_ID));
    }
}
Beispiel #29
0
void hal_uart_send_async(hal_uart_port port, uint8_t size){
    assert(port >= HAL_UART_PORT_1 && port <= HAL_UART_NUMBER_OF_PORTS );
    /* select the respective output buffer */
    struct txbuffer_struct* tx_buffer = get_tx_buffer(port);
    tx_buffer->nbytes = size;
    tx_buffer->counter = 0;
    UART_MODULE uart = logic_uart2phy_uart(port);
    INTClearFlag(INT_SOURCE_UART_TX(uart));
    INTEnable(INT_SOURCE_UART_TX(uart), INT_ENABLED);
}
Beispiel #30
0
void __attribute__((vector(_ADC_VECTOR), interrupt(ipl4), nomips16)) ADC_ISR(void)
{
    if (INTGetFlag(INT_AD1)){
        //when conversion is complete write ADC word to the variable so it can be displayed
        analogIn1 = ReadADC10(0);
        analogIn2 = ReadADC10(1);
        analogRead = TRUE;
        INTClearFlag(INT_AD1);
    }
}