bt_types.h

来自「AMLOGIC DPF source code」· C头文件 代码 · 共 205 行

H
205
字号
#ifndef __BT_TYPES_H
#define __BT_TYPES_H

#ifdef AVOS
	#include <os/ioapi/include/sysdefine.h>
	#include <Unicode/inc/unicode.h>
	#include <listop.h>
	#include <stdint.h>
    #include <compiler.h>
#else
	#include "../misc/unicode.h"
	#include "../misc/list.h"
	
	#define inline			_Inline

	typedef signed char		__s8;
	typedef signed short	__s16;
	typedef signed long		__s32;
	
	typedef unsigned char	__u8;
	typedef unsigned short	__u16;
	typedef unsigned long	__u32;
	
	typedef __s8			int8_t;
	typedef __s16			int16_t;
	typedef __s32			int32_t;
	
	typedef	__u8			uint8_t;
	typedef __u16			uint16_t;
	typedef __u32			uint32_t;

	typedef __u16			__le16;
	typedef __u16			__be16;
	typedef __u32			__le32;
	typedef __u32			__be32;
#endif


#pragma Pack(1)

typedef struct uint64
{
	unsigned char data[8];
} _uint64_t;

typedef struct int64
{
	char data[8];
} _int64_t;

typedef struct uint128
{
	unsigned char data[16];
} uint128_t;

typedef struct int128
{
	char data[16];
} int128_t;

#pragma Pack()

#define __cpu_to_le16(x) 			((__u16)(x))
#define __cpu_to_le32(x) 			((__u32)(x))
#define __cpu_to_le64(src,dst)		memcpy(dst,src,8)
#define __cpu_to_le128(src,dst)		memcpy(dst,src,16)

#define __cpu_to_be16(x) 			((((x)<<8)&0xFF00)|(((x)>>8)&0x00FF))
#define __cpu_to_be32(x) 			((((x)<<24)&0xFF000000)|(((x)<<8)&0x00FF0000)|(((x)>>8)&0x0000FF00)|(((x)>>24)&0x000000FF))
#define __cpu_to_be64(src,dst)		ntoh64(src,dst)
#define __cpu_to_be128(src,dst)		ntoh128(src,dst)

#define __le16_to_cpu(x) 			((__le16)(x))
#define __le32_to_cpu(x) 			((__le32)(x))
#define __le64_to_cpu(src,dst)		memcpy(dst,src,8)
#define __le128_to_cpu(src,dst)		memcpy(dst,src,16)

#define __be16_to_cpu(x) 			((((x)<<8)&0xFF00)|(((x)>>8)&0x00FF))
#define __be32_to_cpu(x) 			((((x)<<24)&0xFF000000)|(((x)<<8)&0x00FF0000)|(((x)>>8)&0x0000FF00)|(((x)>>24)&0x000000FF))
#define __be64_to_cpu(src,dst)		ntoh64(src,dst)
#define __be128_to_cpu(src,dst)		ntoh128(src,dst)


#define BT_UNALIGNED_FUNC

#ifndef BT_UNALIGNED_FUNC
	#define get_byte(ptr,i)						(* ((__u8 *)(ptr) + (i)) )
	#define put_byte(ptr,i,data)				{*((__u8 *)(ptr) + (i)) = (__u8)(data);}
	#define get_unaligned_16(ptr)				(get_byte(ptr,0) | (get_byte(ptr,1)<<8))
	#define get_unaligned_32(ptr)				(get_byte(ptr,0) | (get_byte(ptr,1)<<8) | (get_byte(ptr,2)<<16) | (get_byte(ptr,3)<<24))
	#define put_unaligned_16(word_val,ptr)		{put_byte(ptr,0,(word_val)&0xFF); put_byte(ptr,1,((word_val)>>8)&0xFF);}
	#define put_unaligned_32(dword_val,ptr)		{put_byte(ptr,0,(dword_val)&0xFF); put_byte(ptr,1,((dword_val)>>8)&0xFF); put_byte(ptr,2,((dword_val)>>16)&0xFF); put_byte(ptr,3,((dword_val)>>24)&0xFF);}
#else
	unsigned short get_unaligned_16(void *ptr);
	unsigned long get_unaligned_32(void *ptr);
	void put_unaligned_16(unsigned short data16, void *ptr);
	void put_unaligned_32(unsigned long data32, void *ptr);
#endif

//#define htonl		__cpu_to_be32
//#define htons		__cpu_to_be16
//#define ntohl		__be32_to_cpu
//#define ntohs		__be16_to_cpu

void ntoh64(_uint64_t *src, _uint64_t *dst);
void ntoh128(uint128_t *src, uint128_t *dst);

void bt_set_bit(int nr, volatile void *addr);
void bt_clear_bit(int nr, volatile void *addr);
int bt_test_bit(int nr, volatile void *addr);

typedef unsigned int atomic_t;

#define atomic_read(x)					(*(x))
#define atomic_set(x,y)					(*(x)=(y))
#define atomic_dec(x)					((*(x))--)
#define atomic_inc(x)					((*(x))++)
#define atomic_inc_and_test(v)			(++(*v) == 0)
#define atomic_dec_and_test(v)			(--(*v) == 0)
#define atomic_add(i,x)					(*(x)+=i)

#ifdef AVOS
	#ifdef BT_DEBUG
		void* bt_malloc(size_t len);
		void* bt_realloc(void *p, size_t len);
	#else
		#define bt_malloc				AVMem_malloc
		#define bt_realloc				AVMem_realloc
	#endif
	#if (OS_TASK_DEBUGHELPER_EN&2)
		void bt_free(void *p);
	#else
		#define bt_free					AVMem_free
	#endif
	
	#ifdef BT_DEBUG
		void* bt_umalloc(size_t len);
		void* bt_urealloc(void *p, size_t len);
	#else
		#define bt_umalloc				AVMem_umalloc
		#define bt_urealloc				AVMem_urealloc
	#endif
	#define bt_ufree					bt_free
	
	#ifdef BT_DEBUG
		void* bt_kmalloc(size_t len);
		void* bt_krealloc(void *p, size_t len);
	#else
		#define bt_kmalloc				AVMem_kmalloc
		#define bt_krealloc				AVMem_krealloc
	#endif
	#define bt_kfree					bt_free
#else
	//typedef unsigned int size_t;
	//extern void free(void *);
	//extern void * malloc(size_t);
	#define bt_malloc					malloc
	#define bt_free						free
	
	#define bt_umalloc					malloc
	#define bt_ufree					free
	
	#define bt_kmalloc					malloc
	#define bt_kfree					free
#endif

typedef unsigned int spin_lock_t;
typedef signed int rw_lock_t;


#ifndef CONFIG_BT_HCI_CORE_DEBUG
#undef  BT_DBG
#define BT_DBG(D...)
#endif

#ifndef CONFIG_BT_HCI_CORE_ERROR
#undef  BT_ERR
#define BT_ERR(D...)
#endif

//#define bt_printk(X) {AVSchedLock();printf X;AVSchedUnlock();}
#define bt_printk(X) AVOS_printf X

//in os_cfg.h: #define OS_TICKS_PER_SEC        1000     /* Set the number of ticks in one second
//			   #define OS_MILLIS_PER_TICK      (1000/OS_TICKS_PER_SEC) /* Number of milliseconds per tick */
//			   #define OS_MILLIS_TO_TICKS(m)   (m/OS_MILLIS_PER_TICK)
#undef  HZ
#define HZ OS_TICKS_PER_SEC

//in amsystem.c: WRITE_ISA_REG(IREG_TIMER_BASE, 27*10); /* 100k hz base on 27MHz,a bug exist */
//   			 WRITE_ISA_REG(IREG_PIT1, 100);         /* 1 msec */
//				 Timer1_Handler() -> OSTimeTick() -> OSTime -> AVTimeGet()
#define jiffies		AVTimeGet()
//#define jiffies		(OS_MILLIS_TO_TICKS(AVTimeGet()))

//#define NULL	0

//#define min_t(type,x,y) ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
//#define max_t(type,x,y) ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
#define min_t(x,y) ((x)<(y) ? (x) : (y))
#define max_t(x,y) ((x)>(y) ? (x) : (y))


#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?