c_common.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. /*
  2. * Copyright (c) 2022 OpenLuat & AirM2M
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software without restriction, including without limitation the rights to
  7. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. * the Software, and to permit persons to whom the Software is furnished to do so,
  9. * subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  16. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  17. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  18. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. #ifndef __C_COMMON_H__
  22. #define __C_COMMON_H__
  23. #include <string.h>
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <stdint.h>
  27. #include <stdarg.h>
  28. #ifdef __LUATOS__
  29. #include "luat_conf_bsp.h"
  30. #endif
  31. typedef struct
  32. {
  33. uint32_t MaigcNum; //升级包标识,标识不对直接抛弃
  34. uint32_t CRC32; //后续字节的CRC32校验,所有CRC32规则与ZIP压缩一致
  35. uint32_t Param1; //升级参数,其中byte0升级类型,byte1升级包存放位置,byte2外设总线序号,和platform_define里的外设序号一致
  36. uint32_t Param2; //额外的参数,需要和外置存储总线配合使用,一般是外置存储总线的PIN
  37. uint32_t DataStartAddress;//升级包在flash中的起始地址,外部和内部都可以用
  38. uint32_t DataLen;//升级包大小
  39. uint32_t DataCRC32;//升级包整包数据的CRC32
  40. char FilePath[100];//升级包在文件系统中的绝对路径,如果在flash中则随意填写
  41. }CoreUpgrade_HeadStruct;
  42. typedef struct
  43. {
  44. uint32_t MaigcNum; //升级包标识,标识不对直接抛弃
  45. uint32_t CRC32; //后续字节的CRC32校验,所有CRC32规则与ZIP压缩一致
  46. uint32_t Param1; //升级参数,其中byte0升级类型,byte1升级包存放位置,byte2外设总线序号,和platform_define里的外设序号一致
  47. uint32_t Param2; //额外的参数,需要和外置存储总线配合使用,一般是外置存储总线的PIN
  48. uint32_t DataStartAddress;//升级包在flash中的起始地址,外部和内部都可以用
  49. uint32_t DataLen;//升级包大小
  50. uint32_t MainVersion[5];//目标的底层版本,升级成功的话就是这个版本号了,有些SDK无法提供版本号,用MD5代替
  51. uint8_t CommonMD5[16];//升级包整体数据的MD5
  52. char FilePath[100];//升级包在文件系统中的绝对路径,如果在flash中则随意填写
  53. }CoreUpgrade_HeadCalMD5Struct;
  54. typedef struct
  55. {
  56. uint32_t MaigcNum; //升级包标识,标识不对直接抛弃
  57. uint32_t CRC32; //后续字节的CRC32校验
  58. uint32_t MainVersion;//目标的底层版本,升级成功的话就是这个版本号了
  59. uint32_t AppVersion;//整包的版本号
  60. uint32_t STDVersion;//允许升级的底层版本号
  61. uint32_t DataLen;//升级包大小
  62. uint32_t DataCRC32;//升级包整包数据的CRC32,这里验证传输的准确性
  63. }CoreUpgrade_FileHeadStruct;
  64. typedef struct
  65. {
  66. uint32_t MaigcNum; //升级包标识,标识不对直接抛弃
  67. uint32_t CRC32; //后续字节的CRC32校验
  68. uint32_t MainVersion[5];//目标的底层版本,升级成功的话就是这个版本号了,有些SDK无法提供版本号,用MD5代替
  69. uint32_t AppVersion;//整包的版本号
  70. uint32_t STDVersion[5];//允许升级的底层版本号,有些SDK无法提供版本号,用MD5代替
  71. uint32_t CommonDataLen; //通用升级包数据长度,内容是CoreUpgrade_SectorStruct或者CoreUpgrade_SectorCalMD5Struct
  72. uint32_t SDKDataLen; //特殊升级包数据长度,一般是SDK闭源的升级包
  73. uint8_t CommonMD5[16]; //通用升级包数据的MD5,这里验证传输的准确性
  74. uint8_t SDKMD5[16]; //特殊升级包数据的MD5,这里验证传输的准确性
  75. }CoreUpgrade_FileHeadCalMD5Struct;
  76. typedef struct
  77. {
  78. uint32_t MaigcNum; //升级包标识,标识不对直接抛弃
  79. uint32_t TotalLen; //解压前占据的空间
  80. uint32_t DataLen; //解压后占据的空间,如果和TotalLen一样,则表示未启用压缩,不需要解压,也没有压缩参数
  81. //如果是0,则表示是差分升级
  82. //其他表示是整包升级,数据包经过了lzma压缩
  83. uint32_t DataCRC32; //解压后的数据的CRC32,这里验证烧录的正确性
  84. uint32_t StartAddress; //烧写的起始地址
  85. }CoreUpgrade_SectorStruct;
  86. typedef struct
  87. {
  88. uint32_t MaigcNum; //升级包标识,标识不对直接抛弃
  89. uint32_t TotalLen; //解压前占据的空间
  90. uint32_t DataLen; //解压后占据的空间,如果和TotalLen一样,则表示未启用压缩,不需要解压,也没有压缩参数
  91. //如果是0,则表示是差分升级
  92. //其他表示是整包升级,数据包经过了lzma压缩
  93. uint8_t MD5[16]; //解压后的数据的MD5,这里验证烧录的正确性
  94. uint32_t BlockLen; //压缩时分隔的大小,一般是64K,128K或者256K
  95. uint32_t StartAddress; //烧写的起始地址
  96. }CoreUpgrade_SectorCalMD5Struct;
  97. typedef struct
  98. {
  99. uint32_t param_max_num;
  100. uint32_t param_max_len;
  101. uint32_t param_num;
  102. int8_t *param_str;
  103. }CmdParam;
  104. typedef struct
  105. {
  106. uint8_t Sec;
  107. uint8_t Min;
  108. uint8_t Hour;
  109. uint8_t Week;//表示日期0~6,sun~sat,表示预约时,bit0~bit6,sun~sat
  110. }Time_UserDataStruct;
  111. typedef struct
  112. {
  113. uint16_t Year;
  114. uint8_t Mon;
  115. uint8_t Day;
  116. }Date_UserDataStruct;
  117. typedef union
  118. {
  119. uint32_t dwTime;
  120. Time_UserDataStruct Time;
  121. }Time_Union;
  122. typedef union
  123. {
  124. uint32_t dwDate;
  125. Date_UserDataStruct Date;
  126. }Date_Union;
  127. typedef struct
  128. {
  129. uint8_t *Data;
  130. uint32_t Len;
  131. uint32_t Offset;
  132. uint32_t MaxLength;
  133. uint32_t DataSize;
  134. }Loop_Buffer;
  135. typedef struct
  136. {
  137. uint8_t *Data;
  138. uint32_t Pos;
  139. uint32_t MaxLen;
  140. }Buffer_Struct;
  141. typedef struct
  142. {
  143. uint8_t *pCache[2];
  144. uint32_t pCacheLen[2];
  145. uint32_t MaxLen;
  146. uint8_t CurCacheSn;
  147. }DBuffer_Struct;
  148. typedef union
  149. {
  150. void *p;
  151. char *pc8;
  152. uint8_t *pu8;
  153. uint16_t *pu16;
  154. uint32_t *pu32;
  155. uint32_t u32;
  156. uint8_t u8[4];
  157. uint16_t u16[2];
  158. }PV_Union;
  159. enum
  160. {
  161. ERROR_NONE,
  162. ERROR_NO_SUCH_ID,
  163. ERROR_PERMISSION_DENIED,
  164. ERROR_PARAM_INVALID,
  165. ERROR_PARAM_OVERFLOW,
  166. ERROR_DEVICE_BUSY,
  167. ERROR_OPERATION_FAILED,
  168. ERROR_BUFFER_FULL,
  169. ERROR_NO_MEMORY,
  170. ERROR_CMD_NOT_SUPPORT,
  171. ERROR_NO_DATA1,
  172. ERROR_NO_FLASH,
  173. ERROR_NO_TIMER,
  174. ERROR_TIMEOUT1,
  175. ERROR_SSL_HANDSHAKE,
  176. ERROR_PROTOCL,
  177. ERROR_ID_INVALID,
  178. ERROR_MID_INVALID,
  179. ERROR_RETRY_TOO_MUCH,
  180. ERROR_CMD_BLOCK,
  181. LIST_FIND = 1,
  182. LIST_PASS = 0,
  183. LIST_DEL = -1,
  184. DMA_CB_DONE = 0,
  185. UART_CB_TX_BUFFER_DONE,
  186. UART_CB_TX_ALL_DONE,
  187. UART_CB_RX_NEW,
  188. UART_CB_RX_TIMEOUT,
  189. UART_CB_RX_BUFFER_FULL,
  190. UART_CB_ERROR,
  191. UART_CB_CONNECTED, //串口工具对方已经打开
  192. DMA_CB_ERROR = 0xffffffff,
  193. CORE_EVENT_ID_ANY = 0,
  194. CORE_EVENT_ID_START = 0xf0000000,
  195. CORE_EVENT_TIMEOUT,
  196. CORE_TIMER_TIMEOUT = 0xf0010000,
  197. SERVICE_EVENT_ID_START = 0xf0100000,
  198. DEV_EVENT_ID_START = 0xf0200000,
  199. DEV_SPIFLASH_SPI_DONE,
  200. DEV_SDHC_SPI_DONE,
  201. USB_APP_EVENT_ID_START = 0xf0300000,
  202. USER_EVENT_ID_START = 0xf1000000,
  203. INVALID_EVENT_ID = 0xffffffff,
  204. NW_EVENT_SENT = 0,
  205. NW_EVENT_RECV,
  206. NW_EVENT_ERR,
  207. NW_EVENT_CONNECTED,
  208. NW_EVENT_REMOTE_CLOSE,
  209. NW_EVENT_ACCEPT,
  210. NW_EVENT_CLOSE_OK,
  211. };
  212. #define CRC32_GEN (0x04C11DB7)
  213. #define CRC32_START (0xffffffff)
  214. #define CRC16_CCITT_GEN (0x1021)
  215. #define CRC16_MODBUS_GEN (0x8005)
  216. #define CRC16_START (0xffff)
  217. #define CRC16_IBM_SEED (0xffff)
  218. #define CRC16_CCITT_SEED (0x1D0F)
  219. #ifndef HANDLE
  220. #define HANDLE void *
  221. #define INVALID_HANDLE_VALUE ((void *)0xffffffff)
  222. #define INVALID_PARAM (0xffffffff)
  223. #endif
  224. #ifndef BIT
  225. #define BIT(n) (1UL << (n))
  226. #endif
  227. #ifndef MIN
  228. #define MIN(X,Y) (((X) < (Y))?(X):(Y))
  229. #endif
  230. typedef void (* TaskFun_t)( void * );
  231. typedef void (* CommonFun_t)(void);
  232. typedef void(* CBDataFun_t)(uint8_t *Data, uint32_t Len);
  233. typedef int32_t(*CBFuncEx_t)(void *pData, void *pParam);
  234. typedef uint64_t LongInt;
  235. #define INIT_FUN_EXPORT(fn, location, level) const CommonFun_t __ex_init_##fn __attribute__((section(location level))) = fn
  236. #define INIT_HW_EXPORT(fn, level) INIT_FUN_EXPORT(fn, ".preinit_fun_array.", level)
  237. #define INIT_DRV_EXPORT(fn, level) INIT_FUN_EXPORT(fn, ".init_fun_array.", level)
  238. #define INIT_TASK_EXPORT(fn, level) INIT_FUN_EXPORT(fn, ".task_fun_array.", level)
  239. /* board init routines will be called in board_init() function */
  240. #define INIT_BOARD_EXPORT(fn) INIT_EXPORT(fn, "1")
  241. /* pre/device/component/env/app init routines will be called in init_thread */
  242. /* components pre-initialization (pure software initilization) */
  243. #define INIT_PREV_EXPORT(fn) INIT_EXPORT(fn, "2")
  244. /* device initialization */
  245. #define INIT_DEVICE_EXPORT(fn) INIT_EXPORT(fn, "3")
  246. /* components initialization (dfs, lwip, ...) */
  247. #define INIT_COMPONENT_EXPORT(fn) INIT_EXPORT(fn, "4")
  248. /* environment initialization (mount disk, ...) */
  249. #define INIT_ENV_EXPORT(fn) INIT_EXPORT(fn, "5")
  250. /* appliation initialization (rtgui application etc ...) */
  251. #define INIT_APP_EXPORT(fn) INIT_EXPORT(fn, "6")
  252. typedef struct
  253. {
  254. uint32_t ID;
  255. uint32_t Param1;
  256. uint32_t Param2;
  257. uint32_t Param3;
  258. }OS_EVENT;
  259. typedef struct
  260. {
  261. CBFuncEx_t CB;
  262. union {
  263. void *pParam; //用户回调模式
  264. uint32_t MaxCnt; //设置捕获模式时的最大tick,捕获时的tick
  265. }uParam;
  266. union {
  267. struct {
  268. uint8_t Level; //IO输入输出电平,捕获模式下中断时IO电平
  269. uint8_t PullMode; //IO上下拉控制
  270. } IOArg;
  271. struct {
  272. uint8_t ExtiMode; //中断模式
  273. uint8_t PullMode; //IO上下拉控制
  274. } ExitArg;
  275. uint16_t Time; //delay时间,us
  276. } uArg;
  277. uint8_t Operation; //操作类型
  278. uint8_t PinOrDelay; //IO操作时为IOpin,delay操作时则为微调值,0~47,48为1us
  279. }OPQueue_CmdStruct;
  280. enum
  281. {
  282. UDATA_TYPE_UNDEFINED = 0,
  283. UDATA_MULTIPLE_RESOURCE,
  284. UDATA_TYPE_STRING,
  285. UDATA_TYPE_OPAQUE,
  286. UDATA_TYPE_INTEGER,
  287. UDATA_TYPE_DWORD,
  288. UDATA_TYPE_WORD,
  289. UDATA_TYPE_BYTE,
  290. UDATA_TYPE_FLOAT,
  291. UDATA_TYPE_BOOLEAN,
  292. UDATA_TYPE_UNSIGNED,
  293. UDATA_TYPE_UNUSD
  294. };
  295. typedef struct _u_data_t uData_t;
  296. struct _u_data_t
  297. {
  298. union
  299. {
  300. uint8_t asBoolean;
  301. uint64_t asUnsigned;
  302. int64_t asInteger;
  303. PV_Union asDword;
  304. double asFloat;
  305. struct
  306. {
  307. size_t length;
  308. uint8_t *buffer;
  309. } asBuffer;
  310. struct
  311. {
  312. size_t count;
  313. uData_t *array;
  314. } asChildren;
  315. } value;
  316. uint32_t ID;
  317. uint8_t Type;
  318. };
  319. uint8_t OS_CheckInIrq(void);
  320. #ifdef __BUILD_OS__
  321. HANDLE OS_MutexCreate(void);
  322. HANDLE OS_MutexCreateUnlock(void);
  323. void OS_MutexLock(HANDLE Sem);
  324. int32_t OS_MutexLockWtihTime(HANDLE Sem, uint32_t TimeoutMs);
  325. void OS_MutexRelease(HANDLE Sem);
  326. void OS_MutexDelete(HANDLE Sem);
  327. void OS_SuspendTask(HANDLE taskHandle);
  328. void OS_ResumeTask(HANDLE taskHandle);
  329. uint8_t OS_IsSchedulerRun(void);
  330. #endif
  331. uint32_t OS_EnterCritical(void);
  332. void OS_ExitCritical(uint32_t Critical);
  333. void OS_MemInfo(uint32_t *curalloc, uint32_t *totfree, uint32_t *maxfree);
  334. int32_t OS_InitBuffer(Buffer_Struct *Buf, uint32_t Size);
  335. void OS_DeInitBuffer(Buffer_Struct *Buf);
  336. int32_t OS_ReInitBuffer(Buffer_Struct *Buf, uint32_t Size);
  337. int32_t OS_ReSizeBuffer(Buffer_Struct *Buf, uint32_t Size);
  338. int32_t OS_BufferWrite(Buffer_Struct *Buf, void *Data, uint32_t Len);
  339. int32_t OS_BufferWriteLimit(Buffer_Struct *Buf, void *Data, uint32_t Len);
  340. void OS_BufferRemove(Buffer_Struct *Buf, uint32_t Len);
  341. void DBuffer_Init(DBuffer_Struct *DBuf, uint32_t Size);
  342. void DBuffer_ReInit(DBuffer_Struct *DBuf, uint32_t Size);
  343. void DBuffer_DeInit(DBuffer_Struct *DBuf);
  344. void *DBuffer_GetCache(DBuffer_Struct *DBuf, uint8_t IsCurrent);
  345. void DBuffer_SwapCache(DBuffer_Struct *DBuf);
  346. void DBuffer_SetDataLen(DBuffer_Struct *DBuf, uint32_t Len, uint8_t IsCurrent);
  347. uint32_t DBuffer_GetDataLen(DBuffer_Struct *DBuf, uint8_t IsCurrent);
  348. void Buffer_StaticInit(Buffer_Struct *Buf, void *Src, uint32_t MaxLen);
  349. int32_t Buffer_StaticWrite(Buffer_Struct *Buf, void *Data, uint32_t Len);
  350. void Buffer_Remove(Buffer_Struct *Buf, uint32_t Len);
  351. void LoopBuffer_Init(Loop_Buffer *Buf, void *Src, uint32_t MaxLen, uint32_t DataSize);
  352. uint32_t LoopBuffer_Query(Loop_Buffer *Buf, void *Src, uint32_t Len);
  353. uint32_t LoopBuffer_Read(Loop_Buffer *Buf, void *Src, uint32_t Len);
  354. void LoopBuffer_Del(Loop_Buffer *Buf, uint32_t Len);
  355. uint32_t LoopBuffer_Write(Loop_Buffer *Buf, void *Src, uint32_t Len);
  356. int32_t BSP_SetBit(uint8_t *Data, uint32_t Sn, uint8_t Value);
  357. int32_t BSP_GetBit(uint8_t *Data, uint32_t Sn, uint8_t *Value);
  358. uint8_t BSP_TestBit(uint8_t *Data, uint32_t Sn);
  359. uint8_t XorCheck(void *Src, uint32_t Len, uint8_t CheckStart);
  360. uint8_t SumCheck(uint8_t *Data, uint32_t Len);
  361. uint8_t CRC8Cal(void *Data, uint16_t Len, uint8_t CRC8Last, uint8_t CRCRoot, uint8_t IsReverse);
  362. uint16_t CRC16Cal(void *Data, uint16_t Len, uint16_t CRC16Last, uint16_t CRCRoot, uint8_t IsReverse);
  363. uint32_t AsciiToU32(uint8_t *Src, uint32_t Len);
  364. void CRC32_CreateTable(uint32_t *Tab, uint32_t Gen);
  365. uint32_t CRC32_Cal(uint32_t * CRC32_Table, uint8_t *Buf, uint32_t Size, uint32_t CRC32Last);
  366. uint32_t CmdParseParam(int8_t* pStr, CmdParam *CmdParam, int8_t Cut);
  367. uint8_t IsLeapYear(uint32_t Year);
  368. LongInt UTC2Tamp(Date_UserDataStruct *Date, Time_UserDataStruct *Time);
  369. uint32_t Tamp2UTC(LongInt Sec, Date_UserDataStruct *Date, Time_UserDataStruct *Time, uint32_t LastDDay);
  370. /*
  371. * 转义解包
  372. * 标识Flag,即包头包尾加入Flag
  373. * 数据中遇到Code F1 -> Flag
  374. * 数据中遇到Code F2 -> Code
  375. * 数据中遇到Flag 出错返回0
  376. */
  377. uint32_t TransferUnpack(uint8_t Flag, uint8_t Code, uint8_t F1, uint8_t F2, uint8_t *InBuf, uint32_t Len, uint8_t *OutBuf);
  378. /*
  379. * llist相关代码,大部分来自linux内核
  380. */
  381. /**
  382. * container_of - cast a member of a structure out to the containing structure
  383. *
  384. * @ptr: the pointer to the member.
  385. * @type: the type of the container struct this is embedded in.
  386. * @member: the name of the member within the struct.
  387. *
  388. */
  389. #define container_of_x(ptr, type, member) ({ \
  390. const typeof( ((type *)0)->member ) *__mptr = (ptr); \
  391. (type *)( (char *)__mptr - offsetof(type,member) );})
  392. /*
  393. * These are non-NULL pointers that will result in page faults
  394. * under normal circumstances, used to verify that nobody uses
  395. * non-initialized llist entries.
  396. */
  397. #define LLIST_POISON1 (0)
  398. #define LLIST_POISON2 (0)
  399. /*
  400. * Simple doubly linked llist implementation.
  401. *
  402. * Some of the internal functions ("__xxx") are useful when
  403. * manipulating whole llists rather than single entries, as
  404. * sometimes we already know the next/prev entries and we can
  405. * generate better code by using them directly rather than
  406. * using the generic single-entry routines.
  407. */
  408. typedef struct llist_head_t{
  409. struct llist_head_t *next, *prev;
  410. }llist_head;
  411. #define LLIST_HEAD_INIT(name) { &(name), &(name) }
  412. #define LLIST_HEAD(name) \
  413. llist_head name = LLIST_HEAD_INIT(name)
  414. #define INIT_LLIST_HEAD(ptr) do { \
  415. (ptr)->next = (ptr); (ptr)->prev = (ptr); \
  416. } while (0)
  417. /*
  418. * Insert a new entry between two known consecutive entries.
  419. *
  420. * This is only for internal llist manipulation where we know
  421. * the prev/next entries already!
  422. */
  423. void __llist_add(llist_head *p,
  424. llist_head *prev,
  425. llist_head *next);
  426. /**
  427. * llist_add - add a new entry
  428. * @new: new entry to be added
  429. * @head: llist head to add it after
  430. *
  431. * Insert a new entry after the specified head.
  432. * This is good for implementing stacks.
  433. */
  434. void llist_add(llist_head *p, llist_head *head);
  435. /**
  436. * llist_add_tail - add a new entry
  437. * @new: new entry to be added
  438. * @head: llist head to add it before
  439. *
  440. * Insert a new entry before the specified head.
  441. * This is useful for implementing queues.
  442. */
  443. void llist_add_tail(llist_head *p, llist_head *head);
  444. /*
  445. * Delete a llist entry by making the prev/next entries
  446. * point to each other.
  447. *
  448. * This is only for internal llist manipulation where we know
  449. * the prev/next entries already!
  450. */
  451. void __llist_del(llist_head * prev, llist_head * next);
  452. /**
  453. * llist_del - deletes entry from llist.
  454. * @entry: the element to delete from the llist.
  455. * Note: llist_empty on entry does not return true after this, the entry is
  456. * in an undefined state.
  457. */
  458. void llist_del(llist_head *entry);
  459. /**
  460. * llist_del_init - deletes entry from llist and reinitialize it.
  461. * @entry: the element to delete from the llist.
  462. */
  463. void llist_del_init(llist_head *entry);
  464. /**
  465. * llist_move - delete from one llist and add as another's head
  466. * @llist: the entry to move
  467. * @head: the head that will precede our entry
  468. */
  469. void llist_move(llist_head *llist, llist_head *head);
  470. /**
  471. * llist_move_tail - delete from one llist and add as another's tail
  472. * @llist: the entry to move
  473. * @head: the head that will follow our entry
  474. */
  475. void llist_move_tail(llist_head *llist,
  476. llist_head *head);
  477. /**
  478. * llist_empty - tests whether a llist is empty
  479. * @head: the llist to test.
  480. */
  481. int llist_empty(const llist_head *head);
  482. uint32_t llist_num(const llist_head *head);
  483. void *llist_traversal(llist_head *head, CBFuncEx_t cb, void *pData);
  484. /**
  485. * llist_entry - get the struct for this entry
  486. * @ptr: the &llist_head pointer.
  487. * @type: the type of the struct this is embedded in.
  488. * @member: the name of the llist_struct within the struct.
  489. */
  490. #define llist_entry(ptr, type, member) \
  491. container_of_x(ptr, type, member)
  492. uint16_t BSP_Swap16(uint16_t n);
  493. uint32_t BSP_Swap32(uint32_t n);
  494. uint8_t BytesGet8(const void *ptr);
  495. void BytesPut8(void *ptr, uint8_t v);
  496. uint16_t BytesGetBe16(const void *ptr);
  497. void BytesPutBe16(void *ptr, uint16_t v);
  498. uint32_t BytesGetBe32(const void *ptr);
  499. void BytesPutBe32(void *ptr, uint32_t v);
  500. uint16_t BytesGetLe16(const void *ptr);
  501. void BytesPutLe16(void *ptr, uint16_t v);
  502. uint32_t BytesGetLe32(const void *ptr);
  503. void BytesPutLe32(void *ptr, uint32_t v);
  504. uint64_t BytesGetLe64(const void *ptr);
  505. void BytesPutLe64(void *ptr, uint64_t v);
  506. uint8_t BytesGet8FromBuf(Buffer_Struct *Buf);
  507. void BytesPut8ToBuf(Buffer_Struct *Buf, uint8_t v);
  508. uint16_t BytesGetBe16FromBuf(Buffer_Struct *Buf);
  509. void BytesPutBe16ToBuf(Buffer_Struct *Buf, uint16_t v);
  510. uint32_t BytesGetBe32FromBuf(Buffer_Struct *Buf);
  511. void BytesPutBe32ToBuf(Buffer_Struct *Buf, uint32_t v);
  512. uint16_t BytesGetLe16FromBuf(Buffer_Struct *Buf);
  513. void BytesPutLe16ToBuf(Buffer_Struct *Buf, uint16_t v);
  514. uint32_t BytesGetLe32FromBuf(Buffer_Struct *Buf);
  515. void BytesPutLe32ToBuf(Buffer_Struct *Buf, uint32_t v);
  516. uint64_t BytesGetLe64FromBuf(Buffer_Struct *Buf);
  517. void BytesPutLe64ToBuf(Buffer_Struct *Buf, uint64_t v);
  518. float BytesGetFloatFromBuf(Buffer_Struct *Buf);
  519. void BytesPutFloatToBuf(Buffer_Struct *Buf, float v);
  520. double BytesGetDoubleFromBuf(Buffer_Struct *Buf);
  521. void BytesPutDoubleToBuf(Buffer_Struct *Buf, double v);
  522. /*************************************************************************/
  523. #define malloc luat_heap_malloc
  524. #define free luat_heap_free
  525. #define realloc luat_heap_realloc
  526. #define zalloc luat_heap_zalloc
  527. #define calloc luat_heap_calloc
  528. #ifdef __LUATOS_TICK_64BIT__
  529. extern uint64_t GetSysTickMS(void);
  530. #else
  531. #define GetSysTickMS luat_mcu_ticks
  532. #endif
  533. #ifndef ASSERT
  534. #if defined(__DEBUG__)
  535. #define ASSERT( x ) if( ( x ) == 0 ) { __disable_irq(); DBG_Trace("\r\nassert %s,%d", __FUNCTION__, __LINE__); for( ;; ); }
  536. #else
  537. #define ASSERT( x )
  538. #endif
  539. #endif
  540. #endif