初版
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
#ifndef CIRCULAR_BUF_INTERFACE_H
|
||||
#define CIRCULAR_BUF_INTERFACE_H
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
typedef struct _cbuffer {
|
||||
u8 *begin;
|
||||
u8 *end;
|
||||
u8 *read_ptr;
|
||||
u8 *write_ptr;
|
||||
u8 *tmp_ptr ;
|
||||
u32 tmp_len;
|
||||
u32 data_len;
|
||||
u32 total_len;
|
||||
} cbuffer_t;
|
||||
|
||||
extern void cbuf_init(cbuffer_t *cbuffer, void *buf, u32 size);
|
||||
|
||||
extern u32 cbuf_read(cbuffer_t *cbuffer, void *buf, u32 len);
|
||||
|
||||
extern u32 cbuf_write(cbuffer_t *cbuffer, void *buf, u32 len);
|
||||
|
||||
extern u32 cbuf_is_write_able(cbuffer_t *cbuffer, u32 len);
|
||||
|
||||
extern void *cbuf_write_alloc(cbuffer_t *cbuffer, u32 *len);
|
||||
|
||||
extern void cbuf_write_updata(cbuffer_t *cbuffer, u32 len);
|
||||
|
||||
void *cbuf_read_alloc(cbuffer_t *cbuffer, u32 *len);
|
||||
|
||||
void cbuf_read_updata(cbuffer_t *cbuffer, u32 len);
|
||||
|
||||
void cbuf_clear(cbuffer_t *cbuffer);
|
||||
|
||||
u32 cbuf_rewrite(cbuffer_t *cbuffer, void *begin, void *buf, u32 len);
|
||||
|
||||
void cbuf_discard_prewrite(cbuffer_t *cbuffer);
|
||||
|
||||
void cbuf_updata_prewrite(cbuffer_t *cbuffer);
|
||||
|
||||
u32 cbuf_prewrite(cbuffer_t *cbuffer, void *buf, u32 len);
|
||||
|
||||
u32 cbuf_get_data_size(cbuffer_t *cbuffer);
|
||||
|
||||
void cbuf_read_alloc_len_updata(cbuffer_t *cbuffer, u32 len);
|
||||
|
||||
u32 cbuf_read_alloc_len(cbuffer_t *cbuffer, void *buf, u32 len);
|
||||
#define cbuf_get_writeptr(a) (a)->write_ptr
|
||||
|
||||
#define cbuf_get_readptr(a ) (a)->read_ptr
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifndef __COMMON_H__
|
||||
#define __COMMON_H__
|
||||
|
||||
#include "asm/cpu.h"
|
||||
#include "csfr.h"
|
||||
#include "typedef.h"
|
||||
#include "device_errno.h"
|
||||
#include "wdt.h"
|
||||
//#include "printf.h"
|
||||
|
||||
|
||||
#define SFR(sfr, start, len, dat) (sfr = (sfr & ~((~(0xffffffff << (len))) << (start))) | (((dat) & (~(0xffffffff << (len)))) << (start)))
|
||||
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __DEBUG
|
||||
#define APP_DEBUG 1
|
||||
#else
|
||||
#define APP_DEBUG 0
|
||||
#endif
|
||||
|
||||
// #if APP_DEBUG
|
||||
// #define log_info printf
|
||||
// #define log_error(...)
|
||||
// #define log_info_hexdump printf_buf
|
||||
// #else
|
||||
// #define log_info(...)
|
||||
// #define log_info_hexdump(a,b)
|
||||
// #endif
|
||||
|
||||
// void wdt_clear();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
#ifndef _DEBUG_H_
|
||||
#define _DEBUG_H_
|
||||
|
||||
#include "printf.h"
|
||||
#include "asm/cpu.h"
|
||||
#include "generic/typedef.h"
|
||||
|
||||
#define RedBold "\033[31;1m" // 红色加粗
|
||||
#define RedBoldBlink "\033[31;1;5m" // 红色加粗、闪烁
|
||||
#define GreenBold "\033[32;1m" // 红色加粗
|
||||
#define GreenBoldBlink "\033[32;1;5m" // 红色加粗、闪烁
|
||||
#define YellowBold "\033[33;1m" // 红色加粗
|
||||
#define YellowBoldBlink "\033[33;1;5m" // 红色加粗、闪烁
|
||||
#define BlueBold "\033[34;1m" // 蓝色加粗
|
||||
#define BlueBoldBlink "\033[34;1;5m" // 蓝色加粗、闪烁
|
||||
#define PurpleBold "\033[35;1m" // 紫色加粗
|
||||
#define PurpleBoldBlink "\033[35;1;5m" // 紫色加粗、闪烁
|
||||
#define DGreenBold "\033[36;1m" // 红色加粗
|
||||
#define DGreenBoldBlink "\033[36;1;5m" // 红色加粗、闪烁
|
||||
#define WhiteBold "\033[37;1m" // 红色加粗
|
||||
#define WhiteBoldBlink "\033[37;1;5m" // 红色加粗、闪烁
|
||||
#define Reset "\033[0;25m" // 颜色复位
|
||||
|
||||
#define LOG_VERBOSE v
|
||||
#define LOG_INFO i
|
||||
#define LOG_DEBUG d
|
||||
#define LOG_WARN w
|
||||
#define LOG_ERROR e
|
||||
#define LOG_CHAR c
|
||||
|
||||
#define _STR(x) #x
|
||||
#define STR(x) "["_STR(x)"]"
|
||||
|
||||
|
||||
#define _LOG_TAG_CONST_DECLARE(level, name) extern const char log_tag_const_##level##_##name
|
||||
#define LOG_TAG_CONST_DECLARE(level, name) _LOG_TAG_CONST_DECLARE(level, name)
|
||||
|
||||
#define ___LOG_IS_ENABLE(level, name) (log_tag_const_##level##_##name)
|
||||
#define __LOG_IS_ENABLE(level, name) ___LOG_IS_ENABLE(level, name)
|
||||
#define _LOG_IS_ENABLE(level) __LOG_IS_ENABLE(level, LOG_TAG_CONST)
|
||||
|
||||
#ifdef LOG_TAG_CONST
|
||||
LOG_TAG_CONST_DECLARE(LOG_VERBOSE, LOG_TAG_CONST);
|
||||
LOG_TAG_CONST_DECLARE(LOG_INFO, LOG_TAG_CONST);
|
||||
LOG_TAG_CONST_DECLARE(LOG_DEBUG, LOG_TAG_CONST);
|
||||
LOG_TAG_CONST_DECLARE(LOG_WARN, LOG_TAG_CONST);
|
||||
LOG_TAG_CONST_DECLARE(LOG_ERROR, LOG_TAG_CONST);
|
||||
LOG_TAG_CONST_DECLARE(LOG_CHAR, LOG_TAG_CONST);
|
||||
|
||||
#define _LOG_TAG LOG_TAG
|
||||
#define LOG_IS_ENABLE(level) _LOG_IS_ENABLE(level)
|
||||
|
||||
#else
|
||||
#define _LOG_TAG "[NULL]"
|
||||
#define LOG_IS_ENABLE(x) 0
|
||||
#endif
|
||||
|
||||
#ifdef __DEBUG
|
||||
|
||||
#define log_print printf
|
||||
|
||||
#define log_info(format, ...) \
|
||||
if (LOG_IS_ENABLE(LOG_INFO)) \
|
||||
log_print("[Info] " _LOG_TAG format "\r\n", ## __VA_ARGS__)
|
||||
|
||||
#define log_info_hexdump(x, y) \
|
||||
if (LOG_IS_ENABLE(LOG_INFO)) \
|
||||
printf_buf(x, y)
|
||||
|
||||
|
||||
#define log_debug(format, ...) \
|
||||
if (LOG_IS_ENABLE(LOG_DEBUG)) \
|
||||
log_print("[Debug] " _LOG_TAG format "\r\n", ## __VA_ARGS__)
|
||||
|
||||
#define log_debug_hexdump(x, y) \
|
||||
if (LOG_IS_ENABLE(LOG_DEBUG)) \
|
||||
printf_buf(x, y)
|
||||
|
||||
#define log_error(format, ...) \
|
||||
if (LOG_IS_ENABLE(LOG_ERROR)) \
|
||||
log_print("<Error> " _LOG_TAG format "\r\n", ## __VA_ARGS__)
|
||||
|
||||
#define log_error_hexdump(x, y) \
|
||||
if (LOG_IS_ENABLE(LOG_ERROR)) \
|
||||
printf_buf(x, y)
|
||||
|
||||
#define log_char(x) \
|
||||
if (LOG_IS_ENABLE(LOG_CHAR)) \
|
||||
putchar(x)
|
||||
|
||||
#else
|
||||
|
||||
#define log_info(format, ...)
|
||||
#define log_info_hexdump(x, y)
|
||||
#define log_debug(format, ...)
|
||||
#define log_debug_hexdump(x, y)
|
||||
#define log_error(format, ...)
|
||||
#define log_error_hexdump(x, y)
|
||||
#define log_char(x)
|
||||
|
||||
#endif
|
||||
|
||||
int printf_lite(const char *format, ...);
|
||||
void log_putbyte(char c);
|
||||
void put_buf_lite(void *_buf, u32 len);
|
||||
|
||||
|
||||
#endif//__DEBUG_H_
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
#ifndef _ASM_GENERIC_ERRNO_BASE_H
|
||||
#define _ASM_GENERIC_ERRNO_BASE_H
|
||||
|
||||
#define EPERM 1 /* Operation not permitted */
|
||||
#define ENOENT 2 /* No such file or directory */
|
||||
#define ESRCH 3 /* No such process */
|
||||
#define EINTR 4 /* Interrupted system call */
|
||||
#define EIO 5 /* I/O error */
|
||||
#define ENXIO 6 /* No such device or address */
|
||||
#define E2BIG 7 /* Argument list too long */
|
||||
#define ENOEXEC 8 /* Exec format error */
|
||||
#define EBADF 9 /* Bad file number */
|
||||
#define ECHILD 10 /* No child processes */
|
||||
#define EAGAIN 11 /* Try again */
|
||||
#define ENOMEM 12 /* Out of memory */
|
||||
#define EACCES 13 /* Permission denied */
|
||||
#define EFAULT 14 /* Bad address */
|
||||
#define ENOTBLK 15 /* Block device required */
|
||||
#define EBUSY 16 /* Device or resource busy */
|
||||
#define EEXIST 17 /* File exists */
|
||||
#define EXDEV 18 /* Cross-device link */
|
||||
#define ENODEV 19 /* No such device */
|
||||
#define ENOTDIR 20 /* Not a directory */
|
||||
#define EISDIR 21 /* Is a directory */
|
||||
#define EINVAL 22 /* Invalid argument */
|
||||
#define ENFILE 23 /* File table overflow */
|
||||
#define EMFILE 24 /* Too many open files */
|
||||
#define ENOTTY 25 /* Not a typewriter */
|
||||
#define ETXTBSY 26 /* Text file busy */
|
||||
#define EFBIG 27 /* File too large */
|
||||
#define ENOSPC 28 /* No space left on device */
|
||||
#define ESPIPE 29 /* Illegal seek */
|
||||
#define EROFS 30 /* Read-only file system */
|
||||
#define EMLINK 31 /* Too many links */
|
||||
#define EPIPE 32 /* Broken pipe */
|
||||
#define EDOM 33 /* Math argument out of domain of func */
|
||||
#define ERANGE 34 /* Math result not representable */
|
||||
#define ETIMEDOUT 35 /* Connection timed out */
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef JIFFIES_H
|
||||
#define JIFFIES_H
|
||||
|
||||
#define HZ 100L
|
||||
#define MSEC_PER_SEC 1000L
|
||||
#define USEC_PER_MSEC 1000L
|
||||
#define NSEC_PER_USEC 1000L
|
||||
#define NSEC_PER_MSEC 1000000L
|
||||
#define USEC_PER_SEC 1000000L
|
||||
#define NSEC_PER_SEC 1000000000L
|
||||
#define FSEC_PER_SEC 1000000000000000LL
|
||||
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
extern volatile unsigned long jiffies;
|
||||
extern unsigned long jiffies_msec();
|
||||
extern unsigned long jiffies_half_msec();
|
||||
#endif
|
||||
|
||||
#define maskrom_get_jiffies() jiffies
|
||||
#define maskrom_set_jiffies(n) jiffies = n
|
||||
|
||||
#define JIFFIES_CIRCLE 0x7FFFFFF
|
||||
|
||||
|
||||
#define msecs_to_jiffies_10(msec) ((msec)/10)
|
||||
#define jiffies_to_msecs(jiff) ((jiff)*10)
|
||||
#define msecs_to_jiffies(msec) ((msec)/10)
|
||||
#define time_after(a,b) ((long)(b) - (long)(a) <= 0)
|
||||
#define time_before(a,b) time_after(b, a)
|
||||
|
||||
int jiffies_msec2offset(unsigned long begin_msec, unsigned long end_msec);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,225 @@
|
||||
#ifndef LBUF_H
|
||||
#define LBUF_H
|
||||
|
||||
|
||||
#include "typedef.h"
|
||||
#include "list.h"
|
||||
#include "spinlock.h"
|
||||
|
||||
|
||||
#define LBUF_DEBUG 0
|
||||
|
||||
struct lbuff_head {
|
||||
#if LBUF_DEBUG
|
||||
int magic_a; /*!< 测试验证变量*/
|
||||
#endif
|
||||
struct list_head head; /*!< 指向hentry链表*/
|
||||
struct list_head free; /*!< 指向hfree链表*/
|
||||
spinlock_t lock; /*!< 混合自旋锁,单核是为开关临界区,多核是自旋锁.*/
|
||||
u8 align; /*!< 数据包字节对齐*/
|
||||
u16 priv_len; /*!< 数据包结构体的最小长度*/
|
||||
u32 total_size; /*!< 总大小*/
|
||||
u32 last_addr; /*!< 指向free链表中找到的足够长度的hfree结构体地址*/
|
||||
void *priv;
|
||||
|
||||
#if LBUF_DEBUG
|
||||
int magic_b; /*!< 测试验证变量*/
|
||||
#endif
|
||||
};
|
||||
|
||||
struct lbuff_state {
|
||||
u32 avaliable; /*!< 剩余空间的字节长度*/
|
||||
u32 fragment; /*!< lbuf内存碎片块数量*/
|
||||
u32 max_continue_len; /*!< 最大的剩余内存块的字节长度*/
|
||||
int num; /*!< 剩余内存块数量*/
|
||||
};
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 链表buf初始化
|
||||
*
|
||||
* @param [in] buf 需要lbuf进行管理的内存
|
||||
* @param [in] len 内存长度
|
||||
* @param [in] align 输入对管理的内存进行对齐的参数,避免后续使用因地址不对齐产生碎片
|
||||
* @param [in] priv_head_len 要管理的一个数据包结构体的最小的长度
|
||||
*
|
||||
* @return lbuf操作句柄
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
struct lbuff_head *lbuf_init(void *buf, u32 len, int align, int priv_head_len);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 分配内存空间进行存储数据包
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
* @param [in] len 需要存入的数据包的长度
|
||||
*
|
||||
* @return 成功则返回进行存储数据包的地址,调用时候需要用户把该块内存的类型初始化为数据包结构体的类型。失败则返回NULL。
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void *lbuf_alloc(struct lbuff_head *head, u32 len);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 重新分配lbuf_alloc()返回用于存储数据包的lbuf空间
|
||||
*
|
||||
* @param [in] lbuf lbuf_alloc()返回用于存储数据包的地址
|
||||
* @param [in] size 需重新分配的空间的字节长度.注:size的大小只能比lbuf_alloc()中的len小,即只能重新分配更小的lbuf空间,不能扩大空间.
|
||||
*
|
||||
* @return 重新分配后用于存储数据包的地址。失败则返回空指针。注:重新分配最好使用lbuf_real_size()获取lbuf空间的长度确认是否分配成功
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void *lbuf_realloc(void *lbuf, int size);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 判断lbuf空间内的内容是否为空
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
*
|
||||
* @return 返回1则为空,0则不为空
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
int lbuf_empty(struct lbuff_head *head);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 清空lbuf空间内进行已经分配给数据包的空间
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void lbuf_clear(struct lbuff_head *head);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 把数据包写入分配好的lbuf区域
|
||||
*
|
||||
* @param [in] lbuf lbuf_alloc()返回用于存储数据包的地址
|
||||
* @param [in] channel_map 选择映射到哪个通道,最多8个通道,使用位映射的方式进行通道对应.
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void lbuf_push(void *lbuf, u8 channel_map);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 读取对应的通道映射的lbuf区域存储的内容
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
* @param [in] channel 需要读取的通道值,一般使用BIT(n),n为需要读取的通道
|
||||
*
|
||||
* @return 成功则返回存储对应的通道映射的数据包的地址
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void *lbuf_pop(struct lbuff_head *head, u8 channel);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 释放存储数据包的lbuf空间
|
||||
*
|
||||
* @param [in] lbuf lbuf_alloc()返回用于存储数据包的地址
|
||||
*
|
||||
* @return 0则释放失败,存在地址越界操作或者通道还没有被读完,ref-1,读完后才能完全释放。1则释放成功。
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
int lbuf_free(void *lbuf);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 用于调试,检查是否可以释放存储数据包的lbuf空间
|
||||
*
|
||||
* @param [in] lbuf lbuf_alloc()返回用于存储数据包的地址
|
||||
* @param [in] rets 调用lbuf_free_check()函数的返回地址rets,取值可参考lbuf_free()
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void lbuf_free_check(void *lbuf, u32 rets);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 返回可分配的用来存储数据包的最大lbuf内存空间
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
*
|
||||
* @return 可分配的最大lbuf内存空间的字节长度
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
u32 lbuf_free_space(struct lbuff_head *head);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 获取lbuf空间的状态
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
* @param [out] state lbuff_state结构体
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void lbuf_state(struct lbuff_head *head, struct lbuff_state *state);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief lbuf信息打印
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void lbuf_dump(struct lbuff_head *head);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 获取已经存入lbuf空间的数据包的数量
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
*
|
||||
* @return lbuf存储的数据包的数量
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
int lbuf_traversal(struct lbuff_head *head);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 返回lbuf空间还可以被写入size大小数据包的数量
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
* @param [in] size 欲检测写入数据包的大小
|
||||
*
|
||||
* @return 可以写入的数量
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
int lbuf_avaliable(struct lbuff_head *head, int size);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 返回给数据包分配的内存空间的大小
|
||||
*
|
||||
* @param [in] lbuf lbuf_alloc()返回用于存储数据包的地址
|
||||
*
|
||||
* @return 实际占用空间的字节长度
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
int lbuf_real_size(void *lbuf);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 计算lbuf空间剩下多少剩余空间
|
||||
*
|
||||
* @param [in] head lbuf操作句柄
|
||||
*
|
||||
* @return 剩余空间的字节长度
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
int lbuf_remain_space(struct lbuff_head *head);
|
||||
|
||||
/* --------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief 需要被重复释放的次数+1
|
||||
*
|
||||
* @param [in] lbuf lbuf_alloc()返回用于存储数据包的地址
|
||||
*/
|
||||
/* --------------------------------------------------------------------------*/
|
||||
void lbuf_inc_ref(void *lbuf);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,284 @@
|
||||
#ifndef LIST_H
|
||||
#define LIST_H
|
||||
|
||||
|
||||
/**
|
||||
* container_of - cast a member of a structure out to the containing structure
|
||||
* @ptr: the pointer to the member.
|
||||
* @type: the type of the container struct this is embedded in.
|
||||
* @member: the name of the member within the struct.
|
||||
*
|
||||
*/
|
||||
#ifdef offsetof
|
||||
#undef offsetof
|
||||
#endif
|
||||
#ifdef container_of
|
||||
#undef container_of
|
||||
#endif
|
||||
|
||||
#define list_offsetof(type, memb) \
|
||||
((unsigned long)(&((type *)0)->memb))
|
||||
|
||||
#define container_of(ptr, type, memb) \
|
||||
((type *)((char *)ptr - list_offsetof(type, memb)))
|
||||
|
||||
|
||||
struct list_head {
|
||||
struct list_head *next, *prev;
|
||||
};
|
||||
|
||||
|
||||
#define LIST_HEAD_INIT(name) { &(name), &(name) }
|
||||
|
||||
#define LIST_HEAD(name) \
|
||||
struct list_head name = LIST_HEAD_INIT(name)
|
||||
|
||||
/**
|
||||
* list_entry - get the struct for this entry
|
||||
* @ptr: the &struct list_head pointer.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_entry(ptr, type, member) \
|
||||
container_of(ptr, type, member)
|
||||
|
||||
|
||||
/**
|
||||
* list_first_entry - get the first element from a list
|
||||
* @ptr: the list head to take the element from.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Note, that list is expected to be not empty.
|
||||
*/
|
||||
/* REF_LIST: spi.c */
|
||||
#define list_first_entry(ptr, type, member) \
|
||||
list_entry((ptr)->next, type, member)
|
||||
|
||||
/**
|
||||
* list_for_each - iterate over a list
|
||||
* @pos: the &struct list_head to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each(pos, head) \
|
||||
for (pos = (head)->next; pos != (head); \
|
||||
pos = pos->next)
|
||||
|
||||
/**
|
||||
* list_for_each_safe - iterate over a list safe against removal of list entry
|
||||
* @pos: the &struct list_head to use as a loop counter.
|
||||
* @n: another &struct list_head to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each_safe(pos, n, head) \
|
||||
for (pos = (head)->next, n = pos->next; pos != (head); \
|
||||
pos = n, n = pos->next)
|
||||
|
||||
/**
|
||||
* list_for_each_entry - iterate over list of given type
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry(pos, head, member) \
|
||||
for (pos = list_entry((head)->next, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = list_entry(pos->member.next, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_reverse - iterate backwards over list of given type.
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry_reverse(pos, head, member) \
|
||||
for (pos = list_entry((head)->prev, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = list_entry(pos->member.prev, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @n: another type * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry_safe(pos, n, head, member) \
|
||||
for (pos = list_entry((head)->next, typeof(*pos), member), \
|
||||
n = list_entry(pos->member.next, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = list_entry(n->member.next, typeof(*n), member))
|
||||
|
||||
|
||||
/**
|
||||
* list_empty - tests whether a list is empty
|
||||
* @head: the list to test.
|
||||
*/
|
||||
/* REF_LIST: spi.c */
|
||||
static inline int list_empty(const struct list_head *head)
|
||||
{
|
||||
return head->next == head;
|
||||
}
|
||||
|
||||
/*
|
||||
* Insert a new entry between two known consecutive entries.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
static inline void __list_add(struct list_head *_new,
|
||||
struct list_head *prev,
|
||||
struct list_head *next)
|
||||
{
|
||||
next->prev = _new;
|
||||
_new->next = next;
|
||||
_new->prev = prev;
|
||||
prev->next = _new;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_add_tail - add a new entry
|
||||
* @new: new entry to be added
|
||||
* @head: list head to add it before
|
||||
*
|
||||
* Insert a new entry before the specified head.
|
||||
* This is useful for implementing queues.
|
||||
*/
|
||||
/* REF_LIST: spi.c */
|
||||
static inline void list_add_tail(struct list_head *_new, struct list_head *head)
|
||||
{
|
||||
__list_add(_new, head->prev, head);
|
||||
}
|
||||
|
||||
static inline void __list_del(struct list_head *prev, struct list_head *next)
|
||||
{
|
||||
if (prev == 0 || next == 0) {
|
||||
return;
|
||||
}
|
||||
//ASSERT(prev!=NULL || next!=NULL)
|
||||
next->prev = prev;
|
||||
prev->next = next;
|
||||
}
|
||||
|
||||
static inline void __list_del_entry(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
}
|
||||
|
||||
/* REF_LIST: spi.c */
|
||||
static inline void list_del(struct list_head *entry) //修改过的list_del,这里与list_del_init一样
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
entry->next = entry;
|
||||
entry->prev = entry;
|
||||
}
|
||||
|
||||
/*
|
||||
* Simple doubly linked list implementation.
|
||||
*
|
||||
* Some of the internal functions ("__xxx") are useful when
|
||||
* manipulating whole lists rather than single entries, as
|
||||
* sometimes we already know the next/prev entries and we can
|
||||
* generate better code by using them directly rather than
|
||||
* using the generic single-entry routines.
|
||||
*/
|
||||
|
||||
static inline void INIT_LIST_HEAD(struct list_head *list)
|
||||
{
|
||||
list->next = list;
|
||||
list->prev = list;
|
||||
}
|
||||
|
||||
static inline void list_del_init(struct list_head *entry)
|
||||
{
|
||||
__list_del_entry(entry);
|
||||
INIT_LIST_HEAD(entry);
|
||||
}
|
||||
/**
|
||||
* list_move_tail - delete from one list and add as another's tail
|
||||
* @list: the entry to move
|
||||
* @head: the head that will follow our entry
|
||||
*/
|
||||
static inline void list_move_tail(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
__list_del(list->prev, list->next);
|
||||
list_add_tail(list, head);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_add - add a new entry
|
||||
* @new: new entry to be added
|
||||
* @head: list head to add it after
|
||||
*
|
||||
* Insert a new entry after the specified head.
|
||||
* This is good for implementing stacks.
|
||||
*/
|
||||
static inline void list_add(struct list_head *new, struct list_head *head)
|
||||
{
|
||||
__list_add(new, head, head->next);
|
||||
}
|
||||
|
||||
static inline int list_is_head(struct list_head *head, struct list_head *member)
|
||||
{
|
||||
return head->next == member;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static inline void __list_splice(const struct list_head *list,
|
||||
struct list_head *prev,
|
||||
struct list_head *next)
|
||||
{
|
||||
struct list_head *first = list->next;
|
||||
struct list_head *last = list->prev;
|
||||
|
||||
first->prev = prev;
|
||||
prev->next = first;
|
||||
|
||||
last->next = next;
|
||||
next->prev = last;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_splice_tail_init - join two lists and reinitialise the emptied list
|
||||
* @list: the new list to add.
|
||||
* @head: the place to add it in the first list.
|
||||
*
|
||||
* Each of the lists is a queue.
|
||||
* The list at @list is reinitialised
|
||||
*/
|
||||
static inline void list_splice_tail_init(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
if (!list_empty(list)) {
|
||||
__list_splice(list, head->prev, head);
|
||||
INIT_LIST_HEAD(list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* list_is_singular - tests whether a list has just one entry.
|
||||
* @head: the list to test.
|
||||
*/
|
||||
static inline int list_is_singular(const struct list_head *head)
|
||||
{
|
||||
return !list_empty(head) && (head->next == head->prev);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_splice_tail - join two lists, each list being a queue
|
||||
* @list: the new list to add.
|
||||
* @head: the place to add it in the first list.
|
||||
*/
|
||||
static inline void list_splice_tail(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
if (!list_empty(list)) {
|
||||
__list_splice(list, head->prev, head);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
#ifndef __LOG_H
|
||||
#define __LOG_H
|
||||
|
||||
|
||||
#include "printf.h"
|
||||
|
||||
#define __LOG_VERB 0
|
||||
#define __LOG_DEBUG 1
|
||||
#define __LOG_INFO 2
|
||||
#define __LOG_WARN 3
|
||||
#define __LOG_ERROR 4
|
||||
#define __LOG_CHAR 5
|
||||
|
||||
#define __LOG_ENABLE
|
||||
|
||||
#ifndef __LOG_LEVEL
|
||||
#define __LOG_LEVEL 0
|
||||
#endif
|
||||
|
||||
#ifdef __DEBUG
|
||||
#else
|
||||
#define CONFIG_RELEASE_ENABLE
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_RELEASE_ENABLE
|
||||
#undef __LOG_LEVEL
|
||||
#define __LOG_LEVEL 0xff
|
||||
#endif
|
||||
|
||||
|
||||
#if __LOG_LEVEL > __LOG_VERB
|
||||
#define log_v(...) do {} while (0)
|
||||
#else
|
||||
#define log_v(...) printf(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
|
||||
#if __LOG_LEVEL > __LOG_DEBUG
|
||||
#define log_d(...) do {} while (0)
|
||||
#else
|
||||
#define log_d(...) printf(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if __LOG_LEVEL > __LOG_INFO
|
||||
#define log_i(...) do {} while (0)
|
||||
#else
|
||||
#define log_i(...) printf(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if __LOG_LEVEL > __LOG_WARN
|
||||
#define log_w(...) do {} while (0)
|
||||
#else
|
||||
#define log_w(...) printf(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if __LOG_LEVEL > __LOG_ERROR
|
||||
#define log_e(...) do {} while (0)
|
||||
#else
|
||||
#define log_e(...) printf(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if __LOG_LEVEL > __LOG_CHAR
|
||||
#define log_c(x) do {} while (0)
|
||||
#elif defined __LOG_ENABLE
|
||||
#define log_c(x) putchar(x)
|
||||
#else
|
||||
#define log_c(x)
|
||||
#endif
|
||||
|
||||
|
||||
#define r_printf(x, ...) log_i("\e[31m\e[1m" x "\e[0m", ## __VA_ARGS__)
|
||||
#define g_printf(x, ...) log_i("\e[32m\e[1m" x "\e[0m", ## __VA_ARGS__)
|
||||
#define y_printf(x, ...) log_i("\e[33m\e[1m" x "\e[0m", ## __VA_ARGS__)
|
||||
#define r_f_printf(x, ...) log_i("\e[31m\e[5m\e[1m" x "\e[0m", ## __VA_ARGS__)
|
||||
#define g_f_printf(x, ...) log_i("\e[32m\e[5m\e[1m" x "\e[0m", ## __VA_ARGS__)
|
||||
#define y_f_printf(x, ...) log_i("\e[33m\e[5m\e[1m" x "\e[0m", ## __VA_ARGS__)
|
||||
|
||||
#ifndef __LOG_ENABLE
|
||||
|
||||
#define log_dump(a, b) do {} while(0)
|
||||
#define log_putchar() do {} while(0)
|
||||
#define log_early_init(a) do {} while(0)
|
||||
#define log_level(a) do {} while(0)
|
||||
|
||||
#else
|
||||
|
||||
struct logbuf {
|
||||
u16 len;
|
||||
u16 buf_len;
|
||||
char buf[0];
|
||||
};
|
||||
|
||||
int log_output_lock();
|
||||
|
||||
void log_output_unlock();
|
||||
|
||||
void log_print_time();
|
||||
|
||||
void log_early_init(int buf_size);
|
||||
|
||||
void log_level(int level);
|
||||
|
||||
// void log_print(int level, const char *tag, const char *format, ...);
|
||||
|
||||
void log_dump(const u8 *buf, int len);
|
||||
|
||||
struct logbuf *log_output_start(int len);
|
||||
|
||||
void log_output_end(struct logbuf *);
|
||||
|
||||
void log_putchar(struct logbuf *lb, char c);
|
||||
|
||||
void log_put_u8hex(struct logbuf *lb, unsigned char dat);
|
||||
|
||||
void log_putbyte(char);
|
||||
|
||||
void log_set_time_offset(int offset);
|
||||
|
||||
int log_get_time_offset();
|
||||
|
||||
#endif
|
||||
|
||||
void log_flush();
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,63 @@
|
||||
#ifndef _MSG_H_
|
||||
#define _MSG_H_
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
#if (defined(CONFIG_CPU_BD47) || defined(CONFIG_CPU_BR29)) && defined(BLE_APP_LOW_RAM_USED) // bd47 内存紧缺
|
||||
#define MAX_POOL 100
|
||||
#else
|
||||
#define MAX_POOL 128
|
||||
#endif
|
||||
|
||||
enum {
|
||||
MSG_NO_ERROR = 0,
|
||||
MSG_EVENT_EXIST = -1,
|
||||
MSG_NOT_EVENT = -2,
|
||||
MSG_EVENT_PARAM_ERROR = -3,
|
||||
MSG_BUF_NOT_ENOUGH = -4,
|
||||
};
|
||||
|
||||
#define Q_USER 0x400000
|
||||
enum {
|
||||
LMP_EVENT = Q_USER + 1,
|
||||
LMP_HCI_CMD,
|
||||
LMP_HCI_CMD_TO_CONN,
|
||||
HCI_COMMON_CMD,
|
||||
LL_EVENT,
|
||||
HCI_CMD_TO_LL,
|
||||
HCI_CMD_TO_LL_CONN,
|
||||
TWS_LMP_EVENT,
|
||||
|
||||
BTSTACK_HCI_EVENT,
|
||||
BTSTACK_HCI_ACL,
|
||||
|
||||
//MSG_BT_UPDATA_START = 0x80,
|
||||
//MSG_BT_UPDATE_LOADER_DOWNLOAD_START,
|
||||
MSG_JL_SPEECH_START_PREPARE = 0xB00,
|
||||
MSG_JL_SPEECH_START,
|
||||
MSG_JL_SPEECH_STOP,
|
||||
MSG_JL_GET_DEV_INFO,
|
||||
MSG_JL_GET_DEV_UPDATE_FILE_INFO_OFFSET,
|
||||
MSG_JL_INQUIRE_DEVEICE_IF_CAN_UPDATE,
|
||||
|
||||
MSG_JL_ENTER_UPDATE_MODE,
|
||||
MSG_JL_EXIT_UPDATE_MODE,
|
||||
MSG_JL_UPDATE_DISCONNECT,
|
||||
MSG_JL_UPDATE_REVICE_REBOOT,
|
||||
MSG_JL_SWITCH_CH_SPP,
|
||||
|
||||
MSG_JL_SUCCESS_STATUS_HANDLE,
|
||||
MSG_JL_ERR_STATUS_HANDLE,
|
||||
|
||||
MSG_JL_GET_PRIVATE_INFO,
|
||||
|
||||
MSG_UBOOT_SOFT_POWEROFF,
|
||||
|
||||
|
||||
};
|
||||
|
||||
void task_message_init(void);
|
||||
int task_post_msg(char *name, int argc, ...);
|
||||
int task_post_msg_base(const char *name, int argc, int cmd, int *argv);
|
||||
int task_get_msg(u16 timeout, int len, int *msg);
|
||||
#endif
|
||||
@@ -0,0 +1,76 @@
|
||||
#define SYS_TIMER_H
|
||||
|
||||
|
||||
#include "generic/typedef.h"
|
||||
#include "list.h"
|
||||
|
||||
typedef int sys_timer;
|
||||
|
||||
struct sys_timer {
|
||||
struct list_head entry;
|
||||
void (*func)(void *priv);
|
||||
void *priv;
|
||||
u32 jiffies;
|
||||
u32 msec: 24;
|
||||
u32 del: 1;
|
||||
u32 timeout: 1;
|
||||
u16 id;
|
||||
u8 used;
|
||||
};
|
||||
|
||||
void sys_timer_init();
|
||||
bool __timer_find(struct sys_timer *timer);
|
||||
u16 sys_timer_add(void *priv, void (*func)(void *priv), u32 msec);
|
||||
void sys_timer_schedule(void);
|
||||
void sys_timer_delay_schedule(void);
|
||||
void sys_timer_set_user(struct sys_timer *timer, u32 user);
|
||||
u32 sys_timer_get_user(struct sys_timer *timer);
|
||||
void sys_timer_del_schedule(void);
|
||||
void loop_timer_schedule(void);
|
||||
void sys_timer_re_run(u16 id);
|
||||
void sys_timer_del(u16 t);
|
||||
int sys_timer_modify(u16 id, u32 msec);
|
||||
u16 sys_timeout_add(void *priv, void (*func)(void *priv), u32 msec);
|
||||
void sys_timeout_del(u16 t);
|
||||
/*
|
||||
* For Compatible
|
||||
*/
|
||||
#define sys_hi_timer_schedule()\
|
||||
usr_timer_schedule()
|
||||
|
||||
#define sys_hi_timer_add(a, b, c)\
|
||||
sys_timer_add(a, b, c)
|
||||
|
||||
#define sys_hi_timeout_add(a, b, c)\
|
||||
sys_timeout_add(a, b, c)
|
||||
// usr_timeout_add(a, b, c, 1)
|
||||
|
||||
#define sys_hi_timer_modify(a, b)\
|
||||
sys_timer_modify(a, b)
|
||||
|
||||
#define sys_hi_timeout_modify(a, b)\
|
||||
sys_timer_modify(a, b)
|
||||
|
||||
#define sys_hi_timer_del(a)\
|
||||
sys_timer_del(a)
|
||||
|
||||
#define sys_hi_timeout_del(a)\
|
||||
sys_timer_del(a)
|
||||
|
||||
#define sys_s_hi_timer_add(a, b, c)\
|
||||
sys_timer_add(a, b, c, 0)
|
||||
|
||||
#define sys_s_hi_timerout_add(a, b, c)\
|
||||
sys_timeout_add(a, b, c, 0)
|
||||
|
||||
#define sys_s_hi_timer_modify(a, b)\
|
||||
sys_timer_modify(a, b)
|
||||
|
||||
#define sys_s_hi_timeout_modify(a, b)\
|
||||
sys_timer_modify(a, b)
|
||||
|
||||
#define sys_s_hi_timer_del(a)\
|
||||
sys_timer_del(a)
|
||||
|
||||
#define sys_s_hi_timeout_del(a)\
|
||||
sys_timeout_del(a)
|
||||
@@ -0,0 +1,219 @@
|
||||
/*************************************************************
|
||||
File: typedef.h
|
||||
Author:Juntham
|
||||
Discriptor:
|
||||
数据类型重定义
|
||||
Version:
|
||||
Date:
|
||||
*************************************************************/
|
||||
#ifndef _typedef_h_
|
||||
#define _typedef_h_
|
||||
|
||||
|
||||
#include "asm/cpu.h"
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned long long int uint64_t;
|
||||
|
||||
typedef unsigned char u8, bool, BOOL;
|
||||
typedef char s8;
|
||||
typedef signed short s16;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned int u32;
|
||||
typedef signed int s32;
|
||||
typedef unsigned long long u64;
|
||||
typedef u32 FOURCC;
|
||||
typedef long long s64;
|
||||
typedef unsigned long long u64;
|
||||
|
||||
#ifdef READ_BT_8
|
||||
#undef READ_BT_8
|
||||
#endif
|
||||
|
||||
#ifdef READ_BT_16
|
||||
#undef READ_BT_16
|
||||
#endif
|
||||
|
||||
#ifdef READ_BT_24
|
||||
#undef READ_BT_24
|
||||
#endif
|
||||
|
||||
#ifdef READ_BT_32
|
||||
#undef READ_BT_32
|
||||
#endif
|
||||
|
||||
#define READ_BT_8( buffer, pos) ( ((u8) buffer[pos]))
|
||||
#define READ_BT_16( buffer, pos) ( ((u16) buffer[pos]) | (((u16)buffer[pos+1]) << 8))
|
||||
#define READ_BT_24( buffer, pos) ( ((u32) buffer[pos]) | (((u32)buffer[pos+1]) << 8) | (((u32)buffer[pos+2]) << 16))
|
||||
#define READ_BT_32( buffer, pos) ( ((u32) buffer[pos]) | (((u32)buffer[pos+1]) << 8) | (((u32)buffer[pos+2]) << 16) | (((u32) buffer[pos+3])) << 24)
|
||||
|
||||
#if defined(__GNUC__)
|
||||
|
||||
///<locate code to x segment ever exist
|
||||
#define SEC_USED(x) __attribute__((section(#x),used))
|
||||
///<locate code to x segment optimized by dependency
|
||||
#define SEC(x) __attribute__((section(#x)))
|
||||
#define sec(x) __attribute__((section(#x),used))
|
||||
///<locate data to x segment
|
||||
#define AT(x) __attribute__((section(#x)))
|
||||
#define SET(x) __attribute__((x))
|
||||
#define ALIGNED(x) __attribute__((aligned(x)))
|
||||
#define _GNU_PACKED_ __attribute__((packed))
|
||||
#define _NOINLINE_ __attribute__((noinline))
|
||||
#define _INLINE_ __attribute__((always_inline))
|
||||
#define _WEAK_ __attribute__((weak))
|
||||
#define _WEAKREF_ __attribute__((weakref))
|
||||
#define _NORETURN_ __attribute__((noreturn))
|
||||
#define _NAKED_ __attribute__((naked))
|
||||
#define SET_INTERRUPT __attribute__((interrupt("")))
|
||||
#define ___interrupt __attribute__((interrupt("")))
|
||||
#else
|
||||
|
||||
#define SEC_USED(x)
|
||||
#define SEC(x)
|
||||
#define AT(x)
|
||||
#define SET(x)
|
||||
#define ALIGNED(x)
|
||||
#define _GNU_PACKED_
|
||||
#define _NOINLINE_
|
||||
#define _INLINE_
|
||||
#define _WEAK_
|
||||
#define _WEAKREF_
|
||||
#define _NORETURN_
|
||||
#define _NAKED_
|
||||
#endif
|
||||
|
||||
|
||||
#if CPU_ENDIAN == LITTLE_ENDIAN
|
||||
//#define ntohl(x) (u32)((x>>24)|((x>>8)&0xff00)|(x<<24)|((x&0xff00)<<8))
|
||||
//#define ntoh(x) (u16)((x>>8&0x00ff)|x<<8&0xff00)
|
||||
|
||||
//#define ntohl(x) (u32)((((u32)(x))>>24) | ((((u32)(x))>>8)&0xff00) | (((u32)(x))<<24) | ((((u32)(x))&0xff00)<<8))
|
||||
//#define ntoh(x) (u16)((((u32)(x))>>8&0x00ff) | (((u32)(x))<<8&0xff00))
|
||||
|
||||
//#define NTOH(x) (x) = ntoh(x)
|
||||
//#define NTOHL(x) (x) = ntohl(x)
|
||||
#define LD_WORD(ptr) (u16)(*(u16*)(u8*)(ptr))
|
||||
#define LD_DWORD(ptr) (u32)(*(u32*)(u8*)(ptr))
|
||||
#define ST_WORD(ptr,val) *(u16*)(u8*)(ptr)=(u16)(val)
|
||||
#define ST_DWORD(ptr,val) *(u32*)(u8*)(ptr)=(u32)(val)
|
||||
#else
|
||||
#define ntohl(x) (x)
|
||||
#define ntoh(x) (x)
|
||||
#define NTOH(x) (x) = ntoh(x)
|
||||
#define NTOHL(x) (x) = ntohl(x)
|
||||
#endif
|
||||
|
||||
#if defined(__UPDATE_NEED_SFC) && defined(__APP_IS_OTA) && !defined(__UPDATE_RUN_RAM)
|
||||
#define SFC_MODE_EN
|
||||
#endif
|
||||
|
||||
#if defined(SFC_MODE_EN)
|
||||
#define AT_SPI_CODE AT(.vm_sfc.text.cache)
|
||||
#else
|
||||
#define AT_SPI_CODE
|
||||
#endif
|
||||
|
||||
|
||||
#undef FALSE
|
||||
#define FALSE 0
|
||||
|
||||
#undef TRUE
|
||||
#define TRUE 1
|
||||
|
||||
#define false 0
|
||||
#define true 1
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL (void *)0
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define BIT(n) (1UL << (n))
|
||||
#define BitSET(REG,POS) ((REG) |= (1L << (POS)))
|
||||
#define BitCLR(REG,POS) ((REG) &= (~(1L<< (POS))))
|
||||
#define BitXOR(REG,POS) ((REG) ^= (~(1L << (POS))))
|
||||
#define BitCHK_1(REG,POS) (((REG) & (1L << (POS))) == (1L << (POS)))
|
||||
#define BitCHK_0(REG,POS) (((REG) & (1L << (POS))) == 0x00)
|
||||
#define testBit(REG,POS) ((REG) & (1L << (POS)))
|
||||
|
||||
#define clrBit(x,y) (x) &= ~(1L << (y))
|
||||
#define setBit(x,y) (x) |= (1L << (y))
|
||||
|
||||
|
||||
#define readb(addr) *((volatile unsigned char*)(addr))
|
||||
#define readw(addr) *((volatile unsigned short *)(addr))
|
||||
#define readl(addr) *((volatile unsigned long*)(addr))
|
||||
|
||||
#define writeb(addr, val) *((volatile unsigned char*)(addr)) = (u8)(val)
|
||||
#define writew(addr, val) *((volatile unsigned short *)(addr)) = (u16)(val)
|
||||
#define writel(addr, val) *((volatile unsigned long*)(addr)) = (u32)(val)
|
||||
|
||||
#define ALIGN_4BYTE(size) ((size+3)&0xfffffffc)
|
||||
|
||||
#if CPU_ENDIAN == BIG_ENDIAN
|
||||
#define __cpu_u16(lo, hi) ((lo)|((hi)<<8))
|
||||
#elif CPU_ENDIAN == LITTLE_ENDIAN
|
||||
#define __cpu_u16(lo, hi) ((hi)|((lo)<<8))
|
||||
#else
|
||||
#error "undefine cpu eadin"
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
|
||||
#define ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0]))
|
||||
|
||||
|
||||
#define likely(x) __builtin_expect(!!(x), 1)
|
||||
#define unlikely(x) __builtin_expect(!!(x), 0)
|
||||
|
||||
#define SFR(sfr, start, len, dat) \
|
||||
(sfr = (sfr & ~((~(0xffffffff << (len))) << (start))) | \
|
||||
(((dat) & (~(0xffffffff << (len)))) << (start)))
|
||||
|
||||
|
||||
#include "errno-base.h"
|
||||
#include "string.h"
|
||||
#include "strings.h"
|
||||
#include "malloc.h"
|
||||
#include "jiffies.h"
|
||||
|
||||
|
||||
#ifdef offsetof
|
||||
#undef offsetof
|
||||
#endif
|
||||
|
||||
#ifdef container_of
|
||||
#undef container_of
|
||||
#endif
|
||||
|
||||
#define offsetof(type, memb) \
|
||||
((unsigned long)(&((type *)0)->memb))
|
||||
|
||||
#define container_of(ptr, type, memb) \
|
||||
((type *)((char *)(ptr) - offsetof(type, memb)))
|
||||
|
||||
void delay(unsigned int);
|
||||
|
||||
void delay_us(unsigned int);
|
||||
|
||||
// 只适用32位以内数据比较
|
||||
#define LOOP_OVERTAKE(a, b, n) \
|
||||
((((a) - (b)) & ((1ULL << (n)) - 1)) < ((1UL << ((n) - 1))))
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user