This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

  • Resolved

[FAQ] TI-RTOS: How should an application create kernel objects?

Intellectual 1440 points

Replies: 2

Views: 612

I want to create an application using the TI-RTOS kernel (SYS/BIOS). What options do I have to create kernel objects?

  • There are three methods to creating TI-RTOS kernel objects:

    • Dynamically Create: The application can “create” a kernel object. The API will always need a heap to allocate the object. All module creates require an Error_Block.
    • Dynamically Construct: The application can “construct” a kernel object. The API takes the structure instead of allocating it from a heap. Many of the constructs do not require an Error_Block which also helps reduce code footprint. Some of the constructs might allocate memory internally. See the specific API for more details (e.g. Task_construct will allocate a stack if you don’t provide it).
    • Statically Create: In the application’s .cfg file, you can “statically create” the kernel object. No heap is needed for statically allocated objects. The “filled-in” structure is added into the big generated source file.

    Below are examples of each method:

    Dynamically Create

      #include <ti/sysbios/knl/Semaphore.h>
      ...
      Semaphore_Handle semaphore0;
      Semaphore_Params semaphoreParams;
      Error_Block eb;
      Error_init(&eb);
      Semaphore_Params_init(&semaphoreParams);
      semaphore0 = Semaphore_create(0, &semaphoreParams, &eb);
      if (semaphore0 == NULL) {
          … 
          Semaphore_post(semaphore0);

    Dynamically Construct

      #include <ti/sysbios/knl/Semaphore.h>
      ...
      Semaphore_Struct semaphore0Struct;
      Semaphore_Params semaphoreParams;
      Semaphore_Params_init(&semaphoreParams);
      Semaphore_construct(&semaphore0Struct, 0, &semaphoreParams);
      … 
      Semaphore_post(Semaphore_handle(&semaphore0Struct));

    Note: the constructed object must be converted to a handle to use.

    Statically Create

    The following shows a semaphore being created in the .cfg file.

      var semaphore0Params = new Semaphore.Params();
      Program.global.semaphore0 = Semaphore.create(0, semaphore0Params);

    Here is code that uses this semaphore in the application

      #include <xdc/cfg/global.h> // needed to get the global from the .cfg file
      #include <ti/sysbios/knl/Semaphore.h>
      …
      Semaphore_post(semaphore0); 

    Which method should be used to create kernel objects?

    TI-RTOS examples use the construct mechanism as it seems to be a nice compromise between static and dynamic creates. 

    • Reasons to use Dynamic Create
      • You want flexibility within the application
      • You want an easy programming flow
      • You are fine with dynamic memory allocation
      • ROV always works
    • Reasons to use Dynamic Construct
      • You want flexibility within the application
      • You are managing the kernel structs (instead of just a Handle)
      • You want to minimize/eliminate dynamic memory allocation
      • Majority of the module constructs calls cannot fail (see specific APIs for complete details)
      • Note: ROV does not show contructed object that are embedded in an application structure or on a stack
    • Reasons to use Static Creation
      • You have a very fixed system
      • You want the minimal code footprint size
      • You want to minimize/eliminate dynamic memory allocation
      • ROV always works
      • You don't mind using the .cfg file to create the objects
      • Note: You cannot delete static objects to free the memory

  • In reply to Jaskaran Atwal:

    Nicely done - yet might the 'Subject/Headline' benefit from a slight tweak?

    From: "TI-RTOS-MCU: How should an application create kernel objects?"

    To:      "Application Aid - Choices Available when creating kernel objects!"

    Even though - especially though - your 'audience here' IS captive ... it remains best to 'SELL your post' - as it  must compete for 'eyes/views.'    (And your quality writing deserves high visits!)

    You may note a thread I authored (3rd from top) started in such 'passive voice' (& was barely noted!)      After a day or two - Subject's shift to 'active' - released an 'eye/view deluge'    (128.7K & counting!)

    [edit] Within a 10 day period this 'Frequently Asked' question appeared to be 'Infrequently viewed.'   (i.e. Gained only 100 views)    In contrast - the post w/more 'active' Subject (headline) drew over 1K Visits!


This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.