1 /******************************************************************************
2 * Filename: smph.h
3 * Revised: 2016-10-06 17:21:09 +0200 (Thu, 06 Oct 2016)
4 * Revision: 47343
5 *
6 * Description: Defines and prototypes for the MCU Semaphore.
7 *
8 * Copyright (c) 2015 - 2020, 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 //
41 //! \addtogroup peripheral_group
42 //! @{
43 //! \addtogroup mcusemaphore_api
44 //! @{
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 "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 //
141 //! \brief Acquire a semaphore.
142 //!
143 //! This function acquires the given semaphore, blocking the call until
144 //! the semaphore is available.
145 //!
146 //! \param ui32Semaphore is the semaphore number.
147 //! - \ref SMPH_0
148 //! - \ref SMPH_1
149 //! - ...
150 //! - \ref SMPH_31
151 //!
152 //! \return None
153 //
154 //*****************************************************************************
155 extern void SMPHAcquire(uint32_t ui32Semaphore);
156
157 //*****************************************************************************
158 //
159 //! \brief Try to Acquire a semaphore.
160 //!
161 //! This function tries to acquire the given semaphore, if the semaphore
162 //! could not be claimed the function returns false.
163 //!
164 //! \param ui32Semaphore is the semaphore number.
165 //! - \ref SMPH_0
166 //! - \ref SMPH_1
167 //! - ...
168 //! - \ref SMPH_31
169 //!
170 //! \return Returns if a semaphore was acquired
171 //! - \c true : Semaphore acquired.
172 //! - \c false : Semaphore \b not acquired.
173 //
174 //*****************************************************************************
175 __STATIC_INLINE bool
SMPHTryAcquire(uint32_t ui32Semaphore)176 SMPHTryAcquire(uint32_t ui32Semaphore)
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 }
220
221 //*****************************************************************************
222 //
223 //! \brief Release a semaphore.
224 //!
225 //! This function releases the given semaphore.
226 //!
227 //! \note It is up to the application to provide the convention for clearing
228 //! semaphore.
229 //!
230 //! \param ui32Semaphore is the semaphore number.
231 //! - \ref SMPH_0
232 //! - \ref SMPH_1
233 //! - ...
234 //! - \ref SMPH_31
235 //!
236 //! \return None
237 //
238 //*****************************************************************************
239 __STATIC_INLINE void
SMPHRelease(uint32_t ui32Semaphore)240 SMPHRelease(uint32_t ui32Semaphore)
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 }
280
281 //*****************************************************************************
282 //
283 // Support for DriverLib in ROM:
284 // Redirect to implementation in ROM when available.
285 //
286 //*****************************************************************************
287 #if !defined(DRIVERLIB_NOROM) && !defined(DOXYGEN)
288 #include "../driverlib/rom.h"
289 #ifdef ROM_SMPHAcquire
290 #undef SMPHAcquire
291 #define SMPHAcquire ROM_SMPHAcquire
292 #endif
293 #endif
294
295 //*****************************************************************************
296 //
297 // Mark the end of the C bindings section for C++ compilers.
298 //
299 //*****************************************************************************
300 #ifdef __cplusplus
301 }
302 #endif
303
304 #endif // __SMPH_H__
305
306 //*****************************************************************************
307 //
308 //! Close the Doxygen group.
309 //! @}
310 //! @}
311 //
312 //*****************************************************************************
313