CC13xx Driver Library
smph.h
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: smph.h
3 * Revised: 2015-07-16 12:12:04 +0200 (Thu, 16 Jul 2015)
4 * Revision: 44151
5 *
6 * Description: Defines and prototypes for the MCU Semaphore.
7 *
8 * Copyright (c) 2015, Texas Instruments Incorporated
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 *
14 * 1) Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 *
17 * 2) Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 *
21 * 3) Neither the name of the ORGANIZATION nor the names of its contributors may
22 * be used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 *
37 ******************************************************************************/
38 
39 //*****************************************************************************
40 //
45 //
46 //*****************************************************************************
47 
48 #ifndef __SMPH_H__
49 #define __SMPH_H__
50 
51 //*****************************************************************************
52 //
53 // If building with a C++ compiler, make all of the definitions in this header
54 // have a C binding.
55 //
56 //*****************************************************************************
57 #ifdef __cplusplus
58 extern "C"
59 {
60 #endif
61 
62 #include <stdbool.h>
63 #include <stdint.h>
64 #include <inc/hw_types.h>
65 #include <inc/hw_smph.h>
66 #include <inc/hw_memmap.h>
67 #include <driverlib/debug.h>
68 
69 //*****************************************************************************
70 //
71 // Support for DriverLib in ROM:
72 // This section renames all functions that are not "static inline", so that
73 // calling these functions will default to implementation in flash. At the end
74 // of this file a second renaming will change the defaults to implementation in
75 // ROM for available functions.
76 //
77 // To force use of the implementation in flash, e.g. for debugging:
78 // - Globally: Define DRIVERLIB_NOROM at project level
79 // - Per function: Use prefix "NOROM_" when calling the function
80 //
81 //*****************************************************************************
82 #if !defined(DOXYGEN)
83  #define SMPHAcquire NOROM_SMPHAcquire
84 #endif
85 
86 //*****************************************************************************
87 //
88 // General constants and defines
89 //
90 //*****************************************************************************
91 #define SMPH_FREE 0x00000001 // MCU Semaphore has not been claimed
92 #define SMPH_CLAIMED 0x00000000 // MCU Semaphore has been claimed
93 
94 //*****************************************************************************
95 //
96 // Values that can be passed to SMPHAcquire, SMPHTryAcquire and SMPHRelease
97 // as the ui32Semaphore parameter.
98 //
99 //*****************************************************************************
100 #define SMPH_0 0 // MCU Semaphore 0
101 #define SMPH_1 1 // MCU Semaphore 1
102 #define SMPH_2 2 // MCU Semaphore 2
103 #define SMPH_3 3 // MCU Semaphore 3
104 #define SMPH_4 4 // MCU Semaphore 4
105 #define SMPH_5 5 // MCU Semaphore 5
106 #define SMPH_6 6 // MCU Semaphore 6
107 #define SMPH_7 7 // MCU Semaphore 7
108 #define SMPH_8 8 // MCU Semaphore 8
109 #define SMPH_9 9 // MCU Semaphore 9
110 #define SMPH_10 10 // MCU Semaphore 10
111 #define SMPH_11 11 // MCU Semaphore 11
112 #define SMPH_12 12 // MCU Semaphore 12
113 #define SMPH_13 13 // MCU Semaphore 13
114 #define SMPH_14 14 // MCU Semaphore 14
115 #define SMPH_15 15 // MCU Semaphore 15
116 #define SMPH_16 16 // MCU Semaphore 16
117 #define SMPH_17 17 // MCU Semaphore 17
118 #define SMPH_18 18 // MCU Semaphore 18
119 #define SMPH_19 19 // MCU Semaphore 19
120 #define SMPH_20 20 // MCU Semaphore 20
121 #define SMPH_21 21 // MCU Semaphore 21
122 #define SMPH_22 22 // MCU Semaphore 22
123 #define SMPH_23 23 // MCU Semaphore 23
124 #define SMPH_24 24 // MCU Semaphore 24
125 #define SMPH_25 25 // MCU Semaphore 25
126 #define SMPH_26 26 // MCU Semaphore 26
127 #define SMPH_27 27 // MCU Semaphore 27
128 #define SMPH_28 28 // MCU Semaphore 28
129 #define SMPH_29 29 // MCU Semaphore 29
130 #define SMPH_30 30 // MCU Semaphore 30
131 #define SMPH_31 31 // MCU Semaphore 31
132 
133 //*****************************************************************************
134 //
135 // API Functions and prototypes
136 //
137 //*****************************************************************************
138 
139 //*****************************************************************************
140 //
153 //
154 //*****************************************************************************
155 extern void SMPHAcquire(uint32_t ui32Semaphore);
156 
157 //*****************************************************************************
158 //
173 //
174 //*****************************************************************************
175 __STATIC_INLINE bool
176 SMPHTryAcquire(uint32_t ui32Semaphore)
177 {
178  uint32_t ui32SemaReg;
179 
180  //
181  // Check the arguments.
182  //
183  ASSERT((ui32Semaphore == SMPH_0) ||
184  (ui32Semaphore == SMPH_1) ||
185  (ui32Semaphore == SMPH_2) ||
186  (ui32Semaphore == SMPH_3) ||
187  (ui32Semaphore == SMPH_4) ||
188  (ui32Semaphore == SMPH_5) ||
189  (ui32Semaphore == SMPH_6) ||
190  (ui32Semaphore == SMPH_7) ||
191  (ui32Semaphore == SMPH_8) ||
192  (ui32Semaphore == SMPH_9) ||
193  (ui32Semaphore == SMPH_10) ||
194  (ui32Semaphore == SMPH_11) ||
195  (ui32Semaphore == SMPH_12) ||
196  (ui32Semaphore == SMPH_13) ||
197  (ui32Semaphore == SMPH_14) ||
198  (ui32Semaphore == SMPH_15) ||
199  (ui32Semaphore == SMPH_16) ||
200  (ui32Semaphore == SMPH_17) ||
201  (ui32Semaphore == SMPH_18) ||
202  (ui32Semaphore == SMPH_19) ||
203  (ui32Semaphore == SMPH_20) ||
204  (ui32Semaphore == SMPH_21) ||
205  (ui32Semaphore == SMPH_22) ||
206  (ui32Semaphore == SMPH_23) ||
207  (ui32Semaphore == SMPH_24) ||
208  (ui32Semaphore == SMPH_25) ||
209  (ui32Semaphore == SMPH_26) ||
210  (ui32Semaphore == SMPH_27) ||
211  (ui32Semaphore == SMPH_28) ||
212  (ui32Semaphore == SMPH_29) ||
213  (ui32Semaphore == SMPH_30) ||
214  (ui32Semaphore == SMPH_31));
215 
216  //
217  // Semaphore register reads 1 if lock was acquired
218  // (i.e. SMPH_FREE).
219  //
220  ui32SemaReg = HWREG(SMPH_BASE + SMPH_O_SMPH0 + 4 * ui32Semaphore);
221 
222  return (ui32SemaReg == SMPH_FREE);
223 }
224 
225 //*****************************************************************************
226 //
241 //
242 //*****************************************************************************
243 __STATIC_INLINE void
244 SMPHRelease(uint32_t ui32Semaphore)
245 {
246  //
247  // Check the arguments.
248  //
249  ASSERT((ui32Semaphore == SMPH_0) ||
250  (ui32Semaphore == SMPH_1) ||
251  (ui32Semaphore == SMPH_2) ||
252  (ui32Semaphore == SMPH_3) ||
253  (ui32Semaphore == SMPH_4) ||
254  (ui32Semaphore == SMPH_5) ||
255  (ui32Semaphore == SMPH_6) ||
256  (ui32Semaphore == SMPH_7) ||
257  (ui32Semaphore == SMPH_8) ||
258  (ui32Semaphore == SMPH_9) ||
259  (ui32Semaphore == SMPH_10) ||
260  (ui32Semaphore == SMPH_11) ||
261  (ui32Semaphore == SMPH_12) ||
262  (ui32Semaphore == SMPH_13) ||
263  (ui32Semaphore == SMPH_14) ||
264  (ui32Semaphore == SMPH_15) ||
265  (ui32Semaphore == SMPH_16) ||
266  (ui32Semaphore == SMPH_17) ||
267  (ui32Semaphore == SMPH_18) ||
268  (ui32Semaphore == SMPH_19) ||
269  (ui32Semaphore == SMPH_20) ||
270  (ui32Semaphore == SMPH_21) ||
271  (ui32Semaphore == SMPH_22) ||
272  (ui32Semaphore == SMPH_23) ||
273  (ui32Semaphore == SMPH_24) ||
274  (ui32Semaphore == SMPH_25) ||
275  (ui32Semaphore == SMPH_26) ||
276  (ui32Semaphore == SMPH_27) ||
277  (ui32Semaphore == SMPH_28) ||
278  (ui32Semaphore == SMPH_29) ||
279  (ui32Semaphore == SMPH_30) ||
280  (ui32Semaphore == SMPH_31));
281 
282  //
283  // No check before release, it is up to the application to provide the
284  // conventions for who and when a semaphore can be released.
285  //
286  HWREG(SMPH_BASE + SMPH_O_SMPH0 + 4 * ui32Semaphore) = SMPH_FREE;
287 }
288 
289 //*****************************************************************************
290 //
291 // Support for DriverLib in ROM:
292 // Redirect to implementation in ROM when available.
293 //
294 //*****************************************************************************
295 #if !defined(DRIVERLIB_NOROM) && !defined(DOXYGEN)
296  #include <driverlib/rom.h>
297  #ifdef ROM_SMPHAcquire
298  #undef SMPHAcquire
299  #define SMPHAcquire ROM_SMPHAcquire
300  #endif
301 #endif
302 
303 //*****************************************************************************
304 //
305 // Mark the end of the C bindings section for C++ compilers.
306 //
307 //*****************************************************************************
308 #ifdef __cplusplus
309 }
310 #endif
311 
312 #endif // __SMPH_H__
313 
314 //*****************************************************************************
315 //
319 //
320 //*****************************************************************************
#define SMPH_28
Definition: smph.h:128
#define SMPH_8
Definition: smph.h:108
void SMPHAcquire(uint32_t ui32Semaphore)
Acquire a semaphore.
Definition: smph.c:58
#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
static void SMPHRelease(uint32_t ui32Semaphore)
Release a semaphore.
Definition: smph.h:244
#define SMPH_25
Definition: smph.h:125
#define SMPH_21
Definition: smph.h:121
static bool SMPHTryAcquire(uint32_t ui32Semaphore)
Try to Acquire a semaphore.
Definition: smph.h:176
#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:74
#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