00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "LOW_linkPassiveSerial.h"
00020
00021
00022
00023
00024
00025
00026
00027
00028 LOW_linkPassiveSerial::LOW_linkPassiveSerial( const LOW_portSerialFactory::portSpecifier_t &inSerPortSpec,
00029 const bool inAllowProgPulse) :
00030 LOW_link( false, false, inAllowProgPulse)
00031 {
00032 serialPort = LOW_portSerialFactory::new_portSerial( inSerPortSpec);
00033
00034 resetLinkAdapter();
00035 resetBus();
00036 }
00037
00038
00039
00040 LOW_linkPassiveSerial::~LOW_linkPassiveSerial()
00041 {
00042 serialPort->tty_flush();
00043
00044 delete serialPort;
00045 }
00046
00047
00048
00049
00050
00051
00052
00053
00054 bool LOW_linkPassiveSerial::touchBit( const bool inSendBit, const strongPullup_t inPullup)
00055 {
00056 commLock lock( *this);
00057
00058 uint8_t serSendByte;
00059 bool retVal;
00060
00061 serialPort->tty_flush();
00062
00063
00064 serSendByte = inSendBit ? 0xFF : 0x00;
00065
00066
00067 serialPort->tty_write( serSendByte);
00068
00069 uint8_t tmpByte = serialPort->tty_readByte();
00070 if ( tmpByte & 0x01 )
00071 retVal = true;
00072 else
00073 retVal = false;
00074
00075 strongPullup( inPullup);
00076
00077 return retVal;
00078 }
00079
00080
00081 uint8_t LOW_linkPassiveSerial::touchByte( const uint8_t inSendByte, const strongPullup_t inPullup)
00082 {
00083 commLock lock( *this);
00084
00085 uint8_t mask = 0x01;
00086 uint8_t retVal = 0x00;
00087
00088 for( int a=0; a<8; a++) {
00089 retVal |= touchBit( inSendByte & mask) ? mask : 0x00;
00090 mask <<= 1;
00091 }
00092
00093 strongPullup( inPullup);
00094
00095 return retVal;
00096 }
00097
00098
00099
00100
00101
00102
00103
00104 void LOW_linkPassiveSerial::resetLinkAdapter()
00105 {
00106 commLock lock( *this);
00107
00108 serialPort->tty_configure( LOW_portSerial::none_flowControl, LOW_portSerial::bit6_size,
00109 LOW_portSerial::no_parity, LOW_portSerial::bit1_stopBit, LOW_portSerial::B115200_speed);
00110
00111 serialPort->tty_flush();
00112 }
00113
00114
00115 bool LOW_linkPassiveSerial::resetBus()
00116 {
00117 commLock lock( *this);
00118
00119 const uint8_t resetSendByte = 0xF0;
00120
00121 bool devFound = false;
00122
00123 try {
00124
00125
00126 serialPort->tty_flush();
00127
00128 serialPort->tty_configure( LOW_portSerial::none_flowControl, LOW_portSerial::bit8_size,
00129 LOW_portSerial::no_parity, LOW_portSerial::bit1_stopBit, LOW_portSerial::B10472_speed);
00130
00131
00132 serialPort->tty_write( resetSendByte);
00133
00134 uint8_t tmpByte = serialPort->tty_readByte();
00135
00136 if( tmpByte == 0 )
00137 throw comm_error( "Possible short to ground detected", __FILE__, __LINE__);
00138
00139
00140
00141 if( tmpByte != resetSendByte )
00142 devFound = true;
00143 else
00144 devFound = false;
00145 }
00146 catch( ... ) {
00147
00148 try {
00149 serialPort->tty_configure( LOW_portSerial::none_flowControl, LOW_portSerial::bit6_size,
00150 LOW_portSerial::no_parity, LOW_portSerial::bit1_stopBit, LOW_portSerial::B115200_speed);
00151 }
00152 catch( ... ) {}
00153
00154 throw;
00155 }
00156
00157 serialPort->tty_configure( LOW_portSerial::none_flowControl, LOW_portSerial::bit6_size,
00158 LOW_portSerial::no_parity, LOW_portSerial::bit1_stopBit, LOW_portSerial::B115200_speed);
00159
00160 return devFound;
00161 }
00162
00163
00164 void LOW_linkPassiveSerial::strongPullup( const unsigned long )
00165 {
00166 commLock lock( *this);
00167
00168 LOW_platformMisc::secSleep( strongPullupEmuTime);
00169 }
00170
00171
00172 void LOW_linkPassiveSerial::strongPullup( const strongPullup_t )
00173 {
00174 commLock lock( *this);
00175
00176 LOW_platformMisc::secSleep( strongPullupEmuTime);
00177 }
00178
00179
00180 void LOW_linkPassiveSerial::programPulse( const unsigned long )
00181 {
00182 commLock lock( *this);
00183
00184 if ( ! allowProgPulse )
00185 throw notAllowed_error( "Program pulse not allowed", __FILE__, __LINE__);
00186
00187 if ( ! hasProgramPulse )
00188 throw illegalLevel_error( "Program pulse not available", __FILE__, __LINE__);
00189
00190 throw internal_error( "Program pulse not available, should never be reached", __FILE__, __LINE__);
00191 }
00192
00193
00194 void LOW_linkPassiveSerial::programPulse( const progPulse_t )
00195 {
00196 commLock lock( *this);
00197
00198 if ( ! allowProgPulse )
00199 throw notAllowed_error( "Program pulse not allowed", __FILE__, __LINE__);
00200
00201 if ( ! hasProgramPulse )
00202 throw illegalLevel_error( "Program pulse not available", __FILE__, __LINE__);
00203
00204 throw internal_error( "Program pulse not available, should never be reached", __FILE__, __LINE__);
00205 }