fix reset chip

This commit is contained in:
thewhobox 2023-05-28 12:06:55 +02:00
parent 4cdf6d4ffe
commit 338aa1b825
2 changed files with 31 additions and 12 deletions

View File

@ -123,11 +123,16 @@ void TpUartDataLinkLayer::loop()
{
if (!_enabled)
{
if (millis() - _lastResetChipTime > 1000)
{
//reset chip every 1 seconds
_lastResetChipTime = millis();
_enabled = resetChip();
if(_waitConfirmStartTime == 0)
{
if (millis() - _lastResetChipTime > 1000)
{
//reset chip every 1 seconds
_lastResetChipTime = millis();
_enabled = resetChip();
}
} else {
_enabled = resetChipTick();
}
}
@ -485,17 +490,30 @@ bool TpUartDataLinkLayer::sendFrame(CemiFrame& frame)
bool TpUartDataLinkLayer::resetChip()
{
if(_waitConfirmStartTime > 0) return false;
uint8_t cmd = U_RESET_REQ;
_platform.writeUart(cmd);
int resp = _platform.readUart();
if (resp == U_RESET_IND)
return true;
_waitConfirmStartTime = millis();
while (true)
return false;
}
bool TpUartDataLinkLayer::resetChipTick()
{
int resp = _platform.readUart();
if (resp == U_RESET_IND)
{
int resp = _platform.readUart();
if (resp == U_RESET_IND)
return true;
else if (millis() - _waitConfirmStartTime > RESET_TIMEOUT)
return false;
_waitConfirmStartTime = 0;
return true;
}
else if (millis() - _waitConfirmStartTime > RESET_TIMEOUT)
_waitConfirmStartTime = 0;
return false;
}
void TpUartDataLinkLayer::stopChip()

View File

@ -45,7 +45,7 @@ class TpUartDataLinkLayer : public DataLinkLayer
uint32_t _lastByteRxTime;
uint32_t _lastByteTxTime;
uint32_t _lastLoopTime;
uint32_t _waitConfirmStartTime;
uint32_t _waitConfirmStartTime = 0;
uint32_t _lastResetChipTime = 0;
struct _tx_queue_frame_t
@ -70,6 +70,7 @@ class TpUartDataLinkLayer : public DataLinkLayer
void dataConBytesReceived(uint8_t* buffer, uint16_t length, bool success);
void enterRxWaitEOP();
bool resetChip();
bool resetChipTick();
void stopChip();
ITpUartCallBacks& _cb;