-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds driver and hooks for sending railcom data out. (#551)
This PR enables the dcc_decoder code to interact with a RailCom driver in a way that allows sending railcom data back to the track. - Adds the ability to adjust what timing the railcom driver gets called. This is expectedto change when we generate a cutout versus when we trigger the UART to send data. - adds calls to the RailcomDriver to specify the feedback to be sent - Ensures that railcom data only gets sent for the packet that it belongs to - Adds an STM32 implementation for the railcom send driver, which is derived from the Stm32Uart driver. - Adds a hook in the dcc_decode interrupt that calls an application provided module to compute what railcom feedback we should be sending. ==== * Adds a delta capability for tuning the railcom cutout timing. * Fixes up the compilation of the Tiva DCC decoder target. * Adds API for railcom sender implementation. * Adds railcom sender implementation for STM32. * Adds a call in the DCC interrupt to fill in the railcom feedback. * Adds the send functions to the railcom driver. * Fixes bugs in the stm32 railcom sender. * Removes unneeded forward declaration.
- Loading branch information
1 parent
0c9e3a9
commit 05e5d61
Showing
11 changed files
with
398 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** \copyright | ||
* Copyright (c) 2021, Balazs Racz | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* - Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* - Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* \file PacketProcessor.hxx | ||
* | ||
* Interface used for processing DCC packets to generate the feedback data. | ||
* | ||
* @author Balazs Racz | ||
* @date 10 July 2021 | ||
*/ | ||
|
||
#include "dcc/packet.h" | ||
|
||
class RailcomDriver; | ||
|
||
namespace dcc | ||
{ | ||
|
||
/// Abstract class that is used as a plugin in the DCC decoder. The application | ||
/// logic can implement this class and it will be called from the | ||
/// interrupt. This is necessary to correctly generate the RailCom feedback to | ||
/// be sent back. | ||
class PacketProcessor | ||
{ | ||
public: | ||
/// Called in an OS interrupt with the arrived packet. | ||
virtual void packet_arrived( | ||
const DCCPacket *pkt, RailcomDriver *railcom) = 0; | ||
}; | ||
|
||
} // namespace dcc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** \copyright | ||
* Copyright (c) 2021, Balazs Racz | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* - Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* - Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* \file Stm32RailcomSender.hxx | ||
* | ||
* Implements a RailcomDriver that sends outgoing railcom data through a UART | ||
* TX on an STM32 target. Designed to be invoked from the priority zero | ||
* interrupt of the DCC decoder. | ||
* | ||
* @author Balazs Racz | ||
* @date July 10, 2021 | ||
*/ | ||
|
||
#include "freertos_drivers/st/Stm32RailcomSender.hxx" | ||
|
||
#include "stm32f_hal_conf.hxx" | ||
|
||
/// Called at the beginning of the first window. | ||
void Stm32RailcomSender::start_cutout() | ||
{ | ||
const auto* pkt = ch1Pkt_; | ||
if (!pkt || pkt->feedbackKey != expectedFeedbackKey_) | ||
{ | ||
// Nothing to send or came too late and should not be sent. | ||
return; | ||
} | ||
if (!__HAL_UART_GET_IT(&uartHandle, UART_IT_TXE)) { | ||
// Transmission is not complete yet. That's weird. | ||
return; | ||
} | ||
if (pkt->ch1Size == 0) { | ||
// Nothing to send. | ||
return; | ||
} | ||
uartHandle.Instance->TDR = pkt->ch1Data[0]; | ||
if (pkt->ch1Size > 1) | ||
{ | ||
txBuf->put(pkt->ch1Data + 1, 1); | ||
__HAL_UART_ENABLE_IT(&uartHandle, UART_IT_TXE); | ||
} | ||
} | ||
|
||
void Stm32RailcomSender::middle_cutout() | ||
{ | ||
const auto* pkt = ch2Pkt_; | ||
if (!pkt || pkt->feedbackKey != expectedFeedbackKey_) | ||
{ | ||
// Nothing to send or came too late and should not be sent. | ||
return; | ||
} | ||
if (!__HAL_UART_GET_IT(&uartHandle, UART_IT_TXE)) { | ||
// Transmission is not complete yet. That's weird. | ||
return; | ||
} | ||
if (pkt->ch2Size == 0) { | ||
// Nothing to send. | ||
return; | ||
} | ||
uartHandle.Instance->TDR = pkt->ch2Data[0]; | ||
if (pkt->ch2Size > 1) | ||
{ | ||
txBuf->put(pkt->ch2Data + 1, pkt->ch2Size - 1); | ||
__HAL_UART_ENABLE_IT(&uartHandle, UART_IT_TXE); | ||
} | ||
} |
Oops, something went wrong.