rtdef.h 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2007-01-10 Bernard the first version
  9. * 2008-07-12 Bernard remove all rt_int8, rt_uint32_t etc typedef
  10. * 2010-10-26 yi.qiu add module support
  11. * 2010-11-10 Bernard add cleanup callback function in thread exit.
  12. * 2011-05-09 Bernard use builtin va_arg in GCC 4.x
  13. * 2012-11-16 Bernard change RT_NULL from ((void*)0) to 0.
  14. * 2012-12-29 Bernard change the RT_USING_MEMPOOL location and add
  15. * RT_USING_MEMHEAP condition.
  16. * 2012-12-30 Bernard add more control command for graphic.
  17. * 2013-01-09 Bernard change version number.
  18. * 2015-02-01 Bernard change version number to v2.1.0
  19. * 2017-08-31 Bernard change version number to v3.0.0
  20. * 2017-11-30 Bernard change version number to v3.0.1
  21. * 2017-12-27 Bernard change version number to v3.0.2
  22. * 2018-02-24 Bernard change version number to v3.0.3
  23. * 2018-04-25 Bernard change version number to v3.0.4
  24. * 2018-05-31 Bernard change version number to v3.1.0
  25. * 2018-09-04 Bernard change version number to v3.1.1
  26. * 2018-09-14 Bernard apply Apache License v2.0 to RT-Thread Kernel
  27. * 2018-10-13 Bernard change version number to v4.0.0
  28. * 2018-10-02 Bernard add 64bit arch support
  29. * 2018-11-22 Jesven add smp member to struct rt_thread
  30. * add struct rt_cpu
  31. * add smp relevant macros
  32. * 2019-01-27 Bernard change version number to v4.0.1
  33. * 2019-05-17 Bernard change version number to v4.0.2
  34. * 2019-12-20 Bernard change version number to v4.0.3
  35. * 2020-08-10 Meco Man add macro for struct rt_device_ops
  36. * 2020-10-23 Meco Man define maximum value of ipc type
  37. * 2021-03-19 Meco Man add security devices
  38. * 2021-05-10 armink change version number to v4.0.4
  39. * 2021-11-19 Meco Man change version number to v4.1.0
  40. */
  41. #ifndef __RT_DEF_H__
  42. #define __RT_DEF_H__
  43. /* include rtconfig header to import configuration */
  44. #include <rtconfig.h>
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48. /**
  49. * @addtogroup BasicDef
  50. */
  51. /**@{*/
  52. /* RT-Thread version information */
  53. #define RT_VERSION 4L /**< major version number */
  54. #define RT_SUBVERSION 1L /**< minor version number */
  55. #define RT_REVISION 0L /**< revise version number */
  56. /* RT-Thread version */
  57. #define RTTHREAD_VERSION ((RT_VERSION * 10000) + \
  58. (RT_SUBVERSION * 100) + RT_REVISION)
  59. /* RT-Thread basic data type definitions */
  60. #ifndef RT_USING_ARCH_DATA_TYPE
  61. typedef signed char rt_int8_t; /**< 8bit integer type */
  62. typedef signed short rt_int16_t; /**< 16bit integer type */
  63. typedef signed int rt_int32_t; /**< 32bit integer type */
  64. typedef unsigned char rt_uint8_t; /**< 8bit unsigned integer type */
  65. typedef unsigned short rt_uint16_t; /**< 16bit unsigned integer type */
  66. typedef unsigned int rt_uint32_t; /**< 32bit unsigned integer type */
  67. #ifdef ARCH_CPU_64BIT
  68. typedef signed long rt_int64_t; /**< 64bit integer type */
  69. typedef unsigned long rt_uint64_t; /**< 64bit unsigned integer type */
  70. typedef unsigned long rt_size_t; /**< Type for size number */
  71. #else
  72. typedef signed long long rt_int64_t; /**< 64bit integer type */
  73. typedef unsigned long long rt_uint64_t; /**< 64bit unsigned integer type */
  74. typedef unsigned int rt_size_t; /**< Type for size number */
  75. #endif /* ARCH_CPU_64BIT */
  76. #endif /* RT_USING_ARCH_DATA_TYPE */
  77. typedef int rt_bool_t; /**< boolean type */
  78. typedef long rt_base_t; /**< Nbit CPU related date type */
  79. typedef unsigned long rt_ubase_t; /**< Nbit unsigned CPU related data type */
  80. typedef rt_base_t rt_err_t; /**< Type for error number */
  81. typedef rt_uint32_t rt_time_t; /**< Type for time stamp */
  82. typedef rt_uint32_t rt_tick_t; /**< Type for tick count */
  83. typedef rt_base_t rt_flag_t; /**< Type for flags */
  84. typedef rt_ubase_t rt_dev_t; /**< Type for device */
  85. typedef rt_base_t rt_off_t; /**< Type for offset */
  86. /* boolean type definitions */
  87. #define RT_TRUE 1 /**< boolean true */
  88. #define RT_FALSE 0 /**< boolean fails */
  89. /**@}*/
  90. /* maximum value of base type */
  91. #define RT_UINT8_MAX 0xff /**< Maxium number of UINT8 */
  92. #define RT_UINT16_MAX 0xffff /**< Maxium number of UINT16 */
  93. #define RT_UINT32_MAX 0xffffffff /**< Maxium number of UINT32 */
  94. #define RT_TICK_MAX RT_UINT32_MAX /**< Maxium number of tick */
  95. /* maximum value of ipc type */
  96. #define RT_SEM_VALUE_MAX RT_UINT16_MAX /**< Maxium number of semaphore .value */
  97. #define RT_MUTEX_VALUE_MAX RT_UINT16_MAX /**< Maxium number of mutex .value */
  98. #define RT_MUTEX_HOLD_MAX RT_UINT8_MAX /**< Maxium number of mutex .hold */
  99. #define RT_MB_ENTRY_MAX RT_UINT16_MAX /**< Maxium number of mailbox .entry */
  100. #define RT_MQ_ENTRY_MAX RT_UINT16_MAX /**< Maxium number of message queue .entry */
  101. #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
  102. #define __CLANG_ARM
  103. #endif
  104. /* Compiler Related Definitions */
  105. #if defined(__CC_ARM) || defined(__CLANG_ARM) /* ARM Compiler */
  106. #include <stdarg.h>
  107. #define RT_SECTION(x) __attribute__((section(x)))
  108. #define RT_UNUSED __attribute__((unused))
  109. #define RT_USED __attribute__((used))
  110. #define ALIGN(n) __attribute__((aligned(n)))
  111. #define RT_WEAK __attribute__((weak))
  112. #define rt_inline static __inline
  113. /* module compiling */
  114. #ifdef RT_USING_MODULE
  115. #define RTT_API __declspec(dllimport)
  116. #else
  117. #define RTT_API __declspec(dllexport)
  118. #endif
  119. #elif defined (__IAR_SYSTEMS_ICC__) /* for IAR Compiler */
  120. #include <stdarg.h>
  121. #define RT_SECTION(x) @ x
  122. #define RT_UNUSED
  123. #define RT_USED __root
  124. #define PRAGMA(x) _Pragma(#x)
  125. #define ALIGN(n) PRAGMA(data_alignment=n)
  126. #define RT_WEAK __weak
  127. #define rt_inline static inline
  128. #define RTT_API
  129. #elif defined (__GNUC__) /* GNU GCC Compiler */
  130. #ifdef RT_USING_NEWLIB
  131. #include <stdarg.h>
  132. #else
  133. /* the version of GNU GCC must be greater than 4.x */
  134. typedef __builtin_va_list __gnuc_va_list;
  135. typedef __gnuc_va_list va_list;
  136. #define va_start(v,l) __builtin_va_start(v,l)
  137. #define va_end(v) __builtin_va_end(v)
  138. #define va_arg(v,l) __builtin_va_arg(v,l)
  139. #endif
  140. #define RT_SECTION(x) __attribute__((section(x)))
  141. #define RT_UNUSED __attribute__((unused))
  142. #define RT_USED __attribute__((used))
  143. #define ALIGN(n) __attribute__((aligned(n)))
  144. #define RT_WEAK __attribute__((weak))
  145. #define rt_inline static __inline
  146. #define RTT_API
  147. #elif defined (__ADSPBLACKFIN__) /* for VisualDSP++ Compiler */
  148. #include <stdarg.h>
  149. #define RT_SECTION(x) __attribute__((section(x)))
  150. #define RT_UNUSED __attribute__((unused))
  151. #define RT_USED __attribute__((used))
  152. #define ALIGN(n) __attribute__((aligned(n)))
  153. #define RT_WEAK __attribute__((weak))
  154. #define rt_inline static inline
  155. #define RTT_API
  156. #elif defined (_MSC_VER)
  157. #include <stdarg.h>
  158. #define RT_SECTION(x)
  159. #define RT_UNUSED
  160. #define RT_USED
  161. #define ALIGN(n) __declspec(align(n))
  162. #define RT_WEAK
  163. #define rt_inline static __inline
  164. #define RTT_API
  165. #elif defined (__TI_COMPILER_VERSION__)
  166. #include <stdarg.h>
  167. /* The way that TI compiler set section is different from other(at least
  168. * GCC and MDK) compilers. See ARM Optimizing C/C++ Compiler 5.9.3 for more
  169. * details. */
  170. #define RT_SECTION(x)
  171. #define RT_UNUSED
  172. #define RT_USED
  173. #define PRAGMA(x) _Pragma(#x)
  174. #define ALIGN(n)
  175. #define RT_WEAK
  176. #define rt_inline static inline
  177. #define RTT_API
  178. #elif defined (__TASKING__)
  179. #include <stdarg.h>
  180. #define RT_SECTION(x) __attribute__((section(x)))
  181. #define RT_UNUSED __attribute__((unused))
  182. #define RT_USED __attribute__((used, protect))
  183. #define PRAGMA(x) _Pragma(#x)
  184. #define ALIGN(n) __attribute__((__align(n)))
  185. #define RT_WEAK __attribute__((weak))
  186. #define rt_inline static inline
  187. #define RTT_API
  188. #else
  189. #error not supported tool chain
  190. #endif
  191. /* initialization export */
  192. #ifdef RT_USING_COMPONENTS_INIT
  193. typedef int (*init_fn_t)(void);
  194. #ifdef _MSC_VER /* we do not support MS VC++ compiler */
  195. #pragma section("rti_fn$f",read)
  196. #if RT_DEBUG_INIT
  197. struct rt_init_desc
  198. {
  199. const char* level;
  200. const init_fn_t fn;
  201. const char* fn_name;
  202. };
  203. #define INIT_EXPORT(fn, level) \
  204. const char __rti_level_##fn[] = level"__rt_init_"#fn; \
  205. const char __rti_##fn##_name[] = #fn; \
  206. __declspec(allocate("rti_fn$f")) \
  207. RT_USED const struct rt_init_desc __rt_init_msc_##fn = \
  208. {__rti_level_##fn, fn, __rti_##fn##_name};
  209. #else
  210. struct rt_init_desc
  211. {
  212. const char* level;
  213. const init_fn_t fn;
  214. };
  215. #define INIT_EXPORT(fn, level) \
  216. const char __rti_level_##fn[] = level"__rt_init_"#fn; \
  217. __declspec(allocate("rti_fn$f")) \
  218. RT_USED const struct rt_init_desc __rt_init_msc_##fn = \
  219. {__rti_level_##fn, fn };
  220. #endif
  221. #else
  222. #if RT_DEBUG_INIT
  223. struct rt_init_desc
  224. {
  225. const char* fn_name;
  226. const init_fn_t fn;
  227. };
  228. #define INIT_EXPORT(fn, level) \
  229. const char __rti_##fn##_name[] = #fn; \
  230. RT_USED const struct rt_init_desc __rt_init_desc_##fn RT_SECTION(".rti_fn." level) = \
  231. { __rti_##fn##_name, fn};
  232. #else
  233. #define INIT_EXPORT(fn, level) \
  234. RT_USED const init_fn_t __rt_init_##fn RT_SECTION(".rti_fn." level) = fn
  235. #endif
  236. #endif
  237. #else
  238. #define INIT_EXPORT(fn, level)
  239. #endif
  240. /* board init routines will be called in board_init() function */
  241. #define INIT_BOARD_EXPORT(fn) INIT_EXPORT(fn, "1")
  242. /* pre/device/component/env/app init routines will be called in init_thread */
  243. /* components pre-initialization (pure software initilization) */
  244. #define INIT_PREV_EXPORT(fn) INIT_EXPORT(fn, "2")
  245. /* device initialization */
  246. #define INIT_DEVICE_EXPORT(fn) INIT_EXPORT(fn, "3")
  247. /* components initialization (dfs, lwip, ...) */
  248. #define INIT_COMPONENT_EXPORT(fn) INIT_EXPORT(fn, "4")
  249. /* environment initialization (mount disk, ...) */
  250. #define INIT_ENV_EXPORT(fn) INIT_EXPORT(fn, "5")
  251. /* appliation initialization (rtgui application etc ...) */
  252. #define INIT_APP_EXPORT(fn) INIT_EXPORT(fn, "6")
  253. #if !defined(RT_USING_FINSH)
  254. /* define these to empty, even if not include finsh.h file */
  255. #define FINSH_FUNCTION_EXPORT(name, desc)
  256. #define FINSH_FUNCTION_EXPORT_ALIAS(name, alias, desc)
  257. #define MSH_CMD_EXPORT(command, desc)
  258. #define MSH_CMD_EXPORT_ALIAS(command, alias, desc)
  259. #elif !defined(FINSH_USING_SYMTAB)
  260. #define FINSH_FUNCTION_EXPORT_CMD(name, cmd, desc)
  261. #endif
  262. /* event length */
  263. #define RT_EVENT_LENGTH 32
  264. /* memory management option */
  265. #define RT_MM_PAGE_SIZE 4096
  266. #define RT_MM_PAGE_MASK (RT_MM_PAGE_SIZE - 1)
  267. #define RT_MM_PAGE_BITS 12
  268. /* kernel malloc definitions */
  269. #ifndef RT_KERNEL_MALLOC
  270. #define RT_KERNEL_MALLOC(sz) rt_malloc(sz)
  271. #endif
  272. #ifndef RT_KERNEL_FREE
  273. #define RT_KERNEL_FREE(ptr) rt_free(ptr)
  274. #endif
  275. #ifndef RT_KERNEL_REALLOC
  276. #define RT_KERNEL_REALLOC(ptr, size) rt_realloc(ptr, size)
  277. #endif
  278. /**
  279. * @addtogroup Error
  280. */
  281. /**@{*/
  282. /* RT-Thread error code definitions */
  283. #define RT_EOK 0 /**< There is no error */
  284. #define RT_ERROR 1 /**< A generic error happens */
  285. #define RT_ETIMEOUT 2 /**< Timed out */
  286. #define RT_EFULL 3 /**< The resource is full */
  287. #define RT_EEMPTY 4 /**< The resource is empty */
  288. #define RT_ENOMEM 5 /**< No memory */
  289. #define RT_ENOSYS 6 /**< No system */
  290. #define RT_EBUSY 7 /**< Busy */
  291. #define RT_EIO 8 /**< IO error */
  292. #define RT_EINTR 9 /**< Interrupted system call */
  293. #define RT_EINVAL 10 /**< Invalid argument */
  294. /**@}*/
  295. /**
  296. * @ingroup BasicDef
  297. *
  298. * @def RT_ALIGN(size, align)
  299. * Return the most contiguous size aligned at specified width. RT_ALIGN(13, 4)
  300. * would return 16.
  301. */
  302. #define RT_ALIGN(size, align) (((size) + (align) - 1) & ~((align) - 1))
  303. /**
  304. * @ingroup BasicDef
  305. *
  306. * @def RT_ALIGN_DOWN(size, align)
  307. * Return the down number of aligned at specified width. RT_ALIGN_DOWN(13, 4)
  308. * would return 12.
  309. */
  310. #define RT_ALIGN_DOWN(size, align) ((size) & ~((align) - 1))
  311. /**
  312. * @ingroup BasicDef
  313. *
  314. * @def RT_NULL
  315. * Similar as the \c NULL in C library.
  316. */
  317. #define RT_NULL (0)
  318. /**
  319. * Double List structure
  320. */
  321. struct rt_list_node
  322. {
  323. struct rt_list_node *next; /**< point to next node. */
  324. struct rt_list_node *prev; /**< point to prev node. */
  325. };
  326. typedef struct rt_list_node rt_list_t; /**< Type for lists. */
  327. /**
  328. * Single List structure
  329. */
  330. struct rt_slist_node
  331. {
  332. struct rt_slist_node *next; /**< point to next node. */
  333. };
  334. typedef struct rt_slist_node rt_slist_t; /**< Type for single list. */
  335. /**
  336. * @addtogroup KernelObject
  337. */
  338. /**@{*/
  339. /*
  340. * kernel object macros
  341. */
  342. #define RT_OBJECT_FLAG_MODULE 0x80 /**< is module object. */
  343. /**
  344. * Base structure of Kernel object
  345. */
  346. struct rt_object
  347. {
  348. char name[RT_NAME_MAX]; /**< name of kernel object */
  349. rt_uint8_t type; /**< type of kernel object */
  350. rt_uint8_t flag; /**< flag of kernel object */
  351. #ifdef RT_USING_MODULE
  352. void *module_id; /**< id of application module */
  353. #endif
  354. rt_list_t list; /**< list node of kernel object */
  355. };
  356. typedef struct rt_object *rt_object_t; /**< Type for kernel objects. */
  357. /**
  358. * The object type can be one of the follows with specific
  359. * macros enabled:
  360. * - Thread
  361. * - Semaphore
  362. * - Mutex
  363. * - Event
  364. * - MailBox
  365. * - MessageQueue
  366. * - MemHeap
  367. * - MemPool
  368. * - Device
  369. * - Timer
  370. * - Module
  371. * - Unknown
  372. * - Static
  373. */
  374. enum rt_object_class_type
  375. {
  376. RT_Object_Class_Null = 0x00, /**< The object is not used. */
  377. RT_Object_Class_Thread = 0x01, /**< The object is a thread. */
  378. RT_Object_Class_Semaphore = 0x02, /**< The object is a semaphore. */
  379. RT_Object_Class_Mutex = 0x03, /**< The object is a mutex. */
  380. RT_Object_Class_Event = 0x04, /**< The object is a event. */
  381. RT_Object_Class_MailBox = 0x05, /**< The object is a mail box. */
  382. RT_Object_Class_MessageQueue = 0x06, /**< The object is a message queue. */
  383. RT_Object_Class_MemHeap = 0x07, /**< The object is a memory heap. */
  384. RT_Object_Class_MemPool = 0x08, /**< The object is a memory pool. */
  385. RT_Object_Class_Device = 0x09, /**< The object is a device. */
  386. RT_Object_Class_Timer = 0x0a, /**< The object is a timer. */
  387. RT_Object_Class_Module = 0x0b, /**< The object is a module. */
  388. RT_Object_Class_Memory = 0x0c, /**< The object is a memory. */
  389. RT_Object_Class_Unknown = 0x0e, /**< The object is unknown. */
  390. RT_Object_Class_Static = 0x80 /**< The object is a static object. */
  391. };
  392. /**
  393. * The information of the kernel object
  394. */
  395. struct rt_object_information
  396. {
  397. enum rt_object_class_type type; /**< object class type */
  398. rt_list_t object_list; /**< object list */
  399. rt_size_t object_size; /**< object size */
  400. };
  401. /**
  402. * The hook function call macro
  403. */
  404. #ifdef RT_USING_HOOK
  405. #define RT_OBJECT_HOOK_CALL(func, argv) \
  406. do { if ((func) != RT_NULL) func argv; } while (0)
  407. #else
  408. #define RT_OBJECT_HOOK_CALL(func, argv)
  409. #endif
  410. /**@}*/
  411. /**
  412. * @addtogroup Clock
  413. */
  414. /**@{*/
  415. /**
  416. * clock & timer macros
  417. */
  418. #define RT_TIMER_FLAG_DEACTIVATED 0x0 /**< timer is deactive */
  419. #define RT_TIMER_FLAG_ACTIVATED 0x1 /**< timer is active */
  420. #define RT_TIMER_FLAG_ONE_SHOT 0x0 /**< one shot timer */
  421. #define RT_TIMER_FLAG_PERIODIC 0x2 /**< periodic timer */
  422. #define RT_TIMER_FLAG_HARD_TIMER 0x0 /**< hard timer,the timer's callback function will be called in tick isr. */
  423. #define RT_TIMER_FLAG_SOFT_TIMER 0x4 /**< soft timer,the timer's callback function will be called in timer thread. */
  424. #define RT_TIMER_CTRL_SET_TIME 0x0 /**< set timer control command */
  425. #define RT_TIMER_CTRL_GET_TIME 0x1 /**< get timer control command */
  426. #define RT_TIMER_CTRL_SET_ONESHOT 0x2 /**< change timer to one shot */
  427. #define RT_TIMER_CTRL_SET_PERIODIC 0x3 /**< change timer to periodic */
  428. #define RT_TIMER_CTRL_GET_STATE 0x4 /**< get timer run state active or deactive*/
  429. #ifndef RT_TIMER_SKIP_LIST_LEVEL
  430. #define RT_TIMER_SKIP_LIST_LEVEL 1
  431. #endif
  432. /* 1 or 3 */
  433. #ifndef RT_TIMER_SKIP_LIST_MASK
  434. #define RT_TIMER_SKIP_LIST_MASK 0x3
  435. #endif
  436. /**
  437. * timer structure
  438. */
  439. struct rt_timer
  440. {
  441. struct rt_object parent; /**< inherit from rt_object */
  442. rt_list_t row[RT_TIMER_SKIP_LIST_LEVEL];
  443. void (*timeout_func)(void *parameter); /**< timeout function */
  444. void *parameter; /**< timeout function's parameter */
  445. rt_tick_t init_tick; /**< timer timeout tick */
  446. rt_tick_t timeout_tick; /**< timeout tick */
  447. };
  448. typedef struct rt_timer *rt_timer_t;
  449. /**@}*/
  450. /**
  451. * @addtogroup Signal
  452. */
  453. #ifdef RT_USING_SIGNALS
  454. #include <sys/signal.h>
  455. typedef unsigned long rt_sigset_t;
  456. typedef void (*rt_sighandler_t)(int signo);
  457. typedef siginfo_t rt_siginfo_t;
  458. #define RT_SIG_MAX 32
  459. #endif
  460. /**@}*/
  461. /**
  462. * @addtogroup Thread
  463. */
  464. /**@{*/
  465. /*
  466. * Thread
  467. */
  468. /*
  469. * thread state definitions
  470. */
  471. #define RT_THREAD_INIT 0x00 /**< Initialized status */
  472. #define RT_THREAD_READY 0x01 /**< Ready status */
  473. #define RT_THREAD_SUSPEND 0x02 /**< Suspend status */
  474. #define RT_THREAD_RUNNING 0x03 /**< Running status */
  475. #define RT_THREAD_BLOCK RT_THREAD_SUSPEND /**< Blocked status */
  476. #define RT_THREAD_CLOSE 0x04 /**< Closed status */
  477. #define RT_THREAD_STAT_MASK 0x07
  478. #define RT_THREAD_STAT_YIELD 0x08 /**< indicate whether remaining_tick has been reloaded since last schedule */
  479. #define RT_THREAD_STAT_YIELD_MASK RT_THREAD_STAT_YIELD
  480. #define RT_THREAD_STAT_SIGNAL 0x10 /**< task hold signals */
  481. #define RT_THREAD_STAT_SIGNAL_READY (RT_THREAD_STAT_SIGNAL | RT_THREAD_READY)
  482. #define RT_THREAD_STAT_SIGNAL_WAIT 0x20 /**< task is waiting for signals */
  483. #define RT_THREAD_STAT_SIGNAL_PENDING 0x40 /**< signals is held and it has not been procressed */
  484. #define RT_THREAD_STAT_SIGNAL_MASK 0xf0
  485. /**
  486. * thread control command definitions
  487. */
  488. #define RT_THREAD_CTRL_STARTUP 0x00 /**< Startup thread. */
  489. #define RT_THREAD_CTRL_CLOSE 0x01 /**< Close thread. */
  490. #define RT_THREAD_CTRL_CHANGE_PRIORITY 0x02 /**< Change thread priority. */
  491. #define RT_THREAD_CTRL_INFO 0x03 /**< Get thread information. */
  492. #define RT_THREAD_CTRL_BIND_CPU 0x04 /**< Set thread bind cpu. */
  493. #ifdef RT_USING_SMP
  494. #define RT_CPU_DETACHED RT_CPUS_NR /**< The thread not running on cpu. */
  495. #define RT_CPU_MASK ((1 << RT_CPUS_NR) - 1) /**< All CPUs mask bit. */
  496. #ifndef RT_SCHEDULE_IPI
  497. #define RT_SCHEDULE_IPI 0
  498. #endif
  499. #ifndef RT_STOP_IPI
  500. #define RT_STOP_IPI 1
  501. #endif
  502. /**
  503. * CPUs definitions
  504. *
  505. */
  506. struct rt_cpu
  507. {
  508. struct rt_thread *current_thread;
  509. rt_uint16_t irq_nest;
  510. rt_uint8_t irq_switch_flag;
  511. rt_uint8_t current_priority;
  512. rt_list_t priority_table[RT_THREAD_PRIORITY_MAX];
  513. #if RT_THREAD_PRIORITY_MAX > 32
  514. rt_uint32_t priority_group;
  515. rt_uint8_t ready_table[32];
  516. #else
  517. rt_uint32_t priority_group;
  518. #endif
  519. rt_tick_t tick;
  520. };
  521. #endif
  522. /**
  523. * Thread structure
  524. */
  525. struct rt_thread
  526. {
  527. /* rt object */
  528. char name[RT_NAME_MAX]; /**< the name of thread */
  529. rt_uint8_t type; /**< type of object */
  530. rt_uint8_t flags; /**< thread's flags */
  531. #ifdef RT_USING_MODULE
  532. void *module_id; /**< id of application module */
  533. #endif
  534. rt_list_t list; /**< the object list */
  535. rt_list_t tlist; /**< the thread list */
  536. /* stack point and entry */
  537. void *sp; /**< stack point */
  538. void *entry; /**< entry */
  539. void *parameter; /**< parameter */
  540. void *stack_addr; /**< stack address */
  541. rt_uint32_t stack_size; /**< stack size */
  542. /* error code */
  543. rt_err_t error; /**< error code */
  544. rt_uint8_t stat; /**< thread status */
  545. #ifdef RT_USING_SMP
  546. rt_uint8_t bind_cpu; /**< thread is bind to cpu */
  547. rt_uint8_t oncpu; /**< process on cpu` */
  548. rt_uint16_t scheduler_lock_nest; /**< scheduler lock count */
  549. rt_uint16_t cpus_lock_nest; /**< cpus lock count */
  550. rt_uint16_t critical_lock_nest; /**< critical lock count */
  551. #endif /*RT_USING_SMP*/
  552. /* priority */
  553. rt_uint8_t current_priority; /**< current priority */
  554. rt_uint8_t init_priority; /**< initialized priority */
  555. #if RT_THREAD_PRIORITY_MAX > 32
  556. rt_uint8_t number;
  557. rt_uint8_t high_mask;
  558. #endif
  559. rt_uint32_t number_mask;
  560. #if defined(RT_USING_EVENT)
  561. /* thread event */
  562. rt_uint32_t event_set;
  563. rt_uint8_t event_info;
  564. #endif
  565. #if defined(RT_USING_SIGNALS)
  566. rt_sigset_t sig_pending; /**< the pending signals */
  567. rt_sigset_t sig_mask; /**< the mask bits of signal */
  568. #ifndef RT_USING_SMP
  569. void *sig_ret; /**< the return stack pointer from signal */
  570. #endif
  571. rt_sighandler_t *sig_vectors; /**< vectors of signal handler */
  572. void *si_list; /**< the signal infor list */
  573. #endif
  574. rt_ubase_t init_tick; /**< thread's initialized tick */
  575. rt_ubase_t remaining_tick; /**< remaining tick */
  576. #ifdef RT_USING_CPU_USAGE
  577. rt_uint64_t duration_tick; /**< cpu usage tick */
  578. #endif
  579. struct rt_timer thread_timer; /**< built-in thread timer */
  580. void (*cleanup)(struct rt_thread *tid); /**< cleanup function when thread exit */
  581. /* light weight process if present */
  582. #ifdef RT_USING_LWP
  583. void *lwp;
  584. #endif
  585. rt_ubase_t user_data; /**< private user data beyond this thread */
  586. };
  587. typedef struct rt_thread *rt_thread_t;
  588. /**@}*/
  589. /**
  590. * @addtogroup IPC
  591. */
  592. /**@{*/
  593. /**
  594. * IPC flags and control command definitions
  595. */
  596. #define RT_IPC_FLAG_FIFO 0x00 /**< FIFOed IPC. @ref IPC. */
  597. #define RT_IPC_FLAG_PRIO 0x01 /**< PRIOed IPC. @ref IPC. */
  598. #define RT_IPC_CMD_UNKNOWN 0x00 /**< unknown IPC command */
  599. #define RT_IPC_CMD_RESET 0x01 /**< reset IPC object */
  600. #define RT_WAITING_FOREVER -1 /**< Block forever until get resource. */
  601. #define RT_WAITING_NO 0 /**< Non-block. */
  602. /**
  603. * Base structure of IPC object
  604. */
  605. struct rt_ipc_object
  606. {
  607. struct rt_object parent; /**< inherit from rt_object */
  608. rt_list_t suspend_thread; /**< threads pended on this resource */
  609. };
  610. #ifdef RT_USING_SEMAPHORE
  611. /**
  612. * Semaphore structure
  613. */
  614. struct rt_semaphore
  615. {
  616. struct rt_ipc_object parent; /**< inherit from ipc_object */
  617. rt_uint16_t value; /**< value of semaphore. */
  618. rt_uint16_t reserved; /**< reserved field */
  619. };
  620. typedef struct rt_semaphore *rt_sem_t;
  621. #endif
  622. #ifdef RT_USING_MUTEX
  623. /**
  624. * Mutual exclusion (mutex) structure
  625. */
  626. struct rt_mutex
  627. {
  628. struct rt_ipc_object parent; /**< inherit from ipc_object */
  629. rt_uint16_t value; /**< value of mutex */
  630. rt_uint8_t original_priority; /**< priority of last thread hold the mutex */
  631. rt_uint8_t hold; /**< numbers of thread hold the mutex */
  632. struct rt_thread *owner; /**< current owner of mutex */
  633. };
  634. typedef struct rt_mutex *rt_mutex_t;
  635. #endif
  636. #ifdef RT_USING_EVENT
  637. /**
  638. * flag defintions in event
  639. */
  640. #define RT_EVENT_FLAG_AND 0x01 /**< logic and */
  641. #define RT_EVENT_FLAG_OR 0x02 /**< logic or */
  642. #define RT_EVENT_FLAG_CLEAR 0x04 /**< clear flag */
  643. /*
  644. * event structure
  645. */
  646. struct rt_event
  647. {
  648. struct rt_ipc_object parent; /**< inherit from ipc_object */
  649. rt_uint32_t set; /**< event set */
  650. };
  651. typedef struct rt_event *rt_event_t;
  652. #endif
  653. #ifdef RT_USING_MAILBOX
  654. /**
  655. * mailbox structure
  656. */
  657. struct rt_mailbox
  658. {
  659. struct rt_ipc_object parent; /**< inherit from ipc_object */
  660. rt_ubase_t *msg_pool; /**< start address of message buffer */
  661. rt_uint16_t size; /**< size of message pool */
  662. rt_uint16_t entry; /**< index of messages in msg_pool */
  663. rt_uint16_t in_offset; /**< input offset of the message buffer */
  664. rt_uint16_t out_offset; /**< output offset of the message buffer */
  665. rt_list_t suspend_sender_thread; /**< sender thread suspended on this mailbox */
  666. };
  667. typedef struct rt_mailbox *rt_mailbox_t;
  668. #endif
  669. #ifdef RT_USING_MESSAGEQUEUE
  670. /**
  671. * message queue structure
  672. */
  673. struct rt_messagequeue
  674. {
  675. struct rt_ipc_object parent; /**< inherit from ipc_object */
  676. void *msg_pool; /**< start address of message queue */
  677. rt_uint16_t msg_size; /**< message size of each message */
  678. rt_uint16_t max_msgs; /**< max number of messages */
  679. rt_uint16_t entry; /**< index of messages in the queue */
  680. void *msg_queue_head; /**< list head */
  681. void *msg_queue_tail; /**< list tail */
  682. void *msg_queue_free; /**< pointer indicated the free node of queue */
  683. rt_list_t suspend_sender_thread; /**< sender thread suspended on this message queue */
  684. };
  685. typedef struct rt_messagequeue *rt_mq_t;
  686. #endif
  687. /**@}*/
  688. /**
  689. * @addtogroup MM
  690. */
  691. /**@{*/
  692. #ifdef RT_USING_HEAP
  693. /*
  694. * memory structure
  695. */
  696. struct rt_memory
  697. {
  698. struct rt_object parent; /**< inherit from rt_object */
  699. const char * algorithm; /**< Memory management algorithm name */
  700. rt_ubase_t address; /**< memory start address */
  701. rt_size_t total; /**< memory size */
  702. rt_size_t used; /**< size used */
  703. rt_size_t max; /**< maximum usage */
  704. };
  705. typedef struct rt_memory *rt_mem_t;
  706. #endif
  707. /*
  708. * memory management
  709. * heap & partition
  710. */
  711. #ifdef RT_USING_SMALL_MEM
  712. typedef rt_mem_t rt_smem_t;
  713. #endif
  714. #ifdef RT_USING_SLAB
  715. typedef rt_mem_t rt_slab_t;
  716. #endif
  717. #ifdef RT_USING_MEMHEAP
  718. /**
  719. * memory item on the heap
  720. */
  721. struct rt_memheap_item
  722. {
  723. rt_uint32_t magic; /**< magic number for memheap */
  724. struct rt_memheap *pool_ptr; /**< point of pool */
  725. struct rt_memheap_item *next; /**< next memheap item */
  726. struct rt_memheap_item *prev; /**< prev memheap item */
  727. struct rt_memheap_item *next_free; /**< next free memheap item */
  728. struct rt_memheap_item *prev_free; /**< prev free memheap item */
  729. #ifdef RT_USING_MEMTRACE
  730. rt_uint8_t owner_thread_name[4]; /**< owner thread name */
  731. #endif
  732. };
  733. /**
  734. * Base structure of memory heap object
  735. */
  736. struct rt_memheap
  737. {
  738. struct rt_object parent; /**< inherit from rt_object */
  739. void *start_addr; /**< pool start address and size */
  740. rt_uint32_t pool_size; /**< pool size */
  741. rt_uint32_t available_size; /**< available size */
  742. rt_uint32_t max_used_size; /**< maximum allocated size */
  743. struct rt_memheap_item *block_list; /**< used block list */
  744. struct rt_memheap_item *free_list; /**< free block list */
  745. struct rt_memheap_item free_header; /**< free block list header */
  746. struct rt_semaphore lock; /**< semaphore lock */
  747. rt_bool_t locked; /**< External lock mark */
  748. };
  749. #endif
  750. #ifdef RT_USING_MEMPOOL
  751. /**
  752. * Base structure of Memory pool object
  753. */
  754. struct rt_mempool
  755. {
  756. struct rt_object parent; /**< inherit from rt_object */
  757. void *start_address; /**< memory pool start */
  758. rt_size_t size; /**< size of memory pool */
  759. rt_size_t block_size; /**< size of memory blocks */
  760. rt_uint8_t *block_list; /**< memory blocks list */
  761. rt_size_t block_total_count; /**< numbers of memory block */
  762. rt_size_t block_free_count; /**< numbers of free memory block */
  763. rt_list_t suspend_thread; /**< threads pended on this resource */
  764. };
  765. typedef struct rt_mempool *rt_mp_t;
  766. #endif
  767. /**@}*/
  768. #ifdef RT_USING_DEVICE
  769. /**
  770. * @addtogroup Device
  771. */
  772. /**@{*/
  773. /**
  774. * device (I/O) class type
  775. */
  776. enum rt_device_class_type
  777. {
  778. RT_Device_Class_Char = 0, /**< character device */
  779. RT_Device_Class_Block, /**< block device */
  780. RT_Device_Class_NetIf, /**< net interface */
  781. RT_Device_Class_MTD, /**< memory device */
  782. RT_Device_Class_CAN, /**< CAN device */
  783. RT_Device_Class_RTC, /**< RTC device */
  784. RT_Device_Class_Sound, /**< Sound device */
  785. RT_Device_Class_Graphic, /**< Graphic device */
  786. RT_Device_Class_I2CBUS, /**< I2C bus device */
  787. RT_Device_Class_USBDevice, /**< USB slave device */
  788. RT_Device_Class_USBHost, /**< USB host bus */
  789. RT_Device_Class_USBOTG, /**< USB OTG bus */
  790. RT_Device_Class_SPIBUS, /**< SPI bus device */
  791. RT_Device_Class_SPIDevice, /**< SPI device */
  792. RT_Device_Class_SDIO, /**< SDIO bus device */
  793. RT_Device_Class_PM, /**< PM pseudo device */
  794. RT_Device_Class_Pipe, /**< Pipe device */
  795. RT_Device_Class_Portal, /**< Portal device */
  796. RT_Device_Class_Timer, /**< Timer device */
  797. RT_Device_Class_Miscellaneous, /**< Miscellaneous device */
  798. RT_Device_Class_Sensor, /**< Sensor device */
  799. RT_Device_Class_Touch, /**< Touch device */
  800. RT_Device_Class_PHY, /**< PHY device */
  801. RT_Device_Class_Security, /**< Security device */
  802. RT_Device_Class_Unknown /**< unknown device */
  803. };
  804. /**
  805. * device flags defitions
  806. */
  807. #define RT_DEVICE_FLAG_DEACTIVATE 0x000 /**< device is not not initialized */
  808. #define RT_DEVICE_FLAG_RDONLY 0x001 /**< read only */
  809. #define RT_DEVICE_FLAG_WRONLY 0x002 /**< write only */
  810. #define RT_DEVICE_FLAG_RDWR 0x003 /**< read and write */
  811. #define RT_DEVICE_FLAG_REMOVABLE 0x004 /**< removable device */
  812. #define RT_DEVICE_FLAG_STANDALONE 0x008 /**< standalone device */
  813. #define RT_DEVICE_FLAG_ACTIVATED 0x010 /**< device is activated */
  814. #define RT_DEVICE_FLAG_SUSPENDED 0x020 /**< device is suspended */
  815. #define RT_DEVICE_FLAG_STREAM 0x040 /**< stream mode */
  816. #define RT_DEVICE_FLAG_INT_RX 0x100 /**< INT mode on Rx */
  817. #define RT_DEVICE_FLAG_DMA_RX 0x200 /**< DMA mode on Rx */
  818. #define RT_DEVICE_FLAG_INT_TX 0x400 /**< INT mode on Tx */
  819. #define RT_DEVICE_FLAG_DMA_TX 0x800 /**< DMA mode on Tx */
  820. #define RT_DEVICE_OFLAG_CLOSE 0x000 /**< device is closed */
  821. #define RT_DEVICE_OFLAG_RDONLY 0x001 /**< read only access */
  822. #define RT_DEVICE_OFLAG_WRONLY 0x002 /**< write only access */
  823. #define RT_DEVICE_OFLAG_RDWR 0x003 /**< read and write */
  824. #define RT_DEVICE_OFLAG_OPEN 0x008 /**< device is opened */
  825. #define RT_DEVICE_OFLAG_MASK 0xf0f /**< mask of open flag */
  826. /**
  827. * general device commands
  828. */
  829. #define RT_DEVICE_CTRL_RESUME 0x01 /**< resume device */
  830. #define RT_DEVICE_CTRL_SUSPEND 0x02 /**< suspend device */
  831. #define RT_DEVICE_CTRL_CONFIG 0x03 /**< configure device */
  832. #define RT_DEVICE_CTRL_CLOSE 0x04 /**< close device */
  833. #define RT_DEVICE_CTRL_SET_INT 0x10 /**< set interrupt */
  834. #define RT_DEVICE_CTRL_CLR_INT 0x11 /**< clear interrupt */
  835. #define RT_DEVICE_CTRL_GET_INT 0x12 /**< get interrupt status */
  836. /**
  837. * special device commands
  838. */
  839. #define RT_DEVICE_CTRL_CHAR_STREAM 0x20 /**< stream mode on char device */
  840. #define RT_DEVICE_CTRL_BLK_GETGEOME 0x20 /**< get geometry information */
  841. #define RT_DEVICE_CTRL_BLK_SYNC 0x21 /**< flush data to block device */
  842. #define RT_DEVICE_CTRL_BLK_ERASE 0x22 /**< erase block on block device */
  843. #define RT_DEVICE_CTRL_BLK_AUTOREFRESH 0x23 /**< block device : enter/exit auto refresh mode */
  844. #define RT_DEVICE_CTRL_NETIF_GETMAC 0x20 /**< get mac address */
  845. #define RT_DEVICE_CTRL_MTD_FORMAT 0x20 /**< format a MTD device */
  846. typedef struct rt_device *rt_device_t;
  847. #ifdef RT_USING_DEVICE_OPS
  848. /**
  849. * operations set for device object
  850. */
  851. struct rt_device_ops
  852. {
  853. /* common device interface */
  854. rt_err_t (*init) (rt_device_t dev);
  855. rt_err_t (*open) (rt_device_t dev, rt_uint16_t oflag);
  856. rt_err_t (*close) (rt_device_t dev);
  857. rt_size_t (*read) (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size);
  858. rt_size_t (*write) (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size);
  859. rt_err_t (*control)(rt_device_t dev, int cmd, void *args);
  860. };
  861. #endif
  862. /**
  863. * WaitQueue structure
  864. */
  865. struct rt_wqueue
  866. {
  867. rt_uint32_t flag;
  868. rt_list_t waiting_list;
  869. };
  870. typedef struct rt_wqueue rt_wqueue_t;
  871. /**
  872. * Device structure
  873. */
  874. struct rt_device
  875. {
  876. struct rt_object parent; /**< inherit from rt_object */
  877. enum rt_device_class_type type; /**< device type */
  878. rt_uint16_t flag; /**< device flag */
  879. rt_uint16_t open_flag; /**< device open flag */
  880. rt_uint8_t ref_count; /**< reference count */
  881. rt_uint8_t device_id; /**< 0 - 255 */
  882. /* device call back */
  883. rt_err_t (*rx_indicate)(rt_device_t dev, rt_size_t size);
  884. rt_err_t (*tx_complete)(rt_device_t dev, void *buffer);
  885. #ifdef RT_USING_DEVICE_OPS
  886. const struct rt_device_ops *ops;
  887. #else
  888. /* common device interface */
  889. rt_err_t (*init) (rt_device_t dev);
  890. rt_err_t (*open) (rt_device_t dev, rt_uint16_t oflag);
  891. rt_err_t (*close) (rt_device_t dev);
  892. rt_size_t (*read) (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size);
  893. rt_size_t (*write) (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size);
  894. rt_err_t (*control)(rt_device_t dev, int cmd, void *args);
  895. #endif
  896. #ifdef RT_USING_POSIX_DEVIO
  897. const struct dfs_file_ops *fops;
  898. struct rt_wqueue wait_queue;
  899. #endif
  900. void *user_data; /**< device private data */
  901. };
  902. /**
  903. * block device geometry structure
  904. */
  905. struct rt_device_blk_geometry
  906. {
  907. rt_uint32_t sector_count; /**< count of sectors */
  908. rt_uint32_t bytes_per_sector; /**< number of bytes per sector */
  909. rt_uint32_t block_size; /**< number of bytes to erase one block */
  910. };
  911. /**
  912. * sector arrange struct on block device
  913. */
  914. struct rt_device_blk_sectors
  915. {
  916. rt_uint32_t sector_begin; /**< begin sector */
  917. rt_uint32_t sector_end; /**< end sector */
  918. };
  919. /**
  920. * cursor control command
  921. */
  922. #define RT_DEVICE_CTRL_CURSOR_SET_POSITION 0x10
  923. #define RT_DEVICE_CTRL_CURSOR_SET_TYPE 0x11
  924. /**
  925. * graphic device control command
  926. */
  927. #define RTGRAPHIC_CTRL_RECT_UPDATE 0
  928. #define RTGRAPHIC_CTRL_POWERON 1
  929. #define RTGRAPHIC_CTRL_POWEROFF 2
  930. #define RTGRAPHIC_CTRL_GET_INFO 3
  931. #define RTGRAPHIC_CTRL_SET_MODE 4
  932. #define RTGRAPHIC_CTRL_GET_EXT 5
  933. #define RTGRAPHIC_CTRL_SET_BRIGHTNESS 6
  934. #define RTGRAPHIC_CTRL_GET_BRIGHTNESS 7
  935. #define RTGRAPHIC_CTRL_GET_MODE 8
  936. #define RTGRAPHIC_CTRL_GET_STATUS 9
  937. /* graphic deice */
  938. enum
  939. {
  940. RTGRAPHIC_PIXEL_FORMAT_MONO = 0,
  941. RTGRAPHIC_PIXEL_FORMAT_GRAY4,
  942. RTGRAPHIC_PIXEL_FORMAT_GRAY16,
  943. RTGRAPHIC_PIXEL_FORMAT_RGB332,
  944. RTGRAPHIC_PIXEL_FORMAT_RGB444,
  945. RTGRAPHIC_PIXEL_FORMAT_RGB565,
  946. RTGRAPHIC_PIXEL_FORMAT_RGB565P,
  947. RTGRAPHIC_PIXEL_FORMAT_BGR565 = RTGRAPHIC_PIXEL_FORMAT_RGB565P,
  948. RTGRAPHIC_PIXEL_FORMAT_RGB666,
  949. RTGRAPHIC_PIXEL_FORMAT_RGB888,
  950. RTGRAPHIC_PIXEL_FORMAT_ARGB888,
  951. RTGRAPHIC_PIXEL_FORMAT_ABGR888,
  952. RTGRAPHIC_PIXEL_FORMAT_RESERVED,
  953. };
  954. /**
  955. * build a pixel position according to (x, y) coordinates.
  956. */
  957. #define RTGRAPHIC_PIXEL_POSITION(x, y) ((x << 16) | y)
  958. /**
  959. * graphic device information structure
  960. */
  961. struct rt_device_graphic_info
  962. {
  963. rt_uint8_t pixel_format; /**< graphic format */
  964. rt_uint8_t bits_per_pixel; /**< bits per pixel */
  965. rt_uint16_t pitch; /**< bytes per line */
  966. rt_uint16_t width; /**< width of graphic device */
  967. rt_uint16_t height; /**< height of graphic device */
  968. rt_uint8_t *framebuffer; /**< frame buffer */
  969. };
  970. /**
  971. * rectangle information structure
  972. */
  973. struct rt_device_rect_info
  974. {
  975. rt_uint16_t x; /**< x coordinate */
  976. rt_uint16_t y; /**< y coordinate */
  977. rt_uint16_t width; /**< width */
  978. rt_uint16_t height; /**< height */
  979. };
  980. /**
  981. * graphic operations
  982. */
  983. struct rt_device_graphic_ops
  984. {
  985. void (*set_pixel) (const char *pixel, int x, int y);
  986. void (*get_pixel) (char *pixel, int x, int y);
  987. void (*draw_hline)(const char *pixel, int x1, int x2, int y);
  988. void (*draw_vline)(const char *pixel, int x, int y1, int y2);
  989. void (*blit_line) (const char *pixel, int x, int y, rt_size_t size);
  990. };
  991. #define rt_graphix_ops(device) ((struct rt_device_graphic_ops *)(device->user_data))
  992. /**@}*/
  993. #endif
  994. #ifdef __cplusplus
  995. }
  996. #endif
  997. #ifdef __cplusplus
  998. /* RT-Thread definitions for C++ */
  999. namespace rtthread {
  1000. enum TICK_WAIT {
  1001. WAIT_NONE = 0,
  1002. WAIT_FOREVER = -1,
  1003. };
  1004. }
  1005. #endif /* end of __cplusplus */
  1006. #endif