1 /******************************************************************************
2 * Filename: smph.c
3 *
4 * Description: Driver for the MCU Semaphore.
5 *
6 * Copyright (c) 2015 - 2022, Texas Instruments Incorporated
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 * 1) Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * 2) Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 *
19 * 3) Neither the name of the ORGANIZATION nor the names of its contributors may
20 * be used to endorse or promote products derived from this software without
21 * specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 *
35 ******************************************************************************/
36
37 #include "smph.h"
38
39 //*****************************************************************************
40 //
41 // Handle support for DriverLib in ROM:
42 // This section will undo prototype renaming made in the header file
43 //
44 //*****************************************************************************
45 #if !defined(DOXYGEN)
46 #undef SMPHAcquire
47 #define SMPHAcquire NOROM_SMPHAcquire
48 #endif
49
50 //*****************************************************************************
51 //
52 // Acquire a semaphore
53 //
54 //*****************************************************************************
55 void
SMPHAcquire(uint32_t ui32Semaphore)56 SMPHAcquire(uint32_t ui32Semaphore)
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) ==
96 SMPH_CLAIMED)
97 {
98 }
99 }
100