Changeset 210 in xtideuniversalbios for trunk/Serial_Server
- Timestamp:
- Jan 16, 2012, 4:15:51 AM (13 years ago)
- google:author:
- gregli@hotmail.com
- Location:
- trunk/Serial_Server/library
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Serial_Server/library/Process.cpp
r209 r210 51 51 #define SERIAL_INQUIRE_PORTANDBAUD_PORT 0xfc 52 52 53 void 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 53 74 void processRequests( Serial *serial, Image *image0, Image *image1, int timeoutEnabled, int verboseLevel ) 54 75 { … … 56 77 int workOffset, workCount; 57 78 58 int vtype ;79 int vtype = 0; 59 80 60 81 unsigned long mylba; … … 68 89 Image *img; 69 90 unsigned long cyl, sect, head; 91 unsigned long perfTimer; 70 92 71 93 GetTime_Timeout_Local = GetTime_Timeout(); … … 81 103 buffoffset += len; 82 104 105 // 106 // For debugging, look at the incoming packet 107 // 83 108 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 ); 103 110 104 111 timeout = 0; … … 117 124 lasttick = GetTime(); 118 125 126 // 127 // No work currently to do, look at each character as they come in... 128 // 119 129 if( buffoffset == 1 && !readto ) 120 130 { … … 125 135 else if( (buff.b[0] & SERIAL_COMMAND_HEADERMASK) == SERIAL_COMMAND_HEADER ) 126 136 { 137 // 138 // Found our command header byte to start a commnad sequence, read the next 7 and evaluate 139 // 127 140 readto = 8; 141 continue; 128 142 } 129 143 else 130 144 { 145 // 146 // Spurious characters, discard 147 // 131 148 if( verboseLevel >= 2 ) 132 149 { 133 150 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] ); 135 152 else 136 log( 3, " [%d]", buff.b[0] );153 log( 3, "Spurious: [%d]", buff.b[0] ); 137 154 } 138 155 buffoffset = 0; … … 141 158 } 142 159 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 144 168 // 145 169 if( buffoffset == readto && readto == 514 ) … … 161 185 img->writeSector( &buff.w[0] ); 162 186 187 // 188 // Echo back the CRC 189 // 163 190 if( serial->writeCharacters( &buff.w[256], 2 ) != 2 ) 164 191 log( 1, "Serial Port Write Error" ); … … 168 195 } 169 196 197 // 170 198 // 8 byte command received, or a continuation of the previous command 171 199 // … … 176 204 if( workCount ) 177 205 { 206 // 207 // Continuation... 208 // 178 209 if( buff.b[0] != (workCount-0) ) 179 210 { … … 185 216 else 186 217 { 218 // 219 // New Command... 220 // 187 221 if( (crc = checksum( &buff.w[0], 3 )) != buff.w[3] ) 188 222 { … … 196 230 if( !image1 ) 197 231 { 198 log( 2, "slave drive selected when not supplied" ); 232 log( 2, "Slave drive selected when not supplied" ); 233 img = NULL; 199 234 continue; 200 235 } 201 img = NULL; 236 else 237 img = image1; 202 238 } 203 239 else … … 231 267 workOffset = 0; 232 268 workCount = buff.chs.count; 269 if( verboseLevel > 1 && workCount > 100 ) 270 perfTimer = GetTime(); 233 271 } 234 272 235 273 if( workCount && (workCommand == (SERIAL_COMMAND_WRITE | SERIAL_COMMAND_READWRITE)) ) 236 274 { 275 // 276 // Write command... Setup to receive a sector 277 // 237 278 readto = 514; 238 279 } 239 280 else 240 281 { 282 // 283 // Inquire command... 284 // 241 285 if( workCommand == SERIAL_COMMAND_INQUIRE ) 242 286 { 243 log( 2, "Inquire Disk Information, Drive=%d",244 (buff.inquire.driveAndHead & ATA_DriveAndHead_Drive) >> 4 );245 246 287 if( serial->speedEmulation && 247 288 (buff.inquire.portAndBaud & SERIAL_INQUIRE_PORTANDBAUD_BAUD) != serial->baudRate->divisor ) … … 261 302 img->respondInquire( &buff.w[0], serial->baudRate, buff.inquire.portAndBaud ); 262 303 } 304 // 305 // Read command... 306 // 263 307 else 264 308 { … … 270 314 271 315 if( serial->writeCharacters( &buff.w[0], 514 ) != 514 ) 272 {273 316 log( 1, "Serial Port Write Error" ); 274 }275 317 276 318 workCount--; 277 319 workOffset++; 278 320 } 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 ); 296 345 } 297 346 } 298 347 } 348 349 -
trunk/Serial_Server/library/Serial.cpp
r209 r210 17 17 { 19200, 0xff, "19.2K", "19K" }, 18 18 { 38400, 0x2, "38.4K", "38K" }, 19 { 76800, 0x2, "76.8K", "77K" }, 19 20 { 115200, 0x3, "115.2K", "115K" }, 21 { 153600, 0x3, "153.6K", "154K" }, 20 22 { 230400, 0xff, "230.4K", "230K" }, 21 23 { 460800, 0x1, "460.8K", "460K" },
Note:
See TracChangeset
for help on using the changeset viewer.