Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
TivaDccTimerModule< HW > Class Template Reference

Device driver for decoding a DCC signal on a TI Tiva class microcontroller. More...

#include <TivaDCCDecoder.hxx>

Public Types

using NRZ_Pin = typename HW::NRZ_Pin
 Exports the input pin to the driver on the module interface.
 

Public Member Functions

 DISALLOW_COPY_AND_ASSIGN (TivaDccTimerModule)
 

Static Public Member Functions

static uint32_t get_ticks_per_usec ()
 
static void module_init ()
 Called once during construction time.
 
static void module_enable ()
 Called inline with Device::enable().
 
static void module_disable ()
 Called inline with Device::disable().
 
static void trigger_os_interrupt ()
 Calls a software interrupt.
 
static void dcc_before_cutout_hook ()
 hook
 
static void dcc_packet_finished_hook ()
 hook
 
static void after_feedback_hook ()
 hook
 
static int time_delta_railcom_pre_usec ()
 How many usec later should the railcom cutout start happen.
 
static int time_delta_railcom_mid_usec ()
 How many usec later should the railcom cutout middle happen.
 
static int time_delta_railcom_end_usec ()
 How many usec later should the railcom cutout middle happen.
 
static bool int_get_and_clear_capture_event ()
 Called from the capture interrupt handler.
 
static uint32_t get_capture_counter ()
 Called from the interrupt handler if int_get_and_clear_capture_event said yes.
 
static bool int_get_and_clear_delay_event ()
 Called from the timeout interrupt handler.
 
static void set_cap_timer_delay_usec (int usec)
 Delays a give number of usec using the capture timer feature.
 
static void set_cap_timer_capture ()
 Sets the timer to capture mode.
 
static void set_cap_timer_time ()
 Sets the timer to oneshot (timer) mode.
 
static void stop_cap_timer_time ()
 Called once inline in an interrupt.
 

Static Public Attributes

static constexpr uint32_t TIMER_MAX_VALUE = HW::TIMER_MAX_VALUE
 This is the counter from which the timer starts counting down.
 
static constexpr uint32_t SAMPLE_PERIOD_CLOCKS = HW::SAMPLE_PERIOD_CLOCKS
 After how many timer counts we should take one sample.
 
static constexpr unsigned Q_SIZE = HW::Q_SIZE
 Length of the device queue.
 

Detailed Description

template<class HW>
class TivaDccTimerModule< HW >

Device driver for decoding a DCC signal on a TI Tiva class microcontroller.

This driver exports a filesystem device node, but that file node is not usable for reading or writing anything at the moment. The only feature supported by this device driver right now is that it is able to tell a RailcomDriver when the railcom cutout is supposed to start, when we're in the middle and when it is over. This is necessary for the correct functionality of the railcom driver.

Todo:
: implement actual packet decoding and sending back to the application layer.

Usage: Define a structure declaring your hardware information. See below for what you need to define in there. Instantiate the device driver and pass the pointer to the railcom driver to the constructor. There is no need to touch the device from the application layer.

Example hardware definitions:

struct DCCDecode { static const auto TIMER_BASE = WTIMER4_BASE; static const auto TIMER_PERIPH = SYSCTL_PERIPH_WTIMER4; static const auto TIMER_INTERRUPT = INT_WTIMER4A; static const auto TIMER = TIMER_A; static const auto CFG_CAP_TIME_UP = TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME_UP | TIMER_CFG_B_ONE_SHOT; Interrupt bits. static const auto TIMER_CAP_EVENT = TIMER_CAPA_EVENT; static const auto TIMER_TIM_TIMEOUT = TIMER_TIMA_TIMEOUT;

static const auto OS_INTERRUPT = INT_WTIMER4B; DECL_PIN(NRZPIN, D, 4); static const auto NRZPIN_CONFIG = GPIO_PD4_WT4CCP0;

static const uint32_t TIMER_MAX_VALUE = 0x8000000UL;

static const int Q_SIZE = 16;

};

Definition at line 84 of file TivaDCCDecoder.hxx.

Member Typedef Documentation

◆ NRZ_Pin

template<class HW >
using TivaDccTimerModule< HW >::NRZ_Pin = typename HW::NRZ_Pin

Exports the input pin to the driver on the module interface.

Definition at line 88 of file TivaDCCDecoder.hxx.

Member Function Documentation

◆ after_feedback_hook()

template<class HW >
static void TivaDccTimerModule< HW >::after_feedback_hook ( )
inlinestatic

hook

Definition at line 134 of file TivaDCCDecoder.hxx.

◆ dcc_before_cutout_hook()

template<class HW >
static void TivaDccTimerModule< HW >::dcc_before_cutout_hook ( )
inlinestatic

hook

Definition at line 122 of file TivaDCCDecoder.hxx.

◆ dcc_packet_finished_hook()

template<class HW >
static void TivaDccTimerModule< HW >::dcc_packet_finished_hook ( )
inlinestatic

hook

Definition at line 128 of file TivaDCCDecoder.hxx.

◆ get_capture_counter()

template<class HW >
uint32_t TivaDccTimerModule< HW >::get_capture_counter ( )
inlinestatic

Called from the interrupt handler if int_get_and_clear_capture_event said yes.

Returns
the value of the downcounting capture at the time when the edge was captured.

Definition at line 283 of file TivaDCCDecoder.hxx.

◆ get_ticks_per_usec()

template<class HW >
static uint32_t TivaDccTimerModule< HW >::get_ticks_per_usec ( )
inlinestatic
Returns
Timer clocks per usec.

Definition at line 101 of file TivaDCCDecoder.hxx.

◆ int_get_and_clear_capture_event()

template<class HW >
bool TivaDccTimerModule< HW >::int_get_and_clear_capture_event ( )
inlinestatic

Called from the capture interrupt handler.

Checks interrupt status, clears interrupt.

Returns
true if the interrupt was generated by a capture event.

Definition at line 269 of file TivaDCCDecoder.hxx.

◆ int_get_and_clear_delay_event()

template<class HW >
bool TivaDccTimerModule< HW >::int_get_and_clear_delay_event ( )
inlinestatic

Called from the timeout interrupt handler.

Checks interrupt status, clears timer expired interrupt.

Returns
true if the interrupt was generated by the timer_delay_usec expiring event.

Definition at line 288 of file TivaDCCDecoder.hxx.

◆ module_disable()

template<class HW >
void TivaDccTimerModule< HW >::module_disable ( )
static

Called inline with Device::disable().

Definition at line 259 of file TivaDCCDecoder.hxx.

◆ module_enable()

template<class HW >
void TivaDccTimerModule< HW >::module_enable ( )
static

Called inline with Device::enable().

Definition at line 242 of file TivaDCCDecoder.hxx.

◆ module_init()

template<class HW >
void TivaDccTimerModule< HW >::module_init ( )
static

Called once during construction time.

Definition at line 235 of file TivaDCCDecoder.hxx.

◆ set_cap_timer_capture()

template<class HW >
static void TivaDccTimerModule< HW >::set_cap_timer_capture ( )
inlinestatic

Sets the timer to capture mode.

Needed for the digitization of DCC signal bits.

Definition at line 187 of file TivaDCCDecoder.hxx.

◆ set_cap_timer_delay_usec()

template<class HW >
static void TivaDccTimerModule< HW >::set_cap_timer_delay_usec ( int  usec)
inlinestatic

Delays a give number of usec using the capture timer feature.

Needed for the timing of the railcom cutout.

Parameters
usechow much to delay.

Definition at line 177 of file TivaDCCDecoder.hxx.

◆ set_cap_timer_time()

template<class HW >
static void TivaDccTimerModule< HW >::set_cap_timer_time ( )
inlinestatic

Sets the timer to oneshot (timer) mode.

Called once, then set_cap_timer_delay_usec() will be called multiple times, expecting each to deliver an rcom_interrupt().

Definition at line 209 of file TivaDCCDecoder.hxx.

◆ stop_cap_timer_time()

template<class HW >
static void TivaDccTimerModule< HW >::stop_cap_timer_time ( )
inlinestatic

Called once inline in an interrupt.

Signals that the delay timer is not needed anymore.

Definition at line 227 of file TivaDCCDecoder.hxx.

◆ time_delta_railcom_end_usec()

template<class HW >
static int TivaDccTimerModule< HW >::time_delta_railcom_end_usec ( )
inlinestatic

How many usec later should the railcom cutout middle happen.

Definition at line 152 of file TivaDCCDecoder.hxx.

◆ time_delta_railcom_mid_usec()

template<class HW >
static int TivaDccTimerModule< HW >::time_delta_railcom_mid_usec ( )
inlinestatic

How many usec later should the railcom cutout middle happen.

Definition at line 146 of file TivaDCCDecoder.hxx.

◆ time_delta_railcom_pre_usec()

template<class HW >
static int TivaDccTimerModule< HW >::time_delta_railcom_pre_usec ( )
inlinestatic

How many usec later should the railcom cutout start happen.

Definition at line 140 of file TivaDCCDecoder.hxx.

◆ trigger_os_interrupt()

template<class HW >
static void TivaDccTimerModule< HW >::trigger_os_interrupt ( )
inlinestatic

Calls a software interrupt.

Definition at line 116 of file TivaDCCDecoder.hxx.

Member Data Documentation

◆ Q_SIZE

template<class HW >
constexpr unsigned TivaDccTimerModule< HW >::Q_SIZE = HW::Q_SIZE
staticconstexpr

Length of the device queue.

Definition at line 98 of file TivaDCCDecoder.hxx.

◆ SAMPLE_PERIOD_CLOCKS

template<class HW >
constexpr uint32_t TivaDccTimerModule< HW >::SAMPLE_PERIOD_CLOCKS = HW::SAMPLE_PERIOD_CLOCKS
staticconstexpr

After how many timer counts we should take one sample.

Definition at line 96 of file TivaDCCDecoder.hxx.

◆ TIMER_MAX_VALUE

template<class HW >
constexpr uint32_t TivaDccTimerModule< HW >::TIMER_MAX_VALUE = HW::TIMER_MAX_VALUE
staticconstexpr

This is the counter from which the timer starts counting down.

When the timer overflows, it starts from this value.

Definition at line 94 of file TivaDCCDecoder.hxx.


The documentation for this class was generated from the following file: