2 * -------------------------------------------
3 * CC3220 SDK - v0.10.00.00
4 * -------------------------------------------
6 * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the
20 * Neither the name of Texas Instruments Incorporated nor the names of
21 * its contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //*****************************************************************************
41 // Driver for the Apps-NWP spinlock
43 //*****************************************************************************
45 //*****************************************************************************
47 //! \addtogroup HwSpinLock_api
50 //*****************************************************************************
54 #include "inc/hw_types.h"
55 #include "inc/hw_memmap.h"
56 #include "inc/hw_ints.h"
57 #include "inc/hw_common_reg.h"
58 #include "hwspinlock.h"
60 //*****************************************************************************
61 // Global semaphore register list
62 //*****************************************************************************
63 static const uint32_t HwSpinLock_RegLst[]=
65 COMMON_REG_BASE + COMMON_REG_O_SPI_Properties_Register
68 //*****************************************************************************
70 //! Acquire specified spin lock.
72 //! \param ui32LockID is one of the valid spin lock.
74 //! This function acquires specified spin lock and will not retun util the
75 //! specified lock is acquired.
77 //! The parameter \e ui32LockID should \b HWSPINLOCK_MCSPIS0.
81 //*****************************************************************************
82 void HwSpinLockAcquire(uint32_t ui32LockID)
89 // Extract the bit position from the
92 ui32BitPos = ((ui32LockID >> 16) & 0x0FFF);
93 ui32RegAddr = HwSpinLock_RegLst[ui32LockID & 0xF];
96 // Set the corresponding
97 // ownership bits to 'b01
99 ui32SemVal = (0xFFFFFFFF ^ (0x2 << ui32BitPos));
102 // Retry untill we succeed
106 HWREG(ui32RegAddr) = ui32SemVal;
108 while( !(HWREG(ui32RegAddr) & (1 << ui32BitPos )) );
112 //*****************************************************************************
114 //! Try to acquire specified spin lock.
116 //! \param ui32LockID is one of the valid spin lock.
117 //! \param ui32Retry is the number of reties.
119 //! This function tries acquire specified spin lock in \e ui32Retry retries.
121 //! The parameter \e ui32Retry can be any value between 0 and 2^32.
123 //! return Returns 0 on success, -1 otherwise.
125 //*****************************************************************************
126 int32_t HwSpinLockTryAcquire(uint32_t ui32LockID, uint32_t ui32Retry)
130 uint32_t ui32RegAddr;
133 // Extract the bit position from the
136 ui32BitPos = ((ui32LockID >> 16) & 0x0FFF);
137 ui32RegAddr = HwSpinLock_RegLst[ui32LockID & 0xF];
140 // Set the corresponding
141 // ownership bits to 'b01
143 ui32SemVal = (0xFFFFFFFF ^ (0x2 << ui32BitPos));
146 // Check for 0 retry.
154 // Retry the number of times specified
158 HWREG(ui32RegAddr) = ui32SemVal;
161 while( !(HWREG(ui32RegAddr) & (1 << ui32BitPos )) && ui32Retry );
165 // Check the semaphore status
167 if(HWREG(ui32RegAddr) & (1 << ui32BitPos ))
177 //*****************************************************************************
179 //! Release a previously owned spin lock
181 //! \param ui32LockID is one of the valid spin lock.
183 //! This function releases previously owned spin lock.
187 //*****************************************************************************
188 void HwSpinLockRelease(uint32_t ui32LockID)
194 // Extract the bit position from the
197 ui32BitPos = ((ui32LockID >> 16) & 0x00FF);
200 // Release the spin lock, only if already owned
202 if(HWREG(HwSpinLock_RegLst[ui32LockID & 0xF]) & (1 << ui32BitPos ))
204 ui32SemVal = (0xFFFFFFFF & ~(0x3 << ui32BitPos));
205 HWREG(HwSpinLock_RegLst[ui32LockID & 0xF]) = ui32SemVal;
209 //*****************************************************************************
211 //! Get the current or previous ownership status.
213 //! \param ui32LockID is one of the valid spin lock.
214 //! \param bCurrentStatus is \b true for current status, \b flase otherwise
216 //! This function gets the current or previous ownership status of the
217 //! specified spin lock based on \e bCurrentStatus parameter.
219 //! \return Returns \b HWSPINLOCK_OWNER_APPS, \b HWSPINLOCK_OWNER_NWP or
220 //! \b HWSPINLOCK_OWNER_NONE.
222 //*****************************************************************************
223 uint32_t HwSpinLockTest(uint32_t ui32LockID, bool bCurrentStatus)
231 // Extract the bit position from the
234 ui32BitPos = ((ui32LockID >> 16) & 0x00FF);
239 return((HWREG(HwSpinLock_RegLst[ui32LockID & 0xF]) >> ui32BitPos ) & 0x3 );
244 // Extract the bit position
246 ui32BitPos = ((ui32LockID >> 24) & 0xFF);
249 // Identify which register to read
251 if(ui32LockID & 0xF > 4)
253 ui32SemVal = ((HWREG(COMMON_REG_BASE +
254 COMMON_REG_O_SEMAPHORE_PREV_OWNER1) >> ui32BitPos ) & 0x3);
258 ui32SemVal = ((HWREG(COMMON_REG_BASE +
259 COMMON_REG_O_SEMAPHORE_PREV_OWNER2) >> ui32BitPos ) & 0x3);
269 //*****************************************************************************
271 // Close the Doxygen group.
274 //*****************************************************************************