Example #1
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);


}
Example #2
0
CAN1InterruptHandler(void)
{
    if ((CANGetModuleEvent(CAN1) & CAN_RX_EVENT) != 0)
    {
        if(CANGetPendingEventCode(CAN1) == CAN_CHANNEL1_EVENT)
        {
            CANEnableChannelEvent(CAN1, CAN_CHANNEL1, CAN_RX_CHANNEL_NOT_EMPTY, FALSE);
            isCAN1MsgReceived = TRUE;
        }
    }
    INTClearFlag(INT_CAN1);
}
Example #3
0
//================================================
// Configure the CAN1 interrupt handler
//================================================
void __ISR(_CAN_1_VECTOR, CAN1_INT_PRIORITY) Can1InterruptHandler(void)
{
  // 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 events

  if ((CANGetModuleEvent(CAN1) & CAN_RX_EVENT) != 0)
  {
    LED_CAN_TOGGLE;

    CANRxMessageBuffer *message;

    /*
     * CHANNEL 1 = SWITCHES STATES
     */
    if (CANGetPendingEventCode(CAN1) == CAN_CHANNEL1_EVENT)
    {

      CANEnableChannelEvent(CAN1, CAN_CHANNEL1, CAN_RX_CHANNEL_NOT_EMPTY, FALSE);

      message = CANGetRxMessage(CAN1, CAN_CHANNEL1);

      CanSwitches_t switches;
      switches.bytes.low  = message->data[0];
      switches.bytes.high = message->data[1];

      if (buttons.buttons.bits.steerWheelSw1  != switches.bits.sw1 )
      {
        buttons.buttons.bits.steerWheelSw1  = switches.bits.sw1;
        buttons.chng.bits.steerWheelSw1     = 1;
      }

      if (buttons.buttons.bits.steerWheelSw4  != switches.bits.sw4 )
      {
        buttons.buttons.bits.steerWheelSw4  = switches.bits.sw4;
        buttons.chng.bits.steerWheelSw4     = 1;
      }

      if (buttons.buttons.bits.steerWheelSw10 != switches.bits.sw10)
      {
        buttons.buttons.bits.steerWheelSw10 = switches.bits.sw10;
        buttons.chng.bits.steerWheelSw10    = 1;
      }

      LED_CAN_TOGGLE;
      CANUpdateChannel(CAN1, CAN_CHANNEL1);
      CANEnableChannelEvent(CAN1, CAN_CHANNEL1, CAN_RX_CHANNEL_NOT_EMPTY, TRUE);

    }

    /*
     * CHANNEL 2 = WIND ANGLE
     */
    if (CANGetPendingEventCode(CAN1) == CAN_CHANNEL2_EVENT)
    {

      CANEnableChannelEvent(CAN1, CAN_CHANNEL2, CAN_RX_CHANNEL_NOT_EMPTY, FALSE);

      message = CANGetRxMessage(CAN1, CAN_CHANNEL2);

      memcpy((void *) &rxWindAngle, &message->data[0], 4);
      
      oNewWindAngle = 1;

      CANUpdateChannel(CAN1, CAN_CHANNEL2);
      CANEnableChannelEvent(CAN1, CAN_CHANNEL2, CAN_RX_CHANNEL_NOT_EMPTY, TRUE);
    }
  }

  // The CAN1 Interrupt flag is  cleared at the end of the interrupt routine.
  // This is because the event source that could have caused this interrupt to
  // occur (CAN_RX_CHANNEL_NOT_EMPTY) is disabled. Attempting to clear the
  // CAN1 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_CAN1);
}
Example #4
0
void __attribute__((vector(46), interrupt(ipl4), nomips16)) CAN1InterruptHandler(void)
{
	/* This is the CAN1 Interrupt Handler.
	 * Note that there are many source events in the
	 * CAN1 module for 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 events. */

	if((CANGetModuleEvent(CAN1) & CAN_RX_EVENT) != 0)
	{
		
		/* Within this, you can check which channel caused the 
		 * event by using the CANGetModuleEvent() function
         * which returns a code representing the highest priority
         * pending event. */ 
		
		if(CANGetPendingEventCode(CAN1) == 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.) 
			 * */

			CANRxMessageBuffer * message;
			message = CANGetRxMessage(CAN1,CAN_CHANNEL1);

			// Copy the byte into the local FIFO, if it won't cause an overflow
			if(RXHeadPtr != RXTailPtr - 1)
			{
				if((RXHeadPtr != vCANRXFIFO + sizeof(vCANRXFIFO)) || (RXTailPtr != vCANRXFIFO))
				{
					*RXHeadPtr++ = (message->msgSID.SID >> 8);
					*RXHeadPtr++ = message->msgSID.SID;
					*RXHeadPtr++ = message->data[0];
					*RXHeadPtr++ = message->data[1];
					*RXHeadPtr++ = message->data[2];
					*RXHeadPtr++ = message->data[3];
					*RXHeadPtr++ = message->data[4];
					*RXHeadPtr++ = message->data[5];
					*RXHeadPtr++ = message->data[6];
					*RXHeadPtr++ = message->data[7];
					if(RXHeadPtr >= vCANRXFIFO + sizeof(vCANRXFIFO))
						RXHeadPtr = vCANRXFIFO;
				}
			}
			CANUpdateChannel(CAN1, CAN_CHANNEL1);	
		}