rtdef.h 45 KB

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