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()
|
||||
{
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -53,7 +62,7 @@ void i2cDecoder::updateBitValues(){
|
|||
int coord_bit = serialPtr_bit - (8*coord_byte);
|
||||
unsigned char dataByteSda = sda->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;
|
||||
currentSclValue = dataByteScl & mask;
|
||||
}
|
||||
|
@ -75,14 +84,15 @@ void i2cDecoder::runStateMachine()
|
|||
// if (sclEdge == edge::rising || sclEdge == edge::falling)
|
||||
// qDebug() << "sclEdge";
|
||||
|
||||
// qDebug() << "sdaEdge" << (uint8_t)sdaEdge << "sclEdge" << (uint8_t)sclEdge;
|
||||
// if (sclEdge != edge::held_low)
|
||||
// qDebug() << "sdaEdge" << (uint8_t)sdaEdge << "sclEdge" << (uint8_t)sclEdge;
|
||||
|
||||
if ((sdaEdge == edge::rising) && (sclEdge == edge::falling)) // INVALID STATE TRANSITION
|
||||
{
|
||||
state = transmissionState::unknown;
|
||||
qDebug() << "Dumping I2C state and aborting...";
|
||||
for (int i=32; i>=0; i--)
|
||||
qDebug("%x\t%x", sda->buffer[serialPtr_bit/8 - i] & 0xFF, scl->buffer[serialPtr_bit/8 - i] & 0xFF);
|
||||
for (int i=31; i>=0; i--)
|
||||
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");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -163,7 +163,7 @@ short *isoBuffer::readBuffer(double sampleWindow, int numSamples, bool singleBit
|
|||
front = bufferEnd;
|
||||
idx = (int) round(((double) front - accumulatedDelay));
|
||||
}
|
||||
readData[i] = buffer[idx] & (1<<subIdx);
|
||||
readData[i] = buffer[idx] & (1 << subIdx);
|
||||
|
||||
accumulatedDelay += timeBetweenSamples;
|
||||
}
|
||||
|
@ -197,11 +197,6 @@ void isoBuffer::clearBuffer()
|
|||
}
|
||||
|
||||
back = 0;
|
||||
//serialPtr = 0;
|
||||
//serialDecodingSymbol = false;
|
||||
//symbolCurrent = 0;
|
||||
//symbol = 0;
|
||||
|
||||
firstTime = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -78,9 +78,18 @@ void isoDriver::timerTick(void){
|
|||
bool invalidateTwoWireState = true;
|
||||
switch(driver->deviceMode){
|
||||
case 0:
|
||||
if (deviceMode_prev != 0 && deviceMode_prev != 1 && deviceMode_prev != 2)
|
||||
clearBuffers(true, false, false);
|
||||
|
||||
frameActionGeneric(1,0);
|
||||
break;
|
||||
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;
|
||||
frameActionGeneric(1,2);
|
||||
if(serialDecodeEnabled_CH1 && serialType == 0){
|
||||
|
@ -88,15 +97,28 @@ void isoDriver::timerTick(void){
|
|||
}
|
||||
break;
|
||||
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);
|
||||
break;
|
||||
case 3:
|
||||
if (deviceMode_prev != 3 && deviceMode_prev != 4)
|
||||
clearBuffers(true, false, false);
|
||||
|
||||
frameActionGeneric(2,0);
|
||||
if(serialDecodeEnabled_CH1 && serialType == 0){
|
||||
internalBuffer375_CH1->serialManage(baudRate_CH1, 0);
|
||||
}
|
||||
break;
|
||||
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;
|
||||
frameActionGeneric(2,2);
|
||||
if(serialDecodeEnabled_CH1 && serialType == 0){
|
||||
|
@ -117,9 +139,13 @@ void isoDriver::timerTick(void){
|
|||
case 5:
|
||||
break;
|
||||
case 6:
|
||||
if (deviceMode_prev != 7)
|
||||
clearBuffers(false, true, true);
|
||||
frameActionGeneric(-1,0);
|
||||
break;
|
||||
case 7:
|
||||
if (deviceMode_prev != 7)
|
||||
clearBuffers(false, true, false);
|
||||
multimeterAction();
|
||||
break;
|
||||
default:
|
||||
|
@ -127,6 +153,8 @@ void isoDriver::timerTick(void){
|
|||
}
|
||||
if (invalidateTwoWireState)
|
||||
twoWireStateInvalid = true;
|
||||
|
||||
deviceMode_prev = driver->deviceMode;
|
||||
//free(isoTemp);
|
||||
}
|
||||
|
||||
|
|
|
@ -125,6 +125,7 @@ private:
|
|||
unsigned int length;
|
||||
QFile *snapshotFile_CH1;
|
||||
QFile *snapshotFile_CH2;
|
||||
uint8_t deviceMode_prev;
|
||||
//DAQ
|
||||
double daqLoad_startTime, daqLoad_endTime;
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ unsigned char uartStyleDecoder::getNextUartBit(){
|
|||
int coord_byte = serialPtr_bit/8;
|
||||
int coord_bit = serialPtr_bit - (8*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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue