rtdef.h 42 KB

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