Changeset 215 in xtideuniversalbios for trunk/Serial_Server/library
- Timestamp:
- Jan 19, 2012, 9:17:04 AM (13 years ago)
- google:author:
- gregli@hotmail.com
- Location:
- trunk/Serial_Server/library
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Serial_Server/library/Library.h
r209 r215 53 53 unsigned char divisor; 54 54 char *display; 55 char *altSelection;56 55 }; 57 56 struct baudRate *baudRateMatchString( char *str ); -
trunk/Serial_Server/library/Process.cpp
r213 r215 48 48 #define SERIAL_COMMAND_HEADERMASK 0xe0 49 49 50 #define SERIAL_INQUIRE_PORTANDBAUD_BAUD 3 51 #define SERIAL_INQUIRE_PORTANDBAUD_PORT 0xfc 50 #define SERIAL_INQUIRE_PORTANDBAUD_BAUDMASK 3 51 #define SERIAL_INQUIRE_PORTANDBAUD_PORTMASK 0xfc 52 #define SERIAL_INQUIRE_PORTANDBAUD_STARTINGPORT 0x240 53 54 #define SERIAL_INQUIRE_PORTANDBAUD_PORTTRANSLATE( a ) ( ((a) & SERIAL_INQUIRE_PORTANDBAUD_PORT) << 1 | SERIAL_INQUIRE_PORTANDBAUD_STARTINGPORT ) 52 55 53 56 void logBuff( char *message, unsigned long buffoffset, unsigned long readto, int verboseLevel ) … … 77 80 int workOffset, workCount; 78 81 79 int vtype = 0;80 81 82 unsigned long mylba; 82 83 unsigned long readto; 83 84 unsigned long buffoffset; 84 int timeout;85 85 unsigned long lasttick; 86 86 unsigned short crc; … … 95 95 buffoffset = 0; 96 96 readto = 0; 97 timeout = 0;98 97 workCount = workOffset = workCommand = 0; 98 99 99 lasttick = GetTime(); 100 100 101 while( timeout ||(len = serial->readCharacters( &buff.b[buffoffset], (readto ? readto-buffoffset : 1) )) )101 while( (len = serial->readCharacters( &buff.b[buffoffset], (readto ? readto-buffoffset : 1) )) ) 102 102 { 103 103 buffoffset += len; … … 109 109 logBuff( " Received: ", buffoffset, readto, verboseLevel ); 110 110 111 timeout = 0; 112 113 if( buffoffset != 1 && (timeoutEnabled && GetTime() > lasttick + GetTime_Timeout_Local) ) 111 if( timeoutEnabled && readto && GetTime() > lasttick + GetTime_Timeout_Local ) 114 112 { 115 timeout = 1; 116 buff.b[0] = buff.b[buffoffset]; 117 buffoffset = 0; 118 len = 1; 119 workCount = 0; 120 log( 1, "Timeout waiting on command" ); 121 continue; 113 log( 1, "Timeout waiting on data from client, aborting previous command" ); 114 115 workCount = workOffset = workCommand = 0; 116 readto = 0; 117 118 if( len <= 8 && (buff.b[buffoffset-len] & SERIAL_COMMAND_HEADERMASK) == SERIAL_COMMAND_HEADER ) 119 { 120 // assume that we are at the front of a new command 121 // 122 memcpy( &buff.b[0], &buff.b[buffoffset-len], len ); 123 buffoffset = len; 124 readto = 8; 125 // fall through to normal processing 126 } 127 else if( len == 1 ) 128 { 129 // one new character, treat it like any other new character received, discarding the buffer 130 // 131 buff.b[0] = buff.b[buffoffset-1]; 132 buffoffset = 1; 133 // fall through to normal processing 134 } 135 else 136 { 137 // discard even the newly received data and start listening anew 138 // 139 buffoffset = 0; 140 continue; 141 } 122 142 } 123 143 … … 127 147 // No work currently to do, look at each character as they come in... 128 148 // 129 if( buffoffset == 1 &&!readto )149 if( !readto ) 130 150 { 131 if( workCount ) 132 { 133 readto = 1; 134 } 135 else if( (buff.b[0] & SERIAL_COMMAND_HEADERMASK) == SERIAL_COMMAND_HEADER ) 151 if( (buff.b[0] & SERIAL_COMMAND_HEADERMASK) == SERIAL_COMMAND_HEADER ) 136 152 { 137 153 // … … 193 209 workOffset++; 194 210 workCount--; 211 212 if( workCount ) 213 readto = 1; // looking for continuation ACK 195 214 } 196 215 … … 204 223 if( workCount ) 205 224 { 225 if( verboseLevel > 1 ) 226 log( 2, " Continuation: Offset=%u, Checksum=%04x", workOffset-1, buff.w[256] ); 227 206 228 // 207 229 // Continuation... … … 221 243 if( (crc = checksum( &buff.w[0], 3 )) != buff.w[3] ) 222 244 { 223 log( 0, "Bad Command Checksum: %02x %02x %02x %02x %02x %02x %02x %02x, Checksum=%0 2x",245 log( 0, "Bad Command Checksum: %02x %02x %02x %02x %02x %02x %02x %02x, Checksum=%04x", 224 246 buff.b[0], buff.b[1], buff.b[2], buff.b[3], buff.b[4], buff.b[5], buff.b[6], buff.b[7], crc); 225 247 continue; 226 248 } 227 249 228 if( (buff.inquire.driveAndHead & ATA_DriveAndHead_Drive) ) 229 { 230 if( !image1 ) 231 { 232 log( 1, "Slave drive selected when not supplied" ); 233 img = NULL; 234 continue; 235 } 236 else 237 img = image1; 238 } 239 else 240 img = image0; 250 img = (buff.inquire.driveAndHead & ATA_DriveAndHead_Drive) ? image1 : image0; 241 251 242 252 workCommand = buff.chs.command & SERIAL_COMMAND_RWMASK; … … 248 258 | (((unsigned long) buff.lba.bits08) << 8) 249 259 | ((unsigned long) buff.lba.bits00); 250 vtype = 1;251 260 } 252 261 else … … 255 264 sect = buff.chs.sector; 256 265 head = (buff.chs.driveAndHead & ATA_COMMAND_HEADMASK); 257 mylba = (((cyl*img->head + head)*img->sect) + sect-1); 258 vtype = 2; 259 } 260 261 if( (workCommand & SERIAL_COMMAND_WRITE) && img->readOnly ) 262 { 263 log( 1, "Write attempt to Read Only disk" ); 264 continue; 266 mylba = img ? (((cyl*img->head + head)*img->sect) + sect-1) : 0; 265 267 } 266 268 267 269 workOffset = 0; 268 270 workCount = buff.chs.count; 271 272 if( verboseLevel > 0 ) 273 { 274 char *comStr = (workCommand & SERIAL_COMMAND_WRITE ? "Write" : "Read"); 275 276 if( workCommand == SERIAL_COMMAND_INQUIRE ) 277 log( 1, "Inquire %d: Client Port=0x%x, Client Baud=%s", img == image0 ? 0 : 1, 278 ((buff.inquire.portAndBaud & SERIAL_INQUIRE_PORTANDBAUD_PORTMASK) << 1) 279 + SERIAL_INQUIRE_PORTANDBAUD_STARTINGPORT, 280 baudRateMatchDivisor( buff.inquire.portAndBaud & SERIAL_INQUIRE_PORTANDBAUD_BAUDMASK )->display ); 281 else if( buff.chs.command & ATA_COMMAND_LBA ) 282 log( 1, "%s %d: LBA=%u, Count=%u", comStr, img == image0 ? 0 : 1, 283 mylba, workCount ); 284 else 285 log( 1, "%s %d: Cylinder=%u, Sector=%u, Head=%u, Count=%u, LBA=%u", comStr, img == image0 ? 0 : 1, 286 cyl, sect, head, workCount, mylba ); 287 } 288 289 if( !img ) 290 { 291 log( 1, " No slave drive provided" ); 292 workCount = 0; 293 continue; 294 } 295 296 if( (workCommand & SERIAL_COMMAND_WRITE) && img->readOnly ) 297 { 298 log( 1, " Write attempt to Read Only disk" ); 299 workCount = 0; 300 continue; 301 } 302 269 303 if( verboseLevel > 0 && workCount > 100 ) 270 304 perfTimer = GetTime(); … … 286 320 { 287 321 if( serial->speedEmulation && 288 (buff.inquire.portAndBaud & SERIAL_INQUIRE_PORTANDBAUD_BAUD ) != serial->baudRate->divisor )322 (buff.inquire.portAndBaud & SERIAL_INQUIRE_PORTANDBAUD_BAUDMASK) != serial->baudRate->divisor ) 289 323 { 290 struct baudRate *br; 291 292 br = baudRateMatchDivisor( buff.inquire.portAndBaud & SERIAL_INQUIRE_PORTANDBAUD_BAUD ); 293 294 if( br ) 295 log( 1, " Ignoring Inquire with Baud Rate=%d", br->rate ); 296 else 297 log( 1, " Ignoring Inquire with Unknown Baud Rate (portAndBaud=%d)", buff.inquire.portAndBaud ); 324 log( 1, " Ignoring Inquire with wrong baud rate" ); 298 325 workCount = 0; 299 326 continue; … … 316 343 log( 0, "Serial Port Write Error" ); 317 344 345 if( verboseLevel >= 3 ) 346 logBuff( " Sending: ", 514, 514, verboseLevel ); 347 318 348 workCount--; 319 349 workOffset++; 350 351 if( workCount ) 352 readto = 1; // looking for continuation ACK 320 353 } 321 354 } 322 355 323 if( verboseLevel > 0 ) 324 { 325 char *comStr = (workCommand & SERIAL_COMMAND_WRITE ? "Write" : 326 (workCommand & SERIAL_COMMAND_READWRITE ? "Read" : "Inquire")); 327 328 if( vtype == 1 ) 329 log( 1, "%s %d: LBA=%u, Count=%u", comStr, img == image0 ? 0 : 1, 330 mylba, workCount ); 331 else if( vtype == 2 ) 332 log( 1, "%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( 2, " Continuation: Offset=%u, Checksum=%04x", workOffset-1, buff.w[256] ); 339 340 if( !(workCommand & SERIAL_COMMAND_WRITE) && verboseLevel >= 3 ) 341 logBuff( " Sending: ", 514, 514, verboseLevel ); 342 343 if( workCount == 0 && workOffset > 100 ) 344 log( 1, " Block Complete: %.2lf bytes per second", (512.0 * workOffset) / (GetTime() - perfTimer) * 1000.0 ); 345 } 356 if( workCount == 0 && workOffset > 100 ) 357 log( 1, " Performance: %.2lf bytes per second", (512.0 * workOffset) / (GetTime() - perfTimer) * 1000.0 ); 346 358 } 347 359 } -
trunk/Serial_Server/library/Serial.cpp
r210 r215 12 12 struct baudRate supportedBaudRates[] = 13 13 { 14 { 2400, 0x0, "2400" , NULL },15 { 4800, 0xff, "4800" , NULL },16 { 9600, 0x1, "9600" , NULL },17 { 19200, 0xff, "19.2K" , "19K" },18 { 38400, 0x2, "38.4K" , "38K" },19 { 76800, 0x2, "76.8K", "77K" },20 { 115200, 0x3, "115.2K" , "115K" },21 { 153600, 0x3, "153.6K", "154K" },22 { 230400, 0xff, "230.4K" , "230K" },23 { 460800, 0x1, "460.8K", "460K" },24 { 0, 0, NULL , NULL }14 { 2400, 0x0, "2400" }, 15 { 4800, 0xff, "4800" }, 16 { 9600, 0x1, "9600" }, 17 { 19200, 0xff, "19.2K" }, 18 { 38400, 0x2, "38.4K" }, 19 { 76800, 0xff, "76.8K" }, 20 { 115200, 0x3, "115.2K" }, 21 { 153600, 0xff, "153.6K" }, 22 { 230400, 0xff, "230.4K" }, 23 { 460800, 0xff, "460.8K" }, 24 { 0, 0, NULL } 25 25 }; 26 26 … … 33 33 { 34 34 for( b = supportedBaudRates; b->rate; b++ ) 35 if( b->rate == a )35 if( b->rate == a || (b->rate / 1000) == a || ((b->rate + 500) / 1000) == a ) 36 36 return( b ); 37 37 } 38 39 for( b = supportedBaudRates; b->rate; b++ )40 if( !stricmp( str, b->display ) || (b->altSelection && !stricmp( str, b->altSelection )) )41 return( b );42 38 43 39 return( NULL );
Note:
See TracChangeset
for help on using the changeset viewer.