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

§ SMPHAcquire()

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

§ SMPHRelease()

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

§ SMPHTryAcquire()

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

Macro Definition Documentation

§ SMPH_0

#define SMPH_0   0

§ SMPH_1

#define SMPH_1   1

§ SMPH_10

#define SMPH_10   10

§ SMPH_11

#define SMPH_11   11

§ SMPH_12

#define SMPH_12   12

§ SMPH_13

#define SMPH_13   13

§ SMPH_14

#define SMPH_14   14

§ SMPH_15

#define SMPH_15   15

§ SMPH_16

#define SMPH_16   16

§ SMPH_17

#define SMPH_17   17

§ SMPH_18

#define SMPH_18   18

§ SMPH_19

#define SMPH_19   19

§ SMPH_2

#define SMPH_2   2

§ SMPH_20

#define SMPH_20   20

§ SMPH_21

#define SMPH_21   21

§ SMPH_22

#define SMPH_22   22

§ SMPH_23

#define SMPH_23   23

§ SMPH_24

#define SMPH_24   24

§ SMPH_25

#define SMPH_25   25

§ SMPH_26

#define SMPH_26   26

§ SMPH_27

#define SMPH_27   27

§ SMPH_28

#define SMPH_28   28

§ SMPH_29

#define SMPH_29   29

§ SMPH_3

#define SMPH_3   3

§ SMPH_30

#define SMPH_30   30

§ SMPH_31

#define SMPH_31   31

§ SMPH_4

#define SMPH_4   4

§ SMPH_5

#define SMPH_5   5

§ SMPH_6

#define SMPH_6   6

§ SMPH_7

#define SMPH_7   7

§ SMPH_8

#define SMPH_8   8

§ SMPH_9

#define SMPH_9   9

§ SMPH_CLAIMED

#define SMPH_CLAIMED   0x00000000

Referenced by SMPHAcquire().

§ SMPH_FREE

#define SMPH_FREE   0x00000001

Referenced by SMPHRelease(), and SMPHTryAcquire().