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

查看:29
本文介绍了配置 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);

第一个定义应由仅在目标上使用的宏保护.使用像

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天全站免登陆