📄 ieee1284.c
字号:
Controller, P5ReadPortUchar(Controller + OFFSET_DSR), dcr);
}
Terminate_ExitLabel:
// =============== Host State 28 Termination ===============8
// DIR = Don't Care (Possibly Low)
// IRQEN = Don't Care (Possibly Low)
// 1284/SelectIn = Low
// nReverseReq/**(ECP only) = Don't Care (Possibly High)
// HostAck/HostBusy/nAutoFeed = High (Signals State 28)
// HostClk/nStrobe = High
//
Pdx->CurrentEvent = 28;
dcr = UPDATE_DCR(dcr, DONT_CARE, DONT_CARE, INACTIVE, DONT_CARE, ACTIVE, ACTIVE);
P5WritePortUchar(wPortDCR, dcr);
// We are now back in compatibility mode.
P5SetPhase( Pdx, PHASE_TERMINATE );
Pdx->Connected = FALSE;
Pdx->IsIeeeTerminateOk = FALSE;
DD((PCE)Pdx,DDT,"IeeeTerminate1284Mode - exit - dcr=%x\n", dcr);
return;
}
NTSTATUS
IeeeEnter1284Mode(
IN PPDO_EXTENSION Pdx,
IN UCHAR Extensibility
)
/*++
Routine Description:
This routine performs 1284 negotiation with the peripheral to the
nibble mode protocol.
Arguments:
Controller - Supplies the port address.
DeviceIdRequest - Supplies whether or not this is a request for a device
id.
Return Value:
STATUS_SUCCESS - Successful negotiation.
otherwise - Unsuccessful negotiation.
--*/
{
PUCHAR wPortDCR;
PUCHAR Controller;
UCHAR dcr;
const USHORT sPeriphResponseTime = 35;
Controller = Pdx->Controller;
wPortDCR = Controller + OFFSET_DCR;
/* =============== Host Prep for Pre State 0 ===============8
Set the following just in case someone didn't
put the port in compatibility mode before we got it.
DIR = Don't Care
IRQEN = Don't Care
1284/SelectIn = Low
nReverseReq/ (ECP only)= High for ECP / Don't Care for Nibble
I will do ahead and set it to high
since Nibble doesn't care.
HostAck/HostBusy = High
HostClk/nStrobe = Don't Care
============================================================ */
dcr = P5ReadPortUchar(wPortDCR); // Get content of DCR.
dcr = UPDATE_DCR(dcr, DONT_CARE, DONT_CARE, INACTIVE, ACTIVE, ACTIVE, DONT_CARE);
P5WritePortUchar(wPortDCR, dcr);
KeStallExecutionProcessor(2);
/* =============== Host Pre State 0 Negotiation ===============8
DIR = Low ( Don't Care by spec )
IRQEN = Low ( Don't Care by spec )
1284/SelectIn = Low
nReverseReq/ (ECP only)= High ( Don't Care by spec )
HostAck/HostBusy = High
HostClk/nStrobe = High
============================================================ */
dcr = UPDATE_DCR(dcr, INACTIVE, INACTIVE, INACTIVE, ACTIVE, ACTIVE, ACTIVE);
P5WritePortUchar(wPortDCR, dcr);
KeStallExecutionProcessor(2);
/* =============== Host State 0 Negotiation ===============8
Place the extensibility request value on the data bus - state 0.
============================================================ */
Pdx->CurrentEvent = 0;
P5WritePortUchar(Controller + DATA_OFFSET, Extensibility);
KeStallExecutionProcessor(2);
/* =========== Host State 1 Negotiation Phase ===========8
DIR = Don't Care
IRQEN = Don't Care
1284/SelectIn = High (Signals State 1)
nReverseReq/ (ECP only)= Don't Care
HostAck/HostBusy = Low (Signals state 1)
HostClk/nStrobe = High
============================================================ */
Pdx->CurrentEvent = 1;
dcr = UPDATE_DCR(dcr, DONT_CARE, DONT_CARE, ACTIVE, DONT_CARE, INACTIVE, ACTIVE);
P5WritePortUchar(wPortDCR, dcr);
/* =============== Periph State 2 Negotiation ===============8
PeriphAck/PtrBusy = Don't Care
PeriphClk/PtrClk = low Signals State 2
nAckReverse/AckDataReq = high Signals State 2
XFlag = high Signals State 2
**Note: It is high at state 2
for both ecp and nibble
nPeriphReq/nDataAvail = high Signals State 2
============================================================ */
Pdx->CurrentEvent = 2;
if (!CHECK_DSR(Controller, DONT_CARE, INACTIVE, ACTIVE, ACTIVE, ACTIVE,
sPeriphResponseTime)) {
KeStallExecutionProcessor(2);
dcr = UPDATE_DCR(dcr, DONT_CARE, DONT_CARE, INACTIVE, DONT_CARE, ACTIVE, DONT_CARE);
P5WritePortUchar(wPortDCR, dcr);
DD((PCE)Pdx,DDW,"IeeeEnter1284Mode - controller=%x - extensibility=%x, FAIL - TIMEOUT on Event 2\n",
Pdx->Controller, Extensibility);
P5SetPhase( Pdx, PHASE_UNKNOWN );
Pdx->Connected = FALSE;
Pdx->IsIeeeTerminateOk = FALSE;
return STATUS_INVALID_DEVICE_REQUEST;
}
/* =============== Host State 3 Negotiation ===============8
DIR = Don't Care
IRQEN = Don't Care
1284/SelectIn = High
nReverseReq/ (ECP only)= Don't Care
HostAck/HostBusy = Low
HostClk/nStrobe = Low (signals State 3)
NOTE: Strobe the Extensibility byte
============================================================ */
Pdx->CurrentEvent = 3;
dcr = UPDATE_DCR(dcr, DONT_CARE, DONT_CARE, ACTIVE, DONT_CARE, INACTIVE, INACTIVE);
P5WritePortUchar(wPortDCR, dcr);
// HostClk must be help low for at least .5 microseconds.
//
KeStallExecutionProcessor(2);
/* =============== Host State 4 Negotiation ===============8
DIR = Don't Care
IRQEN = Don't Care
1284/SelectIn = High
nReverseReq/ (ECP only)= Don't Care
HostAck/HostBusy = High (signals State 4)
HostClk/nStrobe = High (signals State 4)
NOTE: nReverseReq should be high in ECP, but this line is only
valid for ECP. Since it isn't used for signaling
anything in negotiation, let's just ignore it for now.
============================================================ */
Pdx->CurrentEvent = 4;
dcr = UPDATE_DCR(dcr, DONT_CARE, DONT_CARE, ACTIVE, DONT_CARE, ACTIVE, ACTIVE);
P5WritePortUchar(wPortDCR, dcr);
/* ============== Periph State 5/6 Negotiation ===============
PeriphAck/PtrBusy = Don't Care. low (ECP) / Don't Care (Nibble)
Since this line differs based on Protocol
Let's not check the line.
PeriphClk/PtrClk = high (Signals State 6)
nAckReverse/AckDataReq = Don't Care. low (ECP) / high (Nibble)
Since this line differs based on Protocol
Let's not check the line.
XFlag = Don't Care. high (ECP) / low (Nibble)
Since this line differs based on Protocol
Let's not check the line.
nPeriphReq/nDataAvail = Don't Care. high (ECP) / low (Nibble)
Since this line differs based on Protocol
Let's not check the line.
============== Periph State 5/6 Negotiation ==============8
NOTES:
- It's ok to lump states 5 and 6 together. In state 5 Nibble,
the periph will set XFlag low and nPeriphReq/nDataAvail low.
The periph will then hold for .5ms then set PeriphClk/PtrClk
high. In ECP, state 5 is nAckReverse/AckDataReq going low and
PeriphAck/PtrBusy going low. Followed by a .5ms pause.
Followed by PeriphClk/PtrClk going high.
============================================================ */
Pdx->CurrentEvent = 5;
if (!CHECK_DSR(Controller, DONT_CARE, ACTIVE, DONT_CARE, DONT_CARE, DONT_CARE,
sPeriphResponseTime)) {
dcr = UPDATE_DCR(dcr, DONT_CARE, DONT_CARE, INACTIVE, DONT_CARE, DONT_CARE, DONT_CARE);
P5WritePortUchar(wPortDCR, dcr);
DD((PCE)Pdx,DDW,"IeeeEnter1284Mode- controller=%x - extensibility=%x, FAIL - TIMEOUT on Events 5/6\n",
Pdx->Controller, Extensibility);
P5SetPhase( Pdx, PHASE_UNKNOWN );
Pdx->Connected = FALSE;
Pdx->IsIeeeTerminateOk = FALSE;
return STATUS_INVALID_DEVICE_REQUEST;
}
KeStallExecutionProcessor(2);
P5SetPhase( Pdx, PHASE_NEGOTIATION );
Pdx->Connected = TRUE;
return STATUS_SUCCESS;
}
VOID
IeeeDetermineSupportedProtocols(
IN PPDO_EXTENSION Pdx
)
/*++
Routine Description:
This routine walks the list of all ieee1284 modes, and
flags each of the ones the peripheral supports in
Pdx->ProtocolModesSupported. This proc is called from
external IOCTL.
Arguments:
Pdx - The parallel device extension
Return Value:
--*/
{
REVERSE_MODE rm;
FORWARD_MODE fm;
// Take CENTRONICS as a given since it is not a
// mode we can neogitate to.
//
// n.b.
// Let's go ahead and mark IEEE_COMPATIBILITY since we
// cannot negotiate into it. But if the someone sets
// IEEE_COMPATIBILITY and the peripheral does not support
// IEEE 1284 compliant compatibility mode then we're gonna
// create one very unhappy peripheral. -- dvrh
Pdx->ProtocolModesSupported = CENTRONICS | IEEE_COMPATIBILITY;
//
// Unlikely that we would be connected, but...
//
ParTerminate(Pdx);
for (fm = FORWARD_FASTEST; fm < FORWARD_NONE; fm++) {
if (afpForward[fm].fnIsModeSupported)
afpForward[fm].fnIsModeSupported(Pdx);
}
for (rm = REVERSE_FASTEST; rm < REVERSE_NONE; rm++) {
if (arpReverse[rm].fnIsModeSupported)
arpReverse[rm].fnIsModeSupported(Pdx);
}
return;
}
NTSTATUS
IeeeNegotiateBestMode(
IN PPDO_EXTENSION Pdx,
IN USHORT usReadMask,
IN USHORT usWriteMask
)
/*++
Routine Description:
This routine walks the list of supported modes, looking for the best
(fastest) mode. It will skip any mode(s) mask passed in.
Arguments:
Pdx - The parallel device extension
Return Value:
STATUS_SUCCESS - Successful negotiation.
otherwise - Unsuccessful negotiation.
--*/
{
REVERSE_MODE rm;
FORWARD_MODE fm;
//
// A USHORT is provided in the extension so that each of the protocols
// can decide whether they need to negotiate each time we go through this
// process...
//
//
// Unlikely that we would be connected, but...
//
DD((PCE)Pdx,DDT,"IeeeNegotiateBestMode - skipping Fwd=%x, Rev=%x\n",usWriteMask, usReadMask);
ParTerminate(Pdx);
Pdx->IdxForwardProtocol = FORWARD_NONE;
Pdx->IdxReverseProtocol = REVERSE_NONE;
for (fm = FORWARD_FASTEST; fm < FORWARD_NONE; fm++) {
if (!(afpForward[fm].Protocol & usWriteMask)) {
if (afpForward[fm].fnIsModeSupported) {
if (afpForward[fm].fnIsModeSupported(Pdx)) {
Pdx->IdxForwardProtocol = (USHORT)fm;
break;
}
}
}
}
for (rm = REVERSE_FASTEST; rm < REVERSE_NONE; rm++) {
if (!(arpReverse[rm].Protocol & usReadMask)) {
if (arpReverse[rm].fnIsModeSupported) {
if (arpReverse[rm].fnIsModeSupported(Pdx)) {
Pdx->IdxReverseProtocol = (USHORT)rm;
break;
}
}
}
}
Pdx->fnRead = arpReverse[Pdx->IdxReverseProtocol].fnRead;
Pdx->fnWrite = afpForward[Pdx->IdxForwardProtocol].fnWrite;
DD((PCE)Pdx,DDT,"IeeeNegotiateBestMode - exit - Fwd=%x, Rev=%x\n",fm,rm);
return STATUS_SUCCESS;
}
NTSTATUS
IeeeNegotiateMode(
IN PPDO_EXTENSION Pdx,
IN USHORT usReadMask,
IN USHORT usWriteMask
)
/*++
Routine Description:
This routine walks the list of supported modes, looking for the best
(fastest) mode which is also in the mode mask passed in.
Arguments:
Pdx - The parallel device extension
Return Value:
STATUS_SUCCESS - Successful negotiation.
otherwise - Unsuccessful negotiation.
--*/
{
REVERSE_MODE rm;
FORWARD_MODE fm;
//
// A USHORT is provided in the extension so that each of the protocols
// can decide whether they need to negotiate each time we go through this
// process...
//
//
// Unlikely that we would be connected, but...
//
ParTerminate(Pdx);
Pdx->IdxForwardProtocol = FORWARD_NONE;
Pdx->IdxReverseProtocol = REVERSE_NONE;
for (fm = FORWARD_FASTEST; fm < FORWARD_NONE; fm++) {
if (afpForward[fm].Protocol & usWriteMask) {
if (afpForward[fm].fnIsModeSupported) {
if (afpForward[fm].fnIsModeSupported(Pdx)) {
Pdx->IdxForwardProtocol = (USHORT)fm;
break;
}
} else {
Pdx->IdxForwardProtocol = (USHORT)fm;
break;
}
}
}
for (rm = REVERSE_FASTEST; rm < REVERSE_NONE; rm++) {
if (arpReverse[rm].Protocol & usReadMask) {
if (arpReverse[rm].fnIsModeSupported) {
if (arpReverse[rm].fnIsModeSupported(Pdx)) {
Pdx->IdxReverseProtocol = (USHORT)rm;
break;
}
} else {
Pdx->IdxReverseProtocol = (USHORT)rm;
break;
}
}
}
DD((PCE)Pdx,DDT,"IeeeNegotiateMode - Fwd=%x, Rev=%x\n",fm,rm);
Pdx->fnRead = arpReverse[Pdx->IdxReverseProtocol].fnRead;
Pdx->fnWrite = afpForward[Pdx->IdxForwardProtocol].fnWrite;
return STATUS_SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -