打印
[AVR单片机]

大家以后不要再用SIGNAL和SIG_xxx了

[复制链接]
4593|6
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
John_Lee|  楼主 | 2008-9-25 17:55 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
原文见:avr-libc: <avr/interrupt.h>: Interrupts

我摘录其中一段:
Starting with avr-libc version 1.4.0, a second style of interrupt vector names has been added, where a short phrase for the vector description is followed by _vect. The short phrase matches the vector name as described in the datasheet of the respective device (and in Atmel's XML files), with spaces replaced by an underscore and other non-alphanumeric characters dropped. Using the suffix _vect is intented to improve portability to other C compilers available for the AVR that use a similar naming convention.

The historical naming style might become deprecated in a future release, so it is not recommended for new projects.

从avr-libc 1.4.0开始,加入了第二种风格的中断向量名称,形式为一个向量描述的短语紧接着_vect。这个短语中的向量名称是AVR器件手册中描述的(Atmel的XML文件也有),名称中的空格用下划线代替,并且去掉非字母数字的其它字符。使用_vect后缀是为了改善与其它C编译器的可移植性,这些AVR编译器使用类似的命名习惯。

老式的命名风格可能会在将来的版本中被摒弃,所以不推荐使用在新的项目中。

相关帖子

沙发
qjy_dali| | 2008-9-25 20:18 | 只看该作者

上次用的时候我也看到了

使用特权

评论回复
板凳
kanprin| | 2008-9-25 20:45 | 只看该作者

恩, 对于新的编译器

( >= gcc 4.2 ),建议用 ISR(XXXX_vect)形式。

想问老师一个问题,关于GCC 4.3.0 处理“结构对齐”的问题。

用winavr20050214编译lwip1.3到时候,在cc.h中如下定义没问题。
gcc 3.4.3 :
#define PACK_STRUCT_FIELD(x) x __attribute__((packed))
#define PACK_STRUCT_STRUCT __attribute__((packed))
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_END

使用:
PACK_STRUCT_BEGIN
struct ip_addr {
  PACK_STRUCT_FIELD(u32_t addr);
} PACK_STRUCT_STRUCT;
PACK_STRUCT_END


但在winavr20080610中这样定义,使用就出问题了,
提示 warning: 'packed' attribute ignored for field of type 'u32_t'

我在帮助文件里找到了相关的说明:

— Macro: HANDLE_SYSV_PRAGMA

Define this macro (to a value of 1) if you want the System V style pragmas #pragma pack(<n>) and #pragma weak <name> [=<value>] to be supported by gcc. 

The pack pragma specifies the maximum alignment (in bytes) of fields within a structure, in much the same way as the __aligned__ and __packed__ __attribute__s do. A pack value of zero resets the behavior to the default. 

A subtlety for Microsoft Visual C/C++ style bit-field packing (e.g. -mms-bitfields) for targets that support it: When a bit-field is inserted into a packed record, the whole size of the underlying type is used by one or more same-size adjacent bit-fields (that is, if its long:3, 32 bits is used in the record, and any additional adjacent long bit-fields are packed into the same chunk of 32 bits. However, if the size changes, a new field of that size is allocated). 

If both MS bit-fields and __attribute__((packed)) are used, the latter will take precedence. If __attribute__((packed)) is used on a single field when MS bit-fields are in use, it will take precedence for that field, but the alignment of the rest of the structure may affect its placement. 

The weak pragma only works if SUPPORTS_WEAK and ASM_WEAKEN_LABEL are defined. If enabled it allows the creation of specifically named weak labels, optionally with a value. 

所以我在makefile里面同时也定义了这个宏
CDEFS = -DHANDLE_SYSV_PRAGMA=1
但还是会出问题,请问我该如何解决这警告呢 ?
谢谢。

使用特权

评论回复
地板
John_Lee|  楼主 | 2008-9-25 23:39 | 只看该作者

packed属性对于AVR来说是没有意义的

因为gcc的avr后端(back-end)已经定义了默认的对齐为1个字节。avr对数据的访问本身来说也是按字节访问的,也就无所谓对齐了。你给它强加一个packed,编译器发觉它是不必要的,反而可能会给你一个warning。

解决方法其实很简单,把__attribute__((packed))去掉即可:
#define PACK_STRUCT_FIELD(x) x
#define PACK_STRUCT_STRUCT
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_END

使用特权

评论回复
5
kanprin| | 2008-9-26 15:04 | 只看该作者

谢谢老师

我看到的是,可以通过设置makefile中的变量 CFLAGS 来传递参数 -fpack-struct 实现结构对齐问题,不知老师说的是不是这个意思?

您说的方法我之前也验证过它的正确性 。 不过我按此方法设置后,另外一个宏定义函数还会警告:

#define ip_addr_debug_print(debug, ipaddr) \
        LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F, \
                ipaddr ? (u16_t)(ntohl((ipaddr)->addr) >> 24) & 0xff : 0, \
                ipaddr ? (u16_t)(ntohl((ipaddr)->addr) >> 16) & 0xff : 0, \
                ipaddr ? (u16_t)(ntohl((ipaddr)->addr) >> 8) & 0xff : 0, \
                ipaddr ? (u16_t)ntohl((ipaddr)->addr) & 0xff : 0))


比如在定义 
struct ip_addr naddr;
然后调用
ip_addr_debug_print(SOCKETS_DEBUG, &naddr);
便会提示
warning: the address of 'naddr' will always evaluate as 'true'

那这个警告如何消除呢?  
 #define ip_addr_debug_print() 里面改为 *ipaddr ? ……  ??

这些都是在新的gcc版本才出现的警告。

使用特权

评论回复
6
John_Lee|  楼主 | 2008-9-26 16:53 | 只看该作者

新的gcc的错误检查比较严格

这个警告和上面所讲的packed没有关系。

首先要说明一下,新版本的编译器在表达式检查方面多加了一个判断:如果是以“常数”与“常数”作比较,将给出一个警告---“xxx will always evaluate as 'true or false'”。但这不影响编译结果。

出现这个警告是因为ip_addr_debug_print宏里面对ipaddr参数做了是否非0的判断,相当于用ipaddr与常数0做了比较。而你使用这个宏时,用了个常数做参数:&naddr这个参数是个编译时能确定的数值,相当于常数(准确的说,应该链接时,但这无所谓,反正是个固定的数值,编译器在逻辑意义上可以把它作为常数)。结果造成了常数与常数比较。

说到解决方法,只要在你的表达式中消除了常数与常数比较,就OK了,你自己去实现。当然,不去管它也没啥。

使用特权

评论回复
7
kanprin| | 2008-9-26 18:21 | 只看该作者

经你这么一说才恍然大悟

原来是常数与常数比较了,呵呵。
谢谢老师。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

33

主题

1466

帖子

21

粉丝