ec_osal.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (c) 2025, sakumisu
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef EC_OSAL_H
  7. #define EC_OSAL_H
  8. #include <stdint.h>
  9. #include <string.h>
  10. #include <stdbool.h>
  11. #ifdef __INCLUDE_NUTTX_CONFIG_H
  12. #define CONFIG_EC_OSAL_THREAD_SET_ARGV int argc, char **argv
  13. #define CONFIG_EC_OSAL_THREAD_GET_ARGV ((uintptr_t)strtoul(argv[1], NULL, 16))
  14. #elif defined(__ZEPHYR__)
  15. #define CONFIG_EC_OSAL_THREAD_SET_ARGV void *p1, void *p2, void *p3
  16. #define CONFIG_EC_OSAL_THREAD_GET_ARGV ((uintptr_t)p1)
  17. #else
  18. #define CONFIG_EC_OSAL_THREAD_SET_ARGV void *argument
  19. #define CONFIG_EC_OSAL_THREAD_GET_ARGV ((uintptr_t)argument)
  20. #endif
  21. #define EC_OSAL_WAITING_FOREVER (0xFFFFFFFFU)
  22. typedef void *ec_osal_thread_t;
  23. typedef void *ec_osal_sem_t;
  24. typedef void *ec_osal_mutex_t;
  25. typedef void *ec_osal_mq_t;
  26. typedef void (*ec_thread_entry_t)(CONFIG_EC_OSAL_THREAD_SET_ARGV);
  27. typedef void (*ec_timer_handler_t)(void *argument);
  28. struct ec_osal_timer {
  29. ec_timer_handler_t handler;
  30. void *argument;
  31. bool is_period;
  32. uint32_t timeout_ms;
  33. void *timer;
  34. };
  35. /*
  36. * Task with smaller priority value indicates higher task priority
  37. */
  38. ec_osal_thread_t ec_osal_thread_create(const char *name, uint32_t stack_size, uint32_t prio, ec_thread_entry_t entry, void *args);
  39. void ec_osal_thread_delete(ec_osal_thread_t thread);
  40. void ec_osal_thread_suspend(ec_osal_thread_t thread);
  41. void ec_osal_thread_resume(ec_osal_thread_t thread);
  42. ec_osal_sem_t ec_osal_sem_create(uint32_t max_count, uint32_t initial_count);
  43. void ec_osal_sem_delete(ec_osal_sem_t sem);
  44. int ec_osal_sem_take(ec_osal_sem_t sem, uint32_t timeout);
  45. int ec_osal_sem_give(ec_osal_sem_t sem);
  46. void ec_osal_sem_reset(ec_osal_sem_t sem);
  47. ec_osal_mutex_t ec_osal_mutex_create(void);
  48. void ec_osal_mutex_delete(ec_osal_mutex_t mutex);
  49. int ec_osal_mutex_take(ec_osal_mutex_t mutex);
  50. int ec_osal_mutex_give(ec_osal_mutex_t mutex);
  51. ec_osal_mq_t ec_osal_mq_create(uint32_t max_msgs);
  52. void ec_osal_mq_delete(ec_osal_mq_t mq);
  53. int ec_osal_mq_send(ec_osal_mq_t mq, uintptr_t addr);
  54. int ec_osal_mq_recv(ec_osal_mq_t mq, uintptr_t *addr, uint32_t timeout);
  55. struct ec_osal_timer *ec_osal_timer_create(const char *name, uint32_t timeout_ms, ec_timer_handler_t handler, void *argument, bool is_period);
  56. void ec_osal_timer_delete(struct ec_osal_timer *timer);
  57. void ec_osal_timer_start(struct ec_osal_timer *timer);
  58. void ec_osal_timer_stop(struct ec_osal_timer *timer);
  59. size_t ec_osal_enter_critical_section(void);
  60. void ec_osal_leave_critical_section(size_t flag);
  61. void ec_osal_msleep(uint32_t delay);
  62. void *ec_osal_malloc(size_t size);
  63. void ec_osal_free(void *ptr);
  64. #endif /* EC_OSAL_H */