// GPI.cpp : Defines the entry point for the DLL application.
//
#include "GPI.h"
#include <windows.h>
#include <memory.h>
#include <nkintr.h>
#include <ceddk.h>
#include <winioctl.h>
#pragma comment(lib,"ceddk.lib")
#define GIO_VENDOR CTL_CODE(FILE_DEVICE_SERIAL_PORT, 2090, METHOD_BUFFERED, FILE_ANY_ACCESS)
static UCHAR * virGpioMemBase = NULL;
/**************************************************************************
* 基础函数定义 *
**************************************************************************/
/************************************************************
* OutPortByte
*
* 向特定GPIO地址输出字节
*/
static void OutPortByte(WORD wAddr,byte bValue)
{
if(NULL != virGpioMemBase)
{
if( W83627_EFER == wAddr)
{
WRITE_PORT_UCHAR(virGpioMemBase,bValue);
}
else
{
WRITE_PORT_UCHAR(virGpioMemBase+1,bValue);
}
RETAILMSG(TRUE, (TEXT(">>Liu wenlong-OutPortByte: Add:0x%x, Val:0x%x\r\n"),wAddr,bValue));
}
else
{
RETAILMSG(TRUE, (TEXT(">>Liu wenlong-OutPortByte return for virGpioMemBase NULL\r\n")));
}
}
/************************************************************
* InPortByte
*
* 从特定GPIO地址读取字节
*/
static byte InPortByte(WORD wAddr)
{
byte tmpRtnVal = 0xFF;
if(NULL != virGpioMemBase)
{
if( W83627_EFER == wAddr)
{
tmpRtnVal = READ_PORT_UCHAR(virGpioMemBase);
}
else
{
tmpRtnVal = READ_PORT_UCHAR(virGpioMemBase+1);
}
RETAILMSG(TRUE, (TEXT(">>--Liu wenlong-InPortByte, Add:0x%x Val:0x%x!\r\n"),wAddr,tmpRtnVal));
}
else
{
RETAILMSG(TRUE, (TEXT(">>Liu wenlong-InPortByte return for virGpioMemBase NULL\r\n")));
}
return tmpRtnVal;
}
/************************************************************
* W83627Set
*
* 设定W8362 PIO A 值
*/
static void W83627Set(byte ucParaVal)
{
RETAILMSG(TRUE, (TEXT(">>++Liu wenlong-W83627Set Val:0x%x!\r\n"),ucParaVal));
//enter the extended function mode,two successive writes of 0x87 must be applied to
//Extended Function Enable Registers(EFERs,i.e. 2Eh)
OutPortByte(W83627_EFER,0x87);
OutPortByte(W83627_EFER,0x87);
//CRF1(GP10-GP17 data register Default 0x00)
//if a port is programmed to be an output port,then its respective bit can be read/write
//if a port is programmed to be an input port,then its respective bit can only be read
OutPortByte(W83627_EFIR,0x07);
OutPortByte(W83627_EFDR,0x08);
//实际写值到对应的寄存器
OutPortByte(W83627_EFIR ,0xF1);
OutPortByte(W83627_EFDR ,ucParaVal);
//exit extended function mode
OutPortByte(W83627_EFER,0xAA);
Sleep(1);
}
/************************************************************
* W83627Set
*
* 读取W8362 PIO A 值
*/
static byte W83627Get()
{
byte tmpVal = 0;
//enter the extended function mode,two successive writes of 0x87 must be applied to
//Extended Function Enable Registers(EFERs,i.e. 2Eh)
OutPortByte(W83627_EFER,0x87);
OutPortByte(W83627_EFER,0x87);
//Configurate the configuration registers
//configure logical device 7(gp10-gp17),configuration register CRF0,CRF1,CRF2
//select logical device 7
OutPortByte(W83627_EFIR,0x07);
OutPortByte(W83627_EFDR,0x08);
//CRF1(GP10-GP17 data register Default 0x00)
//if a port is programmed to be an output port,then its respective bit can be read/write
//if a port is programmed to be an input port,then its respective bit can only be read
OutPortByte(W83627_EFIR,0xF1);
tmpVal = InPortByte(W83627_EFDR);
//exit extended function mode
OutPortByte(W83627_EFER,0xAA);
Sleep(1);
RETAILMSG(TRUE, (TEXT(">>++Liu wenlong-W83627Get4 Val:0x%x!\r\n"),tmpVal));
return (byte)(tmpVal);
}
/************************************************************
* W83627VendorIdGet
*
* 读取W8362 部分厂家编号
*/
static byte W83627VendorIdGet()
{
byte tmpVal = 0;
//enter the extended function mode,two successive writes of 0x87 must be applied to
//Extended Function Enable Registers(EFERs,i.e. 2Eh)
OutPortByte(W83627_EFER,0x87);
OutPortByte(W83627_EFER,0x87);
//Configurate the configuration registers
OutPortByte(W83627_EFER,0x20);
tmpVal = InPortByte(W83627_EFDR);
//exit extended function mode
OutPortByte(W83627_EFER,0xAA);
Sleep(1);
RETAILMSG(TRUE, (TEXT(">>++Liu wenlong-W83627VendorIdGet:0x%x\r\n"),tmpVal));
return (byte)(tmpVal);
}
/************************************************************
* W83627GPIInit
*
* 初始化W83627GPI A 相关的寄存器
*/
static void W83627GPIInit()
{
//enter the extended function mode,two successive writes of 0x87 must be applied to
//Extended Function Enable Registers(EFERs,i.e. 2Eh)
OutPortByte(W83627_EFER,0x87);
OutPortByte(W83627_EFER,0x87);
//Configurate the configuration registers
OutPortByte(W83627_EFIR ,0x2a); //EFIR write control register index to EFIR
OutPortByte(W83627_EFDR ,0x01); //GPIO20 119S
//Configurate the configuration registers
OutPortByte(W83627_EFIR ,0x2b); //EFIR write control register index to EFIR
OutPortByte(W83627_EFDR ,0xFF); //GPIO21~GPIO27
//configure logical device 7(gp10-gp17),configuration register CRF0,CRF1,CRF2
//select logical device 7
OutPortByte(W83627_EFIR,0x07);
OutPortByte(W83627_EFDR,0x08);
OutPortByte(W83627_EFIR,0x30);
OutPortByte(W83627_EFDR,0x01);
//CRF0(GP10-GP17 I/O selection register Default 0xff)
//when set to a ’1’, respective GPIO port is programmed as an input port
//when set to a ’0’, respective GPIO port is programmed as an output port
OutPortByte(W83627_EFIR,0xF0);
OutPortByte(W83627_EFDR,0x00);
//GPIO10,11,12,13输入,14,15,16,17,输出
//CRF2(GP10-GP17 inversion register Default 0x00)
//when set to a ’1’,the imcoming/outgoing port value is inverted
//when set to a ’0’,the imcoming/outgoing port value is the same as in data register
OutPortByte(W83627_EFIR,0xF2);
OutPortByte(W83627_EFDR,0x00);
//CRF1(GP10-GP17 data register Default 0x00)
//if a port is programmed to be an output port,then its respective bit can be read/write
//if a port is programmed to be an input port,then its respective bit can only be read
OutPortByte(W83627_EFIR,0xF1);
OutPortByte(W83627_EFDR,0x00);
//exit extended function mode
OutPortByte(W83627_EFER,0xAA);
Sleep(10);
RETAILMSG(TRUE, (TEXT(">>++Liu wenlong-W83627GPIInit\r\n")));
}
BOOL APIENTRY DllMain(
HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
default:
break;
}
return TRUE;
}
GPI_API DWORD GPI_Init(LPCTSTR pContext,DWORD dwBusContext)
{
PHYSICAL_ADDRESS IoAddress;
IoAddress.LowPart = W83627_EFER;//硬件地址
IoAddress.HighPart = 0;
virGpioMemBase = ( UCHAR *)MmMapIoSpace( IoAddress , 2 , FALSE );
if(NULL != virGpioMemBase)
{
RETAILMSG(TRUE, (TEXT(">>Liu wenlong-OutPortByte:MmMapIoSpace return:0x%x\r\n"),virGpioMemBase));
}
else
{
RETAILMSG(TRUE, (TEXT(">>Liu wenlong-OutPortByte,MmMapIoSpace return NULL\r\n")));
- 1
- 2
- 3
前往页