From: Alun Carp [alun@des.co.uk] Sent: Tuesday, February 27, 2001 11:52 AM To: NT Developers Interest List Subject: [ntdev] RE: How to write port? 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: GlennEverhart@FirstUSA.com To unsubscribe send a blank email to leave-ntdev-247T@lists.osr.com