Changeset 210 in xtideuniversalbios for trunk/Serial_Server


Ignore:
Timestamp:
Jan 16, 2012, 4:15:51 AM (12 years ago)
Author:
gregli@…
google:author:
gregli@hotmail.com
Message:

Various minor bug fixes and improvements to the serial server code.

Location:
trunk/Serial_Server/library
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Serial_Server/library/Process.cpp

    r209 r210  
    5151#define SERIAL_INQUIRE_PORTANDBAUD_PORT 0xfc
    5252
     53void logBuff( char *message, unsigned long buffoffset, unsigned long readto, int verboseLevel )
     54{
     55    char logBuff[ 514*9 + 10 ];
     56    int logCount;
     57
     58    if( verboseLevel == 6 || (verboseLevel >= 4 && buffoffset == readto) )
     59    {
     60        if( verboseLevel == 4 && buffoffset > 11 )
     61            logCount = 11;
     62        else
     63            logCount = buffoffset;
     64
     65        for( int t = 0; t < logCount; t++ )
     66            sprintf( &logBuff[t*9], "[%3d:%02x] ", t, buff.b[t] );
     67        if( logCount != buffoffset )
     68            sprintf( &logBuff[logCount*9], "... " );
     69
     70        log( 4, "%s%s", message, logBuff );
     71    }
     72}
     73
    5374void processRequests( Serial *serial, Image *image0, Image *image1, int timeoutEnabled, int verboseLevel )
    5475{
     
    5677    int workOffset, workCount;
    5778
    58     int vtype;
     79    int vtype = 0;
    5980
    6081    unsigned long mylba;
     
    6889    Image *img;
    6990    unsigned long cyl, sect, head;
     91    unsigned long perfTimer;
    7092
    7193    GetTime_Timeout_Local = GetTime_Timeout();
     
    81103        buffoffset += len;
    82104
     105        //
     106        // For debugging, look at the incoming packet
     107        //
    83108        if( verboseLevel >= 4 )
    84         {
    85             char logBuff[ 514*9 + 10 ];
    86             int logCount;
    87 
    88             if( verboseLevel == 6 || buffoffset == readto )
    89             {
    90                 if( verboseLevel == 4 && buffoffset > 11 )
    91                     logCount = 11;
    92                 else
    93                     logCount = buffoffset;
    94 
    95                 for( int t = 0; t < logCount; t++ )
    96                     sprintf( &logBuff[t*9], "[%3d:%02x] ", t, buff.b[t] );
    97                 if( logCount != buffoffset )
    98                     sprintf( &logBuff[logCount*9], "... " );
    99 
    100                 log( 4, logBuff );
    101             }
    102         }
     109            logBuff( "    Received: ", buffoffset, readto, verboseLevel );
    103110
    104111        timeout = 0;
     
    117124        lasttick = GetTime();
    118125
     126        //
     127        // No work currently to do, look at each character as they come in...
     128        //
    119129        if( buffoffset == 1 && !readto )
    120130        {
     
    125135            else if( (buff.b[0] & SERIAL_COMMAND_HEADERMASK) == SERIAL_COMMAND_HEADER )
    126136            {
     137                //
     138                // Found our command header byte to start a commnad sequence, read the next 7 and evaluate
     139                //
    127140                readto = 8;
     141                continue;
    128142            }
    129143            else
    130144            {
     145                //
     146                // Spurious characters, discard
     147                //
    131148                if( verboseLevel >= 2 )
    132149                {
    133150                    if( buff.b[0] >= 0x20 && buff.b[0] <= 0x7e )
    134                         log( 3, "[%d:%c]", buff.b[0], buff.b[0] );
     151                        log( 3, "Spurious: [%d:%c]", buff.b[0], buff.b[0] );
    135152                    else
    136                         log( 3, "[%d]", buff.b[0] );
     153                        log( 3, "Spurious: [%d]", buff.b[0] );
    137154                }
    138155                buffoffset = 0;
     
    141158        }
    142159
    143         // read 512 bytes from serial port - only one reason for that size: Write Sector
     160        //
     161        // Partial packet received, keep reading...
     162        //
     163        if( readto && buffoffset < readto )
     164            continue;
     165
     166        //
     167        // Read 512 bytes from serial port, only one command reads that many characters: Write Sector
    144168        //
    145169        if( buffoffset == readto && readto == 514 )
     
    161185            img->writeSector( &buff.w[0] );
    162186
     187            //
     188            // Echo back the CRC
     189            //
    163190            if( serial->writeCharacters( &buff.w[256], 2 ) != 2 )
    164191                log( 1, "Serial Port Write Error" );
     
    168195        }
    169196
     197        //
    170198        // 8 byte command received, or a continuation of the previous command
    171199        //
     
    176204            if( workCount )
    177205            {
     206                //
     207                // Continuation...
     208                //
    178209                if( buff.b[0] != (workCount-0) )
    179210                {
     
    185216            else
    186217            {
     218                //
     219                // New Command...
     220                //
    187221                if( (crc = checksum( &buff.w[0], 3 )) != buff.w[3] )
    188222                {
     
    196230                    if( !image1 )
    197231                    {
    198                         log( 2, "slave drive selected when not supplied" );
     232                        log( 2, "Slave drive selected when not supplied" );
     233                        img = NULL;
    199234                        continue;
    200235                    }
    201                     img = NULL;
     236                    else
     237                        img = image1;
    202238                }
    203239                else
     
    231267                workOffset = 0;
    232268                workCount = buff.chs.count;
     269                if( verboseLevel > 1 && workCount > 100 )
     270                    perfTimer = GetTime();
    233271            }
    234272
    235273            if( workCount && (workCommand == (SERIAL_COMMAND_WRITE | SERIAL_COMMAND_READWRITE)) )
    236274            {
     275                //
     276                // Write command...   Setup to receive a sector
     277                //
    237278                readto = 514;
    238279            }
    239280            else
    240281            {
     282                //
     283                // Inquire command...
     284                //
    241285                if( workCommand == SERIAL_COMMAND_INQUIRE )
    242286                {
    243                     log( 2, "Inquire Disk Information, Drive=%d",
    244                          (buff.inquire.driveAndHead & ATA_DriveAndHead_Drive) >> 4 );
    245 
    246287                    if( serial->speedEmulation &&
    247288                        (buff.inquire.portAndBaud & SERIAL_INQUIRE_PORTANDBAUD_BAUD) != serial->baudRate->divisor )
     
    261302                    img->respondInquire( &buff.w[0], serial->baudRate, buff.inquire.portAndBaud );
    262303                }
     304                //
     305                // Read command...
     306                //
    263307                else
    264308                {
     
    270314
    271315                if( serial->writeCharacters( &buff.w[0], 514 ) != 514 )
    272                 {
    273316                    log( 1, "Serial Port Write Error" );
    274                 }
    275317
    276318                workCount--;
    277319                workOffset++;
    278320            }
    279 
    280             if( verboseLevel > 1 )
    281             {
    282                 if( vtype == 1 )
    283                     log( 2, "%s: LBA=%u, Count=%u",
    284                          (workCommand & SERIAL_COMMAND_WRITE ? "Write" : "Read"),
    285                          mylba, workCount );
    286                 else if( vtype == 2 )
    287                     log( 2, "%s: Cylinder=%u, Sector=%u, Head=%u, Count=%u, LBA=%u",
    288                          (workCommand & SERIAL_COMMAND_WRITE ? "Write" : (workCommand & SERIAL_COMMAND_READWRITE ? "Read" : "Inquire")),
    289                          cyl, sect, head, workCount, mylba );
    290 
    291                 vtype = 0;       
    292 
    293                 if( workOffset > 1 )
    294                     log( 3, "       Offset=%u, Checksum=%04x", workOffset-1, buff.w[256] );               
    295             }
     321        }
     322
     323        if( verboseLevel > 1 )
     324        {
     325            char *comStr = (workCommand & SERIAL_COMMAND_WRITE ? "Write" :
     326                            (workCommand & SERIAL_COMMAND_READWRITE ? "Read" : "Inquire"));
     327
     328            if( vtype == 1 )
     329                log( 2, "%s %d: LBA=%u, Count=%u", comStr, img == image0 ? 0 : 1,
     330                     mylba, workCount );
     331            else if( vtype == 2 )
     332                log( 2, "%s %d: Cylinder=%u, Sector=%u, Head=%u, Count=%u, LBA=%u", comStr, img == image0 ? 0 : 1,
     333                     cyl, sect, head, workCount+1, mylba );
     334
     335            vtype = 0;       
     336
     337            if( workOffset > 1 )
     338                log( 3, "    Continuation: Offset=%u, Checksum=%04x", workOffset-1, buff.w[256] );
     339
     340            if( !(workCommand & SERIAL_COMMAND_WRITE) && verboseLevel >= 4 )
     341                logBuff( "    Sending: ", 514, 514, verboseLevel );
     342
     343            if( workCount == 0 && workOffset > 100 )
     344                log( 2, "    Block Complete: %.2lf bytes per second", (512.0 * workOffset) / (GetTime() - perfTimer) * 1000.0 );
    296345        }
    297346    }
    298347}
     348
     349
  • trunk/Serial_Server/library/Serial.cpp

    r209 r210  
    1717    {  19200, 0xff,  "19.2K",  "19K" },
    1818    {  38400,  0x2,  "38.4K",  "38K" },
     19    {  76800,  0x2,  "76.8K",  "77K" },
    1920    { 115200,  0x3, "115.2K", "115K" },
     21    { 153600,  0x3, "153.6K", "154K" },
    2022    { 230400, 0xff, "230.4K", "230K" },
    2123    { 460800,  0x1, "460.8K", "460K" },
Note: See TracChangeset for help on using the changeset viewer.