rt_ai_def.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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_DEF__
  11. #define __RT_AI_DEF__
  12. #include <rtthread.h>
  13. #include <aiconfig.h>
  14. #ifdef __cplusplus
  15. extern "C"{
  16. #endif
  17. #define RT_AI_NULL RT_NULL
  18. #define RT_AI_OK 0
  19. #define RT_AI_ERROR 1
  20. #define RT_AI_EREADY 2
  21. #define RT_AI_EBUSY 3
  22. #define RT_AI_NONE 4
  23. #define RT_AI_EEMPTY 5
  24. #define rt_ai_inline rt_inline
  25. #define RT_AI_INLINE rt_ai_inline
  26. #define RT_AI_UNUSED(x) RT_UNUSED(X);
  27. #define RT_AI_ASSERT(_expr) RT_ASSERT(_expr)
  28. #define rt_ai_malloc(_size) rt_malloc(_size)
  29. #define rt_ai_free(_ptr) rt_free(_ptr)
  30. #define rt_ai_list_t rt_list_t
  31. #define rt_ai_timestamp_t rt_tick_t
  32. #define rt_ai_get_timestamp() rt_tick_get()
  33. #define rt_ai_list_entry(node, type, member) rt_list_entry(node, type, member)
  34. #define rt_ai_list_for_each(pos, head) rt_list_for_each(pos, head)
  35. #define rt_ai_list_insert_after(l, n) rt_list_insert_after(l, n)
  36. #define rt_ai_list_init(l) rt_list_init(l)
  37. typedef rt_uint8_t rt_ai_buffer_t;
  38. typedef rt_uint32_t rt_ai_uint32_t;
  39. typedef rt_uint16_t rt_ai_uint16_t;
  40. #define RT_AI_STATICIAL_TYPE(_type) (RT_AI_CLASS_STATIC | _type)
  41. #define RT_AI_IS_STATICIAL(_type) (RT_AI_CLASS_STATIC & _type)
  42. #define RT_AI_MASK_STATICIAL(_type) ((~RT_AI_CLASS_STATIC) & _type)
  43. /*
  44. * define object type info for the number of rt_ai_core_container items.
  45. */
  46. enum rt_ai_obj_type
  47. {
  48. RT_AI_CLASS_HANDLE = 0, /**< The type is a rt_ai. */
  49. #ifdef RT_AI_USE_RECORD
  50. RT_AI_CLASS_RECORD, /**< The object is a record. */
  51. #endif
  52. RT_AI_CLASS_UNKNOWN, /**< The object is unknown. */
  53. RT_AI_CLASS_STATIC = 0X80, /** RT_AI STATICAL TYPE */
  54. RT_AI_CLASS_STATIC_HANDLE = RT_AI_STATICIAL_TYPE(RT_AI_CLASS_HANDLE),
  55. #ifdef RT_AI_USE_RECORD /**< The type is a statical rt_ai. */
  56. RT_AI_CLASS_STATIC_RECORD = RT_AI_STATICIAL_TYPE(RT_AI_CLASS_RECORD),
  57. #endif /**< The type is a statical record. */
  58. RT_AI_CLASS_STATIC_UNKNOWN = RT_AI_STATICIAL_TYPE(RT_AI_CLASS_UNKNOWN), /**< The type is a statical unknow. */
  59. };
  60. /**
  61. * Base structure of Kernel object
  62. */
  63. struct rt_ai_core
  64. {
  65. char name[RT_AI_NAME_MAX]; /**< name of kernel object */
  66. rt_uint8_t type; /**< type of kernel object */
  67. rt_uint8_t flag; /**< flag of kernel object */
  68. rt_list_t list; /**< list node of kernel object */
  69. };
  70. typedef struct rt_ai_core *rt_ai_core_t; /**< Type for kernel objects. */
  71. typedef struct rt_ai_info *rt_ai_info_t;
  72. struct rt_ai_info
  73. {
  74. rt_ai_uint32_t input_n;
  75. rt_ai_uint32_t output_n;
  76. rt_ai_uint32_t input_n_stack[RT_AI_IO_MAX];
  77. rt_ai_uint32_t output_n_stack[RT_AI_IO_MAX];
  78. rt_ai_uint32_t work_buffer_size;
  79. rt_uint16_t flag;
  80. };
  81. typedef struct rt_ai *rt_ai_t;
  82. /**
  83. * ai handle structure
  84. */
  85. struct rt_ai
  86. {
  87. struct rt_ai_core parent;
  88. rt_ai_uint16_t flag; /**< ai flag */
  89. rt_ai_uint16_t mem_flag;
  90. rt_ai_buffer_t *workbuffer; /** runtime buf */
  91. rt_ai_buffer_t *input[RT_AI_IO_MAX]; /* num of input */
  92. rt_ai_buffer_t *output[RT_AI_IO_MAX]; /* num of output */
  93. struct rt_ai_info info;
  94. void *cfg; /* platform config */
  95. #ifdef RT_USING_AI_OPS
  96. const struct rt_ai_ops *ops;
  97. #else
  98. /* common ai interface
  99. *@return 0:OK; other:fail
  100. */
  101. int (*init) (rt_ai_t ai, rt_ai_buffer_t *buf);
  102. int (*get_input) (rt_ai_t ai, rt_ai_uint32_t index);
  103. int (*run) (rt_ai_t ai, void (*callback)(void *arg), void *arg);
  104. int (*get_output) (rt_ai_t ai, rt_ai_uint32_t index);
  105. int (*get_info) (rt_ai_t ai, rt_ai_buffer_t *buf);
  106. int (*config) (rt_ai_t ai, int cmd, rt_ai_buffer_t *args);
  107. #endif
  108. /* callback when run done */
  109. void (*done_callback_user)(void *arg);
  110. void *arg;
  111. };
  112. /**
  113. * operations set for ai object
  114. */
  115. typedef struct _rt_ai_ops
  116. {
  117. /* common ai interface */
  118. // todo
  119. rt_uint16_t flag;
  120. } rt_ai_ops;
  121. typedef struct rt_ai_record *rt_ai_record_t;
  122. struct rt_ai_record
  123. {
  124. struct rt_ai_core parent;
  125. rt_ai_uint32_t record;
  126. };
  127. #ifdef __cplusplus
  128. }
  129. #endif
  130. #endif