//****************************************************************************
// @Module        Shared Interrupt Routines
// @Filename      SHARED_INT.C
// @Project       USCALE_extLBM.dav
//----------------------------------------------------------------------------
// @Controller    Infineon XC886CLM-8FF
//
// @Compiler      Keil
//
// @Codegenerator 1.3
//
// @Description   This file contains the Shared interrupt routines.
//
//----------------------------------------------------------------------------
// @Date          27.04.2007 16:32:22
//
//****************************************************************************

// USER CODE BEGIN (SHARED_INT_General,1)

// USER CODE END



//****************************************************************************
// @Project Includes
//****************************************************************************

#include "SHARED_INT.H"

// USER CODE BEGIN (SHARED_INT_General,2)

// USER CODE END


//****************************************************************************
// @Macros
//****************************************************************************

// USER CODE BEGIN (SHARED_INT_General,3)

// USER CODE END


//****************************************************************************
// @Defines
//****************************************************************************

// USER CODE BEGIN (SHARED_INT_General,4)

// USER CODE END


//****************************************************************************
// @Typedefs
//****************************************************************************

// USER CODE BEGIN (SHARED_INT_General,5)

// USER CODE END


//****************************************************************************
// @Imported Global Variables
//****************************************************************************

// USER CODE BEGIN (SHARED_INT_General,6)

// USER CODE END


//****************************************************************************
// @Global Variables
//****************************************************************************

// USER CODE BEGIN (SHARED_INT_General,7)
#ifdef	FULL
char TX[]  = {"TX "};
char RX[]  = {"RX "};
char IRQ[] = {"Interrupt "};
char MO[]  = {"MO "};
#endif
// USER CODE END


//****************************************************************************
// @External Prototypes
//****************************************************************************


// USER CODE BEGIN (SHARED_INT_General,8)

// USER CODE END


//****************************************************************************
// @Prototypes Of Local Functions
//****************************************************************************

// USER CODE BEGIN (SHARED_INT_General,9)

// USER CODE END


//****************************************************************************
// @Function      void SHINT_vInit(void) 
//
//----------------------------------------------------------------------------
// @Description   This function initializes the shared interrupts. 
//
//----------------------------------------------------------------------------
// @Returnvalue   None
//
//----------------------------------------------------------------------------
// @Parameters    None
//
//----------------------------------------------------------------------------
// @Date          27.04.2007
//
//****************************************************************************

// USER CODE BEGIN (SHINT_Init,1)

// USER CODE END

void SHINT_vInit(void)
{
  // USER CODE BEGIN (SHINT_Init,2)

  // USER CODE END

  ///  -----------------------------------------------------------------------
  ///  Configuration of the Shared  Interrupts:
  ///  -----------------------------------------------------------------------
  ///  - MultiCAN Node 0 Interrupt is Selected


  IEN0         |=  0x20;         // load interrupt enable register 0

  ///  - MultiCAN Node 1 Interrupt is Selected
  ///  - MultiCAN Node 3 Interrupt is Selected
  ///  - MultiCAN Node 4 Interrupt is Selected


  IEN1         |=  0x19;         // load interrupt enable register 1


  // USER CODE BEGIN (SHINT_Init,3)

  // USER CODE END


} //  End of function SHINT_vInit


//****************************************************************************
// @Function      void SHINT_viXINTR5Isr(void) 
//
//----------------------------------------------------------------------------
// @Description   This is the service routine for the shared interrupt node 
//                XINTR5. XINTR5 ISR Node is shared by Timer 2, UART 
//                Fractional Divider(BRG Interrupt),MultiCAN Node 0 and LIN. 
//                Depending on the selected module interrupt it is called.
//                T2 - Depending on the selected operating mode it is called 
//                when TF2 is set by an overflow or underflow of the timer 2 
//                register or when EXF2 is set by a negative transition on 
//                T2EX.
//                UART - It is called after the BRG timer overflows and sets 
//                the NDOV bit.
//                CAN -  It is called for the  Service Request Node 0 of the 
//                MultiCAN module.
//                Please note that you have to add application specific code 
//                to this function.
//
//----------------------------------------------------------------------------
// @Returnvalue   none
//
//----------------------------------------------------------------------------
// @Parameters    None
//
//----------------------------------------------------------------------------
// @Date          27.04.2007
//
//****************************************************************************

//   You have two choices for interrupt type select in Project Settings Page 
//   under Global Settings Section.
//   If you select CHOICE 1 then ISR will be generated with push and pop.
//   If you select CHOICE 2 then ISR will be generated without push and pop.
//   Default choice is CHOICE 2.
//   Current selection is CHOICE 2 

// USER CODE BEGIN (SHINT_XINTR5Isr,1)

// USER CODE END

void SHINT_viXINTR5Isr(void) interrupt XINTR5INT
{
	// TxIRQ for object 1 ID 7
	//=========================

  CAN_pushAMRegs();              			// push the CAN Access Mediator Registers
  IRCON2 &= ~(ubyte)0x01; 					// Clear CANSRC0

  CAN_vWriteCANAddress(CAN_MSPND0);   		// message pending register
  CAN_vReadEN();               				// Read Mode is enabled
  CAN_DATA0 &= ~(0x02);
  CAN_vWriteEN(D0_VALID);

  CAN_vWriteCANAddress(CAN_MOCTR1); 		// Addressing CAN_MOCTR1
  CAN_DATA0 = 0x02; 						// Reset TxPND flag for object 1
  CAN_vWriteEN(D0_VALID);

  CAN_vWriteCANAddress(CAN_MODATAL1);   	// read CAN data byte
  CAN_vReadEN();
#ifndef	FULL
  puts("\n MO1 : Tx PING ");
#else
  printf("\n  %s%s%s  1 - 0x%02X  PING   ",TX,IRQ,MO,(int)CAN_DATA0);
#endif
  CAN_popAMRegs();               			// restore the CAN Access Mediator Registers
} //  End of function SHINT_viXINTR5Isr


//****************************************************************************
// @Function      void SHINT_viXINTR6Isr(void) 
//
//----------------------------------------------------------------------------
// @Description   This is the service routine for the shared interrupt node 
//                XINTR6. XINTR6 ISR Node is shared by ADC[1:0] and MultiCAN 
//                Nodes 1 & 2. Depending on the selected module interrupt it 
//                is called. 
//                ADC -  It is activated by different interrupt sources 
//                (Channel Interrupts or Event Interrupts).The user obtains 
//                the conversion result by calling the function 
//                ADC_uwGetResultDataX(0,1,2,3).
//                CAN - It is called for the  Service Request Node 1 and 2 of 
//                the MultiCAN module.
//                Please note that you have to add application specific code 
//                to this function.
//
//----------------------------------------------------------------------------
// @Returnvalue   none
//
//----------------------------------------------------------------------------
// @Parameters    None
//
//----------------------------------------------------------------------------
// @Date          27.04.2007
//
//****************************************************************************

//   You have two choices for interrupt type select in Project Settings Page 
//   under Global Settings Section.
//   If you select CHOICE 1 then ISR will be generated with push and pop.
//   If you select CHOICE 2 then ISR will be generated without push and pop.
//   Default choice is CHOICE 2.
//   Current selection is CHOICE 2 

// USER CODE BEGIN (SHINT_XINTR6Isr,1)

// USER CODE END

void SHINT_viXINTR6Isr(void) interrupt XINTR6INT
{
	// RxIRQ for object 0 ID 5
	//=========================

  	CAN_pushAMRegs();              			// push the CAN Access Mediator Registers
	IRCON1 &= ~(ubyte)0x20; 				//   clear CANSRC1
  
    CAN_vWriteCANAddress(CAN_MSPND1);   	// message pending register
    CAN_vReadEN();               			// Read Mode is enabled
	CAN_DATA0 &= ~(0x01);
    CAN_vWriteEN(D0_VALID);

  	CAN_vWriteCANAddress(CAN_MOCTR0); 		// Addressing CAN_MOCTR0
  	CAN_DATA0 = 0x09; 						// Reset RxPND & NewDat flag for object 0
  	CAN_vWriteEN(D0_VALID);
 
	CAN_vWriteCANAddress(CAN_MODATAL0);   	// read CAN data byte
  	CAN_vReadEN();
#ifndef	FULL
	puts("\n MO0 : Rx PONG ");
#else
  	printf("-   %s%s%s  0 - 0x%02X   PONG !!",RX,IRQ,MO,(int)CAN_DATA0);
#endif
	g_ucCanDataValueCount++;
	CAN_vWriteCANAddress(CAN_MODATAL1);   	// read CAN data byte
  	CAN_DATA0 = g_ucCanDataValueCount;
	CAN_vWriteEN(D0_VALID);
	
	CAN_popAMRegs();               			// restore the CAN Access Mediator Registers
	CAN_vTransmit(1);
  	
} //  End of function SHINT_viXINTR6Isr


//****************************************************************************
// @Function      void SHINT_viXINTR9Isr(void) 
//
//----------------------------------------------------------------------------
// @Description   This is the service routine for the shared interrupt node 
//                XINTR9. XINTR9 ISR Node is shared by External Interrupts 
//                3,4 5,6 and MultiCAN Node3 . Depending on the selected 
//                module interrupt it is called. 
//                EXT3- It is called for the External interrupts 3,4,5 and 6. 
//                CAN -  It is called for the  Service Request Node 3 of the 
//                MultiCAN module.
//                Please note that you have to add application specific code 
//                to this function.
//
//----------------------------------------------------------------------------
// @Returnvalue   None
//
//----------------------------------------------------------------------------
// @Parameters    None
//
//----------------------------------------------------------------------------
// @Date          27.04.2007
//
//****************************************************************************

//   You have two choices for interrupt type select in Project Settings Page 
//   under Global Settings Section.
//   If you select CHOICE 1 then ISR will be generated with push and pop.
//   If you select CHOICE 2 then ISR will be generated without push and pop.
//   Default choice is CHOICE 2.
//   Current selection is CHOICE 2 

// USER CODE BEGIN (SHINT_XINTR9Isr,1)

// USER CODE END

void SHINT_viXINTR9Isr(void) interrupt XINTR9INT
{
	// TxIRQ for object 16 ID 5
	//=========================

  	CAN_pushAMRegs();              				// push the CAN Access Mediator Registers
	IRCON2 &= ~(ubyte)0x10; 					//   clear CANSRC3

	CAN_vWriteCANAddress(CAN_MSPND0);   		
  	CAN_vReadEN();               				// Read Mode is enabled
  	CAN_DATA2 &= ~(0x01);
  	CAN_vWriteEN(D2_VALID);

  	CAN_vWriteCANAddress(CAN_MOCTR16); 			// Addressing CAN_MOCTR16
  	CAN_DATA0 = 0x02; 							// Reset TxPND flag for object 16
  	CAN_vWriteEN(D0_VALID);

  	CAN_vWriteCANAddress(CAN_MODATAL16);   		// read CAN data byte
  	CAN_vReadEN();
#ifndef	FULL
	puts("\n MO16: Tx PONG ");
#else
  	printf("\n  %s%s%s 16 - 0x%02X  PONG   ",TX,IRQ,MO,(int)CAN_DATA0);
#endif
	CAN_popAMRegs();               				// restore the CAN Access Mediator Registers

} //  End of function SHINT_viXINTR9Isr


//****************************************************************************
// @Function      void SHINT_viXINTR10Isr(void) 
//
//----------------------------------------------------------------------------
// @Description   This is the service routine for the shared interrupt node 
//                XINTR10. XINTR10 ISR Node is shared by CCU6 Node Pointer 0 
//                and MultiCAN Node 4 . Depending on the selected module 
//                interrupt it is called. 
//                CCU6 - If the content of the corresponding compare timer 
//                (configurable) equals the content of the capture/compare 
//                register or if a capture event occurs at the associated 
//                port pin, the interrupt request flag is set and an 
//                interrupt is triggered (only if enabled).
//                CAN - It is called for the  Service Request Node 4 of the 
//                MultiCAN module.
//                Please note that you have to add application specific code 
//                to this function.
//
//----------------------------------------------------------------------------
// @Returnvalue   None
//
//----------------------------------------------------------------------------
// @Parameters    None
//
//----------------------------------------------------------------------------
// @Date          27.04.2007
//
//****************************************************************************

//   You have two choices for interrupt type select in Project Settings Page 
//   under Global Settings Section.
//   If you select CHOICE 1 then ISR will be generated with push and pop.
//   If you select CHOICE 2 then ISR will be generated without push and pop.
//   Default choice is CHOICE 2.
//   Current selection is CHOICE 2 

// USER CODE BEGIN (NodeI0,1)

// USER CODE END

void SHINT_viXINTR10Isr(void) interrupt XINTR10INT
{
	// RxIRQ for object 17 ID 7
	//=========================
  	CAN_pushAMRegs();              				// push the CAN Access Mediator Registers
	SFR_PAGE(_su3, SST0);          				// switch to page 3

    IRCON3 &= ~(ubyte)0x02; 					//   clear CANSRC4

	CAN_vWriteCANAddress(CAN_MSPND1);   		// message pending register
    CAN_vReadEN();               				// Read Mode is enabled
	CAN_DATA2 &= ~(0x02);
    CAN_vWriteEN(D2_VALID);

  	CAN_vWriteCANAddress(CAN_MOCTR17); 			// Addressing CAN_MOCTR17
  	CAN_DATA0 = 0x09; 							// Reset RxPND & NewDat flag for object 17
  	CAN_vWriteEN(D0_VALID);
    
  	SFR_PAGE(_su3, RST0);          				// restore the old SCU page
	CAN_vWriteCANAddress(CAN_MODATAL1);   		// read CAN data byte
  	CAN_vReadEN();
#ifndef FULL
	puts("\n MO17: Rx PING ");
#else
  	printf("-   %s%s%s 17 - 0x%02X   PING !!",RX,IRQ,MO,(int)CAN_DATA0);
#endif
	CAN_vWriteCANAddress(CAN_MODATAL16);   		// read CAN data byte
  	CAN_DATA0 = ~(CAN_DATA0);					// load Pong answer
	CAN_vWriteEN(D0_VALID);
	CAN_vReadEN();
	
	CAN_popAMRegs();               				// restore the CAN Access Mediator Registers
	CAN_vTransmit(16);
} //  End of function SHINT_viXINTR10Isr

// USER CODE BEGIN (SHARED_INT_General,10)

// USER CODE END


