blob: c8131d19d60ec791e2a4e602b0af00b12493a3a5 [file] [log] [blame]
Austin Schuh41baf202022-01-01 14:33:40 -08001/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2019 Ha Thach (tinyusb.org)
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 *
24 * This file is part of the TinyUSB stack.
25 */
26
27#ifndef _TUSB_OSAL_H_
28#define _TUSB_OSAL_H_
29
30#ifdef __cplusplus
31 extern "C" {
32#endif
33
34/** \addtogroup group_osal
35 * @{ */
36
37#include "common/tusb_common.h"
38
39// Return immediately
40#define OSAL_TIMEOUT_NOTIMEOUT (0)
41// Default timeout
42#define OSAL_TIMEOUT_NORMAL (10)
43// Wait forever
44#define OSAL_TIMEOUT_WAIT_FOREVER (UINT32_MAX)
45
46#define OSAL_TIMEOUT_CONTROL_XFER OSAL_TIMEOUT_WAIT_FOREVER
47
48typedef void (*osal_task_func_t)( void * );
49
50#if CFG_TUSB_OS == OPT_OS_NONE
51 #include "osal_none.h"
52#elif CFG_TUSB_OS == OPT_OS_FREERTOS
53 #include "osal_freertos.h"
54#elif CFG_TUSB_OS == OPT_OS_MYNEWT
55 #include "osal_mynewt.h"
56#elif CFG_TUSB_OS == OPT_OS_PICO
57 #include "osal_pico.h"
58#elif CFG_TUSB_OS == OPT_OS_RTTHREAD
59 #include "osal_rtthread.h"
60#elif CFG_TUSB_OS == OPT_OS_CUSTOM
61 #include "tusb_os_custom.h" // implemented by application
62#else
63 #error OS is not supported yet
64#endif
65
66//--------------------------------------------------------------------+
67// OSAL Porting API
68//--------------------------------------------------------------------+
69
70#if __GNUC__
71#pragma GCC diagnostic push
72#pragma GCC diagnostic ignored "-Wredundant-decls"
73#endif
74//------------- Semaphore -------------//
75static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef);
76static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr);
77static inline bool osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec);
78
79static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl); // TODO removed
80
81//------------- Mutex -------------//
82static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef);
83static inline bool osal_mutex_lock (osal_mutex_t sem_hdl, uint32_t msec);
84static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl);
85
86//------------- Queue -------------//
87static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef);
88static inline bool osal_queue_receive(osal_queue_t qhdl, void* data);
89static inline bool osal_queue_send(osal_queue_t qhdl, void const * data, bool in_isr);
90static inline bool osal_queue_empty(osal_queue_t qhdl);
91#if __GNUC__
92#pragma GCC diagnostic pop
93#endif
94
95#if 0 // TODO remove subtask related macros later
96// Sub Task
97#define OSAL_SUBTASK_BEGIN
98#define OSAL_SUBTASK_END return TUSB_ERROR_NONE;
99
100#define STASK_RETURN(_error) return _error;
101#define STASK_INVOKE(_subtask, _status) (_status) = _subtask
102#define STASK_ASSERT(_cond) TU_VERIFY(_cond, TUSB_ERROR_OSAL_TASK_FAILED)
103#endif
104
105#ifdef __cplusplus
106 }
107#endif
108
109/** @} */
110
111#endif /* _TUSB_OSAL_H_ */