add timeout for TPUART reset (#23)

* bugfix, print not allowed in constructor

* add timeout for chip reset
This commit is contained in:
Bernator 2019-07-23 20:39:41 +02:00 committed by thelsing
parent 0a8c231627
commit d6278192a0
2 changed files with 17 additions and 7 deletions

View File

@ -82,6 +82,7 @@
#define BYTE_TIMEOUT 3 //milli seconds
#define CONFIRM_TIMEOUT 500 //milli seconds
#define RESET_TIMEOUT 100 //milli seconds
void TpUartDataLinkLayer::loop()
{
@ -369,15 +370,18 @@ bool TpUartDataLinkLayer::sendFrame(CemiFrame& frame)
return true;
}
void TpUartDataLinkLayer::resetChip()
bool TpUartDataLinkLayer::resetChip()
{
uint8_t cmd = U_RESET_REQ;
_platform.writeUart(cmd);
_waitConfirmStartTime = _platform.millis();
while (true)
{
int resp = _platform.readUart();
if (resp == U_RESET_IND)
break;
return true;
else if (_platform.millis() - _waitConfirmStartTime > RESET_TIMEOUT)
return false;
}
}
@ -421,10 +425,16 @@ void TpUartDataLinkLayer::enabled(bool value)
if (value && !_enabled)
{
_platform.setupUart();
if (resetChip()){
_enabled = true;
print("ownaddr ");
println(_deviceObject.induvidualAddress(), HEX);
resetChip();
_enabled = true;
}
else{
_enabled = false;
println("ERROR, TPUART not responding");
}
return;
}

View File

@ -56,6 +56,6 @@ class TpUartDataLinkLayer : public DataLinkLayer
bool sendFrame(CemiFrame& frame);
void frameBytesReceived(uint8_t* buffer, uint16_t length);
void dataConBytesReceived(uint8_t* buffer, uint16_t length, bool success);
void resetChip();
bool resetChip();
void stopChip();
};