1 /**
2 * @file os_errno.h
3 * @author ALLWINNERTECH IOT WLAN Team
4 */
5
6 /*
7 * Copyright (C) 2017 ALLWINNERTECH TECHNOLOGY CO., LTD. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the
17 * distribution.
18 * 3. Neither the name of ALLWINNERTECH TECHNOLOGY CO., LTD. nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #ifndef _KERNEL_OS_FREERTOS_OS_ERRNO_H_
36 #define _KERNEL_OS_FREERTOS_OS_ERRNO_H_
37
38 #include "_os_common.h"
39 #include "task.h"
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 /*
46 * Thread safe errno handling for FreeRTOS
47 */
48
49 #if (configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0)
50
51 #define OS_ERRNO_LOCATION_IDX 0
52
53 /**
54 * @brief Get error number of the current thread
55 * @return Error number of the current thread
56 */
OS_GetErrno(void)57 static __always_inline int OS_GetErrno(void)
58 {
59 return (int)pvTaskGetThreadLocalStoragePointer(NULL, OS_ERRNO_LOCATION_IDX);
60 }
61
62 /**
63 * @brief Set error number of the current thread
64 * @param[in] Error number to be set
65 * @return None
66 */
OS_SetErrno(int err)67 static __always_inline void OS_SetErrno(int err)
68 {
69 vTaskSetThreadLocalStoragePointer(NULL, OS_ERRNO_LOCATION_IDX, (void *)err);
70 }
71
72 #endif /* configNUM_THREAD_LOCAL_STORAGE_POINTERS */
73
74 #ifdef __cplusplus
75 }
76 #endif
77
78 #endif /* _KERNEL_OS_FREERTOS_OS_ERRNO_H_ */
79