osal.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2018 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef _OSAL_H_
  15. #define _OSAL_H_
  16. #include <freertos/FreeRTOS.h>
  17. #include <freertos/task.h>
  18. #include <unistd.h>
  19. #include <stdint.h>
  20. #include <esp_timer.h>
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #define OS_SUCCESS ESP_OK
  25. #define OS_FAIL ESP_FAIL
  26. typedef TaskHandle_t othread_t;
  27. static inline int httpd_os_thread_create(othread_t *thread,
  28. const char *name, uint16_t stacksize, int prio,
  29. void (*thread_routine)(void *arg), void *arg,
  30. BaseType_t core_id)
  31. {
  32. StaticTask_t *xTaskBuffer = (StaticTask_t*) heap_caps_malloc(sizeof(StaticTask_t), (MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT));
  33. StackType_t *xStack = heap_caps_malloc(stacksize,(MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT));
  34. *thread = xTaskCreateStaticPinnedToCore(thread_routine, name, stacksize, arg, prio, xStack,xTaskBuffer,core_id);
  35. if (*thread) {
  36. return OS_SUCCESS;
  37. }
  38. return OS_FAIL;
  39. }
  40. /* Only self delete is supported */
  41. static inline void httpd_os_thread_delete(void)
  42. {
  43. vTaskDelete(xTaskGetCurrentTaskHandle());
  44. }
  45. static inline void httpd_os_thread_sleep(int msecs)
  46. {
  47. vTaskDelay(msecs / portTICK_RATE_MS);
  48. }
  49. static inline othread_t httpd_os_thread_handle(void)
  50. {
  51. return xTaskGetCurrentTaskHandle();
  52. }
  53. #ifdef __cplusplus
  54. }
  55. #endif
  56. #endif /* ! _OSAL_H_ */