bf5364094c021dd36db90bf6c56f6cbd903153e6
[open-ath9k-htc-firmware.git] / target_firmware / magpie_fw_dev / target / inc / adf_os_lock.h
1 /**
2  * @ingroup adf_os_public
3  * @file adf_os_lock.h
4  * This file abstracts locking operations.
5  */
6
7 #ifndef _ADF_OS_LOCK_H
8 #define _ADF_OS_LOCK_H
9
10 #include <adf_os_types.h>
11 #include <adf_os_lock_pvt.h>
12
13 /**
14  * @brief Platform spinlock object
15  */
16 typedef __adf_os_spinlock_t        adf_os_spinlock_t;
17
18 /**
19  * @brief Platform mutex object
20  */
21 typedef __adf_os_mutex_t        adf_os_mutex_t;
22
23 /**
24  * @brief Initialize a mutex
25  *
26  * @param[in] m mutex to initialize
27  */
28 static inline void adf_os_init_mutex(adf_os_mutex_t *m)
29 {
30     __adf_os_init_mutex(m);
31 }
32
33 /**
34  * @brief Take the mutex
35  *
36  * @param[in] m mutex to take
37  */
38 static inline int adf_os_mutex_acquire(adf_os_mutex_t *m)
39 {
40     return (__adf_os_mutex_acquire(m));
41 }
42
43 /**
44  * @brief Give the mutex
45  *
46  * @param[in] m mutex to give
47  */
48 static inline void adf_os_mutex_release(adf_os_mutex_t *m)
49 {
50     __adf_os_mutex_release(m);
51 }
52
53 /**
54  * @brief Initialize a spinlock
55  *
56  * @param[in] lock spinlock object pointer
57  */
58 static inline void
59 adf_os_spinlock_init(adf_os_spinlock_t *lock)
60 {
61     __adf_os_spinlock_init(lock);
62 }
63
64
65 /**
66  * @brief Acquire a spinlock by disabling the interrupts
67  *
68  * @param[in]  lock     spinlock object pointer
69  * @param[out] flags    flags used to hold interrupt state
70  */
71 static inline void
72 adf_os_spin_lock_irq(adf_os_spinlock_t *lock, a_uint32_t *flags)
73 {
74     __adf_os_spin_lock_irq(lock,flags);
75 }
76
77
78 /**
79  * @brief Release a spinlock & restore the irq
80  *
81  * @param[in] lock  spinlock object pointer
82  * @param[in] flags flags filled in by @ref adf_os_spin_lock_irq
83  */
84 static inline void
85 adf_os_spin_unlock_irq(adf_os_spinlock_t *lock, a_uint32_t *flags)
86 {
87     __adf_os_spin_unlock_irq(lock,flags);
88 }
89
90
91 /**
92  * @brief locks the spinlock mutex in soft irq context
93  * 
94  * @param[in] lock  spinlock object pointer
95  */
96 static inline void
97 adf_os_spin_lock_bh(adf_os_spinlock_t   *lock)
98 {
99     __adf_os_spin_lock_bh(lock);
100 }
101
102
103 /**
104  * @brief unlocks the spinlock mutex in soft irq context
105  * 
106  * @param[in] lock  spinlock object pointer
107  */
108 static inline void
109 adf_os_spin_unlock_bh(adf_os_spinlock_t *lock)
110 {
111     __adf_os_spin_unlock_bh(lock);
112 }
113
114
115 /**
116  * @brief Execute the input function with spinlock held and interrupt disabled.
117  *
118  * @param[in] hdl       OS handle
119  * @param[in] lock      spinlock to be held for the critical region
120  * @param[in] func      critical region function that to be executed
121  * @param[in] context   context of the critical region function
122  * 
123  * @return Boolean status returned by the critical region function
124  */
125 static inline a_bool_t
126 adf_os_spinlock_irq_exec(adf_os_handle_t           hdl,
127                          adf_os_spinlock_t        *lock,
128                          adf_os_irqlocked_func_t  func,
129                          void                     *arg)
130 {
131     return __adf_os_spinlock_irq_exec(hdl, lock, func, arg);
132 }
133
134 #endif