- Timestamp:
- 01/30/12 00:33:16 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/sc8in1/csctapi/ifd_sc8in1.c
r6304 r6320 24 24 #include "icc_async.h" 25 25 26 #define SC8IN1_TIMEOUT_HACK 1 27 26 28 #define LOCK_SC8IN1 \ 27 29 { \ … … 67 69 // switch SC8in1 to command mode 68 70 IO_Serial_DTR_Set(reader); 69 tcflush(reader->handle, TCIOFLUSH);70 71 71 72 // backup data … … 94 95 } 95 96 Sc8in1_DebugSignals(reader, reader->slot, "CMD11"); 96 IO_Serial_DTR_Set(reader);97 tcflush(reader->handle, TCIOFLUSH);98 97 99 98 // enable EEPROM write … … 112 111 // write cmd 113 112 cs_ddump_mask(D_DEVICE, buff, lenwrite, "IO: Sending: "); 114 if (!write(reader->handle, buff, lenwrite)) { //dont use IO_Serial_Write since mcr commands dont echo back 115 cs_log("SC8in1 Command write error"); 116 return ERROR; 117 } 118 tcdrain(reader->handle); 113 uint32_t dataWritten = 0, dataToWrite = lenwrite; 114 while (dataWritten < lenwrite) { 115 uint32_t written = write(reader->handle, buff, dataToWrite); 116 if (written == -1) { 117 cs_log("SC8in1 Command write error"); 118 return ERROR; 119 } 120 if (written == lenwrite) { 121 break; 122 } 123 else { 124 dataWritten += written; 125 dataToWrite -= written; 126 } 127 } 128 while (1) { 129 int32_t tcdrain_ret = tcdrain(reader->handle); 130 if (tcdrain_ret==-1) { 131 if (errno==EINTR) { 132 //try again in case of Interrupted system call 133 continue; 134 } else 135 cs_log("ERROR in sc8in1_command - tcdrain: (errno=%d %s)", errno, strerror(errno)); 136 return ERROR; 137 } 138 break; 139 } 119 140 120 141 if (IO_Serial_Read(reader, 1000, lenread, buff) == ERROR) { … … 123 144 } 124 145 146 #ifdef SC8IN1_TIMEOUT_HACK 147 // On some system, at least my dockstar, tcdrain returns before the transmitted bytes actually 148 // reach the serial port. This here is an awful hack, to workaround the issue. 149 // We transmit the ECHO command to the device and wait until it sends back the echo char 'A' 150 // to us. This way we can be sure that the main command in buff has been received by the device. 151 // Another way to workaround this issue is to wait for an appropriate amount of time, but i think 152 // thats even worse. 153 if (lenread <= 0 && reader->sc8in1_config->mcr_type) { 154 unsigned char buff_echo_hack[2] = { 0x65, 'A' }; 155 cs_ddump_mask(D_DEVICE, &buff_echo_hack[0], 2, "IO: Sending: "); 156 if (write(reader->handle, &buff_echo_hack[0], 2) != 2) { 157 cs_log("SC8in1 Command write error"); 158 return ERROR; 159 } 160 tcdrain(reader->handle); // should be useless.. but what the hell 161 if (IO_Serial_Read(reader, 1000, 1, &buff_echo_hack[0]) == ERROR) { 162 cs_log("SC8in1 Command read error"); 163 return ERROR; 164 } 165 } 166 #endif 125 167 // restore baudrate only if changed 126 168 if (currentBaudrate) {
Note:
See TracChangeset
for help on using the changeset viewer.