os_wrapper.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (c) 2025 Evlers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. *
  22. * Change Logs:
  23. * Date Author Notes
  24. * 2024-12-26 Evlers first implementation
  25. */
  26. #ifndef __OS_WRAPPER_H
  27. #define __OS_WRAPPER_H
  28. #include "os_header.h"
  29. #include <signal.h>
  30. #include <unistd.h>
  31. #include <sys/types.h>
  32. #include "mempool.h"
  33. #include "esp_hosted_config.h"
  34. #include "hosted_os_adapter.h"
  35. #include "esp_wifi_types.h"
  36. #include "esp_netif_types.h"
  37. #include "common.h"
  38. #define MAX_PAYLOAD_SIZE (MAX_TRANSPORT_BUFFER_SIZE-H_ESP_PAYLOAD_HEADER_OFFSET)
  39. #define RPC__TIMER_ONESHOT (RT_TIMER_FLAG_ONE_SHOT | RT_TIMER_FLAG_SOFT_TIMER)
  40. #define RPC__TIMER_PERIODIC (RT_TIMER_FLAG_PERIODIC | RT_TIMER_FLAG_SOFT_TIMER)
  41. #define HOSTED_BLOCKING RT_WAITING_FOREVER
  42. #define HOSTED_NON_BLOCKING 0
  43. #define HOSTED_BLOCK_MAX HOSTED_BLOCKING
  44. #define thread_handle_t rt_thread_t
  45. #define queue_handle_t rt_mq_t
  46. #define semaphore_handle_t rt_sem_t
  47. #define mutex_handle_t rt_mutex_t
  48. #define spinlock_handle_t struct rt_spinlock
  49. #ifndef likely
  50. #define likely(x) __builtin_expect(!!(x), 1)
  51. #endif
  52. #ifndef unlikely
  53. #define unlikely(x) __builtin_expect(!!(x), 0)
  54. #endif
  55. #define FAST_RAM_ATTR
  56. #define gpio_pin_state_t rt_base_t
  57. #define RPC_TASK_STACK_SIZE ESP_HOSTED_RPC_THREAD_STACK_SIZE
  58. #define RPC_TASK_PRIO ESP_HOSTED_RPC_THREAD_PRIORITY
  59. #define DFLT_TASK_STACK_SIZE ESP_HOSTED_TRANSPORT_THREAD_STACK_SIZE
  60. #define DFLT_TASK_PRIO ESP_HOSTED_TRANSPORT_THREAD_PRIORITY
  61. #define H_GPIO_MODE_DEF_DISABLE PIN_MODE_INPUT
  62. #define H_GPIO_MODE_DEF_INPUT PIN_MODE_INPUT
  63. #define H_GPIO_MODE_DEF_OUTPUT PIN_MODE_OUTPUT
  64. #define H_GPIO_MODE_DEF_OD PIN_MODE_OUTPUT_OD
  65. #define H_GPIO_INTR_POSEDGE PIN_IRQ_MODE_RISING
  66. #define H_GPIO_INTR_NEGEDGE PIN_IRQ_MODE_FALLING
  67. #define H_GPIO_INTR_ANYEDGE PIN_IRQ_MODE_RISING_FALLING
  68. #define H_GPIO_LOW 0
  69. #define H_GPIO_HIGH 1
  70. #define RET_OK 0
  71. #define RET_FAIL -1
  72. #define RET_INVALID -2
  73. #define RET_FAIL_MEM -3
  74. #define RET_FAIL4 -4
  75. #define RET_FAIL_TIMEOUT -5
  76. #define MEM_DUMP(s)
  77. /* -------- Create handle ------- */
  78. #define HOSTED_CREATE_HANDLE(tYPE, hANDLE) { \
  79. hANDLE = (tYPE *)g_h.funcs->_h_malloc(sizeof(tYPE)); \
  80. if (!hANDLE) { \
  81. printf("%s:%u Mem alloc fail while create handle\n", __func__,__LINE__); \
  82. return NULL; \
  83. } \
  84. }
  85. /* -------- Calloc, Free handle ------- */
  86. #define HOSTED_FREE(buff) if (buff) { g_h.funcs->_h_free(buff); buff = NULL; }
  87. #define HOSTED_CALLOC(struct_name, buff, nbytes, gotosym) do { \
  88. buff = (struct_name *)g_h.funcs->_h_calloc(1, nbytes); \
  89. if (!buff) { \
  90. printf("%s, Failed to allocate memory \n", __func__); \
  91. goto gotosym; \
  92. } \
  93. } while(0);
  94. #define HOSTED_MALLOC(struct_name, buff, nbytes, gotosym) do { \
  95. buff = (struct_name *)g_h.funcs->_h_malloc(nbytes); \
  96. if (!buff) { \
  97. printf("%s, Failed to allocate memory \n", __func__); \
  98. goto gotosym; \
  99. } \
  100. } while(0);
  101. #endif /*__OS_WRAPPER_H*/