1 /******************************************************************************
2 * Filename: aux_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 AUX 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 //
41 //! \addtogroup aux_group
42 //! @{
43 //! \addtogroup auxsmph_api
44 //! @{
45 //
46 //*****************************************************************************
47
48 #ifndef __AUX_SMPH_H__
49 #define __AUX_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_aux_smph.h>
66 #include <inc/hw_memmap.h>
67 #include <driverlib/debug.h>
68
69 //*****************************************************************************
70 //
71 // General constants and defines
72 //
73 //*****************************************************************************
74 #define AUX_SMPH_FREE 0x00000001 // MCU Semaphore has not been claimed
75 #define AUX_SMPH_CLAIMED 0x00000000 // MCU Semaphore has been claimed
76
77 //*****************************************************************************
78 //
79 // Values that can be passed to AUXSMPHAcquire and AUXSMPHRelease
80 // as the ui32Semaphore parameter.
81 //
82 //*****************************************************************************
83 #define AUX_SMPH_0 0 // AUX Semaphore 0
84 #define AUX_SMPH_1 1 // AUX Semaphore 1
85 #define AUX_SMPH_2 2 // AUX Semaphore 2
86 #define AUX_SMPH_3 3 // AUX Semaphore 3
87 #define AUX_SMPH_4 4 // AUX Semaphore 4
88 #define AUX_SMPH_5 5 // AUX Semaphore 5
89 #define AUX_SMPH_6 6 // AUX Semaphore 6
90 #define AUX_SMPH_7 7 // AUX Semaphore 7
91
92 //*****************************************************************************
93 //
94 // API Functions and prototypes
95 //
96 //*****************************************************************************
97
98 //*****************************************************************************
99 //
100 //! \brief Acquire an AUX semaphore.
101 //!
102 //! This function acquires the given AUX semaphore, blocking the call until
103 //! the semaphore is available.
104 //!
105 //! \note The semaphore can also be acquired by the dedicated Sensor Controller.
106 //! The System CPU master can thus be competing for the shared resource, i.e.
107 //! the specified semaphore.
108 //!
109 //! \param ui32Semaphore is the semaphore number.
110 //! - \ref AUX_SMPH_0
111 //! - \ref AUX_SMPH_1
112 //! - \ref AUX_SMPH_2
113 //! - \ref AUX_SMPH_3
114 //! - \ref AUX_SMPH_4
115 //! - \ref AUX_SMPH_5
116 //! - \ref AUX_SMPH_6
117 //! - \ref AUX_SMPH_7
118 //!
119 //! \return None
120 //!
121 //! \sa AUXSMPHTryAcquire(), AUXSMPHRelease()
122 //
123 //*****************************************************************************
124 __STATIC_INLINE void
AUXSMPHAcquire(uint32_t ui32Semaphore)125 AUXSMPHAcquire(uint32_t ui32Semaphore)
126 {
127 //
128 // Check the arguments.
129 //
130 ASSERT((ui32Semaphore == AUX_SMPH_0) ||
131 (ui32Semaphore == AUX_SMPH_1) ||
132 (ui32Semaphore == AUX_SMPH_2) ||
133 (ui32Semaphore == AUX_SMPH_3) ||
134 (ui32Semaphore == AUX_SMPH_4) ||
135 (ui32Semaphore == AUX_SMPH_5) ||
136 (ui32Semaphore == AUX_SMPH_6) ||
137 (ui32Semaphore == AUX_SMPH_7));
138
139 //
140 // Wait for semaphore to be released such that it can be claimed
141 // Semaphore register reads 1 when lock was acquired otherwise 0
142 // (i.e. AUX_SMPH_CLAIMED).
143 //
144 while(HWREG(AUX_SMPH_BASE + AUX_SMPH_O_SMPH0 + 4 * ui32Semaphore) ==
145 AUX_SMPH_CLAIMED)
146 {
147 }
148 }
149
150 //*****************************************************************************
151 //
152 //! \brief Try to acquire an AUX semaphore.
153 //!
154 //! This function tries to acquire the given AUX semaphore, if the semaphore
155 //! could not be claimed the function returns false.
156 //!
157 //! \note The semaphore can also be acquired by the dedicated Sensor Controller.
158 //! The System CPU master can thus be competing for the shared resource, i.e.
159 //! the specified semaphore.
160 //!
161 //! \param ui32Semaphore is the semaphore number.
162 //! - \ref AUX_SMPH_0
163 //! - \ref AUX_SMPH_1
164 //! - \ref AUX_SMPH_2
165 //! - \ref AUX_SMPH_3
166 //! - \ref AUX_SMPH_4
167 //! - \ref AUX_SMPH_5
168 //! - \ref AUX_SMPH_6
169 //! - \ref AUX_SMPH_7
170 //!
171 //! \return Returns true if semaphore was acquired, false otherwise
172 //!
173 //! \sa AUXSMPHAcquire(), AUXSMPHRelease()
174 //
175 //*****************************************************************************
176 __STATIC_INLINE bool
AUXSMPHTryAcquire(uint32_t ui32Semaphore)177 AUXSMPHTryAcquire(uint32_t ui32Semaphore)
178 {
179 uint32_t ui32SemaReg;
180
181 //
182 // Check the arguments.
183 //
184 ASSERT((ui32Semaphore == AUX_SMPH_0) ||
185 (ui32Semaphore == AUX_SMPH_1) ||
186 (ui32Semaphore == AUX_SMPH_2) ||
187 (ui32Semaphore == AUX_SMPH_3) ||
188 (ui32Semaphore == AUX_SMPH_4) ||
189 (ui32Semaphore == AUX_SMPH_5) ||
190 (ui32Semaphore == AUX_SMPH_6) ||
191 (ui32Semaphore == AUX_SMPH_7));
192
193 //
194 // AUX Semaphore register reads 1 if lock was acquired
195 // (i.e. SMPH_FREE when read) but subsequent reads will read 0.
196 //
197 ui32SemaReg = HWREG(AUX_SMPH_BASE + AUX_SMPH_O_SMPH0 + 4 * ui32Semaphore);
198
199 return (ui32SemaReg == AUX_SMPH_FREE);
200 }
201
202 //*****************************************************************************
203 //
204 //! \brief Release an AUX semaphore by System CPU master.
205 //!
206 //! This function releases the given AUX semaphore.
207 //!
208 //! \note It is up to the application to provide the convention for clearing
209 //! semaphore.
210 //!
211 //! \note The semaphore can also be acquired by the dedicated Sensor Controller.
212 //! The System CPU master can thus be competing for the shared resource, i.e.
213 //! the specified semaphore.
214 //!
215 //! \param ui32Semaphore is the semaphore number.
216 //! - \ref AUX_SMPH_0
217 //! - \ref AUX_SMPH_1
218 //! - \ref AUX_SMPH_2
219 //! - \ref AUX_SMPH_3
220 //! - \ref AUX_SMPH_4
221 //! - \ref AUX_SMPH_5
222 //! - \ref AUX_SMPH_6
223 //! - \ref AUX_SMPH_7
224 //!
225 //! \return None
226 //!
227 //! \sa AUXSMPHAcquire(), AUXSMPHTryAcquire()
228 //
229 //*****************************************************************************
230 __STATIC_INLINE void
AUXSMPHRelease(uint32_t ui32Semaphore)231 AUXSMPHRelease(uint32_t ui32Semaphore)
232 {
233 //
234 // Check the arguments.
235 //
236 ASSERT((ui32Semaphore == AUX_SMPH_0) ||
237 (ui32Semaphore == AUX_SMPH_1) ||
238 (ui32Semaphore == AUX_SMPH_2) ||
239 (ui32Semaphore == AUX_SMPH_3) ||
240 (ui32Semaphore == AUX_SMPH_4) ||
241 (ui32Semaphore == AUX_SMPH_5) ||
242 (ui32Semaphore == AUX_SMPH_6) ||
243 (ui32Semaphore == AUX_SMPH_7));
244
245 //
246 // No check before release. It is up to the application to provide the
247 // conventions for who and when a semaphore can be released.
248 //
249 HWREG(AUX_SMPH_BASE + AUX_SMPH_O_SMPH0 + 4 * ui32Semaphore) =
250 AUX_SMPH_FREE;
251 }
252
253 //*****************************************************************************
254 //
255 // Mark the end of the C bindings section for C++ compilers.
256 //
257 //*****************************************************************************
258 #ifdef __cplusplus
259 }
260 #endif
261
262 #endif // __AUX_SMPH_H__
263
264 //*****************************************************************************
265 //
266 //! Close the Doxygen group.
267 //! @}
268 //! @}
269 //
270 //*****************************************************************************
271