Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

To get a higher level of abstraction, the CAN signals Signals and messages Messages can be used to abstract the information mappings to the bus Bus communication objects.

Example: The information ‘Nodestatus’ and ‘CPU-Load’ shall be sent in a CAN frame called ‘Status’ with the following definition:

1. CAN-Identifier = 0x150

2. DLC = 2

3. Payload Byte 0 = Current Nodestatus

4. Payload Byte 1 = CPU-Load

The ‘Nodestatus’ shall be settable via the CAN frame called ‘Command’ with the following definition:

5. CAN-Identifier = 0x140

6. DLC = 1

7. Payload Byte 0 = New Nodestatus

If the information ‘Nodestatus’ is changed, the following actions shall be done:

8. New Nodestatus = 1: Start the task ‘Load-Task’

9. New Nodestatus = 2: Stop the task ‘Load-Task’

Source code (Part 1):

#include “can_sig.h”

/* Signal Definition */

enum {

S_NODESTATUS = 0, S_CPULOAD, S_MAX

};

const CANSIG_PARA CanSig[CANSIG_N] = {

/*--- S_NODESTATUS */

{ CANSIG_UNCHANGED, /* Initial Status */

1, /* Width in Bytes */

0, /* Initial Value */

StatusChange }, /* Callback Func. */

/*------ S_CPULOAD */

{ CANSIG_UNCHANGED, /* Initial Status */

1, /* Width in Bytes */

0, /* Initial Value */

0 } /* No Callback */

};

Additional Information:

1. The CAN signals can be defined without any CAN communication knowledge. No information about sending or receiving the information is needed during this state.

2. The enumeration is used to simplify the message definition and ensure to get a consistent message to signal mapping.

3. The CAN signal configuration is done as a global constant to safe RAM space and get a write protected configuration.

4. This variable must be declared globally, because the configuration data will be read while using the CAN signal layer.

5. The callback function definition may In this topic example, two signals called 'Nodestatus' and 'CPU-Load' will be sent in a CAN Message called 'Status' and updated through a CAN Message called 'Command' with the following Signal and Message definitions:

Signal Configuration
Anchor
ex_sig&message_definitions_signals
ex_sig&message_definitions_signals

The Message Configuration below uses CAN Signals. Before CAN Messages can be used, each CAN signal must be configured accordingly. The Signal Configuration can be found in can_cfg.c. However, the "Signal Enumerations" are typically found in can_cfg.h. Signals allow the user to not worry about where a given signal is found within a CAN Message frame, while containing different types of data. For more information about CAN Signals click Here.

Note:

  • A CAN Signal can be defined without any CAN communication knowledge. No information about sending or receiving information is needed during configuration.


Code Block
languagecpp
linenumberstrue
#include  "can_sig.h"

enum {                                           [1]            /* ---------------- SIGNAL ENUMERATIONS --------------- */
   S_NODESTATUS = 0, 
   S_CPULOAD,
   S_MAX,
};

const  CANSIG_PARA  CanSig[CANSIG_N] = {         [2]
                                                                /* ---------------- SIGNAL NODESTATUS ----------------- */
    {CANSIG_UNCHANGED,                           [3A]           /*      Initial Status                                  */ 
      1,                                          [B]           /*      Width in Bytes                                  */ 
      0,                                          [C]           /*      Initial Value                                   */ 
#if (CANSIG_CALLBACK_EN > 0)
      StatusChange},                              [D]           /*      Callback Function: User Defined                 */ 
#else
    },
#endif
                                                                /* ----------------- SIGNAL CPULOAD ------------------- */ 
    {CANSIG_UNCHANGED,                           [3A]           /*      Initial Status                                  */ 
      1,                                          [B]           /*      Width in Bytes                                  */ 
      0,                                          [C]           /*      Initial Value                                   */ 
#if (CANSIG_CALLBACK_EN > 0)
      0}                                          [D]           /*      No Callback                                     */ 
#else
    },
#endif
}; 


Panel
bgColor#f0f0f0

1] Enumeration is used to simpilfy CAN Signal definitions and to ensure a consistent Message-to-Signal mapping.

2] CAN Signal configuration is done as a global constant to save RAM space and get a write-protected configuration. Also, the configuration data will be read while using the CAN Signal Layer.

3] The following will explain the required configuration for each Signal.

A]  States the Initial Status of each signal.

B] States the width in bytes of the CAN signal. The Value here affects the Message Configuration's DLC & Number of Link parameters.

C] States the Initial Value for Each signal.

D] The Callback Function definition can be omitted by configuring the CANSIG_CALLBACK_EN parameter to 0 in can_cfg.

...

Source code (Part 2):

#include “can_msg.h”

/* Message Definition */

enum {

M_STATUS = 0, M_COMMAND, M_MAX

};

...

h


Message Configuration
Anchor
ex_sig&message_definitions_messages
ex_sig&message_definitions_messages

The Message Configuration can be found in can_cfg.c. However, the "Message Enumerations" are typically found in can_cfg.h. Please note that CAN Signals must be configured prior to be used in CAN Messages. For more information on CAN Messages click Here.

Note:

  • A CAN Message can be defined without any knowledge of the information generated and/or the usage of the payload. Only the mapping of the payload (and it's respective parts) must be known.


Code Block
languagecpp
linenumberstrue
#include  "can_msg.h"

enum {                                           [1]            /* --------------- MESSAGE ENUMERATIONS --------------- */
   M_STATUS = 0, 
   M_COMMAND, 
   M_MAX
};

const  CANMSG_PARA  CanMsg[CANMSG_N] =

...

           [2]
{ 
                                                                /* -----------

...

{ 0x150L, /* CAN-Identifier */

CANMSG_TX, /* Message Type */

2, /* DLC of Message */

2, /* No. of Links */

{ { S_NODESTATUS, /* Signal ID */

0 }, /* Byte Position */

{ S_CPULOAD, /* Signal ID */

1 } } }, /* Byte Position */

/*------ M_COMMAND */

{ 0x140L, /* CAN-Identifier */

CANMSG_RX, /* Message Type */

1, /* DLC of Message */

1, /* No. of Links */

{ { S_NODESTATUS, /* Signal ID */

0 } } } /* Byte Position */

};

Additional Information:

1. The CAN messages can be defined without any knowledge of the information generation and/or usage of the payload. Only the mapping of information parts to the payload must be known.

2. The enumeration is used to simplify the message handling.

3. The CAN message configuration is done as a global constant to safe RAM space and get a write protected configuration.

...

------- MESSAGE STATUS ------------------ */
   { 0x123L,                                     [3A]           /*      CAN-Identifier                                  */  
     CANMSG_TX,                                   [B]           /*      Message Type                                    */ 
     2,                                           [C]           /*      DLC of Message                                  */ 
     2,                                                         /*      No. of Links                                    */ 
      { { S_NODESTATUS,                           [D]           /*      Signal ID                                       */ 
         0 },                                     [E]           /*      Byte Position                                   */ 
        { S_CPULOAD,                                            /*      Signal ID                                       */ 
         2 }                                                    /*      Byte Position                                   */ 
      },
   },
                                                                /* ----------------- MESSAGE COMMAND ------------------ */
   { 0x122L,                                     [4A]           /*      CAN-Identifier                                  */ 
     CANMSG_RX,                                   [B]           /*      Message Type                                    */ 
     1,                                           [C]           /*      DLC of Message                                  */ 
     1,                                                         /*      No. of Links                                    */ 
     { { S_NODESTATUS,                            [D]           /*      Signal ID                                       */ 
         0 }                                      [E]           /*      Byte Position                                   */ 
     }
   }
}; 


Panel
bgColor#f0f0f0

1] Enumeration is used to simplify CAN Message definitions and to ensure a consistent Message-to-Signal mapping.

2] CAN Message configuration is done as a global constant to save RAM space and get a write-protected configuration. Also, the configuration data will be read while using the CAN Message Layer.

3] The following will explain the Message 'Status' that will be used to Transmit the current status of the 'Nodestatus' and 'CPU-Load' Signals. These signals will be described above in the Signal Configuration.

A] Shows the CAN ID used to transmit the 'Status' Message on the CAN Bus line.

B] Shows the Message Type for the given message configuration. The 'Status' Message is set to 'Tx'.

C] Explains the DLC of the CAN Message along with the Number of Links mapped. The DLC and the Number of Links can be different based on the amount of Signals, their respective Byte Positions, and the Signal byte width.

D] The specified Signal ID used in the 'Status' CAN Message.

E] The Byte Position of the above Signal ID.

4] The following will explain the Message 'Command' that will be used to Receive the updated status of 'Nodestatus' Signal. This signal will be described above in the Signal Configuration.

A] CAN ID used for the 'Command' Message. The 'Command' Message will not be updated, unless the Rx'd CAN Frame has this CAN ID.

B] Shows the Message Type for the given message configuration. The 'Command' Message is set to 'Rx'.

C] Explains the DLC of the CAN Message along with the Number of Links mapped. The DLC and the Number of Links can be different based on the amount of Signals, their respective Byte Positions, and the Signal byte width.

D] The specified Signal ID used in the 'Command' CAN Message.

E] The Byte Position of the above Signal ID.