This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] TMS320F28069M:为什么在寄存器位结构定义中使用 UINT16类型?

Guru**** 2534260 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1045470/tms320f28069m-why-is-uint16-used-as-the-type-in-register-bit-structure-definition

器件型号:TMS320F28069M

我的问题是关于寄存器位结构的类型。

让我们以 F2806x_GPIO.h 为例、为什么类型是 uint16、而总位数是32。 为什么类型不是 uint32? 该位结构中使用的两种类型会产生什么影响?

struct GPA1_bits{// bits description
UINT16 GPIO0:2;// 1:0 GPIO0
UINT16 GPIO1:2;// 3:2 GPIO1
uint16 GPIO2:2;// 5:4 GPIO2
UINT16 GPIO3:2;// 7:6 GPIO3
UINT16 GPIO4:2;// 9:8 GPIO4
UINT16 GPIO5:2;// 11:10 GPIO5
UINT16 GPIO6:2;// 13:12 GPIO6
UINT16 GPIO7:2;// 15:14 GPIO7
UINT16 GPIO8:2;// 17:16 GPIO8
UINT16 GPIO9:2;// 19:18 GPIO9
UINT16 GPIO10:2;// 21:20 GPIO10
UINT16 GPIO11:2;// 23:22 GPIO11
UINT16 GPIO12:2;// 25:24 GPIO12
UINT16 GPIO13:2;// 27:26 GPIO13
UINT16 GPIO14:2;// 29:28 GPIO14
UINT16 GPIO15:2;// 31:30 GPIO15
};

UNION GPA1_REG{
uint32 all;
struct GPA1_BITS;
};

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Louis、  

    我想它也可以是 uint32。  检查并返回给您。  

     当位字段超过大小(uint16)时。 编译器将分配存储器的下一个时隙(下一个 UINT16)、并将开始使用这些字节。

    每个位字段定义将只占用2个位 (例如 :uint16 GPIO0:2;// 1:0 GPIO0)、整个寄存器占用32个位、因此 UNION 使用 uint32。

    此致

    Siddharth