µC CAN Library - MxV Microcontroller Emulation

Simulated Microcontroller CAN

The MxV uC library simulates a CAN sub-system of a typical microcontroller (µC).  The library provides an interface to a simulated µC CAN used for:

Sending and receiving CAN messages with different IDs on different CAN buses  

Generating receive and transmit interrupt requests

hmtoggle_plus1Initializing the CAN Sub-System
hmtoggle_plus1Configuring the CAN Sub-System
hmtoggle_plus1The Structure of CAN Messages
hmtoggle_plus1Sending CAN Messages

Example:

 

// in the 'AppIF.c' file

 

// global variable used to retain the bus handle

MxVuC_CAN_Device can_bus_handle;

// CAN Rx interrupt service routine

void CAN_Rx_Int(void);

// used to transmit CAN messages

void SendCANMessage(void);

 

void SUT_Init(void)

{

  //Initializes microcontroller simulation and starts to execute main()

  MxVuC_Initialize();

 

 

 

  // initialize the CAN sub-system

  MxVuC_CAN_Initialize();

  // get a handle to bus 0

  can_bus_handle = MxVuC_CAN_Open(0);

  // setup the SUT vector table

  MxVuC_VectorTableSUT[MxVuC_Vector_CAN_Rx] = CAN_Rx_Int;

  // enable the bus

  MxVuC_CAN_Enable(can_bus_handle, mxvTrue);  

  // enable interrupts

  MxVuC_EnableInterrupts();

 

 

  MxVuC_Tick();

}

 

// this function is set in MxV to run every 10ms

void SUT_Tick(void)

{

  MxVuC_CAN_TP_Tick10ms(); // this function must be called every 10ms

  MxVuC_Tick();

}

 

void CAN_Rx_Int(void)

{

  // handle different CAN buses

  switch(MxVuC_CAN_Rx_Bus)

  {

    // deal with all buses that we're not handling

    default:

     {

     } break;

   

    // first CAN bus

    case 0:

     {

        // handle different CAN message IDs on the first bus

        switch(MxVuC_CAN_Rx_Message.id)

        {

          // deal with all message IDs that we're not handling

          default:

           {

           } break;

           

          // handle CAN message ID 0x412

          case 0x412:

           {

              // read the data from MxVuC_CAN_Rx_Message.payload    

           } break;

        }

     } break;

  }

}

 

void SendCANMessage(void)

{

  MxVuC_CAN_Message can_tx_msg = {0};

  uint8 data = 0x7F;

 

  MxVuC_CAN_MakeMessage(&can_tx_msg, 0x700, sizeof(data), 0, &data);

  MxVuC_CAN_Tx(can_bus_handle, &can_tx_msg);

}

Related Topics:

µC Library Overview

Bus Control System Signals

Linking your code with the MxVMC

Connecting to a Hardware Bus

Testing CAN Signals

Network Configuration