rtdef.h 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203
  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. * 2022-01-01 Gabriel improve hooking method
  42. * 2022-01-07 Gabriel move some __on_rt_xxxxx_hook to dedicated c source files
  43. * 2022-01-12 Meco Man remove RT_THREAD_BLOCK
  44. */
  45. #ifndef __RT_DEF_H__
  46. #define __RT_DEF_H__
  47. /* include rtconfig header to import configuration */
  48. #include <rtconfig.h>
  49. #ifdef __cplusplus
  50. extern "C" {
  51. #endif
  52. /**
  53. * @addtogroup BasicDef
  54. */
  55. /**@{*/
  56. /* RT-Thread version information */
  57. #define RT_VERSION 4L /**< major version number */
  58. #define RT_SUBVERSION 1L /**< minor version number */
  59. #define RT_REVISION 0L /**< revise version number */
  60. /* RT-Thread version */
  61. #define RTTHREAD_VERSION ((RT_VERSION * 10000) + \
  62. (RT_SUBVERSION * 100) + RT_REVISION)
  63. /* RT-Thread basic data type definitions */
  64. #ifndef RT_USING_ARCH_DATA_TYPE
  65. typedef signed char rt_int8_t; /**< 8bit integer type */
  66. typedef signed short rt_int16_t; /**< 16bit integer type */
  67. typedef signed int rt_int32_t; /**< 32bit integer type */
  68. typedef unsigned char rt_uint8_t; /**< 8bit unsigned integer type */
  69. typedef unsigned short rt_uint16_t; /**< 16bit unsigned integer type */
  70. typedef unsigned int rt_uint32_t; /**< 32bit unsigned integer type */
  71. #ifdef ARCH_CPU_64BIT
  72. typedef signed long rt_int64_t; /**< 64bit integer type */
  73. typedef unsigned long rt_uint64_t; /**< 64bit unsigned integer type */
  74. typedef unsigned long rt_size_t; /**< Type for size number */
  75. #else
  76. typedef signed long long rt_int64_t; /**< 64bit integer type */
  77. typedef unsigned long long rt_uint64_t; /**< 64bit unsigned integer type */
  78. typedef unsigned int rt_size_t; /**< Type for size number */
  79. #endif /* ARCH_CPU_64BIT */
  80. #endif /* RT_USING_ARCH_DATA_TYPE */
  81. typedef int rt_bool_t; /**< boolean type */
  82. typedef long rt_base_t; /**< Nbit CPU related date type */
  83. typedef unsigned long rt_ubase_t; /**< Nbit unsigned CPU related data type */
  84. typedef rt_base_t rt_err_t; /**< Type for error number */
  85. typedef rt_uint32_t rt_time_t; /**< Type for time stamp */
  86. typedef rt_uint32_t rt_tick_t; /**< Type for tick count */
  87. typedef rt_base_t rt_flag_t; /**< Type for flags */
  88. typedef rt_ubase_t rt_dev_t; /**< Type for device */
  89. typedef rt_base_t rt_off_t; /**< Type for offset */
  90. /* boolean type definitions */
  91. #define RT_TRUE 1 /**< boolean true */
  92. #define RT_FALSE 0 /**< boolean fails */
  93. /**@}*/
  94. /* maximum value of base type */
  95. #define RT_UINT8_MAX 0xff /**< Maximum number of UINT8 */
  96. #define RT_UINT16_MAX 0xffff /**< Maximum number of UINT16 */
  97. #define RT_UINT32_MAX 0xffffffff /**< Maximum number of UINT32 */
  98. #define RT_TICK_MAX RT_UINT32_MAX /**< Maximum number of tick */
  99. /* maximum value of ipc type */
  100. #define RT_SEM_VALUE_MAX RT_UINT16_MAX /**< Maximum number of semaphore .value */
  101. #define RT_MUTEX_VALUE_MAX RT_UINT16_MAX /**< Maximum number of mutex .value */
  102. #define RT_MUTEX_HOLD_MAX RT_UINT8_MAX /**< Maximum number of mutex .hold */
  103. #define RT_MB_ENTRY_MAX RT_UINT16_MAX /**< Maximum number of mailbox .entry */
  104. #define RT_MQ_ENTRY_MAX RT_UINT16_MAX /**< Maximum number of message queue .entry */
  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
  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[] = ".rti_fn." level; \
  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[] = ".rti_fn." level; \
  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 initialization) */
  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. /* application 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. #ifndef RT_USING_HOOK
  400. #define __ON_HOOK_ARGS(__hook, argv)
  401. #define RT_OBJECT_HOOK_CALL(func, argv)
  402. #else
  403. #define RT_OBJECT_HOOK_CALL(func, argv) __on_##func argv
  404. #ifdef RT_HOOK_USING_FUNC_PTR
  405. #define __ON_HOOK_ARGS(__hook, argv) do {if ((__hook) != RT_NULL) __hook argv; } while (0)
  406. #else
  407. #define __ON_HOOK_ARGS(__hook, argv)
  408. #endif
  409. #endif
  410. #ifndef __on_rt_interrupt_switch_hook
  411. #define __on_rt_interrupt_switch_hook() __ON_HOOK_ARGS(rt_interrupt_switch_hook, ())
  412. #endif
  413. #ifndef __on_rt_malloc_hook
  414. #define __on_rt_malloc_hook(addr, size) __ON_HOOK_ARGS(rt_malloc_hook, (addr, size))
  415. #endif
  416. #ifndef __on_rt_free_hook
  417. #define __on_rt_free_hook(rmem) __ON_HOOK_ARGS(rt_free_hook, (rmem))
  418. #endif
  419. /**@}*/
  420. /**
  421. * @addtogroup Clock
  422. */
  423. /**@{*/
  424. /**
  425. * clock & timer macros
  426. */
  427. #define RT_TIMER_FLAG_DEACTIVATED 0x0 /**< timer is deactive */
  428. #define RT_TIMER_FLAG_ACTIVATED 0x1 /**< timer is active */
  429. #define RT_TIMER_FLAG_ONE_SHOT 0x0 /**< one shot timer */
  430. #define RT_TIMER_FLAG_PERIODIC 0x2 /**< periodic timer */
  431. #define RT_TIMER_FLAG_HARD_TIMER 0x0 /**< hard timer,the timer's callback function will be called in tick isr. */
  432. #define RT_TIMER_FLAG_SOFT_TIMER 0x4 /**< soft timer,the timer's callback function will be called in timer thread. */
  433. #define RT_TIMER_CTRL_SET_TIME 0x0 /**< set timer control command */
  434. #define RT_TIMER_CTRL_GET_TIME 0x1 /**< get timer control command */
  435. #define RT_TIMER_CTRL_SET_ONESHOT 0x2 /**< change timer to one shot */
  436. #define RT_TIMER_CTRL_SET_PERIODIC 0x3 /**< change timer to periodic */
  437. #define RT_TIMER_CTRL_GET_STATE 0x4 /**< get timer run state active or deactive*/
  438. #define RT_TIMER_CTRL_GET_REMAIN_TIME 0x5 /**< get the remaining hang time */
  439. #ifndef RT_TIMER_SKIP_LIST_LEVEL
  440. #define RT_TIMER_SKIP_LIST_LEVEL 1
  441. #endif
  442. /* 1 or 3 */
  443. #ifndef RT_TIMER_SKIP_LIST_MASK
  444. #define RT_TIMER_SKIP_LIST_MASK 0x3
  445. #endif
  446. /**
  447. * timer structure
  448. */
  449. struct rt_timer
  450. {
  451. struct rt_object parent; /**< inherit from rt_object */
  452. rt_list_t row[RT_TIMER_SKIP_LIST_LEVEL];
  453. void (*timeout_func)(void *parameter); /**< timeout function */
  454. void *parameter; /**< timeout function's parameter */
  455. rt_tick_t init_tick; /**< timer timeout tick */
  456. rt_tick_t timeout_tick; /**< timeout tick */
  457. };
  458. typedef struct rt_timer *rt_timer_t;
  459. /**@}*/
  460. /**
  461. * @addtogroup Signal
  462. */
  463. #ifdef RT_USING_SIGNALS
  464. #include <sys/signal.h>
  465. typedef unsigned long rt_sigset_t;
  466. typedef void (*rt_sighandler_t)(int signo);
  467. typedef siginfo_t rt_siginfo_t;
  468. #define RT_SIG_MAX 32
  469. #endif
  470. /**@}*/
  471. /**
  472. * @addtogroup Thread
  473. */
  474. /**@{*/
  475. /*
  476. * Thread
  477. */
  478. /*
  479. * thread state definitions
  480. */
  481. #define RT_THREAD_INIT 0x00 /**< Initialized status */
  482. #define RT_THREAD_READY 0x01 /**< Ready status */
  483. #define RT_THREAD_SUSPEND 0x02 /**< Suspend status */
  484. #define RT_THREAD_RUNNING 0x03 /**< Running status */
  485. #define RT_THREAD_CLOSE 0x04 /**< Closed status */
  486. #define RT_THREAD_STAT_MASK 0x07
  487. #define RT_THREAD_STAT_YIELD 0x08 /**< indicate whether remaining_tick has been reloaded since last schedule */
  488. #define RT_THREAD_STAT_YIELD_MASK RT_THREAD_STAT_YIELD
  489. #define RT_THREAD_STAT_SIGNAL 0x10 /**< task hold signals */
  490. #define RT_THREAD_STAT_SIGNAL_READY (RT_THREAD_STAT_SIGNAL | RT_THREAD_READY)
  491. #define RT_THREAD_STAT_SIGNAL_WAIT 0x20 /**< task is waiting for signals */
  492. #define RT_THREAD_STAT_SIGNAL_PENDING 0x40 /**< signals is held and it has not been procressed */
  493. #define RT_THREAD_STAT_SIGNAL_MASK 0xf0
  494. /**
  495. * thread control command definitions
  496. */
  497. #define RT_THREAD_CTRL_STARTUP 0x00 /**< Startup thread. */
  498. #define RT_THREAD_CTRL_CLOSE 0x01 /**< Close thread. */
  499. #define RT_THREAD_CTRL_CHANGE_PRIORITY 0x02 /**< Change thread priority. */
  500. #define RT_THREAD_CTRL_INFO 0x03 /**< Get thread information. */
  501. #define RT_THREAD_CTRL_BIND_CPU 0x04 /**< Set thread bind cpu. */
  502. #ifdef RT_USING_SMP
  503. #define RT_CPU_DETACHED RT_CPUS_NR /**< The thread not running on cpu. */
  504. #define RT_CPU_MASK ((1 << RT_CPUS_NR) - 1) /**< All CPUs mask bit. */
  505. #ifndef RT_SCHEDULE_IPI
  506. #define RT_SCHEDULE_IPI 0
  507. #endif
  508. #ifndef RT_STOP_IPI
  509. #define RT_STOP_IPI 1
  510. #endif
  511. /**
  512. * CPUs definitions
  513. *
  514. */
  515. struct rt_cpu
  516. {
  517. struct rt_thread *current_thread;
  518. rt_uint16_t irq_nest;
  519. rt_uint8_t irq_switch_flag;
  520. rt_uint8_t current_priority;
  521. rt_list_t priority_table[RT_THREAD_PRIORITY_MAX];
  522. #if RT_THREAD_PRIORITY_MAX > 32
  523. rt_uint32_t priority_group;
  524. rt_uint8_t ready_table[32];
  525. #else
  526. rt_uint32_t priority_group;
  527. #endif
  528. rt_tick_t tick;
  529. };
  530. #endif
  531. /**
  532. * Thread structure
  533. */
  534. struct rt_thread
  535. {
  536. /* rt object */
  537. char name[RT_NAME_MAX]; /**< the name of thread */
  538. rt_uint8_t type; /**< type of object */
  539. rt_uint8_t flags; /**< thread's flags */
  540. #ifdef RT_USING_MODULE
  541. void *module_id; /**< id of application module */
  542. #endif
  543. rt_list_t list; /**< the object list */
  544. rt_list_t tlist; /**< the thread list */
  545. /* stack point and entry */
  546. void *sp; /**< stack point */
  547. void *entry; /**< entry */
  548. void *parameter; /**< parameter */
  549. void *stack_addr; /**< stack address */
  550. rt_uint32_t stack_size; /**< stack size */
  551. /* error code */
  552. rt_err_t error; /**< error code */
  553. rt_uint8_t stat; /**< thread status */
  554. #ifdef RT_USING_SMP
  555. rt_uint8_t bind_cpu; /**< thread is bind to cpu */
  556. rt_uint8_t oncpu; /**< process on cpu */
  557. rt_uint16_t scheduler_lock_nest; /**< scheduler lock count */
  558. rt_uint16_t cpus_lock_nest; /**< cpus lock count */
  559. rt_uint16_t critical_lock_nest; /**< critical lock count */
  560. #endif /*RT_USING_SMP*/
  561. /* priority */
  562. rt_uint8_t current_priority; /**< current priority */
  563. #if RT_THREAD_PRIORITY_MAX > 32
  564. rt_uint8_t number;
  565. rt_uint8_t high_mask;
  566. #endif
  567. rt_uint32_t number_mask;
  568. #if defined(RT_USING_EVENT)
  569. /* thread event */
  570. rt_uint32_t event_set;
  571. rt_uint8_t event_info;
  572. #endif
  573. #if defined(RT_USING_SIGNALS)
  574. rt_sigset_t sig_pending; /**< the pending signals */
  575. rt_sigset_t sig_mask; /**< the mask bits of signal */
  576. #ifndef RT_USING_SMP
  577. void *sig_ret; /**< the return stack pointer from signal */
  578. #endif
  579. rt_sighandler_t *sig_vectors; /**< vectors of signal handler */
  580. void *si_list; /**< the signal infor list */
  581. #endif
  582. rt_ubase_t init_tick; /**< thread's initialized tick */
  583. rt_ubase_t remaining_tick; /**< remaining tick */
  584. #ifdef RT_USING_CPU_USAGE
  585. rt_uint64_t duration_tick; /**< cpu usage tick */
  586. #endif
  587. struct rt_timer thread_timer; /**< built-in thread timer */
  588. void (*cleanup)(struct rt_thread *tid); /**< cleanup function when thread exit */
  589. /* light weight process if present */
  590. #ifdef RT_USING_LWP
  591. void *lwp;
  592. #endif
  593. rt_ubase_t user_data; /**< private user data beyond this thread */
  594. };
  595. typedef struct rt_thread *rt_thread_t;
  596. /**@}*/
  597. /**
  598. * @addtogroup IPC
  599. */
  600. /**@{*/
  601. /**
  602. * IPC flags and control command definitions
  603. */
  604. #define RT_IPC_FLAG_FIFO 0x00 /**< FIFOed IPC. @ref IPC. */
  605. #define RT_IPC_FLAG_PRIO 0x01 /**< PRIOed IPC. @ref IPC. */
  606. #define RT_IPC_CMD_UNKNOWN 0x00 /**< unknown IPC command */
  607. #define RT_IPC_CMD_RESET 0x01 /**< reset IPC object */
  608. #define RT_WAITING_FOREVER -1 /**< Block forever until get resource. */
  609. #define RT_WAITING_NO 0 /**< Non-block. */
  610. /**
  611. * Base structure of IPC object
  612. */
  613. struct rt_ipc_object
  614. {
  615. struct rt_object parent; /**< inherit from rt_object */
  616. rt_list_t suspend_thread; /**< threads pended on this resource */
  617. };
  618. #ifdef RT_USING_SEMAPHORE
  619. /**
  620. * Semaphore structure
  621. */
  622. struct rt_semaphore
  623. {
  624. struct rt_ipc_object parent; /**< inherit from ipc_object */
  625. rt_uint16_t value; /**< value of semaphore. */
  626. rt_uint16_t reserved; /**< reserved field */
  627. };
  628. typedef struct rt_semaphore *rt_sem_t;
  629. #endif
  630. #ifdef RT_USING_MUTEX
  631. /**
  632. * Mutual exclusion (mutex) structure
  633. */
  634. struct rt_mutex
  635. {
  636. struct rt_ipc_object parent; /**< inherit from ipc_object */
  637. rt_uint16_t value; /**< value of mutex */
  638. rt_uint8_t original_priority; /**< priority of last thread hold the mutex */
  639. rt_uint8_t hold; /**< numbers of thread hold the mutex */
  640. struct rt_thread *owner; /**< current owner of mutex */
  641. };
  642. typedef struct rt_mutex *rt_mutex_t;
  643. #endif
  644. #ifdef RT_USING_EVENT
  645. /**
  646. * flag definitions in event
  647. */
  648. #define RT_EVENT_FLAG_AND 0x01 /**< logic and */
  649. #define RT_EVENT_FLAG_OR 0x02 /**< logic or */
  650. #define RT_EVENT_FLAG_CLEAR 0x04 /**< clear flag */
  651. /*
  652. * event structure
  653. */
  654. struct rt_event
  655. {
  656. struct rt_ipc_object parent; /**< inherit from ipc_object */
  657. rt_uint32_t set; /**< event set */
  658. };
  659. typedef struct rt_event *rt_event_t;
  660. #endif
  661. #ifdef RT_USING_MAILBOX
  662. /**
  663. * mailbox structure
  664. */
  665. struct rt_mailbox
  666. {
  667. struct rt_ipc_object parent; /**< inherit from ipc_object */
  668. rt_ubase_t *msg_pool; /**< start address of message buffer */
  669. rt_uint16_t size; /**< size of message pool */
  670. rt_uint16_t entry; /**< index of messages in msg_pool */
  671. rt_uint16_t in_offset; /**< input offset of the message buffer */
  672. rt_uint16_t out_offset; /**< output offset of the message buffer */
  673. rt_list_t suspend_sender_thread; /**< sender thread suspended on this mailbox */
  674. };
  675. typedef struct rt_mailbox *rt_mailbox_t;
  676. #endif
  677. #ifdef RT_USING_MESSAGEQUEUE
  678. /**
  679. * message queue structure
  680. */
  681. struct rt_messagequeue
  682. {
  683. struct rt_ipc_object parent; /**< inherit from ipc_object */
  684. void *msg_pool; /**< start address of message queue */
  685. rt_uint16_t msg_size; /**< message size of each message */
  686. rt_uint16_t max_msgs; /**< max number of messages */
  687. rt_uint16_t entry; /**< index of messages in the queue */
  688. void *msg_queue_head; /**< list head */
  689. void *msg_queue_tail; /**< list tail */
  690. void *msg_queue_free; /**< pointer indicated the free node of queue */
  691. rt_list_t suspend_sender_thread; /**< sender thread suspended on this message queue */
  692. };
  693. typedef struct rt_messagequeue *rt_mq_t;
  694. #endif
  695. /**@}*/
  696. /**
  697. * @addtogroup MM
  698. */
  699. /**@{*/
  700. #ifdef RT_USING_HEAP
  701. /*
  702. * memory structure
  703. */
  704. struct rt_memory
  705. {
  706. struct rt_object parent; /**< inherit from rt_object */
  707. const char * algorithm; /**< Memory management algorithm name */
  708. rt_ubase_t address; /**< memory start address */
  709. rt_size_t total; /**< memory size */
  710. rt_size_t used; /**< size used */
  711. rt_size_t max; /**< maximum usage */
  712. };
  713. typedef struct rt_memory *rt_mem_t;
  714. #endif
  715. /*
  716. * memory management
  717. * heap & partition
  718. */
  719. #ifdef RT_USING_SMALL_MEM
  720. typedef rt_mem_t rt_smem_t;
  721. #endif
  722. #ifdef RT_USING_SLAB
  723. typedef rt_mem_t rt_slab_t;
  724. #endif
  725. #ifdef RT_USING_MEMHEAP
  726. /**
  727. * memory item on the heap
  728. */
  729. struct rt_memheap_item
  730. {
  731. rt_uint32_t magic; /**< magic number for memheap */
  732. struct rt_memheap *pool_ptr; /**< point of pool */
  733. struct rt_memheap_item *next; /**< next memheap item */
  734. struct rt_memheap_item *prev; /**< prev memheap item */
  735. struct rt_memheap_item *next_free; /**< next free memheap item */
  736. struct rt_memheap_item *prev_free; /**< prev free memheap item */
  737. #ifdef RT_USING_MEMTRACE
  738. rt_uint8_t owner_thread_name[4]; /**< owner thread name */
  739. #endif
  740. };
  741. /**
  742. * Base structure of memory heap object
  743. */
  744. struct rt_memheap
  745. {
  746. struct rt_object parent; /**< inherit from rt_object */
  747. void *start_addr; /**< pool start address and size */
  748. rt_size_t pool_size; /**< pool size */
  749. rt_size_t available_size; /**< available size */
  750. rt_size_t max_used_size; /**< maximum allocated size */
  751. struct rt_memheap_item *block_list; /**< used block list */
  752. struct rt_memheap_item *free_list; /**< free block list */
  753. struct rt_memheap_item free_header; /**< free block list header */
  754. struct rt_semaphore lock; /**< semaphore lock */
  755. rt_bool_t locked; /**< External lock mark */
  756. };
  757. #endif
  758. #ifdef RT_USING_MEMPOOL
  759. /**
  760. * Base structure of Memory pool object
  761. */
  762. struct rt_mempool
  763. {
  764. struct rt_object parent; /**< inherit from rt_object */
  765. void *start_address; /**< memory pool start */
  766. rt_size_t size; /**< size of memory pool */
  767. rt_size_t block_size; /**< size of memory blocks */
  768. rt_uint8_t *block_list; /**< memory blocks list */
  769. rt_size_t block_total_count; /**< numbers of memory block */
  770. rt_size_t block_free_count; /**< numbers of free memory block */
  771. rt_list_t suspend_thread; /**< threads pended on this resource */
  772. };
  773. typedef struct rt_mempool *rt_mp_t;
  774. #endif
  775. /**@}*/
  776. #ifdef RT_USING_DEVICE
  777. /**
  778. * @addtogroup Device
  779. */
  780. /**@{*/
  781. /**
  782. * device (I/O) class type
  783. */
  784. enum rt_device_class_type
  785. {
  786. RT_Device_Class_Char = 0, /**< character device */
  787. RT_Device_Class_Block, /**< block device */
  788. RT_Device_Class_NetIf, /**< net interface */
  789. RT_Device_Class_MTD, /**< memory device */
  790. RT_Device_Class_CAN, /**< CAN device */
  791. RT_Device_Class_RTC, /**< RTC device */
  792. RT_Device_Class_Sound, /**< Sound device */
  793. RT_Device_Class_Graphic, /**< Graphic device */
  794. RT_Device_Class_I2CBUS, /**< I2C bus device */
  795. RT_Device_Class_USBDevice, /**< USB slave device */
  796. RT_Device_Class_USBHost, /**< USB host bus */
  797. RT_Device_Class_USBOTG, /**< USB OTG bus */
  798. RT_Device_Class_SPIBUS, /**< SPI bus device */
  799. RT_Device_Class_SPIDevice, /**< SPI device */
  800. RT_Device_Class_SDIO, /**< SDIO bus device */
  801. RT_Device_Class_PM, /**< PM pseudo device */
  802. RT_Device_Class_Pipe, /**< Pipe device */
  803. RT_Device_Class_Portal, /**< Portal device */
  804. RT_Device_Class_Timer, /**< Timer device */
  805. RT_Device_Class_Miscellaneous, /**< Miscellaneous device */
  806. RT_Device_Class_Sensor, /**< Sensor device */
  807. RT_Device_Class_Touch, /**< Touch device */
  808. RT_Device_Class_PHY, /**< PHY device */
  809. RT_Device_Class_Security, /**< Security device */
  810. RT_Device_Class_Unknown /**< unknown device */
  811. };
  812. /**
  813. * device flags definitions
  814. */
  815. #define RT_DEVICE_FLAG_DEACTIVATE 0x000 /**< device is not not initialized */
  816. #define RT_DEVICE_FLAG_RDONLY 0x001 /**< read only */
  817. #define RT_DEVICE_FLAG_WRONLY 0x002 /**< write only */
  818. #define RT_DEVICE_FLAG_RDWR 0x003 /**< read and write */
  819. #define RT_DEVICE_FLAG_REMOVABLE 0x004 /**< removable device */
  820. #define RT_DEVICE_FLAG_STANDALONE 0x008 /**< standalone device */
  821. #define RT_DEVICE_FLAG_ACTIVATED 0x010 /**< device is activated */
  822. #define RT_DEVICE_FLAG_SUSPENDED 0x020 /**< device is suspended */
  823. #define RT_DEVICE_FLAG_STREAM 0x040 /**< stream mode */
  824. #define RT_DEVICE_FLAG_INT_RX 0x100 /**< INT mode on Rx */
  825. #define RT_DEVICE_FLAG_DMA_RX 0x200 /**< DMA mode on Rx */
  826. #define RT_DEVICE_FLAG_INT_TX 0x400 /**< INT mode on Tx */
  827. #define RT_DEVICE_FLAG_DMA_TX 0x800 /**< DMA mode on Tx */
  828. #define RT_DEVICE_OFLAG_CLOSE 0x000 /**< device is closed */
  829. #define RT_DEVICE_OFLAG_RDONLY 0x001 /**< read only access */
  830. #define RT_DEVICE_OFLAG_WRONLY 0x002 /**< write only access */
  831. #define RT_DEVICE_OFLAG_RDWR 0x003 /**< read and write */
  832. #define RT_DEVICE_OFLAG_OPEN 0x008 /**< device is opened */
  833. #define RT_DEVICE_OFLAG_MASK 0xf0f /**< mask of open flag */
  834. /**
  835. * general device commands
  836. */
  837. #define RT_DEVICE_CTRL_RESUME 0x01 /**< resume device */
  838. #define RT_DEVICE_CTRL_SUSPEND 0x02 /**< suspend device */
  839. #define RT_DEVICE_CTRL_CONFIG 0x03 /**< configure device */
  840. #define RT_DEVICE_CTRL_CLOSE 0x04 /**< close device */
  841. #define RT_DEVICE_CTRL_SET_INT 0x10 /**< set interrupt */
  842. #define RT_DEVICE_CTRL_CLR_INT 0x11 /**< clear interrupt */
  843. #define RT_DEVICE_CTRL_GET_INT 0x12 /**< get interrupt status */
  844. /**
  845. * special device commands
  846. */
  847. #define RT_DEVICE_CTRL_CHAR_STREAM 0x20 /**< stream mode on char device */
  848. #define RT_DEVICE_CTRL_BLK_GETGEOME 0x20 /**< get geometry information */
  849. #define RT_DEVICE_CTRL_BLK_SYNC 0x21 /**< flush data to block device */
  850. #define RT_DEVICE_CTRL_BLK_ERASE 0x22 /**< erase block on block device */
  851. #define RT_DEVICE_CTRL_BLK_AUTOREFRESH 0x23 /**< block device : enter/exit auto refresh mode */
  852. #define RT_DEVICE_CTRL_NETIF_GETMAC 0x20 /**< get mac address */
  853. #define RT_DEVICE_CTRL_MTD_FORMAT 0x20 /**< format a MTD device */
  854. typedef struct rt_device *rt_device_t;
  855. #ifdef RT_USING_DEVICE_OPS
  856. /**
  857. * operations set for device object
  858. */
  859. struct rt_device_ops
  860. {
  861. /* common device interface */
  862. rt_err_t (*init) (rt_device_t dev);
  863. rt_err_t (*open) (rt_device_t dev, rt_uint16_t oflag);
  864. rt_err_t (*close) (rt_device_t dev);
  865. rt_size_t (*read) (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size);
  866. rt_size_t (*write) (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size);
  867. rt_err_t (*control)(rt_device_t dev, int cmd, void *args);
  868. };
  869. #endif
  870. /**
  871. * WaitQueue structure
  872. */
  873. struct rt_wqueue
  874. {
  875. rt_uint32_t flag;
  876. rt_list_t waiting_list;
  877. };
  878. typedef struct rt_wqueue rt_wqueue_t;
  879. /**
  880. * Device structure
  881. */
  882. struct rt_device
  883. {
  884. struct rt_object parent; /**< inherit from rt_object */
  885. enum rt_device_class_type type; /**< device type */
  886. rt_uint16_t flag; /**< device flag */
  887. rt_uint16_t open_flag; /**< device open flag */
  888. rt_uint8_t ref_count; /**< reference count */
  889. rt_uint8_t device_id; /**< 0 - 255 */
  890. /* device call back */
  891. rt_err_t (*rx_indicate)(rt_device_t dev, rt_size_t size);
  892. rt_err_t (*tx_complete)(rt_device_t dev, void *buffer);
  893. #ifdef RT_USING_DEVICE_OPS
  894. const struct rt_device_ops *ops;
  895. #else
  896. /* common device interface */
  897. rt_err_t (*init) (rt_device_t dev);
  898. rt_err_t (*open) (rt_device_t dev, rt_uint16_t oflag);
  899. rt_err_t (*close) (rt_device_t dev);
  900. rt_size_t (*read) (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size);
  901. rt_size_t (*write) (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size);
  902. rt_err_t (*control)(rt_device_t dev, int cmd, void *args);
  903. #endif
  904. #ifdef RT_USING_POSIX_DEVIO
  905. const struct dfs_file_ops *fops;
  906. struct rt_wqueue wait_queue;
  907. #endif
  908. void *user_data; /**< device private data */
  909. };
  910. /**
  911. * block device geometry structure
  912. */
  913. struct rt_device_blk_geometry
  914. {
  915. rt_uint32_t sector_count; /**< count of sectors */
  916. rt_uint32_t bytes_per_sector; /**< number of bytes per sector */
  917. rt_uint32_t block_size; /**< number of bytes to erase one block */
  918. };
  919. /**
  920. * sector arrange struct on block device
  921. */
  922. struct rt_device_blk_sectors
  923. {
  924. rt_uint32_t sector_begin; /**< begin sector */
  925. rt_uint32_t sector_end; /**< end sector */
  926. };
  927. /**
  928. * cursor control command
  929. */
  930. #define RT_DEVICE_CTRL_CURSOR_SET_POSITION 0x10
  931. #define RT_DEVICE_CTRL_CURSOR_SET_TYPE 0x11
  932. /**
  933. * graphic device control command
  934. */
  935. #define RTGRAPHIC_CTRL_RECT_UPDATE 0
  936. #define RTGRAPHIC_CTRL_POWERON 1
  937. #define RTGRAPHIC_CTRL_POWEROFF 2
  938. #define RTGRAPHIC_CTRL_GET_INFO 3
  939. #define RTGRAPHIC_CTRL_SET_MODE 4
  940. #define RTGRAPHIC_CTRL_GET_EXT 5
  941. #define RTGRAPHIC_CTRL_SET_BRIGHTNESS 6
  942. #define RTGRAPHIC_CTRL_GET_BRIGHTNESS 7
  943. #define RTGRAPHIC_CTRL_GET_MODE 8
  944. #define RTGRAPHIC_CTRL_GET_STATUS 9
  945. #define RTGRAPHIC_CTRL_PAN_DISPLAY 10
  946. #define RTGRAPHIC_CTRL_WAIT_VSYNC 11
  947. /* graphic device */
  948. enum
  949. {
  950. RTGRAPHIC_PIXEL_FORMAT_MONO = 0,
  951. RTGRAPHIC_PIXEL_FORMAT_GRAY4,
  952. RTGRAPHIC_PIXEL_FORMAT_GRAY16,
  953. RTGRAPHIC_PIXEL_FORMAT_RGB332,
  954. RTGRAPHIC_PIXEL_FORMAT_RGB444,
  955. RTGRAPHIC_PIXEL_FORMAT_RGB565,
  956. RTGRAPHIC_PIXEL_FORMAT_RGB565P,
  957. RTGRAPHIC_PIXEL_FORMAT_BGR565 = RTGRAPHIC_PIXEL_FORMAT_RGB565P,
  958. RTGRAPHIC_PIXEL_FORMAT_RGB666,
  959. RTGRAPHIC_PIXEL_FORMAT_RGB888,
  960. RTGRAPHIC_PIXEL_FORMAT_ARGB888,
  961. RTGRAPHIC_PIXEL_FORMAT_ABGR888,
  962. RTGRAPHIC_PIXEL_FORMAT_RESERVED,
  963. };
  964. /**
  965. * build a pixel position according to (x, y) coordinates.
  966. */
  967. #define RTGRAPHIC_PIXEL_POSITION(x, y) ((x << 16) | y)
  968. /**
  969. * graphic device information structure
  970. */
  971. struct rt_device_graphic_info
  972. {
  973. rt_uint8_t pixel_format; /**< graphic format */
  974. rt_uint8_t bits_per_pixel; /**< bits per pixel */
  975. rt_uint16_t pitch; /**< bytes per line */
  976. rt_uint16_t width; /**< width of graphic device */
  977. rt_uint16_t height; /**< height of graphic device */
  978. rt_uint8_t *framebuffer; /**< frame buffer */
  979. rt_uint32_t smem_len; /**< allocated frame buffer size */
  980. };
  981. /**
  982. * rectangle information structure
  983. */
  984. struct rt_device_rect_info
  985. {
  986. rt_uint16_t x; /**< x coordinate */
  987. rt_uint16_t y; /**< y coordinate */
  988. rt_uint16_t width; /**< width */
  989. rt_uint16_t height; /**< height */
  990. };
  991. /**
  992. * graphic operations
  993. */
  994. struct rt_device_graphic_ops
  995. {
  996. void (*set_pixel) (const char *pixel, int x, int y);
  997. void (*get_pixel) (char *pixel, int x, int y);
  998. void (*draw_hline)(const char *pixel, int x1, int x2, int y);
  999. void (*draw_vline)(const char *pixel, int x, int y1, int y2);
  1000. void (*blit_line) (const char *pixel, int x, int y, rt_size_t size);
  1001. };
  1002. #define rt_graphix_ops(device) ((struct rt_device_graphic_ops *)(device->user_data))
  1003. /**@}*/
  1004. #endif
  1005. #ifdef __cplusplus
  1006. }
  1007. #endif
  1008. #ifdef __cplusplus
  1009. /* RT-Thread definitions for C++ */
  1010. namespace rtthread {
  1011. enum TICK_WAIT {
  1012. WAIT_NONE = 0,
  1013. WAIT_FOREVER = -1,
  1014. };
  1015. }
  1016. #endif /* end of __cplusplus */
  1017. #endif