Versions Compared

Key

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

...

  • Write CAN Signal -> Open CAN Message (with Tx Message ID) -> Read Message -> Write CAN Bus

 

Code Block
languagecpp
titleTx_Task()
linenumberstrue
void  Tx_Task (void  *argp)
{
    (void)&argp;                                                /* Suppress Compiler Warning.                           */

        while (DEF_ON) {                                            /* Endless while loop.                                  */
        DemoCnt++;
        CanSigWrite( S_CPULOAD,                          [1]       /* Set an Incrementing Counter.                         */
                    &DemoCnt,
                     1);
        
        if (DemoCnt >= DEF_OCTET_MASK) {
            DemoCnt = 0u;                                       /* Reset Demo Count to 0.                               */
        }
                   
        Send_Status();                                [2]          /* Send Signal Status on CAN bus                        */
        
        OSTimeDlyHMSM(0u, 0u, 0u, 200u);
    }
}

 

 

The communication protocol uses in most cases only the CAN messages. The application is responsible for the values of the mapped CAN signals. The following source code completes the example, started in chapter 6.4 Defining CAN Signals and Messages:

Source code (Protocol RX-Task)

This task could be started within Com_Start() to enable the receive activities as soon as the CAN bus is active.

Description

  1. Local variable to hold the received CAN frame.
  2. Local variable to hold the handle to message of received CAN identifier
  3. Set the RX timeout to 0 to enable the blocking mode, e.g. the function CanBusRead() will wait forever for a CAN frame.
  4. Wait for the next received CAN frame on CAN node 0.
  5. After reception, open the message with the received identifier.
  6. On success, write the received CAN frame to this message. This results in decomposing the CAN frame to all linked CAN signals.

Source code (Protocol Transmit Status)

This function can be called in your transmission task to transmit a specific CAN message, or called within a callback function to transmit information in response to a received CAN message.

Description

...

Code Block
languagecpp
titleSend_Status()
linenumberstrue
void  Send_Status (void)
{
    CANFRM      frm;
    CPU_INT16S  msg;
    CPU_INT08U  busId;
    

    busId = 0u;                                                 /* CAN Device Number/ CAN Controller Number.            */
    msg   = CanMsgOpen(busId,                         [1]       /* Open frame with ID 0x123 on Message Layer.           */
                       0x123u,
                       0);
   if (msg >= 0) {
        CanMsgRead(         msg,                      [2]       /* Read frame from Message Layer.                       */
                   (void *)&frm,
                            sizeof(CANFRM));
                          
        CanBusWrite(         busId,                   [3]       /* Write Frame to CAN Bus Layer.                        */
                    (void *)&frm,
                             sizeof(CANFRM));
   }
}