ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

kdserial.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:       GPL, see COPYING in the top level directory
00003  * PROJECT:         ReactOS kernel
00004  * FILE:            drivers/base/kddll/kdserial.c
00005  * PURPOSE:         Serial communication functions for the kernel debugger.
00006  * PROGRAMMER:      Timo Kreuzer (timo.kreuzer@ewactos.org)
00007  */
00008 
00009 #include "kddll.h"
00010 
00011 
00012 
00013 /******************************************************************************
00014  * \name KdpSendBuffer
00015  * \brief Sends a buffer of data to the serial KD port.
00016  * \param Buffer Pointer to the data.
00017  * \param Size Size of data in bytes.
00018  */
00019 VOID
00020 NTAPI
00021 KdpSendBuffer(
00022     IN PVOID Buffer,
00023     IN ULONG Size)
00024 {
00025     INT i;
00026     for (i = 0; i < Size; i++)
00027     {
00028         KdpSendByte(((PUCHAR)Buffer)[i]);
00029     }
00030 }
00031 
00032 /******************************************************************************
00033  * \name KdpReceiveBuffer
00034  * \brief Recieves data from the KD port and fills a buffer.
00035  * \param Buffer Pointer to a buffer that receives the data.
00036  * \param Size Size of data to receive in bytes.
00037  * \return KDP_PACKET_RECEIVED if successful. 
00038  *         KDP_PACKET_TIMEOUT if the receice timed out.
00039  */
00040 KDP_STATUS
00041 NTAPI
00042 KdpReceiveBuffer(
00043     OUT PVOID Buffer,
00044     IN  ULONG Size)
00045 {
00046     ULONG i;
00047     PUCHAR ByteBuffer = Buffer;
00048     KDP_STATUS Status;
00049 
00050     for (i = 0; i < Size; i++)
00051     {
00052         /* Try to get a byte from the port */
00053         Status = KdpReceiveByte(&ByteBuffer[i]);
00054 
00055         if (Status != KDP_PACKET_RECEIVED)
00056         {
00057             return Status;
00058         }
00059     }
00060 
00061     return KDP_PACKET_RECEIVED;
00062 }
00063 
00064 
00065 /******************************************************************************
00066  * \name KdpReceivePacketLeader
00067  * \brief Recieves a packet leadr from the KD port.
00068  * \param PacketLeader Pointer to an ULONG that receives the packet leader.
00069  * \return KDP_PACKET_RECEIVED if successful. 
00070  *         KDP_PACKET_TIMEOUT if the receive timed out.
00071  *         KDP_PACKET_RESEND if a breakin byte was detected.
00072  */
00073 KDP_STATUS
00074 NTAPI
00075 KdpReceivePacketLeader(
00076     OUT PULONG PacketLeader)
00077 {
00078     UCHAR Index = 0, Byte, Buffer[4];
00079     KDP_STATUS KdStatus;
00080 
00081     /* Set first character to 0 */
00082     Buffer[0] = 0;
00083 
00084     do
00085     {
00086         /* Receive a single byte */
00087         KdStatus = KdpReceiveByte(&Byte);
00088 
00089         /* Check for timeout */
00090         if (KdStatus == KDP_PACKET_TIMEOUT)
00091         {
00092             /* Check if we already got a breakin byte */
00093             if (Buffer[0] == BREAKIN_PACKET_BYTE)
00094             {
00095                 return KDP_PACKET_RESEND;
00096             }
00097 
00098             /* Report timeout */
00099             return KDP_PACKET_TIMEOUT;
00100         }
00101 
00102         /* Check if we received a byte */
00103         if (KdStatus == KDP_PACKET_RECEIVED)
00104         {
00105             /* Check if this is a valid packet leader byte */
00106             if (Byte == PACKET_LEADER_BYTE ||
00107                 Byte == CONTROL_PACKET_LEADER_BYTE)
00108             {
00109                 /* Check if we match the first byte */
00110                 if (Byte != Buffer[0])
00111                 {
00112                     /* No, this is the new byte 0! */
00113                     Index = 0;
00114                 }
00115 
00116                 /* Store the byte in the buffer */
00117                 Buffer[Index] = Byte;
00118 
00119                 /* Continue with next byte */
00120                 Index++;
00121                 continue;
00122             }
00123 
00124             /* Check for breakin byte */
00125             if (Byte == BREAKIN_PACKET_BYTE)
00126             {
00127                 KDDBGPRINT("BREAKIN_PACKET_BYTE\n");
00128                 Index = 0;
00129                 Buffer[0] = Byte;
00130                 continue;
00131             }
00132         }
00133 
00134         /* Restart */
00135         Index = 0;
00136         Buffer[0] = 0;
00137     }
00138     while (Index < 4);
00139 
00140     /* Enable the debugger */
00141     KdDebuggerNotPresent = FALSE;
00142     SharedUserData->KdDebuggerEnabled |= 0x00000002;
00143 
00144     /* Return the received packet leader */
00145     *PacketLeader = *(PULONG)Buffer;
00146 
00147     return KDP_PACKET_RECEIVED;
00148 }
00149 

Generated on Sun May 27 2012 04:27:13 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.