rt_ai_common.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-04-01 liqiwen the first version
  9. */
  10. #ifndef __RT_AI_COMMON__
  11. #define __RT_AI_COMMON__
  12. #include <rt_ai_def.h>
  13. #include <aiconfig.h>
  14. #ifdef __cplusplus
  15. extern "C"{
  16. #endif
  17. #define RT_AI_FLAG_INITED 0x01
  18. #define RT_AI_FLAG_LOADED 0X02
  19. #define RT_AI_FLAG_RUN 0x04
  20. #define RT_AI_FLAG_OUTPUT 0x08
  21. #ifndef rt_ai_list_entry
  22. #define rt_ai_list_entry(node, type, member) ((type *)((char *)(node) - (unsigned long)(&((type *)0)->member)))
  23. #endif //rt_list_entry
  24. #ifndef rt_ai_list_for_each
  25. #define rt_ai_list_for_each(pos, head) for (pos = (head)->next; pos != (head); pos = pos->next)
  26. #endif //rt_list_for_each
  27. #ifndef rt_ai_list_insert_after
  28. rt_ai_inline void list_insert_after(rt_ai_list_t *l, rt_ai_list_t *n)
  29. {
  30. n->next = l->next;
  31. n->prev = l;
  32. l->next->prev = n;
  33. l->next = n;
  34. }
  35. #define rt_ai_list_insert_after(l, n) list_insert_after(l, n)
  36. #endif //rt_list_insert_after
  37. #ifndef rt_ai_list_init
  38. rt_ai_inline void list_init(rt_ai_list_t *l)
  39. {
  40. l->next = l->prev = l;
  41. }
  42. #define rt_ai_list_init(l) list_init(l)
  43. #endif
  44. #ifndef rt_ai_list_remove
  45. rt_ai_inline void list_remove(rt_ai_list_t *n)
  46. {
  47. n->next->prev = n->prev;
  48. n->prev->next = n->next;
  49. n->next = n->prev = n;
  50. }
  51. #define rt_ai_list_remove(l) list_remove(l)
  52. #endif //rt_ai_list_remove
  53. #define RT_AI_ASSERT_RETURN_0(_expr) \
  54. if (!(_expr)) \
  55. { \
  56. AI_LOG_E("RT_AI_ASSERT failure:%s , %s , %d\n",#_expr, __FUNCTION__, __LINE__); \
  57. return -1; \
  58. }
  59. #define RT_AI_ASSERT_RETURN_NULL(_expr) \
  60. if (!(_expr)) \
  61. { \
  62. AI_LOG_E("RT_AI_ASSERT failure:%s , %s , %d\n",#_expr, __FUNCTION__, __LINE__); \
  63. return RT_AI_NULL; \
  64. }
  65. #define RT_AI_ASSERT_RETURN(_expr) \
  66. if (!(_expr)) \
  67. { \
  68. AI_LOG_E("RT_AI_ASSERT failure:%s , %s , %d\n",#_expr, __FUNCTION__, __LINE__); \
  69. return ; \
  70. }
  71. #define ALLOC_WORK_BUFFER_FLAG 0X01
  72. #define ALLOC_INPUT_BUFFER_FLAG 0X02
  73. #define ALLOC_OUTPUT_BUFFER_FLAG 0X04
  74. #define ALLOC_DEFAULT_BUFFER_FLAG 0xffff
  75. #define RT_AI_T(h) ((rt_ai_t)(h))
  76. #define RT_AI_INFO(h) (((rt_ai_t)(h))->info)
  77. #define RT_AI_OUTPUT(_h, _out) (RT_AI_T(_h)->output[_out])
  78. #define RT_AI_INPUT(_h, _out) (RT_AI_T(_h)->input[_out])
  79. #define GET_OUTPUT(_h, _out) RT_AI_OUTPUT(_h, _out)
  80. #define GET_INPUT(_h, _in) RT_AI_INPUT(_h, _out)
  81. #define GET_NUM_OUTPUT(_h) (RT_AI_INFO(_h).output_n)
  82. #define GET_NUM_INPUT(_h) (RT_AI_INFO(_h).input_n)
  83. #define GET_OUTPUT_SIZE(_h, _out) (RT_AI_INFO(_h).output_n_stack[_out])
  84. #define GET_INPUT_SIZE(_h, _in) (RT_AI_INFO(_h).input_n_stack[_out])
  85. #define rt_ai_new(_type, _num) ((_type *)(rt_ai_malloc(sizeof(_type) * (_num))))
  86. #define rt_ai_new_obj(_type) (rt_ai_new(_type, 1))
  87. #define rt_ai_del(_ptr) rt_ai_free(_ptr)
  88. void rt_ai_allocate_buffer(rt_ai_t ai, rt_ai_buffer_t *buf);
  89. #ifdef __cplusplus
  90. }
  91. #endif
  92. #endif