rtdef.h 44 KB

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