• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
59 #ifdef ENV_USE_FREERTOS
60 
61 #include "FreeRTOS.h"
62 #include "semphr.h"
63 
64 /** @addtogroup APP_RTOS_CONFIG_DEFINES Defines
65   * @{
66   */
67 #define ENV_USE_RTOS
68 /** @} */
69 
70 /**
71  * @defgroup APP_RTOS_CONFIG_TYPEDEF Typedefs
72  * @{
73  */
74 
75 /**
76   * @brief Semaphore type definition
77   */
78 typedef SemaphoreHandle_t             sem_t;
79 
80 /**
81   * @brief mutex type definition
82   */
83 typedef SemaphoreHandle_t             mutex_t;
84 
85 /** @} */
86 
87 /** @addtogroup APP_RTOS_CONFIG_DEFINES Defines
88   * @{
89   */
90 #define OS_WAIT_FOREVER               portMAX_DELAY  /**< Block forever until get resource */
91 
92 #define SEM_WAIT_FOREVER              portMAX_DELAY  /**< Wait for the semaphore forever */
93 #define SEM_NO_WAIT                   (0)            /**< Non-block */
94 
95 #define MUTEX_WAIT_FOREVER            portMAX_DELAY  /**< Wait for the mutex forever */
96 #define MUTEX_NO_WAIT                 (0)            /**< Non-block */
97 /** @} */
98 
99 #else
100 
101 /**
102  * @defgroup APP_RTOS_CONFIG_TYPEDEF Typedefs
103  * @{
104  */
105 typedef void                         *sem_t;
106 typedef void                         *mutex_t;
107 /** @} */
108 
109 /** @addtogroup APP_RTOS_CONFIG_DEFINES Defines
110   * @{
111   */
112 #define SEM_WAIT_FOREVER              (0xFFFFUL)  /**< Wait for the semaphore forever. */
113 #define SEM_NO_WAIT                   (0)         /**< Non-block */
114 
115 #define MUTEX_WAIT_FOREVER            (0xFFFFUL)  /**< Wait for the mutex forever */
116 #define MUTEX_NO_WAIT                 (0)         /**< Non-block */
117 /** @} */
118 
119 #endif
120 
121 /** @addtogroup APP_RTOS_CONFIG_DEFINES Defines
122   * @{
123   */
124 #define APP_DRV_SEM_DECL(sem)          sem_t   sem    /**< Define a semaphore instance */
125 #define APP_DRV_MUTEX_DECL(mutex)      mutex_t mutex  /**< Define a mutex instance */
126 /** @} */
127 
128 #ifdef ENV_USE_RTOS
129 /** @addtogroup APP_RTOS_CONFIG_DEFINES Defines
130   * @{
131   */
132 #define ENV_RTOS_USE_SEMP    1    /**< Enable semaphore in app driver */
133 // #define ENV_RTOS_USE_MUTEX 1    /**< Enable mutex in app driver */
134 /** @} */
135 
136 /** @addtogroup APP_RTOS_CONFIG_FUNCTIONS Functions
137   * @{
138   */
139 /**
140  ****************************************************************************************
141  * @brief  Initialize a semaphore.
142  *
143  * @param[in] sem: Pointer to a sem_t parameter which contains the address of the semaphore object.
144  *
145  * @return Result of initialization.
146  ****************************************************************************************
147  */
148 uint16_t app_driver_sem_init(sem_t *sem);
149 
150 /**
151  ****************************************************************************************
152  * @brief  De-initialize a semaphore.
153  *
154  * @param[in] sem: the semaphore object.
155  *
156  * @return Result of De-initialization.
157  ****************************************************************************************
158  */
159 void app_driver_sem_deinit(sem_t sem);
160 
161 /**
162  ****************************************************************************************
163  * @brief  This function will take a semaphore, if the semaphore is unavailable, the
164            thread shall wait for a specified time.
165  *
166  * @param[in] sem: The semaphore object.
167  * @param[in] time_out: The waiting time in milliseconds.
168  *
169  * @return Result of operation.
170  ****************************************************************************************
171  */
172 uint16_t app_driver_sem_pend(sem_t sem, uint32_t time_out);
173 
174 /**
175  ****************************************************************************************
176  * @brief  This function will release a semaphore, if there are threads suspended on
177  *         semaphore, it will be waked up.
178  *
179  * @param[in] sem: The semaphore object.
180  *
181  * @return Result of operation.
182  ****************************************************************************************
183  */
184 uint16_t app_driver_sem_post(sem_t sem);
185 
186 /**
187  ****************************************************************************************
188  * @brief  This function will release a semaphore, it is used in interrupt service function,
189  *         if there are threads suspended on semaphore, it will be waked up.
190  *
191  * @param[in] sem: The semaphore object.
192  *
193  * @return Result of operation.
194  ****************************************************************************************
195  */
196 uint16_t app_driver_sem_post_from_isr(sem_t sem);
197 
198 /**
199  ****************************************************************************************
200  * @brief  Initialize a mutex.
201  *
202  * @param[in] mutex: Pointer to mutex_t parameter which contains the address of the mutex object.
203  *
204  * @return Result of initialization.
205  ****************************************************************************************
206  */
207 uint16_t app_driver_mutex_init(mutex_t *mutex);
208 
209 /**
210  ****************************************************************************************
211  * @brief  De-initialize a mutex.
212  *
213  * @param[in] mutex: the mutex object.
214  *
215  * @return Result of De-initialization.
216  ****************************************************************************************
217  */
218 void app_driver_mutex_deinit(mutex_t mutex);
219 
220 /**
221  ****************************************************************************************
222  * @brief  This function will take a mutex, if the mutex is unavailable, the thread shall
223  *         wait for a specified time.
224  *
225  * @param[in] mutex: The mutex object.
226  * @param[in] time_out: The waiting time in milliseconds.
227  *
228  * @return Result of operation.
229  ****************************************************************************************
230  */
231 uint16_t app_driver_mutex_pend(mutex_t mutex, uint32_t time_out);
232 
233 /**
234  ****************************************************************************************
235  * @brief  This function will release a mutex, if there are threads suspended on mutex,
236  *         it will be waked up.
237  *
238  * @param[in] mutex: The mutex object.
239  *
240  * @return Result of operation.
241  ****************************************************************************************
242  */
243 uint16_t app_driver_mutex_post(mutex_t mutex);
244 /** @} */
245 
246 #else
247 /** @addtogroup APP_RTOS_CONFIG_DEFINES Defines
248   * @{
249   */
250 #define app_driver_sem_init(x)        (0)  /**< Initialize the semaphore. */
251 #define app_driver_sem_deinit(x)           /**< Deinitialize the semphore. */
252 #define app_driver_sem_pend(x, y)     (0)  /**< Pend the semaphore. */
253 #define app_driver_sem_post(x)             /**< Post the semaphore. */
254 #define app_driver_sem_post_from_isr(x)    /**< Post the semaphore from interrupt. */
255 
256 #define app_driver_mutex_init(x)      (0)  /**< Initialize the mutex. */
257 #define app_driver_mutex_deinit(x)         /**< Deinitialize the mutex. */
258 #define app_driver_mutex_pend(x, y)        /**< Pend the mutex. */
259 #define app_driver_mutex_post(x)           /**< Post the mutex. */
260 /** @} */
261 
262 #endif
263 
264 #endif
265 /** @} */
266 /** @} */
267 /** @} */
268 
269