
TI DSP位域寄存器文件(Bit Field and Register-File Structure)结构.pdf
8页很多初学者往往对 TI DSP 的大量的寄存器定义和组织形式感到迷茫,我从 TI 文档 中翻译了这篇文章,希望能对初学者有所帮助 以往寄存器定义一般用宏定义例如: /******************************************************************** * Traditional header file ********************************************************************/ #define Uint16 unsigned int #define Uint32 unsigned long // Memory Map // Addr Register #define SCICCRA (volatile Uint16 *)0x7050 // 0x7050 SCI-A Communications Control #define SCICTL1A (volatile Uint16 *)0x7051 // 0x7051 SCI-A Control Register 1 #define SCIHBAUDA (volatile Uint16 *)0x7052 // 0x7052 SCI-A Baud Register, High Bits #define SCILBAUDA (volatile Uint16 *)0x7053 // 0x7053 SCI-A Baud Register, Low Bits #define SCICTL2A (volatile Uint16 *)0x7054 // 0x7054 SCI-A Control Register 2 #define SCIRXSTA (volatile Uint16 *)0x7055 // 0x7055 SCI-A Receive Status #define SCIRXEMUA (volatile Uint16 *)0x7056 // 0x7056 SCI-A Receive Emulation Data Buffer #define SCIRXBUFA (volatile Uint16 *)0x7057 // 0x7057 SCI-A Receive Data Buffer #define SCITXBUFA (volatile Uint16 *)0x7059 // 0x7059 SCI-A Transmit Data Buffer #define SCIFFTXA (volatile Uint16 *)0x705A // 0x705A SCI-A FIFO Transmit #define SCIFFRXA (volatile Uint16 *)0x705B // 0x705B SCI-A FIFO Receive #define SCIFFCTA (volatile Uint16 *)0x705C // 0x705C SCI-A FIFO Control #define SCIPRIA (volatile Uint16 *)0x705F // 0x705F SCI-A Priority Control #define SCICCRB (volatile Uint16 *)0x7750 // 0x7750 SCI-B Communications Control #define SCICTL1B (volatile Uint16 *)0x7751 // 0x7751 SCI-B Control Register 1 #define SCIHBAUDB (volatile Uint16 *)0x7752 // 0x7752 SCI-B Baud Register, High Bits #define SCILBAUDB (volatile Uint16 *)0x7753 // 0x7753 SCI-B Baud Register, Low Bits #define SCICTL2B (volatile Uint16 *)0x7754 // 0x7754 SCI-B Control Register 2 #define SCIRXSTB (volatile Uint16 *)0x7755 // 0x7755 SCI-B Receive Status #define SCIRXEMUB (volatile Uint16 *)0x7756 // 0x7756 SCI-B Receive Emulation Data Buffer #define SCIRXBUFB (volatile Uint16 *)0x7757 // 0x7757 SCI-B Receive Data Buffer #define SCITXBUFB (volatile Uint16 *)0x7759 // 0x7759 SCI-B Transmit Data Buffer #define SCIFFTXB (volatile Uint16 *)0x775A // 0x775A SCI-B FIFO Transmit #define SCIFFRXB (volatile Uint16 *)0x775B // 0x775B SCI-B FIFO Receive #define SCIFFCTB (volatile Uint16 *)0x775C // 0x775C SCI-B FIFO Control #define SCIPRIB (volatile Uint16 *)0x775F // 0x775F SCI-B Priority Control 使用位域寄存器文件结构,可以更加灵活和高效的访问 DSP 的寄存器。
寄存器文件结构:用 C/C++中结构体成员的方式将 DSP 各种外设的寄存器 的集合在一起,称之为寄存器文件结构 位域定义:位域用于定义寄存器中每个功能块的名字和长度 ((1)))寄存器文件的定义寄存器文件的定义 以 F2812 的 SCI 外设寄存器为例介绍寄存器文件的定义下面的程序段用 C/C++结构体成员的方式将 SCI 各个寄存器组合成为一个结构体类型 SCI_REGS /******************************************************************** * SCI header file * Defines a register file structure for the SCI peripheral ********************************************************************/ #define Uint16 unsigned int #define Uint32 unsigned long struct SCI_REGS { Uint16 SCICCR_REG SCICCR; // Communications control register Uint16 SCICTL1_REG SCICTL1; // Control register 1 Uint16 SCIHBAUD; // Baud rate (high) register Uint16 SCILBAUD; // Baud rate (low) register Uint16 SCICTL2_REG SCICTL2; // Control register 2 Uint16 SCIRXST_REG SCIRXST; // Receive status register Uint16 SCIRXEMU; // Receive emulation buffer register Uint16 SCIRXBUF_REG SCIRXBUF; // Receive data buffer Uint16 rsvd1; // reserved Uint16 SCITXBUF; // Transmit data buffer Uint16 SCIFFTX_REG SCIFFTX; // FIFO transmit register Uint16 SCIFFRX_REG SCIFFRX; // FIFO receive register Uint16 SCIFFCT_REG SCIFFCT; // FIFO control register Uint16 rsvd2; // reserved Uint16 rsvd3; // reserved Uint16 SCIPRI_REG SCIPRI; // FIFO Priority control }; 单纯的结构体定义本身并没有生成任何变量,下面的代码段用结构体类型 SCI_REGS 定义了 DSP 的两个 SCI 模块的寄存器文件 SciaRegs 和 ScibRegs。
/******************************************************************** * Source file using register-file structures * Create a variable for each of the SCI register files ********************************************************************/ volatile struct SCI_REGS SciaRegs; volatile struct SCI_REGS ScibRegs; 上面代码中的关键字 volatile 非常重要,一个被声明为 volatile 的变量 可以随时被程序本身之外的事件改变例如,外设寄存器可以被 DSP 硬件本身 或中断改变,如果寄存器没有被声明为 volatile,编译器就会假设寄存器只会 在它在代码中出现的地方被改变,从而编译器可能会把在其他地方访问寄存器 看作不必要而优化掉一个被声明了 volatile 的变量的访问是不会被优化掉 的。
((2 2)寄存器文件结构的空间分配)寄存器文件结构的空间分配 编译器为代码和数据分配和重定位的存储块,这些块称为 section将 section 指定到存储空间是在链接命令文件(linker command file)中完成的 默认情况下,编译器会将 SciaRegs 和 ScibRegs 这样的全局和静态变量指 定到.ebss 或者.bss section但是,在基于硬件抽象层(abstraction layer, hardware abstraction layer 是操作系统中逻辑层中的硬件层,通过硬件抽象 层,可以使操作系统忽略硬件细节,以一种抽象方式来访问硬件)的情况下,寄 存器文件变量被定位到同一个外设寄存器区域应用编译器的预处理指令 DATA_SECTION,每一个寄存器变量都被指定到.bss/.ebss 之外的一个特定的数 据段 C 中,预处理指令 DATA_SECTION 的语法是: #pragma DATA_SECTION (symbol,“section name“) C++中,预处理指令 DATA_SECTION 的语法是: #pragma DATA_SECTION (“section name“) DATA_SECTION 预处理指令将 symbol 定位到名为 section name 的存储空间 中。
下面的代码中,应用预处理指令 DATA_SECTION 将寄存器文件结构变量 SciaRegs 和 ScibRegs 分别定位到名为 SciaRegsFil。
