配置SourceTrail以使用@语法接受嵌入式c/c ++头文件 [英] Configure SourceTrail to accept embedded c/c++ header files with @ syntax

查看:82
本文介绍了配置SourceTrail以使用@语法接受嵌入式c/c ++头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Sourcetrail( https://www.sourcetrail.com/)来迅速进入pic18系列微控制器的一些旧的嵌入式c/c ++源代码.

I'm attempting to use Sourcetrail (https://www.sourcetrail.com/) to quickly get into some old embedded c/c++ source code for the pic18 series of microcontrollers.

导入硬件包含文件时出现错误,该文件使用奇异的方法定义可位寻址的硬件寄存器的硬件地址,例如 pic18f26k22.h 中的以下内容.

I get errors when importing the hardware include files, which uses an exotic method to define the hardware address of the bit addressable hardware registers, such as the below from pic18f26k22.h.

typedef union {
    struct {
        unsigned ANSA0                  :1;
        unsigned ANSA1                  :1;
        unsigned ANSA2                  :1;
        unsigned ANSA3                  :1;
        unsigned                        :1;
        unsigned ANSA5                  :1;
    };
} ANSELAbits_t;

extern volatile ANSELAbits_t ANSELAbits @ 0xF38;

您可能已经猜到了,SourceTrail被 @ 0xF38 部分所迷惑,并且期望只是一个分号.嵌入式系统的许多其他c/c ++编译器都使用该方法,因此我认为存在一个简单的修复方法.

As you probably guessed, SourceTrail is confused by the @ 0xF38 part and expect just a semicolon. The method is used by a number of other c/c++ compilers for embedded systems, so I assume a simple fix exists.

首先,要弄清楚:@用于将volatile变量作为位或字节地址放置在内存映射中的特定位置.(与8086 CPU具有内存和IO寻址系统的方式略有相似).在这种情况下,MPLab c/c ++编译器附带了全局包含(用于数百个不同的微控制器).为了便于分析,我可以复制全局包含文件,并在SourceTrail中设置指向全局包含的其他路径-以便可以根据需要进行修改.我希望不要触摸项目文件,因为它们仍需要在原始设置中进行编译.

First, to clarify: The @ is used to place the volatile variable at a specific place in the memory map, either as a bit or a byte address. (Slightly similar to how the 8086 CPU had memory and IO addressing systems). It's used in the global includes (for hundredts of different microcontrollers) that in this case came with the MPLab c/c++ compiler. For analysis purpuse I can make a copy of the global include files, and set up a different path to the global includes in SourceTrail - so they can be modified as much as needed. I would prefer to not touch the project files, as they still need to compile in the original setup.

在尝试@Antti Haapala回答时,我发现需要考虑以下类型的用法:

While attempting @Antti Haapala answer, I found the following types of usage that needs to be taken into account:

extern volatile unsigned char           BAUDCON1            @ 0xFB8;

#ifndef BANKMASK
#define BANKMASK(addr) ((addr)&0FFh)
#endif
extern volatile __bit                   ABDEN1              @ (((unsigned) &BAUDCON1)*8) + 0;
#define                                 ABDEN1_bit          BANKMASK(BAUDCON1), 0

我找不到在任何地方定义的 __ bit ,但这是一个特殊的结构,用于保存该位的位地址(而非字节地址).

I can not find __bit defined anywhere, but it's a special construct that holds the bit address (not byte address) of the bit.

推荐答案

@在C中不是有效的令牌,因此您也不能将其用作宏标识符.最简单的解决方案是使用一个宏来处理@地址,即

@ is not a valid token in C, so you cannot use it as a macro identifier either. The easiest solution would be to handle the @ address with a macro, i.e.

#ifdef somethingsomething
#define AT(address) @ address
#else
#define AT(address)
#endif

extern volatile ANSELAbits_t ANSELAbits AT(0xF38);

第一个定义应由仅在目标上使用的宏保护.使用简单的Perl脚本(如

The first definition should be guarded by a macro that is used only on the target. It should be quite easy to do the change with a simple Perl script like

perl -pi -e 's/@\s*([0-9a-fA-FxX]+)/AT($1)/g' *.c *.h


如果按原样在供应商提供的头文件中使用此 @ 语法,则对其感到羞耻.


If this @ syntax is used in the vendor-provided header files as is, then shame on them.

这篇关于配置SourceTrail以使用@语法接受嵌入式c/c ++头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆