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

« Previous Version 10 Current »

Now that CAN Signals and Messages have been defined and configured, it is time to initialize them in the application. Please refer to the previous section if CAN Signals and Messages haven't been defined and configured. 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.

Initialization and Creation

Before using CAN Signals and Messages, both Signals and Messages should be initialized and created during Startup. 

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]

 

Application Signals

The following will explain additional details about CAN Signals used in the Application Layer, including the use of the Signal Callback Function initially mentioned in the ' Signal Configuration' section. Please note that write-access to a CAN Signal is possible anywhere in an application. The following will show a snippet of how to write to a Signal and the use of the Callback function for a given signal.

 

void  App_Task (void  *argp)
{
    (void)&argp;                                                /* Suppress Compiler Warning.                           */

    ...                                               [1]
    
    while (DEF_ON) {                                            /* Endless while loop.                                  */
        ...
        CanSigWrite( S_NODESTATUS,                              /* Write to the 'Nodestatus' Signal.					*/
                    &StatusUpdateVar,
                     1);
                   
        Send_Status();                                [2]       /* Send Signal Status on CAN bus                        */
        
        ...
    }
}

... 

void  StatusChange (void         *Signal,             [3]
                   CANSIG_VAL_T  *NewVal,
                   CPU_INT32U     CallbackId)
{
    (void)&Signal;                                              /* Suppress Compiler Warning.                           */
    if (CallbackId == CANSIG_CALLBACK_READ_ID) {      [4]
        if (*NewVal == 1) {                           [5]
            /* $$$ - Start Load-Task - $$$ */
        } else {
            /* $$$ - Stop Load-Task - $$$ */
        }
    }
}

  • No labels