
- UID
- 838606
- 性别
- 男
- 来自
- 湖南长沙
|

既然大家都不回,这个程序我懂了,在这里解说一下里面调用的子函数,希望不懂得看看,网上很少有,懂英文的可以在microblaze结构那里点击右键,查看API函数,赛灵思解说的很详细,
int XGpio_CfgInitialize (
XGpio *InstancePtr ,
XGpio_Config *Config ,
u32 EffectiveAddr
)
//成功:返回值:XST_SUCCESS
实用调用函数给出的配置数据对XGpio进行初始化
InstancePtr:
是指向XGpio实例的指针。指针的内存空间必须有调用函数给分配好。通过XGpio API对其进行操作的函数可以通过这个指针来实现。
Config:
包含了指定GPIO设备的结构信息。通过Config文件的内容可以对InstancePtr进行初始化。通过在每次调用时给予不同的配置文件,这个函数可以初始化多个设备实例
EffectiveAddr:
是虚拟内存空间的设备基址。一旦这个函数被使用,调用函数要对从EffectiveAddr地址到设备物理基址的无变化地址映射负责。如果地址变化了,将会发生未知错误。如果不使用地址映射,直接将Config->BaseAddress(设备的物理地址) 传送给这个参数就可以了。
00000000000000000000000000000000000000000000000000000000000000000000000
u32 XGpio_DiscreteRead (
XGpio * InstancePtr , //通过GPIO操作的寄存器
unsigned Channel //GPIO核有两个通道,这里就是通道的选择0_1
)
无返回值
00000000000000000000000000000000000000000000000000000000000000000000000
void XGpio_DiscreteClear (
XGpio * InstancePtr , //通过GPIO操作的寄存器
unsigned Channel , //GPIO核有两个通道,这里就是通道的选择0_1
u32 Mask //32位 0x00000000
)
返回值:Current copy of the discretes register
对特定GPIO通道的离散寄存器清零
InstancePtr:
是XGpio进行操作的指针。
Channel:
包含了要进行操作的通道(1或者2)
Mask:
是一个位数据的集合,这个集合将被写入离散的数据寄存器。其他数据寄存器不会受影响。
void XGpio_DiscreteSet (
XGpio * InstancePtr , //通过GPIO操作的寄存器
unsigned Channel , //GPIO核有两个通道,这里就是通道的选择0_1
u32 Mask //32位 0x00000000
)
无返回值
这两个函数只对Mask中对应位为1的位有影响,比如,XGpio_DiscreteSet(&lcd240128,1,Ox00000001)将LCl3240128_pin<O>置1,而不影响其他位;同理,XGpio_DiscteteClear(&1cd240128,1,0x00000001)将LCD240128_pin<0>置0,而不影响其他位。
0000000000000000000000000000000000000000000000000000000000000000000000000000
void XGpio_DiscreteWrite (
XGpio * InstancePtr, //通过GPIO操作的寄存器
unsigned Channel, //GPIO核有两个通道,这里就是通道的选择0_1
u32 Data //写入的数据,可以自己定义,可以通过其他变量获取
)
无返回值
0000000000000000000000000000000000000000000000000000000000000000000000000000
u32 XGpio_GetDataDirection (
XGpio * InstancePtr ,
unsigned Channel
)
这个函数不太清楚,不过有个实例可以看看
返回值:Bits set to 0 are output and bits set to 1 are input.
void XGpio_SetDataDirection (
XGpio * InstancePtr ,
unsigned Channel ,
u32 DirectionMask //0x0:output-------0xffffffff:input
)
无返回值
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
int XGpio_Initialize (
XGpio *InstancePtr , //所定义的变量XXX:XGpio XXX;
u16 DeviceId //实际应写成:XPAR_XXX_DEVICE_ID
)
成功返回值:XST_SUCCESS 失败返回值:XST_DEVICE_NOT_FOUND 000000000000000000000000000000000000000000000000000000000000000000000
几个关于中断的函数总结
void XGpio_InterruptClear (
XGpio *InstancePtr ,
u32 Mask
)
无返回值
void XGpio_InterruptDisable (
XGpio * InstancePtr ,
u32 Mask
)
无返回值
void XGpio_InterruptEnable (
XGpio * InstancePtr ,
u32 Mask
)
无返回值
u32 XGpio_InterruptGetEnabled ( XGpio * InstancePtr )
无返回值
u32 XGpio_InterruptGetStatus ( XGpio * InstancePtr )
void XGpio_InterruptGlobalDisable ( XGpio * InstancePtr )
无返回值
void XGpio_InterruptGlobalEnable ( XGpio * InstancePtr )
无返回值
00000000000000000000000000000000000000000000000000000000000000000000000000000
XGpio_Config* XGpio_LookupConfig ( u16 DeviceId ) //实际应写成:XPAR_XXX_DEVICE_ID
查找设备ID的设备配置
0000000000000000000000000000000000000000000000000000000000000000000000000000000
int XGpio_SelfTest ( XGpio * InstancePtr )
关于GPIO的几个源代码文件
xgpio.h
xgpio_extra.c
xgpio_g.c
xgpio_i.h
xgpio_intr.c
xgpio_l.h
xgpio_selftest.c
xgpio_sinit.c
0000000000000000000000000000000000000000000000000000000
#define XGPIO_DATA2_OFFSET //Data register for 2nd channel
#define XGPIO_DATA_OFFSET //Data register for 1st channel
#define XGPIO_GIE_OFFSET //Glogal interrupt enable register
#define XGPIO_IER_OFFSET //Interrupt enable register
#define XGPIO_IR_CH1_MASK //Mask for the 1st channel
#define XGPIO_IR_CH2_MASK //Mask for the 2nd channel
#define XGPIO_IR_MASK //Mask of all bits
#define XGPIO_ISR_OFFSET //Interrupt status register
#define XGpio_mGetDataReg (BaseAddress, Channel ) //Get the data register of the specified GPIO channel.
BaseAddress contains the base address of the GPIO device.
Channel contains the channel (1 or 2) to operate on.
#define XGpio_mReadReg (BaseAddress, RegOffset)
//Read a value from a GPIO register. A 32 bit read is performed. If the GPIO component is implemented in a smaller width, only the least significant data is read from the register. The most significant data will be read as 0.BaseAddress is the base address of the GPIO device.
Register is the register offset from the base to read from.
Data is the data from the register.
#define XGpio_mSetDataReg (BaseAddress, Channel, Data)
//Set the data register of the specified GPIO channel.
BaseAddress contains the base address of the GPIO device.
Channel contains the channel (1 or 2) to operate on.
Data is the value to be written to the data register.
#define XGpio_mWriteReg (BaseAddress, RegOffset, Data)
Write a value to a GPIO register. A 32 bit write is performed. If the GPIO component is implemented in a smaller width, only the least significant data is written.
BaseAddress is the base address of the GPIO device.
RegOffset is the register offset from the base to write to.
Data is the data written to the register.
#define XGPIO_TRI2_OFFSET //I/O direction reg for 2nd channel
#define XGPIO_TRI_OFFSET //I/O direction reg for 1st channel
五个GPIO的例子研究
NO1:
#include "xparameters.h"
#include "xgpio.h"
#include "xgpio_l.h"
#include "xutil.h"
int main (void)
{
XGpio dip, push;
int i, psb_check, dip_check;
XGpio LEDs8_Bit;
printf("-- Start of the Program --\r\n");
XGpio_Initialize(&dip, XPAR_DIP_DEVICE_ID); // device ID号的定义规则
XGpio_SetDataDirection(&dip, 1, 0xffffffff); // 必须注明通道号,否则出错
XGpio_Initialize(&push, XPAR_PUSH_DEVICE_ID);
XGpio_SetDataDirection(&push, 1, 0xffffffff);
XGpio_Initialize(&LEDs8_Bit, XPAR_LEDS_8BIT_DEVICE_ID);
XGpio_SetDataDirection(&LEDs8_Bit, 1, 0x0);
while (1)
{
psb_check = XGpio_DiscreteRead(&push, 1);
xil_printf("Push Buttons Status %x\r\n", psb_check); //: /n会使超级终端斜着显示
dip_check = XGpio_DiscreteRead(&dip, 1);
xil_printf("DIP Switch Status %x\r\n", dip_check); //: /r/n 会使正常往下显示
XGpio_DiscreteWrite(&LEDs8_Bit, 1, dip_check);
for (i=0; i<999999; i++);
}
}
NO2:
#define GPIO_INPUT_SWITCH1 0xffffffff /* Input discrete comes from a switch */
#define GPIO_OUTPUT_LED_FAULT 0x00010000 /* LED. Illuminated if discrete set to 1 */
#define GPIO_OUTPUT_LED_POWER 0x00020000 /* LED. Illuminated if discrete set to 1 */
#include "xbasic_types.h"
#include "xstatus.h"
#include "xparameters.h"
#include "xgpio.h"
#include "xgpio_l.h"
#include "xutil.h"
int main (void)
{
Xuint32 Data;
XStatus Status;
XGpio dip, push;
int i, psb_check, dip_check;
XGpio LEDs8_Bit;
printf("-- Start of the Program --\r\n");
XGpio_Initialize(&push, XPAR_PUSH_DEVICE_ID);
XGpio_SetDataDirection(&push, 1, 0xffffffff);
XGpio_Initialize(&LEDs8_Bit, XPAR_LEDS_8BIT_DEVICE_ID);
XGpio_SetDataDirection(&LEDs8_Bit, 1, 0x0);
Status = XGpio_Initialize(&dip, XPAR_DIP_DEVICE_ID);
if (Status != XST_SUCCESS) // XStatus Status为嵌入式中状态的定义关键字
{
printf("000\n");
}
else
{
printf("111\n");
}
XGpio_SetDataDirection(&dip,1,GPIO_INPUT_SWITCH1);
XGpio_DiscreteSet (&dip,1,GPIO_OUTPUT_LED_POWER);
XGpio_DiscreteClear (&dip,1,GPIO_OUTPUT_LED_FAULT);
while (1)
{
Data = XGpio_DiscreteRead(&dip,1); //检测按键是否被按下
xil_printf("Data=%x\r\n",Data);
if (Data & GPIO_INPUT_SWITCH1) { xil_printf("111\r\n"); } //有按下
else { xil_printf("222\r\n");} // /r/n //没按下
for (i=0; i<9999999; i++);
} |
|