From 1fda00d6836d2cdef1d6f065cf4a65ec4a965603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Tue, 23 Apr 2013 00:41:45 +0000 Subject: [PATCH] =?UTF-8?q?[KDCOM]=20-=20Use=20stdlib.h=20header=20instead?= =?UTF-8?q?=20of=20declaring=20the=20atol=20function's=20prototype=20(caug?= =?UTF-8?q?ht=20by=20J=C3=A9r=C3=B4me).=20-=20Clarify=20the=20loop=20in=20?= =?UTF-8?q?KdpSendPacket=20(by=20Timo).=20NOTE:=20I=20also=20noticed=20tha?= =?UTF-8?q?t=20it=20was=20not=20this=20loop-change=20that=20fixed=20reconn?= =?UTF-8?q?ection=20(see=20commit=20message=20of=20r58823),=20but=20one=20?= =?UTF-8?q?of=20the=20changes=20of=20revision=20r58822=20(certainly=20the?= =?UTF-8?q?=20one=20in=20the=20KdpReceiveByte=20function)=20(ironically=20?= =?UTF-8?q?I=20said=20"Seems=20to=20fix..."=20since=20I=20noticed=20that?= =?UTF-8?q?=20change=20of=20behaviour=20when=20I=20was=20trying=20to=20pla?= =?UTF-8?q?y=20with=20the=20code=20in=20KdpSendPacket=20with=20modificatio?= =?UTF-8?q?ns=20of=20r58822,=20but=20I=20didn't=20notice=20that=20in=20fac?= =?UTF-8?q?t=20it=20happened=20with=20changes=20of=20r58822.=20It=20is=20o?= =?UTF-8?q?nly=20today=20that=20I=20constated=20that,=20during=20a=20rever?= =?UTF-8?q?t=20of=20r58823=20+=20test=20+=20a=20remark=20from=20Timo).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit svn path=/trunk/; revision=58834 --- reactos/drivers/base/kddll/kdcom.c | 3 +- reactos/drivers/base/kddll/kddll.c | 54 +++++++++++++++++---------- reactos/drivers/base/kddll/kdserial.c | 9 ++++- 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/reactos/drivers/base/kddll/kdcom.c b/reactos/drivers/base/kddll/kdcom.c index 985dfa75e0b..1b401707a45 100644 --- a/reactos/drivers/base/kddll/kdcom.c +++ b/reactos/drivers/base/kddll/kdcom.c @@ -8,8 +8,7 @@ #include "kddll.h" #include - -long atol(const char *str); +#include /* Serial debug connection */ diff --git a/reactos/drivers/base/kddll/kddll.c b/reactos/drivers/base/kddll/kddll.c index 3976dea4bb9..99b4ad09c40 100644 --- a/reactos/drivers/base/kddll/kddll.c +++ b/reactos/drivers/base/kddll/kddll.c @@ -34,7 +34,10 @@ KdpCalculateChecksum( PUCHAR ByteBuffer = Buffer; ULONG Checksum = 0; - while (Length-- > 0) Checksum += (ULONG)*ByteBuffer++; + while (Length-- > 0) + { + Checksum += (ULONG)*ByteBuffer++; + } return Checksum; } @@ -335,18 +338,8 @@ KdSendPacket( Retries = KdContext->KdpDefaultRetries; - do + for (;;) { - if (Retries == 0) - { - /* PACKET_TYPE_KD_DEBUG_IO is allowed to instantly timeout */ - if (PacketType == PACKET_TYPE_KD_DEBUG_IO) - { - /* No response, silently fail. */ - return; - } - } - /* Set the packet id */ Packet.PacketId = CurrentPacketId; @@ -357,7 +350,10 @@ KdSendPacket( KdpSendBuffer(MessageHeader->Buffer, MessageHeader->Length); /* If we have meesage data, also send it */ - if (MessageData) KdpSendBuffer(MessageData->Buffer, MessageData->Length); + if (MessageData) + { + KdpSendBuffer(MessageData->Buffer, MessageData->Length); + } /* Finalize with a trailing byte */ KdpSendByte(PACKET_TRAILING_BYTE); @@ -368,17 +364,37 @@ KdSendPacket( NULL, NULL, KdContext); - if (KdStatus == KDP_PACKET_TIMEOUT) + + /* Did we succeed? */ + if (KdStatus == KDP_PACKET_RECEIVED) { - if (Retries > 0) Retries--; + /* Packet received, we can quit the loop */ + CurrentPacketId &= ~SYNC_PACKET_ID; + break; } + else if (KdStatus == KDP_PACKET_TIMEOUT) + { + /* Timeout, decrement the retry count */ + if (Retries > 0) + Retries--; + + /* + * If the retry count reaches zero, bail out + * for packet types allowed to timeout. + */ + if (Retries == 0) + { + if (PacketType == PACKET_TYPE_KD_DEBUG_IO) + { + return; + } + } + } + // else (KdStatus == KDP_PACKET_RESEND) /* Resend the packet */ /* Packet timed out, send it again */ KDDBGPRINT("KdSendPacket got KdStatus 0x%x\n", KdStatus); - - } while (KdStatus != KDP_PACKET_RECEIVED); - - CurrentPacketId &= ~SYNC_PACKET_ID; + } } /* EOF */ diff --git a/reactos/drivers/base/kddll/kdserial.c b/reactos/drivers/base/kddll/kdserial.c index f884b554872..a7dcc8fd84f 100644 --- a/reactos/drivers/base/kddll/kdserial.c +++ b/reactos/drivers/base/kddll/kdserial.c @@ -24,7 +24,10 @@ KdpSendBuffer( { PUCHAR ByteBuffer = Buffer; - while (Size-- > 0) KdpSendByte(*ByteBuffer++); + while (Size-- > 0) + { + KdpSendByte(*ByteBuffer++); + } } /****************************************************************************** @@ -49,7 +52,9 @@ KdpReceiveBuffer( { /* Try to get a byte from the port */ Status = KdpReceiveByte(&Byte); - if (Status != KDP_PACKET_RECEIVED) return Status; + if (Status != KDP_PACKET_RECEIVED) + return Status; + *ByteBuffer++ = Byte; }