Versions Compared

Key

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

To encapsulate the CAN protocol from the applicationNow that CAN Signals and Messages have been defined and configured, it is advised to use only the CAN signals within the application part. The following source code makes use of the definitions explained in Defining time to encapsulate them in the application. Please refer to the previous section if CAN Signals and Messages.

...

haven't been defined and configured.

Application Startup

Before using CAN Signals and Messages, both Signals and Messages should be initialized and created during Startup. The following code snippets are taken from can_demo.c found in $:\Micrium\Software\uC-CAN\Examples\<OS> where 'OS' is either NONE (for No-OS), uCOS-II or uCOS-III. 

Code Block
languagecpp
linenumberstrue
void  App_CAN_Startup (void)
{
    CPU_INT16S    can_err;
    CANMSG_PARA  *m;
#if (CANSIG_STATIC_CONFIG == 0u)
    CANSIG_PARA  *s;
#endif

    ...
                                                                /* ------------------- uC/CAN SETUP ------------------- */
    CanSigInit(0L);                                   [1]       /* Initialize CAN Signals.                              */
#if (CANSIG_STATIC_CONFIG == 0u)                      [2]
    s = CanSig;
    while (s < &CanSig[S_MAX]) {                                /* Create CAN Signals                                   */
        can_err = CanSigCreate(s);
        if (can_err < 0) {
           while (1);                                           /* Failure Handling Here.                               */
        }
        s++;
    }
#endif
    CanMsgInit(0L);                                   [3]       /* Initialize CAN Messages.                             */
    m = (CANMSG_PARA *)CanMsg;
    while (m < &CanMsg[CANMSG_N]) {                   [4]       /* Create CAN Messages.                                 */
        can_err = CanMsgCreate(m);
        if (can_err < 0) {
           while (1);                                           /* Failure Handling Here.                               */
        }
        m++;
    }

    ...                                               [5]

Description

  1. Initialize the CAN signal layer
  2. If dynamic signal handling is enabled loop through all constant CAN signal parameter list and create the signals
  3. Initialize the CAN message layer
  4. Loop through all constant CAN message parameter list and create the messages
  5. Start the communication bus as described in chapter 6.2 Enable the CAN bus

Source code (Application Task)

Description

  1. Anywhere in your application the write access to the CAN signal is possible.
  2. This function will send the status message to the CAN bus. The source code of the function is shown below.
  3. This callback-function is included in the signal configuration parameter list for the signal status. The function is called, when the change of the signal value is detected.
  4. The parameter CallbackId is used to identify where this callback-function was called from.
  5. The parameter NewVal holds the new CAN signal value and is used to determine the required start / stop action of the Load-Task.