Counting Semaphores in the Treck Stack

Jump to: navigation, search

Table of Contents >> Appendix A: Configuration Notes


The Treck stack uses an operating system's existing counting semaphores. If your operating system does not support counting semaphores, Treck can use your OS's event flag mechanism to create its own.

Using an OS's existing counting semaphores is typically a more efficient method. We have two separate counting semaphore versions. The first method will grant counting semaphore requests by task priority, and is implemented in the <source\kernel\trcousem.c> module. The second method (lighter version) will grant counting semaphore requests in FIFO (First In, First Out) order, and is implemented in the <source\kernel\trctsem2.c> module.


Counting Semaphore Implementation with Task Priority Order

Functions to Call

The user must call the following functions. This may require some data type modifications.

  1. The user must call tfTaskInit() prior to calling tfStartTreck(), and prior to launching any task that utilizes the Treck task.
  2. Before launching a task that utilizes the Treck stack, the user must call tfTaskRegister() for that task, passing the taskIdPtr filled out by tfKernelGetCurrentTaskId() and set the priority of the task. The task index of the particular task will be returned. An index bigger than or equal to TM_NUMTSK indicates an overflow or a failure.
  3. The data type for the task ID may also need modification. It is assumed that the task ID can be stored as an integer. If this is not the case, replace taskIdPtr->genInParm and tskIdUnion.genIntParm (located in tfKernelGetCurrentTaskId() and tfTaskIdToIndex()), with the appropriate data type (as defined in ttUserGenericUnion).


Macros to Modify

The user must modify the following macros:

  • TM_NUMTSK
This is the number of tasks making calls to the Treck stack. Default 12.
  • tm_task_priority_lower_same
This macro is defined as:
((taskAPri) <= (taskBPri))
If priorities are arranged so that lower values have higher priority, modify the macro to be:
((taskAPri) >= (taskBPri))

Functions to Define


Counting Semaphore Implementation with FIFO Order

Funcitons to Call

The user must call tfTaskInit(), prior to calling tfStartTreck(), and prior to launching any task that utilizes the Treck task.


Macros to Define

  • TM_NUMEVT
This is the number of events needed by the Treck stack. This number should match the number of tasks making calls to the Treck stack. Default 12.


Functions to Define


Table of Contents >> Appendix A: Configuration Notes