Versions Compared

Key

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

...

Received messages are processed by the function msgIdentification(). The argument passed to this function is of the type CAN_MSG_T. It is defined in the module co_stru.hand contains the CAN message. Assembling the CAN message into a variable of type CAN_MSG_T and the call to msgIdentification() is done in the function FlushMbox() from the module cdriver.c.

Code Block
languagec
typedef struct {

...


    COB_KIND_T cobType;  /* COB type */

...


    COB_IDENT_T cobId;   /* COB-ID */

...


    UNSIGNED8 pData[8];  /* CAN message data */

...


    UNSIGNED8 length;    /* if bit CO_RTR_REQ is set -> RTR */

...


} CAN_MSG_T;

Listing 28:  structure of CAN message

...

The default implementation of the flag set/reset macros are located in co_flag.h and co_drv.h.

Code Block
languagec
#define SET_COLIB_FLAG(FLAG)   (GL_ARRAY(coLibFlags) |= (FLAG))

...


#define RESET_COLIB_FLAG(FLAG) (GL_ARRAY(coLibFlags) &=˜(FLAG))

...


#define SET_CAN_FLAG(FLAG)     GL_ARRAY(coCanFlags) |= (FLAG)

...


#define RESET_CAN_FLAG(FLAG)   GL_ARRAY(coCanFlags) &= ˜(FLAG)

Changes are possible by a user specific setting in the cal_conf.h. A good working change is an additional atomic command or anything alike. An example is shown in Listing 29.

Code Block
languagec
#define SET_CAN_FLAG(FLAG) do{ \

...


    DISABLE_CPU_INTERRUPTS(); \

...


    GL_ARRAY(coCanFlags) |= (FLAG); \

...


    RESTORE_CPU_INTERRUPTS(); \

...


} while(0)

Listing 29: example for atomic flag access

...

The default buffer handling is activated in the Industrial Communication Creatorwith the option Driver uses Library buffer. The size of the send and receive buffer can be set independently of each other. The Industrial Communication Creatorgenerates the following settings in the header file cal_conf.h:

Code Block
languagec
#define CONFIG_COLIB_BUFFER   1

...


#define CONFIG_TX_BUFFER_SIZE 10

...


#define CONFIG_RX_BUFFER_SIZE 10

 

This example uses 10 entries separately in the send and receive buffer. The data in the buffers are of type BUFFER_ENTRY_T.

Code Block
languagec
typedef enum {EMPTY, FULL} MEM_STAT_T;

...



typedef struct {

...


    VOLATILE MEM_STAT_T eStat;

...


    COB_KIND_T eType;

...


    COB_IDENT_T cobId;

...


    UNSIGNED8 bLength;

...


    UNSIGNED8 pData[8];

...


    UNSIGNED8 bChannel;

...


} BUFFER_ENTRY_T;

Listing 30: structure of an entry in the CAN buffer

...

Process flow of a buffer read cycle

Code Block
languagec
BUFFER_ENTRY_T * pBuffer;

...

 

...



/* allow buffer access */

...


BUFFER_INIT_PTR(TX, Read);

...

 

...



/* buffer full? */

...


CHECK_BUFFER_READ(RX)

...

    {

...


{
    /* read from the buffer */

...


    length = BUFFER_READ(RX, bLength);

...


    ...

...


    /* release buffer */

...


    BUFFER_ENTRY_INCR(RX, Read, EMPTY);

...


}

Listing 31: buffer handling

...