Versions Compared

Key

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

...

Code Block
languagecpp
linenumberstrue
#include  "can_frm.h"
#include  "can_bus.h"

#if (APP_CAN_DEMO_SELECT == APP_CAN_ECHO_DEMO)
void  Echo_Task (void  *argp)                         [1]
{
    CANFRM      frm;
    CPU_INT08U  busId;
    CPU_INT16U  timeout;
   
    (void)&argp;                                                /* Suppress Compiler Warning.                           */
   
    busId   = 0u;                                     [2]       /* CAN Device Number/ CAN Controller Number.            */
    timeout = 0u;
    CanBusIoCtl( busId,                                         /* Rx Timeout is set to wait forever for a new Frame.   */
                 CANBUS_SET_RX_TIMEOUT,
                &timeout);                            [3]

    while (DEF_ON) {                                            /* Endless while loop.                                  */
        CanBusRead(         busId,                    [4]       /* Wait for new CAN Frame to Arrive.                    */
                   (void *)&frm,
                            sizeof(CANFRM));

        frm.Identifier = 0x100L;                      [5]       /* Change Frame ID.                                     */

        CanBusWrite(         busId,                   [6]       /* Echo back same data with updated Frame ID.           */
                    (void *)&frm,
                             sizeof(CANFRM));
    }
}
#endif


Panel
bgColor#f0f0f0

1] The 'ECHO' Task example is taken from µC/OS-II or -III can_demo.c files. Although the 'ECHO' Task example is the same when using No OS, the user must be aware of minor changes between No OS and µC/OS-II or -III.

2] CAN Bus ID based on the CAN Bus Channel desired to use.

3] Set the RX timeout to 0 to enable the blocking mode, e.g. the function CanBusRead() will wait for a CAN frame forever. Otherwise set a timeout and check returned error code of [4] if a timeout has occurred.

  • For µC/OS-II or -III demos, the 'ECHO' task has been configured to blocking mode.

4] Wait for the next received CAN Frame.

5] After reception, change the CAN Identifier in the Received Frame.

6] Transmit the Received CAN Frame with the changed CAN ID on the desired CAN Bus Channel.