Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

To get a higher level of abstraction, the CAN signals and messages can be used to abstract the information mappings to the 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 be omitted by configuring the CANSIG_CALLBACK_EN parameter to 0.

Source code (Part 2):

#include “can_msg.h”

/* Message Definition */

enum {

M_STATUS = 0, M_COMMAND, M_MAX

};

const CANMSG_PARA CanMsg[CANMSG_N] = {

/*------- M_STATUS */

{ 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.

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

  • No labels