rtdef.h 43 KB

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