app_rtos_cfg.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file app_rtos_cfg.h
5 * @author BLE Driver Team
6 * @brief Header file of app rtos config code.
7 *
8 ****************************************************************************************
9 * @attention
10 #####Copyright (c) 2019 GOODIX
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 * Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 * Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 * Neither the name of GOODIX nor the names of its contributors may be used
21 to endorse or promote products derived from this software without
22 specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35 ****************************************************************************************
36 */
37
38 /** @addtogroup PERIPHERAL Peripheral Driver
39 * @{
40 */
41
42 /** @addtogroup APP_DRIVER APP DRIVER
43 * @{
44 */
45
46 /** @defgroup APP_RTOS_CONFIG RTOS CONFIG
47 * @brief ADC RTOS CONFIG
48 * @{
49 */
50
51
52 #ifndef __APP_RTOS_ADAPTER_H
53 #define __APP_RTOS_ADAPTER_H
54 /*
55 * INCLUDE FILES
56 *****************************************************************************************
57 */
58 #include <string.h>
59 #include <stdint.h>
60
61 #ifdef ENV_USE_FREERTOS
62
63 #include "FreeRTOS.h"
64 #include "semphr.h"
65
66 /** @addtogroup APP_RTOS_CONFIG_DEFINES Defines
67 * @{
68 */
69 #define ENV_USE_RTOS
70 /** @} */
71
72 /**
73 * @defgroup APP_RTOS_CONFIG_TYPEDEF Typedefs
74 * @{
75 */
76
77 /**
78 * @brief Semaphore type definition
79 */
80 typedef SemaphoreHandle_t sem_t;
81
82 /**
83 * @brief mutex type definition
84 */
85 typedef SemaphoreHandle_t mutex_t;
86
87 /** @} */
88
89 /** @addtogroup APP_RTOS_CONFIG_DEFINES Defines
90 * @{
91 */
92 #define OS_WAIT_FOREVER portMAX_DELAY /**< Block forever until get resource */
93
94 #define SEM_WAIT_FOREVER portMAX_DELAY /**< Wait for the semaphore forever */
95 #define SEM_NO_WAIT (0) /**< Non-block */
96
97 #define MUTEX_WAIT_FOREVER portMAX_DELAY /**< Wait for the mutex forever */
98 #define MUTEX_NO_WAIT (0) /**< Non-block */
99 /** @} */
100
101 #else
102
103 /**
104 * @defgroup APP_RTOS_CONFIG_TYPEDEF Typedefs
105 * @{
106 */
107
108 /**
109 * @brief Semaphore type definition
110 */
111 typedef void * sem_t;
112
113 /**
114 * @brief mutex type definition
115 */
116 typedef void * mutex_t;
117 /** @} */
118
119 /** @addtogroup APP_RTOS_CONFIG_DEFINES Defines
120 * @{
121 */
122 #define SEM_WAIT_FOREVER (0xFFFFUL) /**< Wait for the semaphore forever. */
123 #define SEM_NO_WAIT (0) /**< Non-block */
124
125 #define MUTEX_WAIT_FOREVER (0xFFFFUL) /**< Wait for the mutex forever */
126 #define MUTEX_NO_WAIT (0) /**< Non-block */
127 /** @} */
128
129 #endif
130
131 /** @addtogroup APP_RTOS_CONFIG_DEFINES Defines
132 * @{
133 */
134 #define APP_DRV_SEM_DECL(sem) sem_t sem /**< Define a semaphore instance */
135 #define APP_DRV_MUTEX_DECL(mutex) mutex_t mutex /**< Define a mutex instance */
136
137 #define APP_DRV_SEM_STATIC(sem) static APP_DRV_SEM_DECL(sem) /**< Define a static semaphore instance */
138 #define APP_DRV_MUTEX_STATIC(mutex) static APP_DRV_MUTEX_DECL(mutex) /**< Define a static mutex instance */
139 /** @} */
140
141 #ifdef ENV_USE_RTOS
142 /** @addtogroup APP_RTOS_CONFIG_DEFINES Defines
143 * @{
144 */
145 #define ENV_RTOS_USE_SEMP 1 /**< Enable semaphore in app driver */
146 //#define ENV_RTOS_USE_MUTEX 1 /**< Enable mutex in app driver */
147 /** @} */
148
149 /** @addtogroup APP_RTOS_CONFIG_FUNCTIONS Functions
150 * @{
151 */
152 /**
153 ****************************************************************************************
154 * @brief Initialize a semaphore.
155 *
156 * @param[in] sem: Pointer to a sem_t parameter which contains the address of the semaphore object.
157 *
158 * @return Result of initialization.
159 ****************************************************************************************
160 */
161 uint16_t app_driver_sem_init(sem_t *sem);
162
163 /**
164 ****************************************************************************************
165 * @brief De-initialize a semaphore.
166 *
167 * @param[in] sem: the semaphore object.
168 *
169 * @return Result of De-initialization.
170 ****************************************************************************************
171 */
172 void app_driver_sem_deinit(sem_t sem);
173
174 /**
175 ****************************************************************************************
176 * @brief This function will take a semaphore, if the semaphore is unavailable, the
177 thread shall wait for a specified time.
178 *
179 * @param[in] sem: The semaphore object.
180 * @param[in] time_out: The waiting time in milliseconds.
181 *
182 * @return Result of operation.
183 ****************************************************************************************
184 */
185 uint16_t app_driver_sem_pend(sem_t sem, uint32_t time_out);
186
187 /**
188 ****************************************************************************************
189 * @brief This function will release a semaphore, if there are threads suspended on
190 * semaphore, it will be waked up.
191 *
192 * @param[in] sem: The semaphore object.
193 *
194 * @return Result of operation.
195 ****************************************************************************************
196 */
197 uint16_t app_driver_sem_post(sem_t sem);
198
199 /**
200 ****************************************************************************************
201 * @brief This function will release a semaphore, it is used in interrupt service function,
202 * if there are threads suspended on semaphore, it will be waked up.
203 *
204 * @param[in] sem: The semaphore object.
205 *
206 * @return Result of operation.
207 ****************************************************************************************
208 */
209 uint16_t app_driver_sem_post_from_isr(sem_t sem);
210
211 /**
212 ****************************************************************************************
213 * @brief Initialize a mutex.
214 *
215 * @param[in] mutex: Pointer to mutex_t parameter which contains the address of the mutex object.
216 *
217 * @return Result of initialization.
218 ****************************************************************************************
219 */
220 uint16_t app_driver_mutex_init(mutex_t *mutex);
221
222 /**
223 ****************************************************************************************
224 * @brief De-initialize a mutex.
225 *
226 * @param[in] mutex: the mutex object.
227 *
228 * @return Result of De-initialization.
229 ****************************************************************************************
230 */
231 void app_driver_mutex_deinit(mutex_t mutex);
232
233 /**
234 ****************************************************************************************
235 * @brief This function will take a mutex, if the mutex is unavailable, the thread shall
236 * wait for a specified time.
237 *
238 * @param[in] mutex: The mutex object.
239 * @param[in] time_out: The waiting time in milliseconds.
240 *
241 * @return Result of operation.
242 ****************************************************************************************
243 */
244 uint16_t app_driver_mutex_pend(mutex_t mutex, uint32_t time_out);
245
246 /**
247 ****************************************************************************************
248 * @brief This function will release a mutex, if there are threads suspended on mutex,
249 * it will be waked up.
250 *
251 * @param[in] mutex: The mutex object.
252 *
253 * @return Result of operation.
254 ****************************************************************************************
255 */
256 uint16_t app_driver_mutex_post(mutex_t mutex);
257 /** @} */
258
259 #else
260 /** @addtogroup APP_RTOS_CONFIG_DEFINES Defines
261 * @{
262 */
263 #define app_driver_sem_init(x) (0) /**< Initialize the semaphore. */
264 #define app_driver_sem_deinit(x) /**< Deinitialize the semphore. */
265 #define app_driver_sem_pend(x, y) (0) /**< Pend the semaphore. */
266 #define app_driver_sem_post(x) /**< Post the semaphore. */
267 #define app_driver_sem_post_from_isr(x) /**< Post the semaphore from interrupt. */
268
269 #define app_driver_mutex_init(x) (0) /**< Initialize the mutex. */
270 #define app_driver_mutex_deinit(x) /**< Deinitialize the mutex. */
271 #define app_driver_mutex_pend(x, y) /**< Pend the mutex. */
272 #define app_driver_mutex_post(x) /**< Post the mutex. */
273 /** @} */
274
275 #endif
276
277 #endif
278 /** @} */
279 /** @} */
280 /** @} */
app_driver_sem_post_from_isr
#define app_driver_sem_post_from_isr(x)
Post the semaphore from interrupt.
Definition: app_rtos_cfg.h:267
app_driver_sem_deinit
#define app_driver_sem_deinit(x)
Deinitialize the semphore.
Definition: app_rtos_cfg.h:264
app_driver_mutex_deinit
#define app_driver_mutex_deinit(x)
Deinitialize the mutex.
Definition: app_rtos_cfg.h:270
app_driver_mutex_pend
#define app_driver_mutex_pend(x, y)
Pend the mutex.
Definition: app_rtos_cfg.h:271
app_driver_mutex_post
#define app_driver_mutex_post(x)
Post the mutex.
Definition: app_rtos_cfg.h:272
app_driver_sem_post
#define app_driver_sem_post(x)
Post the semaphore.
Definition: app_rtos_cfg.h:266
app_driver_sem_init
#define app_driver_sem_init(x)
Initialize the semaphore.
Definition: app_rtos_cfg.h:263
app_driver_mutex_init
#define app_driver_mutex_init(x)
Initialize the mutex.
Definition: app_rtos_cfg.h:269
mutex_t
void * mutex_t
mutex type definition
Definition: app_rtos_cfg.h:116
app_driver_sem_pend
#define app_driver_sem_pend(x, y)
Pend the semaphore.
Definition: app_rtos_cfg.h:265
sem_t
void * sem_t
Semaphore type definition.
Definition: app_rtos_cfg.h:111