CC26xx Driver Library
[smph.h] Semaphore

Functions

void SMPHAcquire (uint32_t ui32Semaphore)
 Acquire a semaphore. More...
 
static bool SMPHTryAcquire (uint32_t ui32Semaphore)
 Try to Acquire a semaphore. More...
 
static void SMPHRelease (uint32_t ui32Semaphore)
 Release a semaphore. More...
 

Detailed Description

Introduction

The MCU Semaphore offers 32 semaphores that each can be claimed and released in an atomic operation. One and only one semaphore can be handled during a transaction.

Claiming a semaphore causes subsequent claims/reads to return '0' (i.e. "not available"). How the semaphores are used and respected is decided by software.

API

The API functions can be grouped like this:

Semaphore acquire:

Semaphore release:

Function Documentation

void SMPHAcquire ( uint32_t  ui32Semaphore)

Acquire a semaphore.

This function acquires the given semaphore, blocking the call until the semaphore is available.

Parameters
ui32Semaphoreis the semaphore number.
Returns
None
59 {
60  // Check the arguments.
61  ASSERT((ui32Semaphore == SMPH_0) ||
62  (ui32Semaphore == SMPH_1) ||
63  (ui32Semaphore == SMPH_2) ||
64  (ui32Semaphore == SMPH_3) ||
65  (ui32Semaphore == SMPH_4) ||
66  (ui32Semaphore == SMPH_5) ||
67  (ui32Semaphore == SMPH_6) ||
68  (ui32Semaphore == SMPH_7) ||
69  (ui32Semaphore == SMPH_8) ||
70  (ui32Semaphore == SMPH_9) ||
71  (ui32Semaphore == SMPH_10) ||
72  (ui32Semaphore == SMPH_11) ||
73  (ui32Semaphore == SMPH_12) ||
74  (ui32Semaphore == SMPH_13) ||
75  (ui32Semaphore == SMPH_14) ||
76  (ui32Semaphore == SMPH_15) ||
77  (ui32Semaphore == SMPH_16) ||
78  (ui32Semaphore == SMPH_17) ||
79  (ui32Semaphore == SMPH_18) ||
80  (ui32Semaphore == SMPH_19) ||
81  (ui32Semaphore == SMPH_20) ||
82  (ui32Semaphore == SMPH_21) ||
83  (ui32Semaphore == SMPH_22) ||
84  (ui32Semaphore == SMPH_23) ||
85  (ui32Semaphore == SMPH_24) ||
86  (ui32Semaphore == SMPH_25) ||
87  (ui32Semaphore == SMPH_26) ||
88  (ui32Semaphore == SMPH_27) ||
89  (ui32Semaphore == SMPH_28) ||
90  (ui32Semaphore == SMPH_29) ||
91  (ui32Semaphore == SMPH_30) ||
92  (ui32Semaphore == SMPH_31));
93 
94  // Wait for semaphore to be release such that it can be claimed
95  // Semaphore register reads 1 when lock was acquired otherwise 0
96  // (i.e. SMPH_CLAIMED).
97  while(HWREG(SMPH_BASE + SMPH_O_SMPH0 + 4 * ui32Semaphore) ==
99  {
100  }
101 }
#define SMPH_28
Definition: smph.h:128
#define SMPH_8
Definition: smph.h:108
#define SMPH_4
Definition: smph.h:104
#define SMPH_18
Definition: smph.h:118
#define SMPH_1
Definition: smph.h:101
#define SMPH_11
Definition: smph.h:111
#define SMPH_31
Definition: smph.h:131
#define SMPH_6
Definition: smph.h:106
#define SMPH_25
Definition: smph.h:125
#define SMPH_21
Definition: smph.h:121
#define SMPH_24
Definition: smph.h:124
#define SMPH_19
Definition: smph.h:119
#define SMPH_12
Definition: smph.h:112
#define SMPH_9
Definition: smph.h:109
#define SMPH_29
Definition: smph.h:129
#define SMPH_23
Definition: smph.h:123
#define ASSERT(expr)
Definition: debug.h:73
#define SMPH_17
Definition: smph.h:117
#define SMPH_13
Definition: smph.h:113
#define SMPH_0
Definition: smph.h:100
#define SMPH_26
Definition: smph.h:126
#define SMPH_2
Definition: smph.h:102
#define SMPH_14
Definition: smph.h:114
#define SMPH_30
Definition: smph.h:130
#define SMPH_5
Definition: smph.h:105
#define SMPH_10
Definition: smph.h:110
#define SMPH_27
Definition: smph.h:127
#define SMPH_15
Definition: smph.h:115
#define SMPH_16
Definition: smph.h:116
#define SMPH_7
Definition: smph.h:107
#define SMPH_20
Definition: smph.h:120
#define SMPH_3
Definition: smph.h:103
#define SMPH_22
Definition: smph.h:122
#define SMPH_CLAIMED
Definition: smph.h:92
static void SMPHRelease ( uint32_t  ui32Semaphore)
inlinestatic

Release a semaphore.

This function releases the given semaphore.

Note
It is up to the application to provide the convention for clearing semaphore.
Parameters
ui32Semaphoreis the semaphore number.
Returns
None
241 {
242  // Check the arguments.
243  ASSERT((ui32Semaphore == SMPH_0) ||
244  (ui32Semaphore == SMPH_1) ||
245  (ui32Semaphore == SMPH_2) ||
246  (ui32Semaphore == SMPH_3) ||
247  (ui32Semaphore == SMPH_4) ||
248  (ui32Semaphore == SMPH_5) ||
249  (ui32Semaphore == SMPH_6) ||
250  (ui32Semaphore == SMPH_7) ||
251  (ui32Semaphore == SMPH_8) ||
252  (ui32Semaphore == SMPH_9) ||
253  (ui32Semaphore == SMPH_10) ||
254  (ui32Semaphore == SMPH_11) ||
255  (ui32Semaphore == SMPH_12) ||
256  (ui32Semaphore == SMPH_13) ||
257  (ui32Semaphore == SMPH_14) ||
258  (ui32Semaphore == SMPH_15) ||
259  (ui32Semaphore == SMPH_16) ||
260  (ui32Semaphore == SMPH_17) ||
261  (ui32Semaphore == SMPH_18) ||
262  (ui32Semaphore == SMPH_19) ||
263  (ui32Semaphore == SMPH_20) ||
264  (ui32Semaphore == SMPH_21) ||
265  (ui32Semaphore == SMPH_22) ||
266  (ui32Semaphore == SMPH_23) ||
267  (ui32Semaphore == SMPH_24) ||
268  (ui32Semaphore == SMPH_25) ||
269  (ui32Semaphore == SMPH_26) ||
270  (ui32Semaphore == SMPH_27) ||
271  (ui32Semaphore == SMPH_28) ||
272  (ui32Semaphore == SMPH_29) ||
273  (ui32Semaphore == SMPH_30) ||
274  (ui32Semaphore == SMPH_31));
275 
276  // No check before release, it is up to the application to provide the
277  // conventions for who and when a semaphore can be released.
278  HWREG(SMPH_BASE + SMPH_O_SMPH0 + 4 * ui32Semaphore) = SMPH_FREE;
279 }
#define SMPH_28
Definition: smph.h:128
#define SMPH_8
Definition: smph.h:108
#define SMPH_4
Definition: smph.h:104
#define SMPH_18
Definition: smph.h:118
#define SMPH_1
Definition: smph.h:101
#define SMPH_FREE
Definition: smph.h:91
#define SMPH_11
Definition: smph.h:111
#define SMPH_31
Definition: smph.h:131
#define SMPH_6
Definition: smph.h:106
#define SMPH_25
Definition: smph.h:125
#define SMPH_21
Definition: smph.h:121
#define SMPH_24
Definition: smph.h:124
#define SMPH_19
Definition: smph.h:119
#define SMPH_12
Definition: smph.h:112
#define SMPH_9
Definition: smph.h:109
#define SMPH_29
Definition: smph.h:129
#define SMPH_23
Definition: smph.h:123
#define ASSERT(expr)
Definition: debug.h:73
#define SMPH_17
Definition: smph.h:117
#define SMPH_13
Definition: smph.h:113
#define SMPH_0
Definition: smph.h:100
#define SMPH_26
Definition: smph.h:126
#define SMPH_2
Definition: smph.h:102
#define SMPH_14
Definition: smph.h:114
#define SMPH_30
Definition: smph.h:130
#define SMPH_5
Definition: smph.h:105
#define SMPH_10
Definition: smph.h:110
#define SMPH_27
Definition: smph.h:127
#define SMPH_15
Definition: smph.h:115
#define SMPH_16
Definition: smph.h:116
#define SMPH_7
Definition: smph.h:107
#define SMPH_20
Definition: smph.h:120
#define SMPH_3
Definition: smph.h:103
#define SMPH_22
Definition: smph.h:122
static bool SMPHTryAcquire ( uint32_t  ui32Semaphore)
inlinestatic

Try to Acquire a semaphore.

This function tries to acquire the given semaphore, if the semaphore could not be claimed the function returns false.

Parameters
ui32Semaphoreis the semaphore number.
Returns
Returns if a semaphore was acquired
  • true : Semaphore acquired.
  • false : Semaphore not acquired.
177 {
178  uint32_t ui32SemaReg;
179 
180  // Check the arguments.
181  ASSERT((ui32Semaphore == SMPH_0) ||
182  (ui32Semaphore == SMPH_1) ||
183  (ui32Semaphore == SMPH_2) ||
184  (ui32Semaphore == SMPH_3) ||
185  (ui32Semaphore == SMPH_4) ||
186  (ui32Semaphore == SMPH_5) ||
187  (ui32Semaphore == SMPH_6) ||
188  (ui32Semaphore == SMPH_7) ||
189  (ui32Semaphore == SMPH_8) ||
190  (ui32Semaphore == SMPH_9) ||
191  (ui32Semaphore == SMPH_10) ||
192  (ui32Semaphore == SMPH_11) ||
193  (ui32Semaphore == SMPH_12) ||
194  (ui32Semaphore == SMPH_13) ||
195  (ui32Semaphore == SMPH_14) ||
196  (ui32Semaphore == SMPH_15) ||
197  (ui32Semaphore == SMPH_16) ||
198  (ui32Semaphore == SMPH_17) ||
199  (ui32Semaphore == SMPH_18) ||
200  (ui32Semaphore == SMPH_19) ||
201  (ui32Semaphore == SMPH_20) ||
202  (ui32Semaphore == SMPH_21) ||
203  (ui32Semaphore == SMPH_22) ||
204  (ui32Semaphore == SMPH_23) ||
205  (ui32Semaphore == SMPH_24) ||
206  (ui32Semaphore == SMPH_25) ||
207  (ui32Semaphore == SMPH_26) ||
208  (ui32Semaphore == SMPH_27) ||
209  (ui32Semaphore == SMPH_28) ||
210  (ui32Semaphore == SMPH_29) ||
211  (ui32Semaphore == SMPH_30) ||
212  (ui32Semaphore == SMPH_31));
213 
214  // Semaphore register reads 1 if lock was acquired
215  // (i.e. SMPH_FREE).
216  ui32SemaReg = HWREG(SMPH_BASE + SMPH_O_SMPH0 + 4 * ui32Semaphore);
217 
218  return (ui32SemaReg == SMPH_FREE);
219 }
#define SMPH_28
Definition: smph.h:128
#define SMPH_8
Definition: smph.h:108
#define SMPH_4
Definition: smph.h:104
#define SMPH_18
Definition: smph.h:118
#define SMPH_1
Definition: smph.h:101
#define SMPH_FREE
Definition: smph.h:91
#define SMPH_11
Definition: smph.h:111
#define SMPH_31
Definition: smph.h:131
#define SMPH_6
Definition: smph.h:106
#define SMPH_25
Definition: smph.h:125
#define SMPH_21
Definition: smph.h:121
#define SMPH_24
Definition: smph.h:124
#define SMPH_19
Definition: smph.h:119
#define SMPH_12
Definition: smph.h:112
#define SMPH_9
Definition: smph.h:109
#define SMPH_29
Definition: smph.h:129
#define SMPH_23
Definition: smph.h:123
#define ASSERT(expr)
Definition: debug.h:73
#define SMPH_17
Definition: smph.h:117
#define SMPH_13
Definition: smph.h:113
#define SMPH_0
Definition: smph.h:100
#define SMPH_26
Definition: smph.h:126
#define SMPH_2
Definition: smph.h:102
#define SMPH_14
Definition: smph.h:114
#define SMPH_30
Definition: smph.h:130
#define SMPH_5
Definition: smph.h:105
#define SMPH_10
Definition: smph.h:110
#define SMPH_27
Definition: smph.h:127
#define SMPH_15
Definition: smph.h:115
#define SMPH_16
Definition: smph.h:116
#define SMPH_7
Definition: smph.h:107
#define SMPH_20
Definition: smph.h:120
#define SMPH_3
Definition: smph.h:103
#define SMPH_22
Definition: smph.h:122

Macro Definition Documentation

#define SMPH_0   0
#define SMPH_1   1
#define SMPH_10   10
#define SMPH_11   11
#define SMPH_12   12
#define SMPH_13   13
#define SMPH_14   14
#define SMPH_15   15
#define SMPH_16   16
#define SMPH_17   17
#define SMPH_18   18
#define SMPH_19   19
#define SMPH_2   2
#define SMPH_20   20
#define SMPH_21   21
#define SMPH_22   22
#define SMPH_23   23
#define SMPH_24   24
#define SMPH_25   25
#define SMPH_26   26
#define SMPH_27   27
#define SMPH_28   28
#define SMPH_29   29
#define SMPH_3   3
#define SMPH_30   30
#define SMPH_31   31
#define SMPH_4   4
#define SMPH_5   5
#define SMPH_6   6
#define SMPH_7   7
#define SMPH_8   8
#define SMPH_9   9
#define SMPH_CLAIMED   0x00000000

Referenced by SMPHAcquire().

#define SMPH_FREE   0x00000001

Referenced by SMPHRelease(), and SMPHTryAcquire().