我目前正在參加在線課程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