hal_thread.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef SUNXI_HAL_THREAD_H
  2. #define SUNXI_HAL_THREAD_H
  3. #ifdef __cplusplus
  4. extern "C"
  5. {
  6. #endif
  7. #ifdef CONFIG_KERNEL_FREERTOS
  8. #include <pthread.h>
  9. void *kthread_create(void (*threadfn)(void *data), void *data, const char *namefmt, ...);
  10. int kthread_stop(void *thread);
  11. #else
  12. #include <rtthread.h>
  13. #define HAL_THREAD_STACK_SIZE (0x2000)
  14. #define HAL_THREAD_PRIORITY ( 15)
  15. #define HAL_THREAD_TIMESLICE ( 10)
  16. void *kthread_create(void (*threadfn)(void *data), void *data, const char *namefmt, ...);
  17. int kthread_stop(void *thread);
  18. int kthread_start(void *thread);
  19. int kthread_wakeup(void *thread);
  20. int kthread_suspend(void *thread);
  21. /**
  22. * kthread_run - create and wake a thread.
  23. * @threadfn: the function to run until signal_pending(current).
  24. * @data: data ptr for @threadfn.
  25. * @namefmt: printf-style name for the thread.
  26. *
  27. * Description: Convenient wrapper for kthread_create() followed by
  28. * wake_up_process(). Returns the kthread or ERR_PTR(-ENOMEM).
  29. */
  30. #define kthread_run(threadfn, data, namefmt, ...) \
  31. ({ \
  32. struct rt_thread *__k \
  33. = kthread_create(threadfn, data, namefmt, ## __VA_ARGS__); \
  34. if (!IS_ERR((unsigned long)__k)) \
  35. rt_thread_startup(__k); \
  36. __k; \
  37. })
  38. //#define in_interrupt(...) rt_interrupt_get_nest()
  39. #endif
  40. #ifdef __cplusplus
  41. }
  42. #endif
  43. #endif