[转载]DSP28_GPIO.h头文件说明_人生几何_新浪博客

原文地址:DSP28_GPIO.h头文件说明 作者:simplorer

//
//      TMDX ALPHA RELEASE
//      Intended for product evaluation purposes
//
//###########################################################################
//
// FILE:    DSP28_Gpio.h
//
// TITLE:    DSP28 General Purpose I/O Definitions.
//
//###########################################################################
//
//  Ver | dd mmm yyyy | Who  | Description of changes
// =====|=============|======|===============================================
//  0.55| 06 May 2002 | L.H. | EzDSP Alpha Release
//  0.56| 20 May 2002 | L.H. | No change
//  0.57| 24 May 2002 | L.H. | Fixed typo's on GPIOG registers
//###########################################################################

#ifndef DSP28_GPIO_H
#define DSP28_GPIO_H

//----------------------------------------------------
// General purpose I/O (GPIO) Register Bit Definitions                                              

//----------------------------------------------------
// GPIO A mux control register bit definitions */                                   
//
//
struct GPAMUX_BITS  {      // bits   description
   Uint16 PWM1_GPIOA0:1;     // 0 
   Uint16 PWM2_GPIOA1:1;     // 1
   Uint16 PWM3_GPIOA2:1;     // 2 
   Uint16 PWM4_GPIOA3:1;     // 3 
   Uint16 PWM5_GPIOA4:1;     // 4 
   Uint16 PWM6_GPIOA5:1;     // 5
   Uint16 T1PWM_GPIOA6:1;    // 6 
   Uint16 T2PWM_GPIOA7:1;    // 7       
   Uint16 CAP1Q1_GPIOA8:1;   // 8
   Uint16 CAP2Q2_GPIOA9:1;   // 9
   Uint16 CAP3QI1_GPIOA10:1; // 10
   Uint16 TDIRA_GPIOA11:1;   // 11
   Uint16 TCLKINA_GPIOA12:1; // 12
   Uint16 C1TRIP_GPIOA13:1;  // 13 
   Uint16 C2TRIP_GPIOA14:1;  // 14 
   Uint16 C3TRIP_GPIOA15:1;  // 15  
};

union GPAMUX_REG {
   Uint16        all;
   struct GPAMUX_BITS bit;
};

//---------------------------------------------------------------------------------------
// GPIO A Direction control register bit definitions                                   
//
//
struct GPADIR_BITS  {      // bits   description
   Uint16 GPIOA0:1;          // 0 
   Uint16 GPIOA1:1;          // 1
   Uint16 GPIOA2:1;          // 2 
   Uint16 GPIOA3:1;          // 3 
   Uint16 GPIOA4:1;          // 4 
   Uint16 GPIOA5:1;          // 5
   Uint16 GPIOA6:1;          // 6 
   Uint16 GPIOA7:1;          // 7       
   Uint16 GPIOA8:1;          // 8
   Uint16 GPIOA9:1;          // 9
   Uint16 GPIOA10:1;         // 10
   Uint16 GPIOA11:1;         // 11
   Uint16 GPIOA12:1;         // 12
   Uint16 GPIOA13:1;         // 13 
   Uint16 GPIOA14:1;         // 14 
   Uint16 GPIOA15:1;         // 15  
};

union GPADIR_REG {
   Uint16               all;
   struct GPADIR_BITS bit;
};

//----------------------------------
// GPA Qualregister bit definitions
//
//

struct GPAQUAL_BITS {      // bits   description
   Uint16     QUALPRD:8;     // 0:7    Qualification Sampling Period
   Uint16 rsvd1:8;           // 15:8   reserved
};

union GPAQUAL_REG {
   Uint16              all;
   struct GPAQUAL_BITS BIT;
};         

//---------------------------------------------------------------------------------------
// GPIO A Data register bit definitions                                   
//
//
struct GPADAT_BITS  {      // bits   description
   Uint16 GPIOA0:1;          // 0 
   Uint16 GPIOA1:1;          // 1
   Uint16 GPIOA2:1;          // 2 
   Uint16 GPIOA3:1;          // 3 
   Uint16 GPIOA4:1;          // 4 
   Uint16 GPIOA5:1;          // 5
   Uint16 GPIOA6:1;          // 6 
   Uint16 GPIOA7:1;          // 7       
   Uint16 GPIOA8:1;          // 8
   Uint16 GPIOA9:1;          // 9
   Uint16 GPIOA10:1;         // 10
   Uint16 GPIOA11:1;         // 11
   Uint16 GPIOA12:1;         // 12
   Uint16 GPIOA13:1;         // 13 
   Uint16 GPIOA14:1;         // 14 
   Uint16 GPIOA15:1;         // 15  
};

union GPADAT_REG {
   Uint16        all;
   struct GPADAT_BITS bit;
};

//---------------------------------------------------------------------------------------
// GPIO A Data set bit definitions                                   
//
//
struct GPASET_BITS  {      // bits   description
   Uint16 GPIOA0:1;          // 0 
   Uint16 GPIOA1:1;          // 1
   Uint16 GPIOA2:1;          // 2 
   Uint16 GPIOA3:1;          // 3 
   Uint16 GPIOA4:1;          // 4 
   Uint16 GPIOA5:1;          // 5
   Uint16 GPIOA6:1;          // 6 
   Uint16 GPIOA7:1;          // 7       
   Uint16 GPIOA8:1;          // 8
   Uint16 GPIOA9:1;          // 9
   Uint16 GPIOA10:1;         // 10
   Uint16 GPIOA11:1;         // 11
   Uint16 GPIOA12:1;         // 12
   Uint16 GPIOA13:1;         // 13 
   Uint16 GPIOA14:1;         // 14 
   Uint16 GPIOA15:1;         // 15  
};

union GPASET_REG {
   Uint16        all;
   struct GPASET_BITS bit;
};

//---------------------------------------------------------------------------------------
// GPIO A Data clear register bit definitions                                   
//
//
struct GPACLEAR_BITS  {    // bits   description
   Uint16 GPIOA0:1;          // 0 
   Uint16 GPIOA1:1;          // 1
   Uint16 GPIOA2:1;          // 2 
   Uint16 GPIOA3:1;          // 3 
   Uint16 GPIOA4:1;          // 4 
   Uint16 GPIOA5:1;          // 5
   Uint16 GPIOA6:1;          // 6 
   Uint16 GPIOA7:1;          // 7       
   Uint16 GPIOA8:1;          // 8
   Uint16 GPIOA9:1;          // 9
   Uint16 GPIOA10:1;         // 10
   Uint16 GPIOA11:1;         // 11
   Uint16 GPIOA12:1;         // 12
   Uint16 GPIOA13:1;         // 13 
   Uint16 GPIOA14:1;         // 14 
   Uint16 GPIOA15:1;         // 15  
};

union GPACLEAR_REG {
   Uint16        all;
   struct GPACLEAR_BITS bit;
};

//---------------------------------------------------------------------------------------
// GPIO A Data toggle register bit definitions                                   
//
//
struct GPATOGGLE_BITS  {   // bits   description
   Uint16 GPIOA0:1;          // 0 
   Uint16 GPIOA1:1;          // 1
   Uint16 GPIOA2:1;          // 2 
   Uint16 GPIOA3:1;          // 3 
   Uint16 GPIOA4:1;          // 4 
   Uint16 GPIOA5:1;          // 5
   Uint16 GPIOA6:1;          // 6 
   Uint16 GPIOA7:1;          // 7       
   Uint16 GPIOA8:1;          // 8
   Uint16 GPIOA9:1;          // 9
   Uint16 GPIOA10:1;         // 10
   Uint16 GPIOA11:1;         // 11
   Uint16 GPIOA12:1;         // 12
   Uint16 GPIOA13:1;         // 13 
   Uint16 GPIOA14:1;         // 14 
   Uint16 GPIOA15:1;         // 15  
};

union GPATOGGLE_REG {
   Uint16        all;
   struct GPATOGGLE_BITS bit;
};

………………………………………………

此处省略端口B、D、E、F、G五组端口的类似定义

struct GPIO_MUX_REGS {
   union  GPAMUX_REG   GPAMUX;
   union  GPADIR_REG   GPADIR;
   union  GPAQUAL_REG  GPAQUAL;
   Uint16   rsvd1;
   union  GPBMUX_REG   GPBMUX;
   union  GPBDIR_REG   GPBDIR;
   union  GPBQUAL_REG  GPBQUAL;  
   Uint16   rsvd2[5];
   union  GPDMUX_REG   GPDMUX;
   union  GPDDIR_REG   GPDDIR;
   union  GPDQUAL_REG  GPDQUAL;  
   Uint16   rsvd3;
   union  GPEMUX_REG   GPEMUX;
   union  GPEDIR_REG   GPEDIR;
   union  GPEQUAL_REG  GPEQUAL;  
   Uint16   rsvd4;
   union  GPFMUX_REG   GPFMUX;
   union  GPFDIR_REG   GPFDIR;
   Uint16   rsvd5[2];
   union  GPGMUX_REG   GPGMUX;
   union  GPGDIR_REG   GPGDIR;
   Uint16   rsvd6[6];
};

struct GPIO_DATA_REGS {
   union  GPADAT_REG    GPADAT;
   union  GPASET_REG    GPASET;
   union  GPACLEAR_REG  GPACLEAR;
   union  GPATOGGLE_REG GPATOGGLE;
   union  GPBDAT_REG    GPBDAT;
   union  GPBSET_REG    GPBSET;
   union  GPBCLEAR_REG  GPBCLEAR;
   union  GPBTOGGLE_REG GPBTOGGLE;
   Uint16   rsvd1[4];
   union  GPDDAT_REG    GPDDAT;
   union  GPDSET_REG    GPDSET;
   union  GPDCLEAR_REG  GPDCLEAR;
   union  GPDTOGGLE_REG GPDTOGGLE;
   union  GPEDAT_REG    GPEDAT;
   union  GPESET_REG    GPESET;
   union  GPECLEAR_REG  GPECLEAR;
   union  GPETOGGLE_REG GPETOGGLE;
   union  GPFDAT_REG    GPFDAT;
   union  GPFSET_REG    GPFSET;
   union  GPFCLEAR_REG  GPFCLEAR;
   union  GPFTOGGLE_REG GPFTOGGLE;
   union  GPGDAT_REG    GPGDAT;
   union  GPGSET_REG    GPGSET;
   union  GPGCLEAR_REG  GPGCLEAR;
   union  GPGTOGGLE_REG GPGTOGGLE;
   Uint16   rsvd2[4];     
};    

//---------------------------------------------------------------------------
// GPI/O External References & Function Declarations:
//
extern volatile struct GPIO_MUX_REGS GpioMuxRegs;
extern volatile struct GPIO_DATA_REGS GpioDataRegs;

#endif  // end of DSP28_GPIO_H definition

//===========================================================================
// No more.
//===========================================================================

对于f2812来说,拥有56个GPIO,这些IO中大部分是与实现专用功能的引脚共用。56个GPIO分为A、B、D、E、F、G六组,其中A、B为16个GPIO一组,D为4个GPIO一组,E为3个GPIO一组,F为15个GPIO一组,G为2个GPIO一组。

实现管脚复用,方向控制,数据读写的寄存器分为两类:GpioMuxRegs与GpioDataRegs。

1. GpioMuxRegs寄存器地址分配:

image

image

GpioMuxRegs寄存器主要包含三种类型的寄存器:GPxMUX寄存器,GPxDIR寄存器,GPxQUAL寄存器。

1.1. GPxMUX寄存器

可以称为功能选择寄存器,使用x代替A、B、D、E、F、G,下同。用于确定IO的功能。

GPxMUX.bit.xx = 0,xx通用数字IO
GPxMUX.bit.xx = 1,xx外围IO引脚

1.2. GPxDIR寄存器

可以称为管脚方向寄存器,如果某管脚已经设置为通用数字IO,则GPxDIR寄存器确定此IO是输入还是输出。

GPxDIR.bit.xx = 0,xx配置为输入
GPxDIR.bit.xx = 1,xx配置为输出

器件复位后,GPxMUX与GPxDIR寄存器默认值均为0。

1.3. GPxQUAL寄存器

可以称为量化寄存器,设置采样脉冲。在GPIO配置为通用IO后,F2812的IO引脚有对输入过滤噪声的功能,即对IO输入电平采样,在采样设置的次数后都是一个电平,才会确定有效。假如设置为输入高电平,采样10次,那么这10都为高电平才认为输入高有效,GPxDAT寄存器相应位才会改变。

需要注意的是,F和G组GPIO无此寄存器。

2. GpioDataRegs寄存器地址分配:

image

image

GPxDataRegs寄存器主要包含三种类型的寄存器:GPxDAT寄存器,GPxSET寄存器,GPxCLEAR寄存器,GPxTOGGLE寄存器。

2.1. GPxDAT寄存器

可以称为IO数据寄存器,当IO配置为输出时,对GPxDAT中写数据就可以决定输出状态:

GPxDAT.bit.xx = 0,输出0
GPxDAT.bit.xx = 1,输出1

当IO配置为输入时,读取GPxDAT中的数据就可以决定输入状态。
注意:当引脚配置为通用IO时,相应的外设功能必须被屏蔽,否则可能会引发中断。使用GPxDAT 寄存器更改输出引脚的电平时,请务必小心不要错误地更改另一引脚的电平。例如,如果您打算通过使用读取- 修改- 写入指令写入GPADAT 寄存器第0 位来更改GPIOA0 的输出锁定电平。如果另一个I/O 端口A 信号在该指令的读取和写入阶段之间更改了电平,则可能出现问题。另外可以通过使用GPxSET、GPxCLEAR 和GPxTOGGLE 寄存器载入输出锁定来避免这种情况。

2.2. GPxSET寄存器

可以称为置位寄存器,每个IO口都有一个置位寄存器,只能写不能读,也就是只能用在输出上,写1可以使输出为1,写0没有变化。

GPxSET.bit.xx = 0,被忽略;
GPxSET.bit.xx = 1,且引脚配置为输出,则输出1

2.3. GPxCLEAR寄存器

可以称为复位寄存器,每个IO口都有一个复位寄存器,只能写不能读,也就是只能用在输出上,写1可以使输出为1,写0没有变化。

GPxSET.bit.xx = 0,被忽略;
GPxSET.bit.xx = 1,且引脚配置为输出,则输出0

2.4. GPxTOGGLE寄存器

可以称为翻转寄存器,每个IO口都有一个翻转寄存器,只能写不能读,也就是只能用在输出上,写1可以使输出翻转,写0没有变化。

GPxTOGGLE.bit.xx = 0,被忽略;
GPxTOGGLE.bit.xx = 1,且引脚配置为输出,则输出翻转

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值