How to write port?

ntdev
Hi,
I’m a beginner for writing driver in NT/2000.
My driver works in X86 platform,so I guess I can use WRITE_PORT_UCHAR directly,
just like this:
PUCHAR Port;
UCHAR Port1,byte;

Port1 = 0x70;
Port = &Port1;
byte = 0x30;

WRITE_PORT_UCHAR( Port, byte);

I want to write data to port 70H , but it doesn’t work.
And I think the port maybe need to be mapped into memory space.
Please someone tell me why & how to do it?
Thanks for a lot.

ecriee
ecriee@2911.net


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

The port address parameters passed to the HAL IO functions should be passed
as values not references, or pointers to the address. Thus if you want to
talk to base port address 3f0 you use

inChar = READ_PORT_UCHAR(0x3f0+10, 0xa0);

Your code will work if you make port a pointer:

WRITE_PORT_UCHAR(*Port, byte);

Gary G. Little
Sr. Staff Engineer
Broadband Storage, LLC
xxxxx@broadstor.com
xxxxx@delphieng.com

-----Original Message-----
From: ecriee [mailto:ecriee@2911.net]
Sent: Monday, February 26, 2001 9:01 AM
To: NT Developers Interest List
Subject: [ntdev] How to write port?

ntdev
Hi,
I’m a beginner for writing driver in NT/2000.
My driver works in X86 platform,so I guess I can use
WRITE_PORT_UCHAR directly,
just like this:
PUCHAR Port;
UCHAR Port1,byte;

Port1 = 0x70;
Port = &Port1;
byte = 0x30;

WRITE_PORT_UCHAR( Port, byte);

I want to write data to port 70H , but it doesn’t work.
And I think the port maybe need to be mapped into memory space.
Please someone tell me why & how to do it?
Thanks for a lot.

ecriee
ecriee@2911.net


You are currently subscribed to ntdev as: xxxxx@delphieng.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Here is a simplified copy of a port write routine we use for putting data
onto an LPT port:

notes -
lpPortInfo paramter points to a structure containing data about the LPT port
in question, the MappedAddress member is a PHYSICAL_ADDRESS structure filled
in with a call to HalTranslateBusAddress, it contains the memory mapped
address of the physical hardware port.
PortRegister indicates which LPT register to write to, this is either 0, 1
or 2 and is used as an index into the Offsets array (member of lpPortInfo)
which contains the actual offsets to use for the registers. We have some
custom hardware which combines the status and control registers.
Data - this is the actual data byte to write to the port.

typedef struct _tPortInfo
{
DWORD LptNum; // LPT Port number
PHYSICAL_ADDRESS DataReg; // The Lpt Port address ie
0x378, 0x278
PHYSICAL_ADDRESS MappedAddress; // The Mapped Port address
ULONG PortType; // Port type - IO or Memory
ULONG IsPcmcia; // Is it a PCMCIA Card?
PHYSICAL_ADDRESS ECPDataReg; // The ECP Port Address
PHYSICAL_ADDRESS ECPMappedAddress; // The ECP Mapped port address
WORD Offsets[3]; // LPT port register offsets
struct _tPortInfo * nextPort; // next item in the list
} PORTINFO,* PPORTINFO,FAR * LPPORTINFO;

#define DATA_OFFSET 0
#define STATUS_OFFSET 1
#define CONTROL_OFFSET 2

void PortWrite ( LPPORTINFO lpPortInfo, WORD PortRegister, BYTE Data )
{
if( lpPortInfo )
{
if( PortRegister > CONTROL_OFFSET )
PortRegister = DATA_OFFSET;
if( lpPortInfo->PortType == 1 )
WRITE_PORT_UCHAR( (PUCHAR) (lpPortInfo->MappedAddress.LowPart +
lpPortInfo->Offsets[PortRegister]), Data );
else
WRITE_REGISTER_UCHAR( (PUCHAR)
(lpPortInfo->MappedAddress.LowPart + lpPortInfo->Offsets[PortRegister]),
Data );
}
}

Hope this helps

Alun Carp
Driver Development Team Leader
Data Encryption Systems Limited

-----Original Message-----
From: ecriee [mailto:ecriee@2911.net]
Sent: 26 February 2001 17:01
To: NT Developers Interest List
Subject: [ntdev] How to write port?

ntdev
Hi,
I’m a beginner for writing driver in NT/2000.
My driver works in X86 platform,so I guess I can use
WRITE_PORT_UCHAR directly,
just like this:
PUCHAR Port;
UCHAR Port1,byte;

Port1 = 0x70;
Port = &Port1;
byte = 0x30;

WRITE_PORT_UCHAR( Port, byte);

I want to write data to port 70H , but it doesn’t work.
And I think the port maybe need to be mapped into memory space.
Please someone tell me why & how to do it?
Thanks for a lot.

ecriee
ecriee@2911.net


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

First of all,thanks for help.

Now,my driver works very well,the code is below:

/////////////////////////////////////////////////////////////////////
PUCHAR PPort;
UCHAR byte;
ULONG ioport;
PHYSICAL_ADDRESS PortAddress;
ULONG AddressSpace = 1; // IO space

//
ioport = 0x70;
byte = 0x20;

PortAddress.QuadPart = ioport;

HalTranslateBusAddress (Isa, 0, PortAddress, &AddressSpace, &PortAddress);
PPort = (PUCHAR)PortAddress.LowPart;

WRITE_PORT_UCHAR( PPort, byte);
//…

Before call WRITE_PORT_UCHAR,we must call HalTranslateBusAddress to convert(enable)
the address( I searched WinNT 4.0 DDK document for the function). And the code works
on X86,for other platform,I think,we must call MmMapIoSpace also.

Thanks very much.


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

It’s nice to hear greate message …
That’s my pleasure…

First of all,thanks for help.

Now,my driver works very well,the code is below:

/////////////////////////////////////////////////////////////////////
PUCHAR PPort;
UCHAR byte;
ULONG ioport;
PHYSICAL_ADDRESS PortAddress;
ULONG AddressSpace = 1; // IO space

//
ioport = 0x70;
byte = 0x20;

PortAddress.QuadPart = ioport;

HalTranslateBusAddress (Isa, 0, PortAddress, &AddressSpace, &PortAddress);
PPort = (PUCHAR)PortAddress.LowPart;

WRITE_PORT_UCHAR( PPort, byte);
//…

Before call WRITE_PORT_UCHAR,we must call HalTranslateBusAddress to convert(enable)
the address( I searched WinNT 4.0 DDK document for the function). And the code works
on X86,for other platform,I think,we must call MmMapIoSpace also.

Thanks very much.


You are currently subscribed to ntdev as: xxxxx@dreamwiz.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Best Regard
Yun-Gun.JEONG

[Á¤¿¬±Ù]-[Yun-Gun.JEONG]

Developing Kernel-Mode Device Driver for Windows NT/2000 (WDM)

RTOS(Real-Time Operating System) Device Drivers & Applications

SoftLogic (ISaGRAF & ISaPRO) Admin and develop Device Drivers

OS : VxWorks , RTX-DCX-PlatformEvaluator, Windows NT/2000


[private e-mail address : xxxxx@dreamwiz.com]


DreamWiz Free Mail @ http://www.dreamwiz.com/
DreamSearch Click the world!!! http://search.dreamwiz.com/