Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
traxanos committed Mar 14, 2024
1 parent b6d295c commit b4913c8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/arduino_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ int ArduinoPlatform::uartAvailable()

size_t ArduinoPlatform::writeUart(const uint8_t data)
{
//printHex("<p", &data, 1);
// printHex("<p", &data, 1);
return _knxSerial->write(data);
}

Expand Down
46 changes: 26 additions & 20 deletions src/knx/tpuart_data_link_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,13 @@ void TpUartDataLinkLayer::processRxByte()
else if ((byte & U_STATE_MASK) == U_STATE_IND)
{
_tpState |= (byte ^ U_STATE_MASK);
// #ifndef NCN5120
// /*
// * Filtere "Protocol errors" weil auf anderen BCU wie der Siements dies gesetzt, when das timing nicht stimmt.
// * Leider ist kein perfektes Timing möglich so dass dieser Fehler ignoriert wird. Hat auch keine bekannte Auswirkungen.
// */
// _tpState &= 0b11101000;
// #endif
#ifndef NCN5120
/*
* Filtere "Protocol errors" weil auf anderen BCU wie der Siements dies gesetzt, when das timing nicht stimmt.
* Leider ist kein perfektes Timing möglich so dass dieser Fehler ignoriert wird. Hat auch keine bekannte Auswirkungen.
*/
_tpState &= 0b11101000;
#endif
}
else if ((byte & U_CONFIGURE_MASK) == U_CONFIGURE_IND)
{
Expand Down Expand Up @@ -565,13 +565,14 @@ void TpUartDataLinkLayer::setFrameRepetition(uint8_t nack, uint8_t busy)

bool TpUartDataLinkLayer::sendFrame(CemiFrame &cemiFrame)
{
if (!_connected)
{
dataConReceived(cemiFrame, false);
return false;
}
// if (!_connected)
// {
// dataConReceived(cemiFrame, false);
// return false;
// }

TpFrame *tpFrame = new TpFrame(cemiFrame);
// printHex(" TP>: ", tpFrame->data(), tpFrame->size());
pushTxFrameQueue(tpFrame);
return true;
}
Expand Down Expand Up @@ -674,7 +675,7 @@ void TpUartDataLinkLayer::connected(bool state /* = true */)

bool TpUartDataLinkLayer::reset()
{
// println("Reset TP");
println("Reset TP");
if (!_initialized)
{
_platform.setupUart();
Expand All @@ -689,8 +690,10 @@ bool TpUartDataLinkLayer::reset()
_rxInvalidFrameCounter = 0;
_rxInvalidFrameCounter = 0;
_rxUnkownControlCounter = 0;
_txFrame->reset();
_rxFrame->reset();
if (_txFrame != nullptr)
_txFrame->reset();
if (_rxFrame != nullptr)
_rxFrame->reset();
_rxState = RX_IDLE;
_txState = TX_IDLE;
_connected = false;
Expand Down Expand Up @@ -830,7 +833,8 @@ void TpUartDataLinkLayer::checkConnected()
{
if (_connected)
{
const uint32_t timeout = _monitoring ? 10000 : 3000;
// 5000 instead 3000 because siemens tpuart
const uint32_t timeout = _monitoring ? 10000 : 5000;

if ((millis() - _rxLastTime) > timeout)
connected(false);
Expand Down Expand Up @@ -874,9 +878,8 @@ void TpUartDataLinkLayer::loop()
* Dennoch gibt es Situationen, wo ein Frame nicht geschlossen wurde, weil Bytes verloren geangen sind oder wie beim Busmonitor
* bewusst auf ein Ack gewartet werden muss.
*/
// if (!_platform.uartAvailable() && _rxFrame->size() > 0 && (millis() - _rxLastTime) >= 3)
// if (!_platform.uartAvailable() && _rxFrame->size() > 0 && (millis() - _rxLastTime) > 2)
// {
// println((millis() - _rxLastTime));
// processRxFrameComplete();
// }
}
Expand Down Expand Up @@ -931,11 +934,14 @@ bool TpUartDataLinkLayer::processTxFrameBytes()
*/
for (uint16_t i = 0; i < _txFrame->size(); i++)
{
const uint8_t offset = (i >> 6);
const uint8_t position = (i & 0x3F);
uint8_t offset = (i >> 6);
uint8_t position = (i & 0x3F);

if (offset)
{
// position++;
_platform.writeUart(U_L_DATA_OFFSET_REQ | offset);
}

if (i == (_txFrame->size() - 1)) // Letztes Bytes (Checksumme)
_platform.writeUart(U_L_DATA_END_REQ | position);
Expand Down
4 changes: 2 additions & 2 deletions src/rp2040_arduino_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ void __time_critical_func(uartDmaRestart)()
{
// println("Restart");
uartDmaRestartCount = uartDmaWritePosition() - readBufferCount();
__compiler_memory_barrier;
asm volatile("" ::: "memory");
dma_hw->ints0 = 1u << uartDmaChannel; // clear DMA IRQ0 flag
__compiler_memory_barrier;
asm volatile("" ::: "memory");
dma_channel_set_write_addr(uartDmaChannel, uartDmaBuffer, true);
}
#endif
Expand Down

0 comments on commit b4913c8

Please sign in to comment.