rtdef.h 45 KB

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