rtdef.h 43 KB

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