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 APP 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 typedef void * sem_t;
108 typedef void * mutex_t;
109 /** @} */
110
111 /** @addtogroup APP_RTOS_CONFIG_DEFINES Defines
112 * @{
113 */
114 #define SEM_WAIT_FOREVER (0xFFFFUL) /**< Wait for the semaphore forever. */
115 #define SEM_NO_WAIT (0) /**< Non-block */
116
117 #define MUTEX_WAIT_FOREVER (0xFFFFUL) /**< Wait for the mutex forever */
118 #define MUTEX_NO_WAIT (0) /**< Non-block */
119 /** @} */
120
121 #endif
122
123 /** @addtogroup APP_RTOS_CONFIG_DEFINES Defines
124 * @{
125 */
126 #define APP_DRV_SEM_DECL(sem) sem_t sem /**< Define a semaphore instance */
127 #define APP_DRV_MUTEX_DECL(mutex) mutex_t mutex /**< Define a mutex instance */
128 /** @} */
129
130 #ifdef ENV_USE_RTOS
131 /** @addtogroup APP_RTOS_CONFIG_DEFINES Defines
132 * @{
133 */
134 #define ENV_RTOS_USE_SEMP 1 /**< Enable semaphore in app driver */
135 //#define ENV_RTOS_USE_MUTEX 1 /**< Enable mutex in app driver */
136 /** @} */
137
138 /** @addtogroup APP_RTOS_CONFIG_FUNCTIONS Functions
139 * @{
140 */
141 /**
142 ****************************************************************************************
143 * @brief Initialize a semaphore.
144 *
145 * @param[in] sem: Pointer to a sem_t parameter which contains the address of the semaphore object.
146 *
147 * @return Result of initialization.
148 ****************************************************************************************
149 */
150 uint16_t app_driver_sem_init(sem_t *sem);
151
152 /**
153 ****************************************************************************************
154 * @brief De-initialize a semaphore.
155 *
156 * @param[in] sem: the semaphore object.
157 *
158 * @return Result of De-initialization.
159 ****************************************************************************************
160 */
161 void app_driver_sem_deinit(sem_t sem);
162
163 /**
164 ****************************************************************************************
165 * @brief This function will take a semaphore, if the semaphore is unavailable, the
166 thread shall wait for a specified time.
167 *
168 * @param[in] sem: The semaphore object.
169 * @param[in] time_out: The waiting time in milliseconds.
170 *
171 * @return Result of operation.
172 ****************************************************************************************
173 */
174 uint16_t app_driver_sem_pend(sem_t sem, uint32_t time_out);
175
176 /**
177 ****************************************************************************************
178 * @brief This function will release a semaphore, if there are threads suspended on
179 * semaphore, it will be waked up.
180 *
181 * @param[in] sem: The semaphore object.
182 *
183 * @return Result of operation.
184 ****************************************************************************************
185 */
186 uint16_t app_driver_sem_post(sem_t sem);
187
188 /**
189 ****************************************************************************************
190 * @brief This function will release a semaphore, it is used in interrupt service function,
191 * if there are threads suspended on semaphore, it will be waked up.
192 *
193 * @param[in] sem: The semaphore object.
194 *
195 * @return Result of operation.
196 ****************************************************************************************
197 */
198 uint16_t app_driver_sem_post_from_isr(sem_t sem);
199
200 /**
201 ****************************************************************************************
202 * @brief Initialize a mutex.
203 *
204 * @param[in] mutex: Pointer to mutex_t parameter which contains the address of the mutex object.
205 *
206 * @return Result of initialization.
207 ****************************************************************************************
208 */
209 uint16_t app_driver_mutex_init(mutex_t *mutex);
210
211 /**
212 ****************************************************************************************
213 * @brief De-initialize a mutex.
214 *
215 * @param[in] mutex: the mutex object.
216 *
217 * @return Result of De-initialization.
218 ****************************************************************************************
219 */
220 void app_driver_mutex_deinit(mutex_t mutex);
221
222 /**
223 ****************************************************************************************
224 * @brief This function will take a mutex, if the mutex is unavailable, the thread shall
225 * wait for a specified time.
226 *
227 * @param[in] mutex: The mutex object.
228 * @param[in] time_out: The waiting time in milliseconds.
229 *
230 * @return Result of operation.
231 ****************************************************************************************
232 */
233 uint16_t app_driver_mutex_pend(mutex_t mutex, uint32_t time_out);
234
235 /**
236 ****************************************************************************************
237 * @brief This function will release a mutex, if there are threads suspended on mutex,
238 * it will be waked up.
239 *
240 * @param[in] mutex: The mutex object.
241 *
242 * @return Result of operation.
243 ****************************************************************************************
244 */
245 uint16_t app_driver_mutex_post(mutex_t mutex);
246 /** @} */
247
248 #else
249 /** @addtogroup APP_RTOS_CONFIG_DEFINES Defines
250 * @{
251 */
252 #define app_driver_sem_init(x) (0) /**< Initialize the semaphore. */
253 #define app_driver_sem_deinit(x) /**< Deinitialize the semphore. */
254 #define app_driver_sem_pend(x, y) (0) /**< Pend the semaphore. */
255 #define app_driver_sem_post(x) /**< Post the semaphore. */
256 #define app_driver_sem_post_from_isr(x) /**< Post the semaphore from interrupt. */
257
258 #define app_driver_mutex_init(x) (0) /**< Initialize the mutex. */
259 #define app_driver_mutex_deinit(x) /**< Deinitialize the mutex. */
260 #define app_driver_mutex_pend(x, y) /**< Pend the mutex. */
261 #define app_driver_mutex_post(x) /**< Post the mutex. */
262 /** @} */
263
264 #endif
265
266 #endif
267 /** @} */
268 /** @} */
269 /** @} */
270
app_driver_sem_post_from_isr
#define app_driver_sem_post_from_isr(x)
Post the semaphore from interrupt.
Definition: app_rtos_cfg.h:256
app_driver_sem_deinit
#define app_driver_sem_deinit(x)
Deinitialize the semphore.
Definition: app_rtos_cfg.h:253
app_driver_mutex_deinit
#define app_driver_mutex_deinit(x)
Deinitialize the mutex.
Definition: app_rtos_cfg.h:259
app_driver_mutex_pend
#define app_driver_mutex_pend(x, y)
Pend the mutex.
Definition: app_rtos_cfg.h:260
app_driver_mutex_post
#define app_driver_mutex_post(x)
Post the mutex.
Definition: app_rtos_cfg.h:261
app_driver_sem_post
#define app_driver_sem_post(x)
Post the semaphore.
Definition: app_rtos_cfg.h:255
app_driver_sem_init
#define app_driver_sem_init(x)
Initialize the semaphore.
Definition: app_rtos_cfg.h:252
app_driver_mutex_init
#define app_driver_mutex_init(x)
Initialize the mutex.
Definition: app_rtos_cfg.h:258
mutex_t
void * mutex_t
Definition: app_rtos_cfg.h:108
app_driver_sem_pend
#define app_driver_sem_pend(x, y)
Pend the semaphore.
Definition: app_rtos_cfg.h:254
sem_t
void * sem_t
Definition: app_rtos_cfg.h:107