ec_osal.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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_thread_entry_t)(CONFIG_EC_OSAL_THREAD_SET_ARGV);
  26. typedef void (*ec_timer_handler_t)(void *argument);
  27. struct ec_osal_timer {
  28. ec_timer_handler_t handler;
  29. void *argument;
  30. bool is_period;
  31. uint32_t timeout_ms;
  32. void *timer;
  33. };
  34. /*
  35. * Task with smaller priority value indicates higher task priority
  36. */
  37. 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);
  38. void ec_osal_thread_delete(ec_osal_thread_t thread);
  39. void ec_osal_thread_suspend(ec_osal_thread_t thread);
  40. void ec_osal_thread_resume(ec_osal_thread_t thread);
  41. ec_osal_sem_t ec_osal_sem_create(uint32_t max_count, uint32_t initial_count);
  42. void ec_osal_sem_delete(ec_osal_sem_t sem);
  43. int ec_osal_sem_take(ec_osal_sem_t sem, uint32_t timeout);
  44. int ec_osal_sem_give(ec_osal_sem_t sem);
  45. void ec_osal_sem_reset(ec_osal_sem_t sem);
  46. ec_osal_mutex_t ec_osal_mutex_create(void);
  47. void ec_osal_mutex_delete(ec_osal_mutex_t mutex);
  48. int ec_osal_mutex_take(ec_osal_mutex_t mutex);
  49. int ec_osal_mutex_give(ec_osal_mutex_t mutex);
  50. 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);
  51. void ec_osal_timer_delete(struct ec_osal_timer *timer);
  52. void ec_osal_timer_start(struct ec_osal_timer *timer);
  53. void ec_osal_timer_stop(struct ec_osal_timer *timer);
  54. size_t ec_osal_enter_critical_section(void);
  55. void ec_osal_leave_critical_section(size_t flag);
  56. void ec_osal_msleep(uint32_t delay);
  57. void *ec_osal_malloc(size_t size);
  58. void ec_osal_free(void *ptr);
  59. #endif /* EC_OSAL_H */