Versions Compared

Key

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

...

To enable µC/OS-II semaphore services, you must set the configuration constants in OS_CFG.H. Specifically, table 7.1 shows which services are compiled based on the value of configuration constants found in OS_CFG.H. You should note that NONE of the semaphore services are enabled when OS_SEM_EN is set to 0. To enable the feature (i.e. service), simply set the configuration constant to 1. You will notice that OSSemCreate(), OSSemPend() and OSSemPost() cannot be individually disabled like the other services. That’s because they are always needed when you enable µC/OS-II semaphore management.

Table 7.1 Semaphore configuration constants in OS_CFG.H.

µC/OS-II Semaphore Service>Enabled when set to 1 in OS_CFG.H

OSSemAccept()

OS_SEM_ACCEPT_EN

OSSemCreate()

 

OSSemDel()

OS_SEM_DEL_EN

OSSemPend()

 
OSSemPendAbort()OS_SEM_PEND_ABORT_EN

OSSemPost()

 

OSSemQuery()

OS_SEM_QUERY_EN

OSSemSet()OS_SEM_SET_EN

Figure 7.1 shows a flow diagram to illustrate the relationship between tasks, ISRs, and a semaphore. Note that the symbology used to represent a semaphore is either a key or a flag. You would us a key symbol in such flow diagrams if the semaphore is used to access shared resources. The N next to the key represents how many resources are available. N is 1 for a binary semaphore. Use a flag symbol when a semaphore is used to signal the occurrence of an event. N in this case represents the number of times the event can be signaled. The hourglass represents a timeout that can be specified with the OSSemPend() call.

As you can see from Figure 7.1, a task or an ISR can call OSSemAccept(), OSSemPost() or OSSemQuery(). However, only tasks are allowed to call OSSemDel() or OSSemPend().

Figure 7.1 Relationships between tasks, ISRs, and a semaphore.

Creating a Semaphore, OSSemCreate()

...

Figure 7.2 shows the content of the ECB just before OSSemCreate() returns.Figure 7.2 ECB just before OSSemCreate() returns.

...