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; }