#include
#include "GpioDriver.h"
#include "stdafx.h"
typedef struct _GPIO{
volatile unsigned int PORTCFG0; // 0x000 R/W Port Configuration Register 0
volatile unsigned int PORTCFG1; // 0x004 R/W Port Configuration Register 1
volatile unsigned int PORTCFG2; // 0x008 R/W Port Configuration Register 2
volatile unsigned int PORTCFG3; // 0x00C R/W Port Configuration Register 3
volatile unsigned int PORTCFG4; // 0x010 R/W Port Configuration Register 4
volatile unsigned int PORTCFG5; // 0x014 R/W Port Configuration Register 5
volatile unsigned int PORTCFG6; // 0x018 R/W Port Configuration Register 6
volatile unsigned int PORTCFG7; // 0x01C R/W Port Configuration Register 7
volatile unsigned int PORTCFG8; // 0x020 R/W Port Configuration Register 8
volatile unsigned int PORTCFG9; // 0x024 R/W Port Configuration Register 9
volatile unsigned int PORTCFG10; // 0x028 R/W Port Configuration Register 10
volatile unsigned int PORTCFG11; // 0x02C R/W Port Configuration Register 11
volatile unsigned int PORTCFG12; // 0x030 R/W Port Configuration Register 12
volatile unsigned int PORTCFG13; // 0x034 R/W Port Configuration Register 13
volatile unsigned int NOTDEFINE0; // 0x038 -
volatile unsigned int NOTDEFINE1; // 0x03C -
volatile unsigned int GPADAT; // 0x040 R/W 0x00000000 GPA Data Register
volatile unsigned int GPAEN; // 0x044 R/W 0x00000000 GPA Output Enable Register
volatile unsigned int GPASET; // 0x048 W - OR function on GPA Output Data
volatile unsigned int GPACLR; // 0x04C W - BIC function on GPA Output Data
volatile unsigned int GPAXOR; // 0x050 W - XOR function on GPA Output Data
volatile unsigned int NOTDEFINE2; // 0x054
volatile unsigned int NOTDEFINE3; // 0x058
volatile unsigned int NOTDEFINE4; // 0x05C
volatile unsigned int GPBDAT; // 0x060 R/W 0x00000000 GPB Data Register
volatile unsigned int GPBEN; // 0x064 R/W 0x00000000 GPB Output Enable Registe
volatile unsigned int GPBSET; // 0x068 W - OR function on GPB Output Data
volatile unsigned int GPBCLR; // 0x06C W - BIC function on GPB Output Data
volatile unsigned int GPBXOR; // 0x070 W - XOR function on GPB Output Data
volatile unsigned int NOTDEFINE5; // 0x074
volatile unsigned int NOTDEFINE6; // 0x078
volatile unsigned int NOTDEFINE7; // 0x07C
volatile unsigned int GPCDAT; // 0x080 R/W 0x00000000 GPC Data Register
volatile unsigned int GPCEN; // 0x084 R/W 0x00000000 GPC Output Enable Register
volatile unsigned int GPCSET; // 0x088 W - OR function on GPC Output Data
volatile unsigned int GPCCLR; // 0x08C W - BIC function on GPC Output Data
volatile unsigned int GPCXOR; // 0x090 W - XOR function on GPC Output Data
volatile unsigned int NOTDEFINE8; // 0x094
volatile unsigned int NOTDEFINE9; // 0x098
volatile unsigned int NOTDEFINE10; // 0x09C
volatile unsigned int GPDDAT; // 0x0A0 R/W 0x00000000 GPD Data Register
volatile unsigned int GPDEN; // 0x0A4 R/W 0x00000000 GPD Output Enable Register
volatile unsigned int GPDSET; // 0x0A8 W - OR function on GPD Output Data
volatile unsigned int GPDCLR; // 0x0AC W - BIC function on GPD Output Data
volatile unsigned int GPDXOR; // 0x0B0 W - XOR function on GPD Output Data
volatile unsigned int NOTDEFINE11; // 0x0B4
volatile unsigned int NOTDEFINE12; // 0x0B8
volatile unsigned int NOTDEFINE13; // 0x0BC
volatile unsigned int GPEDAT; // 0x0C0 R/W 0x00000000 GPE Data Register
volatile unsigned int GPEEN; // 0x0C4 R/W 0x00000000 GPE Output Enable Register
volatile unsigned int GPESET; // 0x0C8 W - OR function on GPE Output Data
volatile unsigned int GPECLR; // 0x0CC W - BIC function on GPE Output Data
volatile unsigned int GPEXOR; // 0x0D0 W - XOR function on GPE Output Data
volatile unsigned int NOTDEFINE14[3]; // 0x0D4,0x0D8,0x0DC
volatile unsigned int GPFDAT; // 0x0E0 R/W 0x00000000 GPF Data Register
volatile unsigned int GPFEN; //0x0E4 R/W 0x00000000 GPF Output Enable Register
volatile unsigned int GPFSET; //0x0E8 W - OR function on GPF Output Data
volatile unsigned int GPFCLR; //0x0EC W - BIC function on GPF Output Data
volatile unsigned int GPFXOR; //0x0F0 W - XOR function on GPF Output Data
volatile unsigned int NOTDEFINE15[3]; //RESERVED 0x0F4 0x0F8 0x0FC
volatile unsigned int CPUD0 ; //0x100 R/W Pull-Up/Down Control Register 0
volatile unsigned int CPUD1; // 0x104 R/W Pull-Up/Down Control Register 1
volatile unsigned int CPUD2 ; //0x108 R/W Pull-Up/Down Control Register 2
volatile unsigned int CPUD3 ; //0x10C R/W Pull-Up/Down Control Register 3
volatile unsigned int CPUD4; // 0x110 R/W Pull-Up/Down Control Register 4
volatile unsigned int CPUD5; // 0x114 R/W Pull-Up/Down Control Register 5
volatile unsigned int CPUD6; // 0x118 R/W Pull-Up/Down Control Register 6
volatile unsigned int CPUD7; // 0x11C R/W Pull-Up/Down Control Register 7
volatile unsigned int CPUD8; // 0x120 R/W Pull-Up/Down Control Register 8
volatile unsigned int CPUD9 ; //0x124 R/W Pull-Up/Down Control Register 9
volatile unsigned int CPDRV0; // 0x128 R/W Driver strength Control Register 0
volatile unsigned int CPDRV1; // 0x12C R/W
volatile unsigned int AINCFG; // 0x130 R/W 0x00000000 Analog Input Pad Control Register
volatile unsigned int EINTSEL0; // 0x134 R/W 0x00000000 External Interrupt Select Register 0
volatile unsigned int EINTSEL1; // 0x138 R/W 0x00000000 External Interrupt Select Register 1
volatile unsigned int IRQSEL; // 0x13C R/W 0x00000000 Interrupt Select Register
}GPIO, *PGPIO;
#define IOCTL_GPIO_SET_PIN 0x0000050
#define IOCTL_GPIO_CLR_PIN 0x0000070
#define IOCTL_GPIO_DIS_PIN 0x0000090
//?????÷???????á????
static volatile GPIO * v_pIOPregs;
static int g_OpenCount = 0; // ?????ò???????÷
#define BASE_ADDRESS 0xF005A000
#define ADDRESS_INTERVAL_GPIO 0x04
#define GPx_GPA 0
static BOOL MyGPIO_InitAddresses(void)
{
BOOL RetValue = TRUE;
// IO Register Allocation
v_pIOPregs = (volatile GPIO *)VirtualAlloc(0, sizeof(GPIO), MEM_RESERVE, PAGE_NOACCESS);
if (v_pIOPregs == NULL)
{
ERRORMSG(1,(TEXT("For IOPregs : VirtualAlloc failed!\r\n")));
RetValue = FALSE;
}
else
{
if (!VirtualCopy((PVOID)v_pIOPregs, (PVOID)(BASE_ADDRESS >> 8), sizeof(GPIO), PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE))
{
ERRORMSG(1,(TEXT("For IOPregs: VirtualCopy failed!\r\n")));
RetValue = FALSE;
}
}
if (!RetValue)
{
RETAILMSG (1, (TEXT("::: PIO_InitializeAddresses - Fail!!\r\n") ));
if (v_pIOPregs)
{
VirtualFree((PVOID) v_pIOPregs, 0, MEM_RELEASE);
}
v_pIOPregs = NULL;
RetValue = FALSE;
return RetValue;
}
//?????????÷????GPIOE8
v_pIOPregs->PORTCFG10 &= ~(0x0f << 12);
v_pIOPregs->PORTCFG10 |= (0x01 << 12);
//?????????÷??????????
v_pIOPregs->GPEEN |= (0x01 << 8);
return(RetValue);
}
DWORD PIO_Init(DWORD dwContext)
{
MyGPIO_InitAddresses();
g_OpenCount = 0;
return (DWORD)1;
}
BOOL DllEntry(HINSTANCE hinst_dll, DWORD reason, LPVOID reserved)
{
switch (reason) {
case DLL_PROCESS_ATTACH:
RETAILMSG(1, (TEXT("[GPIO] Process Attach\r\n")));
break;
case DLL_PROCESS_DETACH:
RETAILMSG(1, (TEXT("[GPIO] Process Detach\r\n")));
break;
}
return TRUE;
}
BOOL PIO_Close(DWORD Handle)
{
g_OpenCount = 0;
return TRUE;
}
BOOL PIO_Deinit(DWORD dwContext)
{
g_OpenCount = 0;
if (v_pIOPregs)
VirtualFree((PVOID) v_pIOPregs, 0, MEM_RELEASE); /* ??·??ê?????é?????? */
return TRUE;
}
DWORD PIO_Open(DWORD dwData, DWORD dwAccess, DWORD dwShareMode)
{
if (g_OpenCount > 0)
return 0;
g_OpenCount++;
return g_OpenCount; /* ·????????????????? */
}
BOOL GPIO_SetPin(DWORD dwIoControlCode, BYTE PinNum)
{
//?è???????????÷??1
v_pIOPregs->GPESET |= (0x01 << 8);
//????????
v_pIOPregs->CPUD7 &= ~(0x03 << 30);
v_pIOPregs->CPUD7 |= (0x01 << 30);
return TRUE;
}
BOOL GPIO_ClrPin(DWORD dwIoControlCode, BYTE PinNum)
{
//?è???????????÷??0
v_pIOPregs->GPECLR |= (0x01 << 8);
//????????
v_pIOPregs->CPUD7 &= ~(0x03 << 30);
v_pIOPregs->CPUD7 |= (0x02 << 30);
return TRUE;
}
BOOL GPIO_Display(DWORD dwIoControlCode, BYTE PinNum)
{
v_pIOPregs->PORTCFG10 &= ~(0x01 << 12);
return TRUE;
}
BOOL
PIO_IOControl(
DWORD Handle,
DWORD dwIoControlCode,
PBYTE pInBuf,
DWORD nInBufSize,
PBYTE pOutBuf,
DWORD nOutBufSize,
PDWORD pBytesReturned
)
{
BOOL bErr = FALSE;
switch(dwIoControlCode)
{
case IOCTL_GPIO_SET_PIN:
GPIO_SetPin(dwIoControlCode, *pInBuf);
break;
case IOCTL_GPIO_CLR_PIN:
GPIO_ClrPin(dwIoControlCode, *pInBuf);
break;
case IOCTL_GPIO_DIS_PIN:
GPIO_Display(dwIoControlCode, *pInBuf);
break;
}
return true;
}
在PIO_IOControl,GPIO_SetPin, GPIO_ClrPin, GPIO_Display, 这几个函数都加下打印信息,看看调用是否正常
1.加载成功了吗?
2.你做测试,总得有一个应用程序来调用驱动吧,是怎么写的?
引用: 引用 4 楼 luocan1986 的回复:
引用 1 楼 veabol 的回复:
在PIO_IOControl,GPIO_SetPin, GPIO_ClrPin, GPIO_Display, 这几个函数都加下打印信息,看看调用是否正常
USB连接的 用什么函数打印哦?
没有串口向PC发送数据吗?串口输出和KITL总得有种方式来调试驱动吧,否则。。。。难啊
引用: 引用 8 楼 veabol 的回复:
引用 4 楼 luocan1986 的回复:
引用 1 楼 veabol 的回复:
在PIO_IOControl,GPIO_SetPin, GPIO_ClrPin, GPIO_Display, 这几个函数都加下打印信息,看看调用是否正常
USB连接的 用什么函数打印哦?
没有串口向PC发送数据吗?串口输出和KITL总得有种方式来调试驱动吧,否则。。。。难啊
有串口哈。。
测试程序写了。。。通过IOCONTROL向底层发送信息。。。我发现 GPEDAT对应的值已经改变了。但是波形还是为高,把GPEDAT设为0 无法拉低!
引用: 引用 9 楼 luocan1986 的回复:
引用 8 楼 veabol 的回复:
引用 4 楼 luocan1986 的回复:
引用 1 楼 veabol 的回复:
在PIO_IOControl,GPIO_SetPin, GPIO_ClrPin, GPIO_Display, 这几个函数都加下打印信息,看看调用是否正常
USB连接的 用什么函数打印哦?
没有串口向PC发送数据吗?串口输出和KITL总得有种方式来调试驱动吧,否则。。。。难啊
有串口哈。。
测试程序写了。。。通过IOCONTROL向底层发送信息。。。我发现 GPEDAT对应的值已经改变了。但是波形还是为高,把GPEDAT设为0? 无法拉低!
晕菜啊,要有波形必须设置为输出。
但是输出之后GPEDAT是不能读的,只能写
所以你说值已经改变,说明你要么没有设置输出,要么读入的是随机值!
找到原因了,是因为我再Init里面对配置寄存器做的初始化,然后有可能其他驱动修改了这个值。
感谢大家。。。结贴给分!