mirror of https://github.com/EspoTek/Labrador.git
Timings approximately correct for i2c
This commit is contained in:
parent
e5bfb2e748
commit
124bcd3a61
|
@ -15,7 +15,16 @@ i2cDecoder::i2cDecoder(isoBuffer* sda_in, isoBuffer* scl_in, uint32_t clockRate)
|
||||||
void i2cDecoder::reset()
|
void i2cDecoder::reset()
|
||||||
{
|
{
|
||||||
qDebug () << "Resetting I2C";
|
qDebug () << "Resetting I2C";
|
||||||
|
|
||||||
|
if (sda->back != scl->back)
|
||||||
|
{
|
||||||
|
// Perhaps the data could be saved, but just resetting them seems much safer
|
||||||
|
sda->clearBuffer();
|
||||||
|
scl->clearBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
serialPtr_bit = sda->back * 8;
|
serialPtr_bit = sda->back * 8;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,7 +62,7 @@ void i2cDecoder::updateBitValues(){
|
||||||
int coord_bit = serialPtr_bit - (8*coord_byte);
|
int coord_bit = serialPtr_bit - (8*coord_byte);
|
||||||
unsigned char dataByteSda = sda->buffer[coord_byte];
|
unsigned char dataByteSda = sda->buffer[coord_byte];
|
||||||
unsigned char dataByteScl = scl->buffer[coord_byte];
|
unsigned char dataByteScl = scl->buffer[coord_byte];
|
||||||
unsigned char mask = (1 << coord_bit);
|
unsigned char mask = (0x01 << coord_bit);
|
||||||
currentSdaValue = dataByteSda & mask;
|
currentSdaValue = dataByteSda & mask;
|
||||||
currentSclValue = dataByteScl & mask;
|
currentSclValue = dataByteScl & mask;
|
||||||
}
|
}
|
||||||
|
@ -75,14 +84,15 @@ void i2cDecoder::runStateMachine()
|
||||||
// if (sclEdge == edge::rising || sclEdge == edge::falling)
|
// if (sclEdge == edge::rising || sclEdge == edge::falling)
|
||||||
// qDebug() << "sclEdge";
|
// qDebug() << "sclEdge";
|
||||||
|
|
||||||
|
// if (sclEdge != edge::held_low)
|
||||||
// qDebug() << "sdaEdge" << (uint8_t)sdaEdge << "sclEdge" << (uint8_t)sclEdge;
|
// qDebug() << "sdaEdge" << (uint8_t)sdaEdge << "sclEdge" << (uint8_t)sclEdge;
|
||||||
|
|
||||||
if ((sdaEdge == edge::rising) && (sclEdge == edge::falling)) // INVALID STATE TRANSITION
|
if ((sdaEdge == edge::rising) && (sclEdge == edge::falling)) // INVALID STATE TRANSITION
|
||||||
{
|
{
|
||||||
state = transmissionState::unknown;
|
state = transmissionState::unknown;
|
||||||
qDebug() << "Dumping I2C state and aborting...";
|
qDebug() << "Dumping I2C state and aborting...";
|
||||||
for (int i=32; i>=0; i--)
|
for (int i=31; i>=0; i--)
|
||||||
qDebug("%x\t%x", sda->buffer[serialPtr_bit/8 - i] & 0xFF, scl->buffer[serialPtr_bit/8 - i] & 0xFF);
|
qDebug("%02x\t%02x", sda->buffer[serialPtr_bit/8 - i] & 0xFF, scl->buffer[serialPtr_bit/8 - i] & 0xFF);
|
||||||
throw std::runtime_error("unknown i2c transmission state");
|
throw std::runtime_error("unknown i2c transmission state");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -197,11 +197,6 @@ void isoBuffer::clearBuffer()
|
||||||
}
|
}
|
||||||
|
|
||||||
back = 0;
|
back = 0;
|
||||||
//serialPtr = 0;
|
|
||||||
//serialDecodingSymbol = false;
|
|
||||||
//symbolCurrent = 0;
|
|
||||||
//symbol = 0;
|
|
||||||
|
|
||||||
firstTime = true;
|
firstTime = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,9 +78,18 @@ void isoDriver::timerTick(void){
|
||||||
bool invalidateTwoWireState = true;
|
bool invalidateTwoWireState = true;
|
||||||
switch(driver->deviceMode){
|
switch(driver->deviceMode){
|
||||||
case 0:
|
case 0:
|
||||||
|
if (deviceMode_prev != 0 && deviceMode_prev != 1 && deviceMode_prev != 2)
|
||||||
|
clearBuffers(true, false, false);
|
||||||
|
|
||||||
frameActionGeneric(1,0);
|
frameActionGeneric(1,0);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
if (deviceMode_prev != 0 && deviceMode_prev != 1 && deviceMode_prev != 2)
|
||||||
|
clearBuffers(true, false, false);
|
||||||
|
|
||||||
|
if (deviceMode_prev != 1)
|
||||||
|
clearBuffers(false, true, false);
|
||||||
|
|
||||||
internalBuffer375_CH2->channel = 1;
|
internalBuffer375_CH2->channel = 1;
|
||||||
frameActionGeneric(1,2);
|
frameActionGeneric(1,2);
|
||||||
if(serialDecodeEnabled_CH1 && serialType == 0){
|
if(serialDecodeEnabled_CH1 && serialType == 0){
|
||||||
|
@ -88,15 +97,28 @@ void isoDriver::timerTick(void){
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
if (deviceMode_prev != 0 && deviceMode_prev != 1 && deviceMode_prev != 2)
|
||||||
|
clearBuffers(true, false, false);
|
||||||
|
if (deviceMode_prev != 2)
|
||||||
|
clearBuffers(false, true, false);
|
||||||
|
|
||||||
frameActionGeneric(1,1);
|
frameActionGeneric(1,1);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
|
if (deviceMode_prev != 3 && deviceMode_prev != 4)
|
||||||
|
clearBuffers(true, false, false);
|
||||||
|
|
||||||
frameActionGeneric(2,0);
|
frameActionGeneric(2,0);
|
||||||
if(serialDecodeEnabled_CH1 && serialType == 0){
|
if(serialDecodeEnabled_CH1 && serialType == 0){
|
||||||
internalBuffer375_CH1->serialManage(baudRate_CH1, 0);
|
internalBuffer375_CH1->serialManage(baudRate_CH1, 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
|
if (deviceMode_prev != 3 && deviceMode_prev != 4)
|
||||||
|
clearBuffers(true, false, false);
|
||||||
|
if (deviceMode_prev != 4)
|
||||||
|
clearBuffers(false, true, false);
|
||||||
|
|
||||||
internalBuffer375_CH2->channel = 2;
|
internalBuffer375_CH2->channel = 2;
|
||||||
frameActionGeneric(2,2);
|
frameActionGeneric(2,2);
|
||||||
if(serialDecodeEnabled_CH1 && serialType == 0){
|
if(serialDecodeEnabled_CH1 && serialType == 0){
|
||||||
|
@ -117,9 +139,13 @@ void isoDriver::timerTick(void){
|
||||||
case 5:
|
case 5:
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
|
if (deviceMode_prev != 7)
|
||||||
|
clearBuffers(false, true, true);
|
||||||
frameActionGeneric(-1,0);
|
frameActionGeneric(-1,0);
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
|
if (deviceMode_prev != 7)
|
||||||
|
clearBuffers(false, true, false);
|
||||||
multimeterAction();
|
multimeterAction();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -127,6 +153,8 @@ void isoDriver::timerTick(void){
|
||||||
}
|
}
|
||||||
if (invalidateTwoWireState)
|
if (invalidateTwoWireState)
|
||||||
twoWireStateInvalid = true;
|
twoWireStateInvalid = true;
|
||||||
|
|
||||||
|
deviceMode_prev = driver->deviceMode;
|
||||||
//free(isoTemp);
|
//free(isoTemp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -125,6 +125,7 @@ private:
|
||||||
unsigned int length;
|
unsigned int length;
|
||||||
QFile *snapshotFile_CH1;
|
QFile *snapshotFile_CH1;
|
||||||
QFile *snapshotFile_CH2;
|
QFile *snapshotFile_CH2;
|
||||||
|
uint8_t deviceMode_prev;
|
||||||
//DAQ
|
//DAQ
|
||||||
double daqLoad_startTime, daqLoad_endTime;
|
double daqLoad_startTime, daqLoad_endTime;
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ unsigned char uartStyleDecoder::getNextUartBit(){
|
||||||
int coord_byte = serialPtr_bit/8;
|
int coord_byte = serialPtr_bit/8;
|
||||||
int coord_bit = serialPtr_bit - (8*coord_byte);
|
int coord_bit = serialPtr_bit - (8*coord_byte);
|
||||||
unsigned char dataByte = parent->buffer[coord_byte];
|
unsigned char dataByte = parent->buffer[coord_byte];
|
||||||
unsigned char mask = (1 << coord_bit);
|
unsigned char mask = (0x01 << coord_bit);
|
||||||
return ((dataByte & mask) ? 1 : 0);
|
return ((dataByte & mask) ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue