Versions Compared

Key

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

...

The other macros are necessary for allocating and releasing the object dictionary. The communication and application part can be protected separately. The Listing 32 shows this mechanism as an example of RTX51 for the multi-line version. For the single line version the parameter canLine is not necessary.

Code Block
languagec
/* use semaphore for protection */

...


#define CO_SEMA_L0      13

...


#define CO_SEMA_L1      14

...

 



#define CO_APPL_PART_ALLOC(canLine) \

...


    if(canLine == 0)    \

...


        os_wait(K_MBX+CO_SEMA_L0, 0, NULL) \

...


    else \

...


        os_wait(K_MBX+CO_SEMA_L1, 0, NULL)

...

 



#define CO_APPL_PART_RELEASE(canLine)    \

...


    if(canLine == 0)    \

...


        os_send_token(CO_SEMA_L0) \

...


    else \

...


        os_send_token(CO_SEMA_L1) 

...

 



void resetActualVelocity(void)

...


{

...


    /* allocate OD application part */

...


    CO_APPL_PART_ALLOC(0);

...

 



    /* reset velocity value (CAN line 0)*/

...


    l0_actual_velocity = 0;

...

 



    /* release OD application part */

...


    CO_APPL_PART_RELEASE(0);

...


}

Listing 32: example for resource protection for RTX51

Between allocation and release of a resource only a few instructions should be made, in order to prevent unnecessary blocking of other tasks.

Code Block
languagec
#define CO_SEMA_L0      13

...


#define CO_SEMA_L1      14

...

 



#define CO_NEW_RX_MSG(canLine)     \

...


    if(canLine == 0)    \

...


        os_send_token(CO_SEMA_L0); \

...


    else \

...


        os_send_token(CO_SEMA_L1);

...

 



while (1)

...


{

...


    /* sleep while no new message on

...

  • - if a new message is received

  • - if the CANopen timer is expired

  • in order to check all CANopen timers */

...

 line
      - if a new message is received
      - if the CANopen timer is expired
        in order to check all CANopen timers */
    os_wait(K_MBX+CO_SEMA_L0, 0, NULL);

...

 



    /* interpret message for line 0 or handle CANopen timers */

...


    FlushMbox(0);

...


}

Listing 33: example for process activation for RTX51

...