Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
csr_framework_ext.c
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  (c) Cambridge Silicon Radio Limited 2010
4  All rights reserved and confidential information of CSR
5 
6  Refer to LICENSE.txt included with this source for details
7  on the license terms.
8 
9 *****************************************************************************/
10 
11 #include <linux/kernel.h>
12 #include <linux/version.h>
13 #include <linux/kthread.h>
14 #include <linux/module.h>
15 #include <linux/freezer.h>
16 #include <linux/semaphore.h>
17 #include <linux/slab.h>
18 #include <linux/bitops.h>
19 
20 #include "csr_framework_ext.h"
21 #include "csr_panic.h"
22 
23 /*----------------------------------------------------------------------------*
24  * NAME
25  * CsrMutexCreate
26  *
27  * DESCRIPTION
28  * Create a mutex and return a handle to the created mutex.
29  *
30  * RETURNS
31  * Possible values:
32  * CSR_RESULT_SUCCESS in case of success
33  * CSR_FE_RESULT_NO_MORE_MUTEXES in case of out of mutex resources
34  * CSR_FE_RESULT_INVALID_POINTER in case the mutexHandle pointer is invalid
35  *
36  *----------------------------------------------------------------------------*/
38 {
39  if (mutexHandle == NULL)
40  {
42  }
43 
44  sema_init(mutexHandle, 1);
45 
46  return CSR_RESULT_SUCCESS;
47 }
48 
49 /*----------------------------------------------------------------------------*
50  * NAME
51  * CsrMutexDestroy
52  *
53  * DESCRIPTION
54  * Destroy the previously created mutex.
55  *
56  * RETURNS
57  * void
58  *
59  *----------------------------------------------------------------------------*/
60 void CsrMutexDestroy(CsrMutexHandle *mutexHandle)
61 {
62 }
63 
64 /*----------------------------------------------------------------------------*
65  * NAME
66  * CsrMutexLock
67  *
68  * DESCRIPTION
69  * Lock the mutex refered to by the provided handle.
70  *
71  * RETURNS
72  * Possible values:
73  * CSR_RESULT_SUCCESS in case of success
74  * CSR_FE_RESULT_INVALID_HANDLE in case the mutexHandle is invalid
75  *
76  *----------------------------------------------------------------------------*/
78 {
79  if (mutexHandle == NULL)
80  {
82  }
83 
84  if (down_interruptible(mutexHandle))
85  {
86  CsrPanic(CSR_TECH_FW, CSR_PANIC_FW_UNEXPECTED_VALUE, "CsrMutexLock Failed");
88  }
89 
90  return CSR_RESULT_SUCCESS;
91 }
92 
93 /*----------------------------------------------------------------------------*
94  * NAME
95  * CsrMutexUnlock
96  *
97  * DESCRIPTION
98  * Unlock the mutex refered to by the provided handle.
99  *
100  * RETURNS
101  * Possible values:
102  * CSR_RESULT_SUCCESS in case of success
103  * CSR_FE_RESULT_INVALID_HANDLE in case the mutexHandle is invalid
104  *
105  *----------------------------------------------------------------------------*/
107 {
108  if (mutexHandle == NULL)
109  {
111  }
112 
113  up(mutexHandle);
114 
115  return CSR_RESULT_SUCCESS;
116 }
117 
118 /*----------------------------------------------------------------------------*
119  * NAME
120  * CsrThreadSleep
121  *
122  * DESCRIPTION
123  * Sleep for a given period.
124  *
125  * RETURNS
126  * void
127  *
128  *----------------------------------------------------------------------------*/
129 void CsrThreadSleep(u16 sleepTimeInMs)
130 {
131  unsigned long t;
132 
133  /* Convert t in ms to jiffies and round up */
134  t = ((sleepTimeInMs * HZ) + 999) / 1000;
136 }