1 /*****************************************************************************
3 (c) Cambridge Silicon Radio Limited 2010
4 All rights reserved and confidential information of CSR
6 Refer to LICENSE.txt included with this source for details
9 *****************************************************************************/
11 #include <linux/kernel.h>
12 #include <linux/kthread.h>
13 #include <linux/module.h>
14 #include <linux/freezer.h>
15 #include <linux/semaphore.h>
16 #include <linux/slab.h>
17 #include <linux/bitops.h>
19 #include "csr_framework_ext.h"
20 #include "csr_panic.h"
22 /*----------------------------------------------------------------------------*
27 * Create a mutex and return a handle to the created mutex.
31 * CSR_RESULT_SUCCESS in case of success
32 * CSR_FE_RESULT_NO_MORE_MUTEXES in case of out of mutex resources
33 * CSR_FE_RESULT_INVALID_POINTER in case the mutexHandle pointer is invalid
35 *----------------------------------------------------------------------------*/
36 CsrResult
CsrMutexCreate(CsrMutexHandle
*mutexHandle
)
38 if (mutexHandle
== NULL
)
40 return CSR_FE_RESULT_INVALID_POINTER
;
43 sema_init(mutexHandle
, 1);
45 return CSR_RESULT_SUCCESS
;
48 /*----------------------------------------------------------------------------*
53 * Destroy the previously created mutex.
58 *----------------------------------------------------------------------------*/
59 void CsrMutexDestroy(CsrMutexHandle
*mutexHandle
)
63 /*----------------------------------------------------------------------------*
68 * Unlock the mutex refered to by the provided handle.
72 * CSR_RESULT_SUCCESS in case of success
73 * CSR_FE_RESULT_INVALID_HANDLE in case the mutexHandle is invalid
75 *----------------------------------------------------------------------------*/
76 CsrResult
CsrMutexUnlock(CsrMutexHandle
*mutexHandle
)
78 if (mutexHandle
== NULL
)
80 return CSR_FE_RESULT_INVALID_POINTER
;
85 return CSR_RESULT_SUCCESS
;
88 /*----------------------------------------------------------------------------*
93 * Sleep for a given period.
98 *----------------------------------------------------------------------------*/
99 void CsrThreadSleep(u16 sleepTimeInMs
)
103 /* Convert t in ms to jiffies and round up */
104 t
= ((sleepTimeInMs
* HZ
) + 999) / 1000;
105 schedule_timeout_uninterruptible(t
);
107 EXPORT_SYMBOL_GPL(CsrThreadSleep
);