1 /*
2 * SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #ifndef _OSAL_H_
8 #define _OSAL_H_
9
10 #include <freertos/FreeRTOS.h>
11 #include <freertos/task.h>
12 #include <unistd.h>
13 #include <stdint.h>
14 #include <esp_timer.h>
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 #define OS_SUCCESS ESP_OK
21 #define OS_FAIL ESP_FAIL
22
23 typedef TaskHandle_t othread_t;
24
httpd_os_thread_create(othread_t * thread,const char * name,uint16_t stacksize,int prio,void (* thread_routine)(void * arg),void * arg,BaseType_t core_id)25 static inline int httpd_os_thread_create(othread_t *thread,
26 const char *name, uint16_t stacksize, int prio,
27 void (*thread_routine)(void *arg), void *arg,
28 BaseType_t core_id)
29 {
30 int ret = xTaskCreatePinnedToCore(thread_routine, name, stacksize, arg, prio, thread, core_id);
31 if (ret == pdPASS) {
32 return OS_SUCCESS;
33 }
34 return OS_FAIL;
35 }
36
37 /* Only self delete is supported */
httpd_os_thread_delete(void)38 static inline void httpd_os_thread_delete(void)
39 {
40 vTaskDelete(xTaskGetCurrentTaskHandle());
41 }
42
httpd_os_thread_sleep(int msecs)43 static inline void httpd_os_thread_sleep(int msecs)
44 {
45 vTaskDelay(msecs / portTICK_RATE_MS);
46 }
47
httpd_os_thread_handle(void)48 static inline othread_t httpd_os_thread_handle(void)
49 {
50 return xTaskGetCurrentTaskHandle();
51 }
52
53 #ifdef __cplusplus
54 }
55 #endif
56
57 #endif /* ! _OSAL_H_ */
58