rtdef.h 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242
  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_Unknown = 0x0d, /**< The object is unknown. */
  359. RT_Object_Class_Static = 0x80 /**< The object is a static object. */
  360. };
  361. /**
  362. * The information of the kernel object
  363. */
  364. struct rt_object_information
  365. {
  366. enum rt_object_class_type type; /**< object class type */
  367. rt_list_t object_list; /**< object list */
  368. rt_size_t object_size; /**< object size */
  369. };
  370. /**
  371. * The hook function call macro
  372. */
  373. #ifdef RT_USING_HOOK
  374. #define RT_OBJECT_HOOK_CALL(func, argv) \
  375. do { if ((func) != RT_NULL) func argv; } while (0)
  376. #else
  377. #define RT_OBJECT_HOOK_CALL(func, argv)
  378. #endif
  379. /**@}*/
  380. /**
  381. * @addtogroup Clock
  382. */
  383. /**@{*/
  384. /**
  385. * clock & timer macros
  386. */
  387. #define RT_TIMER_FLAG_DEACTIVATED 0x0 /**< timer is deactive */
  388. #define RT_TIMER_FLAG_ACTIVATED 0x1 /**< timer is active */
  389. #define RT_TIMER_FLAG_ONE_SHOT 0x0 /**< one shot timer */
  390. #define RT_TIMER_FLAG_PERIODIC 0x2 /**< periodic timer */
  391. #define RT_TIMER_FLAG_HARD_TIMER 0x0 /**< hard timer,the timer's callback function will be called in tick isr. */
  392. #define RT_TIMER_FLAG_SOFT_TIMER 0x4 /**< soft timer,the timer's callback function will be called in timer thread. */
  393. #define RT_TIMER_CTRL_SET_TIME 0x0 /**< set timer control command */
  394. #define RT_TIMER_CTRL_GET_TIME 0x1 /**< get timer control command */
  395. #define RT_TIMER_CTRL_SET_ONESHOT 0x2 /**< change timer to one shot */
  396. #define RT_TIMER_CTRL_SET_PERIODIC 0x3 /**< change timer to periodic */
  397. #define RT_TIMER_CTRL_GET_STATE 0x4 /**< get timer run state active or deactive*/
  398. #define RT_TIMER_CTRL_GET_FUNC 0x5 /**< get timer timeout func */
  399. #define RT_TIMER_CTRL_SET_FUNC 0x6 /**< set timer timeout func */
  400. #define RT_TIMER_CTRL_GET_PARM 0x7 /**< get timer parameter */
  401. #define RT_TIMER_CTRL_SET_PARM 0x8 /**< get timer parameter */
  402. #ifndef RT_TIMER_SKIP_LIST_LEVEL
  403. #define RT_TIMER_SKIP_LIST_LEVEL 1
  404. #endif
  405. /* 1 or 3 */
  406. #ifndef RT_TIMER_SKIP_LIST_MASK
  407. #define RT_TIMER_SKIP_LIST_MASK 0x3
  408. #endif
  409. /**
  410. * timer structure
  411. */
  412. struct rt_timer
  413. {
  414. struct rt_object parent; /**< inherit from rt_object */
  415. rt_list_t row[RT_TIMER_SKIP_LIST_LEVEL];
  416. void (*timeout_func)(void *parameter); /**< timeout function */
  417. void *parameter; /**< timeout function's parameter */
  418. rt_tick_t init_tick; /**< timer timeout tick */
  419. rt_tick_t timeout_tick; /**< timeout tick */
  420. };
  421. typedef struct rt_timer *rt_timer_t;
  422. /**@}*/
  423. /**
  424. * @addtogroup Signal
  425. */
  426. #ifdef RT_USING_SIGNALS
  427. #include <libc/libc_signal.h>
  428. typedef unsigned long rt_sigset_t;
  429. typedef void (*rt_sighandler_t)(int signo);
  430. typedef siginfo_t rt_siginfo_t;
  431. #define RT_SIG_MAX 32
  432. #endif
  433. /**@}*/
  434. /**
  435. * @addtogroup Thread
  436. */
  437. /**@{*/
  438. /*
  439. * Thread
  440. */
  441. /*
  442. * thread state definitions
  443. */
  444. #define RT_THREAD_INIT 0x00 /**< Initialized status */
  445. #define RT_THREAD_CLOSE 0x01 /**< Closed status */
  446. #define RT_THREAD_READY 0x02 /**< Ready status */
  447. #define RT_THREAD_RUNNING 0x03 /**< Running status */
  448. /*
  449. * for rt_thread_set_suspend_state()
  450. */
  451. enum
  452. {
  453. RT_INTERRUPTIBLE = 0,
  454. RT_KILLABLE,
  455. RT_UNINTERRUPTIBLE,
  456. };
  457. #define RT_THREAD_SUSPEND_MASK 0x04
  458. #define RT_SIGNAL_COMMON_WAKEUP_MASK 0x02
  459. #define RT_SIGNAL_KILL_WAKEUP_MASK 0x01
  460. #define RT_THREAD_SUSPEND_INTERRUPTIBLE (RT_THREAD_SUSPEND_MASK) /**< Suspend interruptable 0x4 */
  461. #define RT_THREAD_SUSPEND RT_THREAD_SUSPEND_INTERRUPTIBLE
  462. #define RT_THREAD_SUSPEND_KILLABLE (RT_THREAD_SUSPEND_MASK | RT_SIGNAL_COMMON_WAKEUP_MASK) /**< Suspend with killable 0x6 */
  463. #define RT_THREAD_SUSPEND_UNINTERRUPTIBLE (RT_THREAD_SUSPEND_MASK | RT_SIGNAL_COMMON_WAKEUP_MASK | RT_SIGNAL_KILL_WAKEUP_MASK) /**< Suspend with uninterruptable 0x7 */
  464. #define RT_THREAD_STAT_MASK 0x07
  465. #define RT_THREAD_STAT_YIELD 0x08 /**< indicate whether remaining_tick has been reloaded since last schedule */
  466. #define RT_THREAD_STAT_YIELD_MASK RT_THREAD_STAT_YIELD
  467. #define RT_THREAD_STAT_SIGNAL 0x10 /**< task hold signals */
  468. #define RT_THREAD_STAT_SIGNAL_READY (RT_THREAD_STAT_SIGNAL | RT_THREAD_READY)
  469. #define RT_THREAD_STAT_SIGNAL_WAIT 0x20 /**< task is waiting for signals */
  470. #define RT_THREAD_STAT_SIGNAL_PENDING 0x40 /**< signals is held and it has not been procressed */
  471. #define RT_THREAD_STAT_SIGNAL_MASK 0xf0
  472. /**
  473. * thread control command definitions
  474. */
  475. #define RT_THREAD_CTRL_STARTUP 0x00 /**< Startup thread. */
  476. #define RT_THREAD_CTRL_CLOSE 0x01 /**< Close thread. */
  477. #define RT_THREAD_CTRL_CHANGE_PRIORITY 0x02 /**< Change thread priority. */
  478. #define RT_THREAD_CTRL_INFO 0x03 /**< Get thread information. */
  479. #define RT_THREAD_CTRL_BIND_CPU 0x04 /**< Set thread bind cpu. */
  480. #ifdef RT_USING_SMP
  481. #define RT_CPU_DETACHED RT_CPUS_NR /**< The thread not running on cpu. */
  482. #define RT_CPU_MASK ((1 << RT_CPUS_NR) - 1) /**< All CPUs mask bit. */
  483. #ifndef RT_SCHEDULE_IPI
  484. #define RT_SCHEDULE_IPI 0
  485. #endif
  486. /**
  487. * CPUs definitions
  488. *
  489. */
  490. struct rt_cpu
  491. {
  492. struct rt_thread *current_thread;
  493. rt_uint16_t irq_nest;
  494. rt_uint8_t irq_switch_flag;
  495. rt_uint8_t current_priority;
  496. rt_list_t priority_table[RT_THREAD_PRIORITY_MAX];
  497. #if RT_THREAD_PRIORITY_MAX > 32
  498. rt_uint32_t priority_group;
  499. rt_uint8_t ready_table[32];
  500. #else
  501. rt_uint32_t priority_group;
  502. #endif
  503. rt_tick_t tick;
  504. };
  505. #endif
  506. struct rt_thread;
  507. #ifdef RT_USING_LWP
  508. typedef rt_err_t (*rt_wakeup_func_t)(void *object, struct rt_thread *thread);
  509. struct rt_wakeup
  510. {
  511. rt_wakeup_func_t func;
  512. void *user_data;
  513. };
  514. #define _LWP_NSIG 64
  515. #define _LWP_NSIG_BPW 32
  516. #define _LWP_NSIG_WORDS (_LWP_NSIG / _LWP_NSIG_BPW)
  517. typedef void (*lwp_sighandler_t)(int);
  518. typedef struct {
  519. unsigned long sig[_LWP_NSIG_WORDS];
  520. } lwp_sigset_t;
  521. struct rt_user_context
  522. {
  523. void *sp;
  524. void *pc;
  525. void *flag;
  526. };
  527. #endif
  528. /**
  529. * Thread structure
  530. */
  531. struct rt_thread
  532. {
  533. /* rt object */
  534. char name[RT_NAME_MAX]; /**< the name of thread */
  535. rt_uint8_t type; /**< type of object */
  536. rt_uint8_t flags; /**< thread's flags */
  537. #ifdef RT_USING_MODULE
  538. void *module_id; /**< id of application module */
  539. #endif
  540. #ifdef RT_USING_LWP
  541. rt_list_t lwp_obj_list; /**< list node of kernel object for lwp */
  542. #endif
  543. rt_list_t list; /**< the object list */
  544. rt_list_t tlist; /**< the thread list */
  545. /* stack point and entry */
  546. void *sp; /**< stack point */
  547. void *entry; /**< entry */
  548. void *parameter; /**< parameter */
  549. void *stack_addr; /**< stack address */
  550. rt_uint32_t stack_size; /**< stack size */
  551. /* error code */
  552. rt_err_t error; /**< error code */
  553. rt_uint8_t stat; /**< thread status */
  554. #ifdef RT_USING_SMP
  555. rt_uint8_t bind_cpu; /**< thread is bind to cpu */
  556. rt_uint8_t oncpu; /**< process on cpu` */
  557. rt_uint16_t scheduler_lock_nest; /**< scheduler lock count */
  558. rt_uint16_t cpus_lock_nest; /**< cpus lock count */
  559. rt_uint16_t critical_lock_nest; /**< critical lock count */
  560. #endif /*RT_USING_SMP*/
  561. /* priority */
  562. rt_uint8_t current_priority; /**< current priority */
  563. rt_uint8_t init_priority; /**< initialized priority */
  564. #if RT_THREAD_PRIORITY_MAX > 32
  565. rt_uint8_t number;
  566. rt_uint8_t high_mask;
  567. #endif
  568. rt_uint32_t number_mask;
  569. #if defined(RT_USING_EVENT)
  570. /* thread event */
  571. rt_uint32_t event_set;
  572. rt_uint8_t event_info;
  573. #endif
  574. #if defined(RT_USING_SIGNALS)
  575. rt_sigset_t sig_pending; /**< the pending signals */
  576. rt_sigset_t sig_mask; /**< the mask bits of signal */
  577. #ifndef RT_USING_SMP
  578. void *sig_ret; /**< the return stack pointer from signal */
  579. #endif
  580. rt_sighandler_t *sig_vectors; /**< vectors of signal handler */
  581. void *si_list; /**< the signal infor list */
  582. #endif
  583. #if defined(RT_USING_LWP)
  584. void *msg_ret; /**< the return msg */
  585. #endif
  586. rt_ubase_t init_tick; /**< thread's initialized tick */
  587. rt_ubase_t remaining_tick; /**< remaining tick */
  588. rt_ubase_t tick_mark;
  589. rt_ubase_t run_tick;
  590. struct rt_timer thread_timer; /**< built-in thread timer */
  591. void (*cleanup)(struct rt_thread *tid); /**< cleanup function when thread exit */
  592. /* light weight process if present */
  593. #ifdef RT_USING_LWP
  594. void *lwp;
  595. /* for user create */
  596. void *user_entry;
  597. void *user_stack;
  598. rt_uint32_t user_stack_size;
  599. rt_uint32_t *kernel_sp; /**< kernel stack point */
  600. rt_list_t sibling; /**< next thread of same process */
  601. lwp_sigset_t signal;
  602. lwp_sigset_t signal_mask;
  603. int signal_mask_bak;
  604. rt_uint32_t signal_in_process;
  605. lwp_sighandler_t signal_handler[_LWP_NSIG];
  606. struct rt_user_context user_ctx;
  607. struct rt_wakeup wakeup; /**< wakeup data */
  608. int exit_request;
  609. #ifdef RT_USING_USERSPACE
  610. int step_exec;
  611. int debug_ret_user;
  612. int debug_suspend;
  613. struct rt_hw_exp_stack *regs;
  614. void * thread_idr; /** lwp thread indicator */
  615. #endif
  616. #endif
  617. rt_ubase_t user_data; /**< private user data beyond this thread */
  618. };
  619. typedef struct rt_thread *rt_thread_t;
  620. /**@}*/
  621. /**
  622. * @addtogroup IPC
  623. */
  624. /**@{*/
  625. /**
  626. * IPC flags and control command definitions
  627. */
  628. #define RT_IPC_FLAG_FIFO 0x00 /**< FIFOed IPC. @ref IPC. */
  629. #define RT_IPC_FLAG_PRIO 0x01 /**< PRIOed IPC. @ref IPC. */
  630. #define RT_IPC_CMD_UNKNOWN 0x00 /**< unknown IPC command */
  631. #define RT_IPC_CMD_RESET 0x01 /**< reset IPC object */
  632. #define RT_WAITING_FOREVER -1 /**< Block forever until get resource. */
  633. #define RT_WAITING_NO 0 /**< Non-block. */
  634. /**
  635. * Base structure of IPC object
  636. */
  637. struct rt_ipc_object
  638. {
  639. struct rt_object parent; /**< inherit from rt_object */
  640. rt_list_t suspend_thread; /**< threads pended on this resource */
  641. };
  642. #ifdef RT_USING_SEMAPHORE
  643. /**
  644. * Semaphore structure
  645. */
  646. struct rt_semaphore
  647. {
  648. struct rt_ipc_object parent; /**< inherit from ipc_object */
  649. rt_uint16_t value; /**< value of semaphore. */
  650. rt_uint16_t reserved; /**< reserved field */
  651. };
  652. typedef struct rt_semaphore *rt_sem_t;
  653. #endif
  654. #ifdef RT_USING_MUTEX
  655. /**
  656. * Mutual exclusion (mutex) structure
  657. */
  658. struct rt_mutex
  659. {
  660. struct rt_ipc_object parent; /**< inherit from ipc_object */
  661. rt_uint16_t value; /**< value of mutex */
  662. rt_uint8_t original_priority; /**< priority of last thread hold the mutex */
  663. rt_uint8_t hold; /**< numbers of thread hold the mutex */
  664. struct rt_thread *owner; /**< current owner of mutex */
  665. };
  666. typedef struct rt_mutex *rt_mutex_t;
  667. #endif
  668. #ifdef RT_USING_EVENT
  669. /**
  670. * flag defintions in event
  671. */
  672. #define RT_EVENT_FLAG_AND 0x01 /**< logic and */
  673. #define RT_EVENT_FLAG_OR 0x02 /**< logic or */
  674. #define RT_EVENT_FLAG_CLEAR 0x04 /**< clear flag */
  675. /*
  676. * event structure
  677. */
  678. struct rt_event
  679. {
  680. struct rt_ipc_object parent; /**< inherit from ipc_object */
  681. rt_uint32_t set; /**< event set */
  682. };
  683. typedef struct rt_event *rt_event_t;
  684. #endif
  685. #ifdef RT_USING_MAILBOX
  686. /**
  687. * mailbox structure
  688. */
  689. struct rt_mailbox
  690. {
  691. struct rt_ipc_object parent; /**< inherit from ipc_object */
  692. rt_ubase_t *msg_pool; /**< start address of message buffer */
  693. rt_uint16_t size; /**< size of message pool */
  694. rt_uint16_t entry; /**< index of messages in msg_pool */
  695. rt_uint16_t in_offset; /**< input offset of the message buffer */
  696. rt_uint16_t out_offset; /**< output offset of the message buffer */
  697. rt_list_t suspend_sender_thread; /**< sender thread suspended on this mailbox */
  698. };
  699. typedef struct rt_mailbox *rt_mailbox_t;
  700. #endif
  701. #ifdef RT_USING_MESSAGEQUEUE
  702. /**
  703. * message queue structure
  704. */
  705. struct rt_messagequeue
  706. {
  707. struct rt_ipc_object parent; /**< inherit from ipc_object */
  708. void *msg_pool; /**< start address of message queue */
  709. rt_uint16_t msg_size; /**< message size of each message */
  710. rt_uint16_t max_msgs; /**< max number of messages */
  711. rt_uint16_t entry; /**< index of messages in the queue */
  712. void *msg_queue_head; /**< list head */
  713. void *msg_queue_tail; /**< list tail */
  714. void *msg_queue_free; /**< pointer indicated the free node of queue */
  715. rt_list_t suspend_sender_thread; /**< sender thread suspended on this message queue */
  716. };
  717. typedef struct rt_messagequeue *rt_mq_t;
  718. #endif
  719. /**@}*/
  720. /**
  721. * @addtogroup MM
  722. */
  723. /**@{*/
  724. /*
  725. * memory management
  726. * heap & partition
  727. */
  728. #ifdef RT_USING_MEMHEAP
  729. /**
  730. * memory item on the heap
  731. */
  732. struct rt_memheap_item
  733. {
  734. rt_uint32_t magic; /**< magic number for memheap */
  735. struct rt_memheap *pool_ptr; /**< point of pool */
  736. struct rt_memheap_item *next; /**< next memheap item */
  737. struct rt_memheap_item *prev; /**< prev memheap item */
  738. struct rt_memheap_item *next_free; /**< next free memheap item */
  739. struct rt_memheap_item *prev_free; /**< prev free memheap item */
  740. };
  741. /**
  742. * Base structure of memory heap object
  743. */
  744. struct rt_memheap
  745. {
  746. struct rt_object parent; /**< inherit from rt_object */
  747. void *start_addr; /**< pool start address and size */
  748. rt_uint32_t pool_size; /**< pool size */
  749. rt_uint32_t available_size; /**< available size */
  750. rt_uint32_t max_used_size; /**< maximum allocated size */
  751. struct rt_memheap_item *block_list; /**< used block list */
  752. struct rt_memheap_item *free_list; /**< free block list */
  753. struct rt_memheap_item free_header; /**< free block list header */
  754. struct rt_semaphore lock; /**< semaphore lock */
  755. };
  756. #endif
  757. #ifdef RT_USING_MEMPOOL
  758. /**
  759. * Base structure of Memory pool object
  760. */
  761. struct rt_mempool
  762. {
  763. struct rt_object parent; /**< inherit from rt_object */
  764. void *start_address; /**< memory pool start */
  765. rt_size_t size; /**< size of memory pool */
  766. rt_size_t block_size; /**< size of memory blocks */
  767. rt_uint8_t *block_list; /**< memory blocks list */
  768. rt_size_t block_total_count; /**< numbers of memory block */
  769. rt_size_t block_free_count; /**< numbers of free memory block */
  770. rt_list_t suspend_thread; /**< threads pended on this resource */
  771. };
  772. typedef struct rt_mempool *rt_mp_t;
  773. #endif
  774. /**@}*/
  775. #ifdef RT_USING_DEVICE
  776. /**
  777. * @addtogroup Device
  778. */
  779. /**@{*/
  780. /**
  781. * device (I/O) class type
  782. */
  783. enum rt_device_class_type
  784. {
  785. RT_Device_Class_Char = 0, /**< character device */
  786. RT_Device_Class_Block, /**< block device */
  787. RT_Device_Class_NetIf, /**< net interface */
  788. RT_Device_Class_MTD, /**< memory device */
  789. RT_Device_Class_CAN, /**< CAN device */
  790. RT_Device_Class_RTC, /**< RTC device */
  791. RT_Device_Class_Sound, /**< Sound device */
  792. RT_Device_Class_Graphic, /**< Graphic device */
  793. RT_Device_Class_I2CBUS, /**< I2C bus device */
  794. RT_Device_Class_USBDevice, /**< USB slave device */
  795. RT_Device_Class_USBHost, /**< USB host bus */
  796. RT_Device_Class_SPIBUS, /**< SPI bus device */
  797. RT_Device_Class_SPIDevice, /**< SPI device */
  798. RT_Device_Class_SDIO, /**< SDIO bus device */
  799. RT_Device_Class_PM, /**< PM pseudo device */
  800. RT_Device_Class_Pipe, /**< Pipe device */
  801. RT_Device_Class_Portal, /**< Portal device */
  802. RT_Device_Class_Timer, /**< Timer device */
  803. RT_Device_Class_Miscellaneous, /**< Miscellaneous device */
  804. RT_Device_Class_Sensor, /**< Sensor device */
  805. RT_Device_Class_Touch, /**< Touch device */
  806. RT_Device_Class_PHY, /**< PHY device */
  807. RT_Device_Class_Unknown /**< unknown device */
  808. };
  809. /**
  810. * device flags defitions
  811. */
  812. #define RT_DEVICE_FLAG_DEACTIVATE 0x000 /**< device is not not initialized */
  813. #define RT_DEVICE_FLAG_RDONLY 0x001 /**< read only */
  814. #define RT_DEVICE_FLAG_WRONLY 0x002 /**< write only */
  815. #define RT_DEVICE_FLAG_RDWR 0x003 /**< read and write */
  816. #define RT_DEVICE_FLAG_REMOVABLE 0x004 /**< removable device */
  817. #define RT_DEVICE_FLAG_STANDALONE 0x008 /**< standalone device */
  818. #define RT_DEVICE_FLAG_ACTIVATED 0x010 /**< device is activated */
  819. #define RT_DEVICE_FLAG_SUSPENDED 0x020 /**< device is suspended */
  820. #define RT_DEVICE_FLAG_STREAM 0x040 /**< stream mode */
  821. #define RT_DEVICE_FLAG_INT_RX 0x100 /**< INT mode on Rx */
  822. #define RT_DEVICE_FLAG_DMA_RX 0x200 /**< DMA mode on Rx */
  823. #define RT_DEVICE_FLAG_INT_TX 0x400 /**< INT mode on Tx */
  824. #define RT_DEVICE_FLAG_DMA_TX 0x800 /**< DMA mode on Tx */
  825. #define RT_DEVICE_OFLAG_CLOSE 0x000 /**< device is closed */
  826. #define RT_DEVICE_OFLAG_RDONLY 0x001 /**< read only access */
  827. #define RT_DEVICE_OFLAG_WRONLY 0x002 /**< write only access */
  828. #define RT_DEVICE_OFLAG_RDWR 0x003 /**< read and write */
  829. #define RT_DEVICE_OFLAG_OPEN 0x008 /**< device is opened */
  830. #define RT_DEVICE_OFLAG_MASK 0xf0f /**< mask of open flag */
  831. /**
  832. * general device commands
  833. */
  834. #define RT_DEVICE_CTRL_RESUME 0x01 /**< resume device */
  835. #define RT_DEVICE_CTRL_SUSPEND 0x02 /**< suspend device */
  836. #define RT_DEVICE_CTRL_CONFIG 0x03 /**< configure device */
  837. #define RT_DEVICE_CTRL_CLOSE 0x04 /**< close device */
  838. #define RT_DEVICE_CTRL_NOTIFY_SET 0x05 /**< set notify func */
  839. #define RT_DEVICE_CTRL_CONSOLE_OFLAG 0x06 /**< get console open flag */
  840. #define RT_DEVICE_CTRL_SET_INT 0x10 /**< set interrupt */
  841. #define RT_DEVICE_CTRL_CLR_INT 0x11 /**< clear interrupt */
  842. #define RT_DEVICE_CTRL_GET_INT 0x12 /**< get interrupt status */
  843. /**
  844. * special device commands
  845. */
  846. #define RT_DEVICE_CTRL_CHAR_STREAM 0x10 /**< stream mode on char device */
  847. #define RT_DEVICE_CTRL_BLK_GETGEOME 0x10 /**< get geometry information */
  848. #define RT_DEVICE_CTRL_BLK_SYNC 0x11 /**< flush data to block device */
  849. #define RT_DEVICE_CTRL_BLK_ERASE 0x12 /**< erase block on block device */
  850. #define RT_DEVICE_CTRL_BLK_AUTOREFRESH 0x13 /**< block device : enter/exit auto refresh mode */
  851. #define RT_DEVICE_CTRL_NETIF_GETMAC 0x10 /**< get mac address */
  852. #define RT_DEVICE_CTRL_MTD_FORMAT 0x10 /**< format a MTD device */
  853. #define RT_DEVICE_CTRL_RTC_GET_TIME 0x10 /**< get time */
  854. #define RT_DEVICE_CTRL_RTC_SET_TIME 0x11 /**< set time */
  855. #define RT_DEVICE_CTRL_RTC_GET_ALARM 0x12 /**< get alarm */
  856. #define RT_DEVICE_CTRL_RTC_SET_ALARM 0x13 /**< set alarm */
  857. typedef struct rt_device *rt_device_t;
  858. #ifdef RT_USING_DEVICE_OPS
  859. /**
  860. * operations set for device object
  861. */
  862. struct rt_device_ops
  863. {
  864. /* common device interface */
  865. rt_err_t (*init) (rt_device_t dev);
  866. rt_err_t (*open) (rt_device_t dev, rt_uint16_t oflag);
  867. rt_err_t (*close) (rt_device_t dev);
  868. rt_size_t (*read) (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size);
  869. rt_size_t (*write) (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size);
  870. rt_err_t (*control)(rt_device_t dev, int cmd, void *args);
  871. };
  872. #endif
  873. /**
  874. * WaitQueue structure
  875. */
  876. struct rt_wqueue
  877. {
  878. rt_uint32_t flag;
  879. rt_list_t waiting_list;
  880. };
  881. typedef struct rt_wqueue rt_wqueue_t;
  882. /**
  883. * Device structure
  884. */
  885. struct rt_device
  886. {
  887. struct rt_object parent; /**< inherit from rt_object */
  888. enum rt_device_class_type type; /**< device type */
  889. rt_uint16_t flag; /**< device flag */
  890. rt_uint16_t open_flag; /**< device open flag */
  891. rt_uint8_t ref_count; /**< reference count */
  892. rt_uint8_t device_id; /**< 0 - 255 */
  893. /* device call back */
  894. rt_err_t (*rx_indicate)(rt_device_t dev, rt_size_t size);
  895. rt_err_t (*tx_complete)(rt_device_t dev, void *buffer);
  896. #ifdef RT_USING_DEVICE_OPS
  897. const struct rt_device_ops *ops;
  898. #else
  899. /* common device interface */
  900. rt_err_t (*init) (rt_device_t dev);
  901. rt_err_t (*open) (rt_device_t dev, rt_uint16_t oflag);
  902. rt_err_t (*close) (rt_device_t dev);
  903. rt_size_t (*read) (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size);
  904. rt_size_t (*write) (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size);
  905. rt_err_t (*control)(rt_device_t dev, int cmd, void *args);
  906. #endif
  907. #if defined(RT_USING_POSIX)
  908. const struct dfs_file_ops *fops;
  909. struct rt_wqueue wait_queue;
  910. #endif
  911. void *user_data; /**< device private data */
  912. };
  913. /**
  914. * Notify structure
  915. */
  916. struct rt_device_notify
  917. {
  918. void (*notify)(rt_device_t dev);
  919. struct rt_device *dev;
  920. };
  921. #ifdef RT_USING_LWP
  922. struct rt_channel
  923. {
  924. struct rt_ipc_object parent; /**< inherit from object */
  925. struct rt_thread *reply; /**< the thread will be reply */
  926. rt_list_t wait_msg; /**< the wait queue of sender msg */
  927. rt_list_t wait_thread; /**< the wait queue of sender thread */
  928. rt_wqueue_t reader_queue; /**< channel poll queue */
  929. rt_uint8_t stat; /**< the status of this channel */
  930. rt_ubase_t ref;
  931. };
  932. typedef struct rt_channel *rt_channel_t;
  933. #endif
  934. /**
  935. * block device geometry structure
  936. */
  937. struct rt_device_blk_geometry
  938. {
  939. rt_uint32_t sector_count; /**< count of sectors */
  940. rt_uint32_t bytes_per_sector; /**< number of bytes per sector */
  941. rt_uint32_t block_size; /**< number of bytes to erase one block */
  942. };
  943. /**
  944. * sector arrange struct on block device
  945. */
  946. struct rt_device_blk_sectors
  947. {
  948. rt_uint32_t sector_begin; /**< begin sector */
  949. rt_uint32_t sector_end; /**< end sector */
  950. };
  951. /**
  952. * cursor control command
  953. */
  954. #define RT_DEVICE_CTRL_CURSOR_SET_POSITION 0x10
  955. #define RT_DEVICE_CTRL_CURSOR_SET_TYPE 0x11
  956. /**
  957. * graphic device control command
  958. */
  959. #define RTGRAPHIC_CTRL_RECT_UPDATE 0
  960. #define RTGRAPHIC_CTRL_POWERON 1
  961. #define RTGRAPHIC_CTRL_POWEROFF 2
  962. #define RTGRAPHIC_CTRL_GET_INFO 3
  963. #define RTGRAPHIC_CTRL_SET_MODE 4
  964. #define RTGRAPHIC_CTRL_GET_EXT 5
  965. /* graphic deice */
  966. enum
  967. {
  968. RTGRAPHIC_PIXEL_FORMAT_MONO = 0,
  969. RTGRAPHIC_PIXEL_FORMAT_GRAY4,
  970. RTGRAPHIC_PIXEL_FORMAT_GRAY16,
  971. RTGRAPHIC_PIXEL_FORMAT_RGB332,
  972. RTGRAPHIC_PIXEL_FORMAT_RGB444,
  973. RTGRAPHIC_PIXEL_FORMAT_RGB565,
  974. RTGRAPHIC_PIXEL_FORMAT_RGB565P,
  975. RTGRAPHIC_PIXEL_FORMAT_BGR565 = RTGRAPHIC_PIXEL_FORMAT_RGB565P,
  976. RTGRAPHIC_PIXEL_FORMAT_RGB666,
  977. RTGRAPHIC_PIXEL_FORMAT_RGB888,
  978. RTGRAPHIC_PIXEL_FORMAT_ARGB888,
  979. RTGRAPHIC_PIXEL_FORMAT_ABGR888,
  980. RTGRAPHIC_PIXEL_FORMAT_ARGB565,
  981. RTGRAPHIC_PIXEL_FORMAT_ALPHA,
  982. RTGRAPHIC_PIXEL_FORMAT_COLOR,
  983. };
  984. /**
  985. * build a pixel position according to (x, y) coordinates.
  986. */
  987. #define RTGRAPHIC_PIXEL_POSITION(x, y) ((x << 16) | y)
  988. /**
  989. * graphic device information structure
  990. */
  991. struct rt_device_graphic_info
  992. {
  993. rt_uint8_t pixel_format; /**< graphic format */
  994. rt_uint8_t bits_per_pixel; /**< bits per pixel */
  995. rt_uint16_t reserved; /**< reserved field */
  996. rt_uint16_t width; /**< width of graphic device */
  997. rt_uint16_t height; /**< height of graphic device */
  998. rt_uint8_t *framebuffer; /**< frame buffer */
  999. };
  1000. /**
  1001. * rectangle information structure
  1002. */
  1003. struct rt_device_rect_info
  1004. {
  1005. rt_uint16_t x; /**< x coordinate */
  1006. rt_uint16_t y; /**< y coordinate */
  1007. rt_uint16_t width; /**< width */
  1008. rt_uint16_t height; /**< height */
  1009. };
  1010. /**
  1011. * graphic operations
  1012. */
  1013. struct rt_device_graphic_ops
  1014. {
  1015. void (*set_pixel) (const char *pixel, int x, int y);
  1016. void (*get_pixel) (char *pixel, int x, int y);
  1017. void (*draw_hline)(const char *pixel, int x1, int x2, int y);
  1018. void (*draw_vline)(const char *pixel, int x, int y1, int y2);
  1019. void (*blit_line) (const char *pixel, int x, int y, rt_size_t size);
  1020. };
  1021. #define rt_graphix_ops(device) ((struct rt_device_graphic_ops *)(device->user_data))
  1022. /**@}*/
  1023. #endif
  1024. /* definitions for libc */
  1025. #include "rtlibc.h"
  1026. #ifdef __cplusplus
  1027. }
  1028. #endif
  1029. #ifdef __cplusplus
  1030. /* RT-Thread definitions for C++ */
  1031. namespace rtthread {
  1032. enum TICK_WAIT {
  1033. WAIT_NONE = 0,
  1034. WAIT_FOREVER = -1,
  1035. };
  1036. }
  1037. #endif /* end of __cplusplus */
  1038. #endif