小编Ama*_*ury的帖子

C、硬件抽象层中“extern”类型的变量

我正在研究硬件抽象层。此 HAL 的目的是在 Linux 驱动程序和 MCU 驱动程序之间轻松切换。

我正在研究 SPI 接口。下面是HAL“打开”SPI接口的函数签名。

hal/spi.h

spi_handle_t spi_open(spi_port_t channel, spi_config_t config);

Run Code Online (Sandbox Code Playgroud)

spi_port_t :

  • 在 Linux 上,它是一个基本类型:uint32_t
  • 在 MCU 上,它是一个结构体。

spi_config_t :

  • 在 Linux 和 MCU 上,它都是一个结构体,但具有不同的字段。

所以在mcu/spi.c 中,我在某个时候有:

typedef spiBASE_t spi_channel_t;
typedef spiDAT1_t spi_config_t;

spi_handle_t spi_open(spi_channel_t channel, spi_config_t config) {
.
.
.
}
Run Code Online (Sandbox Code Playgroud)

对于linux/spi.c:

typedef uint32_t spi_channel_t;
typedef ChannelConfig_t spi_config_t;

spi_handle_t spi_open(spi_channel_t channel, spi_config_t config) {
.
.
.
}
Run Code Online (Sandbox Code Playgroud)

现在问题出在hal/spi.h 中,我需要定义什么是 spi_channel_t 和 spi_config_t。

有没有办法制作类似的东西(我知道用 extern 是不可能的,但为了解释问题......): …

c embedded types hal extern

2
推荐指数
1
解决办法
72
查看次数

标签 统计

c ×1

embedded ×1

extern ×1

hal ×1

types ×1