我目前正在参加在线课程UT.6.02x嵌入式系统 - 塑造世界,它使用Tiva C TM4C123GXL LaunchPad。我也在阅读“ARM Cortex-M3和Cortex-M4处理器的权威指南”一书。在本书中提到了一个名为CMSIS的标准库,其中GPIO端口的寄存器是作为结构实现的。Tiva C TM4C123GXL界面库
预订代码:
typedef struct
{
_IO uint32_t CRL;
_IO uint32_t CRH;
//and so on ...
} GPIO_TypeDef;
#define PERIPH_BASE ((uint32_t)0x40000000) //Peripheral base address
#define APB2PERIPH_BASE (PERIPH_BASE + 0x10000)
#define GPIOA_BASE (APB2PERIPH_BASE + 0x0800)
#define GPIOA ((GPIO_TypeDef*) GPIOA_BASE)
其中_IO被定义为挥发性的。如果我想将GPIOA CRL寄存器设置为0,我可以键入GPIOA-> CRL = 0;如果我想将GPIOA CRL寄存器设置为0,则可以键入GPIOA-> CRL = 0。 而且我也可以调用诸如GPIO_Reset(GPIOA)之类的函数。
对于类,教授尚未使用该库,而不是他包括一个头文件tm4c123gh6pm.h,它定义每一个寄存器,用于分别每个端口:
类代码:
#define GPIO_PORTA_DATA_BITS_R ((volatile unsigned long *)0x40004000)
#define GPIO_PORTA_DATA_R (*((volatile unsigned long *)0x400043FC))
#define GPIO_PORTA_DIR_R (*((volatile unsigned long *)0x40004400))
#define GPIO_PORTA_IS_R (*((volatile unsigned long *)0x40004404))
#define GPIO_PORTA_IBE_R (*((volatile unsigned long *)0x40004408))
#define GPIO_PORTA_IEV_R (*((volatile unsigned long *)0x4000440C))
#define GPIO_PORTA_IM_R (*((volatile unsigned long *)0x40004410))
#define GPIO_PORTA_RIS_R (*((volatile unsigned long *)0x40004414))
#define GPIO_PORTA_MIS_R (*((volatile unsigned long *)0x40004418))
#define GPIO_PORTA_ICR_R (*((volatile unsigned long *)0x4000441C))
#define GPIO_PORTA_AFSEL_R (*((volatile unsigned long *)0x40004420))
#define GPIO_PORTA_DR2R_R (*((volatile unsigned long *)0x40004500))
#define GPIO_PORTA_DR4R_R (*((volatile unsigned long *)0x40004504))
#define GPIO_PORTA_DR8R_R (*((volatile unsigned long *)0x40004508))
#define GPIO_PORTA_ODR_R (*((volatile unsigned long *)0x4000450C))
#define GPIO_PORTA_PUR_R (*((volatile unsigned long *)0x40004510))
#define GPIO_PORTA_PDR_R (*((volatile unsigned long *)0x40004514))
#define GPIO_PORTA_SLR_R (*((volatile unsigned long *)0x40004518))
#define GPIO_PORTA_DEN_R (*((volatile unsigned long *)0x4000451C))
#define GPIO_PORTA_LOCK_R (*((volatile unsigned long *)0x40004520))
#define GPIO_PORTA_CR_R (*((volatile unsigned long *)0x40004524))
#define GPIO_PORTA_AMSEL_R (*((volatile unsigned long *)0x40004528))
#define GPIO_PORTA_PCTL_R (*((volatile unsigned long *)0x4000452C))
#define GPIO_PORTA_ADCCTL_R (*((volatile unsigned long *)0x40004530))
#define GPIO_PORTA_DMACTL_R (*((volatile unsigned long *)0x40004534))
其似乎使寄存器操作更麻烦。
这个头文件在这个类以外的其他地方使用吗?它是否被认为是CMSIS的一部分?
这两个文件有什么区别?
你的教授是回答有关课程材料问题的最佳人选。他可能有一些使用这个头文件的具体原因,这个头文件涉及到他在课程中将要讲述的一些概念。他可能只是喜欢它,因为_he_发现它更方便 - 问他。 – 2015-02-08 07:04:28
区别在于它们不同,几乎完全按照您阐述的方式 - 一个例子是供应商如何为示例GPIO控制器定义CMSIS风格的结构,另一个是(如果您看该文件的顶部)一些实际的寄存器定义取自特定供应商的SDK,用于特定的SoC。 [CMSIS只是推荐的标准抽象层](http://www.arm.com/products/processors/cortex-m/cortex-microcontroller-software-interface-standard.php),供应商可以自由选择实施它或不。 – Notlikethat 2015-02-08 12:23:43
另外,从用户的角度来看,这种情况下的差异主要归结为偶尔在名称中键入'_'而不是' - >'来访问寄存器 - 是否真的很重要? – Notlikethat 2015-02-08 12:27:48