rtdef.h 47 KB

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