rtdef.h 43 KB

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