mikroSDK Reference Manual
osal.h
1/*
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#include "common/tusb_common.h"
35
36typedef void (*osal_task_func_t)( void * );
37
38// Timeout
39#define OSAL_TIMEOUT_NOTIMEOUT (0) // Return immediately
40#define OSAL_TIMEOUT_NORMAL (10) // Default timeout
41#define OSAL_TIMEOUT_WAIT_FOREVER (UINT32_MAX) // Wait forever
42#define OSAL_TIMEOUT_CONTROL_XFER OSAL_TIMEOUT_WAIT_FOREVER
43
44// Mutex is required when using a preempted RTOS or MCU has multiple cores
45#if (CFG_TUSB_OS == OPT_OS_NONE) && !TUP_MCU_MULTIPLE_CORE
46 #define OSAL_MUTEX_REQUIRED 0
47 #define OSAL_MUTEX_DEF(_name) uint8_t :0
48#else
49 #define OSAL_MUTEX_REQUIRED 1
50 #define OSAL_MUTEX_DEF(_name) osal_mutex_def_t _name
51#endif
52
53// OS thin implementation
54#if CFG_TUSB_OS == OPT_OS_NONE
55 #include "osal_none.h"
56#elif CFG_TUSB_OS == OPT_OS_FREERTOS
57 #include "osal_freertos.h"
58#elif CFG_TUSB_OS == OPT_OS_MYNEWT
59 #include "osal_mynewt.h"
60#elif CFG_TUSB_OS == OPT_OS_PICO
61 #include "osal_pico.h"
62#elif CFG_TUSB_OS == OPT_OS_RTTHREAD
63 #include "osal_rtthread.h"
64#elif CFG_TUSB_OS == OPT_OS_RTX4
65 #include "osal_rtx4.h"
66#elif CFG_TUSB_OS == OPT_OS_CUSTOM
67 #include "tusb_os_custom.h" // implemented by application
68#else
69 #error OS is not supported yet
70#endif
71
72//--------------------------------------------------------------------+
73// OSAL Porting API
74// Should be implemented as static inline function in osal_port.h header
75/*
76 osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef);
77 bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr);
78 bool osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec);
79 void osal_semaphore_reset(osal_semaphore_t sem_hdl); // TODO removed
80
81 osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef);
82 bool osal_mutex_lock (osal_mutex_t sem_hdl, uint32_t msec);
83 bool osal_mutex_unlock(osal_mutex_t mutex_hdl);
84
85 osal_queue_t osal_queue_create(osal_queue_def_t* qdef);
86 bool osal_queue_receive(osal_queue_t qhdl, void* data, uint32_t msec);
87 bool osal_queue_send(osal_queue_t qhdl, void const * data, bool in_isr);
88 bool osal_queue_empty(osal_queue_t qhdl);
89*/
90//--------------------------------------------------------------------+
91
92#ifdef __cplusplus
93 }
94#endif
95
96#endif /* _TUSB_OSAL_H_ */