Part 4 - Can Bus Model

Parent Previous Next

VisualSim                                                                                                                              


Can Bus Model


Block Diagram

The CAN Controller contains Transmit and Receive objects. The CAN Bus helps us to share the data between CAN Controllers. The CAN Controller1 starts transmitting the data from their Transmit object through a single wire called CAN Bus for every 1 msec. The Receiving object of the CAN Controller2 has a Queue. This model explains the performance evaluation of the simple CAN Bus Model and derives the step-by-step approach of developing CAN Bus Model as shown below.   

 

CAN Bus Block Diagram

Figure 1: CAN Bus Block Diagram (Source: Paolo Giusto, General Motors)

Flow Diagram of CAN Bus Model

Can_Bus_Flow_Diagram

Figure 2: CAN Bus Model

CAN Bus Model

To construct the model, we need to set the simulator (Digital), define the parameters and describing the model flow by adding blocks. The Traffic block sends out the 'Processor_DS' data structure based on the parameters Input_Rate1(Device1) and Input_Rate2 (Device2) using fixed distribution. The Expression_LIst block that follows the Traffic block sets the A_Bytes, A_Destination, A_Source, A_Priority, and a few other fields. CAN_Controller contains a transmit object and receive objects. The Token is passed from the Transmit Object through the single wire called CAN_Bus to the Receiving Object of another CAN_Controller. Receiving Object need to have a receive queue that gets messages every 1.0 msec.

A fully assembled model must look as below. You can also compare your model with the following model:


CAN_Bus_Model

Figure 3: CAN Bus Model

Construction Steps

The construction of the above model is described below.

Step 1   

  1. Open a new Block Diagram by selecting File > New > Block Diagram.
  2. Drag the Digital block (Model > Simulator > Digital) onto the block diagram. Make its parameter "EndTime =  10.0". Maintain the default values for all of its other parameters.
  3. Setup the parameter (ModelSetup > Parameter=) as shown in Fig 4.
  4. Setup the traffic using the Traffic block (Traffic >Traffic).
  5. Setup the parameters for the Traffic block (Double-click the Traffic block.)
    1. Data_Structure_Name: “Processor_DS”
    2. Generate the token based on parameters Input_Rate1 and Input_Rate2 
    3. Time_Distribution type: Fixed Interval

CAN_Bus_Evaluation_Model

Figure 4: CAN Bus Evaluation Model-Step 1

Parameters_for_Master_1

Figure 5: Parameters for Master 1

Step 2

The following diagram shows the implementation of fragmentation in the transmit object using the While Block:

Implementation of fragmentation in the transmit object using the??IF_Else and While Block

Figure 6: CAN Bus Evaluation Model-Step 2

  1. Drag the ExpressionList block (Behavior > ExpressionList) to fill in the transaction Field.  Double-click the block and do the following:

Parameters_for_Expr_Script

Figure 7: Parameters for Expr Script

  1. Fragment the input token using the While Block (Full Library > Defining_Flow > Basic_Processing > While).

For example, let us consider  A_Bytes = 100, Burst_Size = 64.

Then, First Fragment=> (A_Bytes = 100, A_Bytes_Remaining = 36, A_Bytes_Sent = 64).

Second Fragment => (A_Bytes = 100, A_Bytes_Remaining = 0, A_Bytes_Sent = 36).

 

Parameters_for_While

Figure 8: Parameters for Expr Script

Step 3

  1. Pass the fragmented port_token in a single wire channel using the SystemResource block (Resources > SystemResource) and the Mapper block (Mappers > Mapper). (See Figure 9).

CAN_Bus_Evaluation_Model-Step_3

Figure 9: CAN Bus Evaluation Model-Step 3

  1. Setup the Parameter Field for the SystemResource.
  1. Resource_Name  =>  Assigns the scheduler name as per convenient and it should be same as the Mapper name.
  2. Round_Robin_Time_Slice => describes the time for each process
  3. Clock_Rate_Mhz
  4. Max_Scheduler_Length => Length of the Scheduler
  5. Scheduler_Type => type of Scheduling about to proceed

 

Parameters_for_channel

Figure 10: Parameters For Channel

Step 4

  1. Receive object will be a "Server" (Resources -> Server ). This block will delay the request for 1 msec and then transmits the packet out.

 

Parameters_for_Smart_Timed_Res

Figure12. Parameters for Server

Can_Bus_Evaluation_Model_Step_4

Figure 13. CAN Bus Evaluation Model-Step 4

Step 5

  1. Use the Case Switch block and redirect to the appropriate destination (Full Library > Defining_Flow > Case_Switch).
  2. Derive the latency for both Masters and plot it using the TimeDataPlotter.

 

Figure 11: CAN Bus Evaluation Model-Step 5  

Evaluation

  1. Listen to Port

            Using the Listen-to-Port, we can find the token transaction with respect to the timing and we can debug the output.

 

Listen_to_port

Figure14. Listen to Port

Sample Output of the Mapper Listen-to-Port is as follows:

OUTPUT AT TIME   ------ 40.30 ns ------

{A_Addr_Ctrl_Flag        = true,

A_Address_Max           = 100,

A_Address_Min            = 1,

A_Branch                     = false,

A_Bytes                        = 19,

A_Bytes_Remaining     = 0,

A_Bytes_Sent              = 19,

A_Command                 = "Read",

A_Data                         = "MyData",

A_Destination               = "Device1",

A_First_Word                = true,

A_Hop                          = "Device1",

A_IDX                           = 0,

A_IDY                           = 0,

A_Instruction                 = {"ADD", "ADD"}

A_Instruction_Reorder  = {1}

A_Interrupt                    = false,

A_Prefetch                   = false,

A_Priority                       = 0,

A_Proc_Return             = -1,

A_Protocol_State          = "MyState",

A_Return                       = -1,

A_Source                       = "CAN_1",

A_Status                        = "Status",

A_Task_Address            = 1,

A_Task_Flag                  = false,

A_Task_ID                     = 0L,

A_Task_Name               = "Name",

A_Task_Source             = "Src",

A_Time                           = 0.0,

A_Variables                     = 16,

BLOCK                            = "Traffic1",

CAN_Time                      = 2,

DELTA                            = 0.0,

DS_NAME                      = "Processor_DS",

ID                                    = 1,

INDEX                             = 1,

TIME                               = 1.0E-10}

 

OUTPUT AT TIME   ------ 100.30 ns ------

{A_Addr_Ctrl_Flag         = true,

A_Address_Max            = 100,

A_Address_Min             = 1,

A_Branch                      = false,

A_Bytes                         = 30,

A_Bytes_Remaining      = 0,

A_Bytes_Sent               = 30,

A_Command                 = "Read",

A_Data                         = "MyData",

A_Destination               = "Device2",

A_First_Word                = true,

A_Hop                          = "Device2",

A_IDX                           = 0,

A_IDY                           = 0,

A_Instruction                 = {"ADD", "ADD"}

A_Instruction_Reorder  = {1}

A_Interrupt                    = false,

A_Prefetch                    = false,

A_Priority                       = 0,

A_Proc_Return             = -1,

A_Protocol_State         = "MyState",

A_Return                      = -1,

A_Source                      = "CAN_2",

A_Status                       = "Status",

A_Task_Address          = 1,

A_Task_Flag                 = false,

A_Task_ID                    = 0L,

A_Task_Name              = "Name",

A_Task_Source            = "Src",

A_Time                          = 0.0,

A_Variables                   = 16,

BLOCK                          = "Traffic2",

CAN_Time                    = 3,

DELTA                          = 0.0,

DS_NAME                    = "Processor_DS",

ID                                 = 1,

INDEX                          = 2,

TIME                            = 1.0E-10}

  1. Listen to Block

            Using the Listen-to-Block, we can find the functionality of the block with respect to its timing and functionality.

 

Listen_to_Block

Figure15. Listen to Block

Sample Output of the Mapper Listen to Block are as follows:

NEW TASK  (1001) TNow: 3.0E-10  Parent: Mapper  Data Structure:

{A_Addr_Ctrl_Flag          = true,

A_Address_Max             = 100,

A_Address_Min              = 1,

A_Branch                       = false,

A_Bytes                          = 73,

A_Bytes_Remaining       = 41,

A_Bytes_Sent                = 32,

A_Command                  = "Read",

A_Data                          = "MyData",

A_Destination                = "Device1",

A_First_Word                 = true,

A_Hop                           = "Device1",

A_IDX                            = 0,

A_IDY                            = 0,

A_Instruction                  = {"ADD", "ADD"},

A_Instruction_Reorder   = {1},

A_Interrupt                     = false,

A_Prefetch                     = false,

A_Priority                        = 0,

A_Proc_Return              = -1,

A_Protocol_State          = "MyState",

A_Return                       = -1,

A_Source                      = "CAN_1",

A_Status                        = "Status",

A_Task_Address           = 1,

A_Task_Flag                 = false,

A_Task_ID                    = 0L,

A_Task_Name              = "Name",

A_Task_Source            = "Src",

A_Time                          = 0.0,

A_Variables                   = 16,

BLOCK                          = "Traffic1",

CAN_Time                    = 9,

DELTA                          = 0.0,

DS_NAME                    = "Processor_DS",

ID                                  = 1,

INDEX                          = 1,

TIME                             = 1.0E-10}

Next Name: CAN_Bus  Task_Name: Name

 SEND TASK (1001) TNow: 3.0E-10  Parent: Mapper

Called postfire()

 NEW TASK  (1002) TNow:  3.0E-10  Parent: Mapper  Data Structure:

{A_Addr_Ctrl_Flag         = true,

A_Address_Max            = 100,

A_Address_Min             = 1,

A_Branch                      = false,

A_Bytes                         = 81,

A_Bytes_Remaining      = 49,

A_Bytes_Sent                = 32,

A_Command                  = "Read",

A_Data                          = "MyData",

A_Destination                = "Device2",

A_First_Word                 = true,

A_Hop                           = "Device2",

A_IDX                            = 0,

A_IDY                            = 0,

A_Instruction                  = {"ADD", "ADD"},

A_Instruction_Reorder   = {1},

A_Interrupt                     = false,

A_Prefetch                     = false,

A_Priority                        = 0,

A_Proc_Return               = -1,

A_Protocol_State           = "MyState",

A_Return                        = -1,

A_Source                       = "CAN_2",

A_Status                         = "Status",

A_Task_Address            = 1,

A_Task_Flag                  = false,

A_Task_ID                     = 0L,

A_Task_Name               = "Name",

A_Task_Source             = "Src",

A_Time                          = 0.0,

A_Variables                   = 16,

BLOCK                          = "Traffic2",

CAN_Time                     = 10,

DELTA                          = 0.0,

DS_NAME                    = "Processor_DS",

ID                                  = 1,

INDEX                           = 2,

TIME                             = 1.0E-10}

Next Name: CAN_Bus  Task_Name: Name

 SEND TASK (1002) TNow: 3.0E-10  Parent: Mapper