我为 AVR XMega 微 Controller 编写了一个引导加载程序,并且该引导加载程序由配置文件配置:
Config_Bootloader.h
#ifndef CONFIG_BOOTLOADER_H_
#define CONFIG_BOOTLOADER_H_
#include <avr/io.h>
#define BOOTLOADER_INTERFACE &USARTE0
#define BOOTLOADER_BAUD 115200
#define BOOTLOADER_TX 3
#endif /* CONFIG_BOOTLOADER_H_ */
此配置文件应该由另一个包含文件进行预处理,以获取一些寄存器值等。
Bootloader_Preprocessing.h
#ifndef BOOTLOADER_PREPROCESSING_H_
#define BOOTLOADER_PREPROCESSING_H_
#include <avr/io.h>
#ifdef USARTE0
#if(BOOTLOADER_INTERFACE == &USARTE0)
#define BOOTLOADER_PORT &PORTE
#else
#error "Invalid bootloader interface!"
#endif
#endif
#if(BOOTLOADER_BAUD == 9600)
#define BOOTLOADER_BRREG_VALUE 12
#define BOOTLOADER_SCALE_VALUE 0
#elif(BOOTLOADER_BAUD == 19200)
#define BOOTLOADER_BRREG_VALUE 11
#define BOOTLOADER_SCALE_VALUE -1
#elif(BOOTLOADER_BAUD == 38400)
#define BOOTLOADER_BRREG_VALUE 9
#define BOOTLOADER_SCALE_VALUE -2
#elif(BOOTLOADER_BAUD == 57600)
#define BOOTLOADER_BRREG_VALUE 75
#define BOOTLOADER_SCALE_VALUE -6
#elif(BOOTLOADER_BAUD == 115200)
#define BOOTLOADER_BRREG_VALUE 11
#define BOOTLOADER_SCALE_VALUE -7
#else
#error "Invalid baud rate for bootloader!"
#endif
#endif /* BOOTLOADER_PREPROCESSING_H_ */
我将这两个文件都包含到我的 Bootloader.h
#ifndef BOOTLOADER_H_
#define BOOTLOADER_H_
#include "Config_Bootloader.h"
#include "Bootloader_Preprocessing.h"
#endif /* BOOTLOADER_H_ */
我收到以下错误和警告:
> #define BOOTLOADER_INTERFACE &USARTE0
operator '&' has no left operand
> #if(BOOTLOADER_INTERFACE == &USARTE0)
in expansion of macro 'BOOTLOADER_INTERFACE'
#error "Invalid bootloader interface!"
那么为什么地址比较不起作用?
最佳答案
预处理器中不存在“地址”之类的东西,因此无法在#if
预处理器指令中对它们进行比较。
参见the GCC docs for #IF
有关它可以做什么和不能做什么的详细信息。请参阅您正在使用的预处理器的文档,可能适用其他/不同的限制(您将其标记为 AVR)。
您的预处理器似乎得出结论,运算符 &
必须是按位运算符 &,它是二元运算符,因此需要左操作数。
关于c - 预处理器的 If 条件问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56642242/