鄙人觉得Nios II HAL自带的数据类型宏真的不好用,而且还有个alt_前缀,移植很麻烦。
代码1 alt_types.h
#ifndef __ALT_TYPES_H__
#define __ALT_TYPES_H__
/******************************************************************************
* *
* License Agreement *
* *
* Copyright (c) 2003 Altera Corporation, San Jose, California, USA. *
* All rights reserved. *
* *
******************************************************************************/
/*
* Don't declare these typedefs if this file is included by assembly source.
*/
#ifndef ALT_ASM_SRC
typedef signed char alt_8;
typedef unsigned char alt_u8;
typedef signed short alt_16;
typedef unsigned short alt_u16;
typedef signed long alt_32;
typedef unsigned long alt_u32;
typedef long long alt_64;
typedef unsigned long long alt_u64;
#endif
#define ALT_INLINE __inline__
#define ALT_ALWAYS_INLINE __attribute__ ((always_inline))
#define ALT_WEAK __attribute__((weak))
#endif /* __ALT_TYPES_H__ */
我习惯于使用STM32的数据类型宏,因为都是32位的RISC处理器,所以都是通用的,推荐大家也使用。哈哈,看起来都比较清爽。
代码2 my_types.h
// copy from stm32f10x_type.h
#ifndef MY_TYPES_H_
#define MY_TYPES_H_
typedef signed long s32;
typedef signed short s16;
typedef signed char s8;
typedef signed long const sc32; /* Read Only */
typedef signed short const sc16; /* Read Only */
typedef signed char const sc8; /* Read Only */
typedef volatile signed long vs32;
typedef volatile signed short vs16;
typedef volatile signed char vs8;
typedef volatile signed long const vsc32; /* Read Only */
typedef volatile signed short const vsc16; /* Read Only */
typedef volatile signed char const vsc8; /* Read Only */
typedef unsigned long u32;
typedef unsigned short u16;
typedef unsigned char u8;
typedef unsigned long const uc32; /* Read Only */
typedef unsigned short const uc16; /* Read Only */
typedef unsigned char const uc8; /* Read Only */
typedef volatile unsigned long vu32;
typedef volatile unsigned short vu16;
typedef volatile unsigned char vu8;
typedef volatile unsigned long const vuc32; /* Read Only */
typedef volatile unsigned short const vuc16; /* Read Only */
typedef volatile unsigned char const vuc8; /* Read Only */
typedef enum {FALSE = 0, TRUE = !FALSE} bool;
#endif /* MY_TYPES_H_ */
下面给个my_types.h的使用范例。
代码3 PIO寄存器结构体
#include "my_types.h"
// PIO Data structure
typedef struct
{
vu32 DATA : 32;
vu32 DIRECTION : 32;
vu32 INTERRUPT_MASK : 32;
vu32 EDGE_CAPTURE : 32;
}PIO_T;
|