|
Open Model Railroad Network (OpenMRN)
|
Helper module for decoding a DCC signal on an STM32 class microcontroller. More...
#include <Stm32DCCDecoder.hxx>
Public Types | |
| using | NRZ_Pin = typename HW::NRZ_Pin |
| Exports the input pin to the driver on the module interface. | |
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 | before_cutout_hook () |
| hook | |
| 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 given number of usec using the usec 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 = 0xffff |
| This is the counter from which the timer starts counting down. | |
| static constexpr uint32_t | SAMPLE_PERIOD_CLOCKS = HW::SAMPLE_PERIOD_TICKS |
| After how many timer counts we should take one sample for occupancy feedback. | |
| static constexpr unsigned | Q_SIZE = HW::Q_SIZE |
| Length of the device queue. | |
Private Member Functions | |
| Stm32DccTimerModule () | |
| Private constructor. This class cannot be instantiated. | |
| DISALLOW_COPY_AND_ASSIGN (Stm32DccTimerModule) | |
Static Private Member Functions | |
| static void | init_timer (TIM_HandleTypeDef *handle, TIM_TypeDef *instance) |
| Initializes a timer resource (shared for all channels). | |
| static uint32_t | get_raw_capture_counter () |
| Helper function to read the raw capture register value. | |
| static TIM_TypeDef * | capture_timer () |
| static TIM_HandleTypeDef * | capture_timer_handle () |
| static TIM_TypeDef * | usec_timer () |
| static TIM_HandleTypeDef * | usec_timer_handle () |
| static bool | shared_timers () |
Static Private Attributes | |
| static TIM_HandleTypeDef | captureTimerHandle_ |
| static TIM_HandleTypeDef | usecTimerHandle_ |
| static uint32_t | usecTimerStart_ |
| Holds the base value from where the usec timer should be counting down when the delay_usec call is invoked. | |
Helper module for decoding a DCC signal on an STM32 class microcontroller.
Usage: Define a structure HW declaring certain constants around your timer usage.
Example hardware definitions:
Definition at line 115 of file Stm32DCCDecoder.hxx.
| using Stm32DccTimerModule< HW >::NRZ_Pin = typename HW::NRZ_Pin |
Exports the input pin to the driver on the module interface.
Definition at line 119 of file Stm32DCCDecoder.hxx.
|
inlinestatic |
hook
Definition at line 173 of file Stm32DCCDecoder.hxx.
|
inlinestatic |
hook
Definition at line 155 of file Stm32DCCDecoder.hxx.
|
inlinestaticprivate |
Definition at line 296 of file Stm32DCCDecoder.hxx.
|
inlinestaticprivate |
Definition at line 301 of file Stm32DCCDecoder.hxx.
|
inlinestatic |
hook
Definition at line 161 of file Stm32DCCDecoder.hxx.
|
inlinestatic |
hook
Definition at line 167 of file Stm32DCCDecoder.hxx.
|
inlinestatic |
Called from the interrupt handler if int_get_and_clear_capture_event said yes.
Definition at line 463 of file Stm32DCCDecoder.hxx.
|
inlinestaticprivate |
Helper function to read the raw capture register value.
Definition at line 469 of file Stm32DCCDecoder.hxx.
|
inlinestatic |
Definition at line 133 of file Stm32DCCDecoder.hxx.
|
inlinestaticprivate |
Initializes a timer resource (shared for all channels).
| handle | pointer to the HAL timer handle. |
| instance | pointer to the timer registers, such as TIM3. |
Definition at line 275 of file Stm32DCCDecoder.hxx.
|
inlinestatic |
Called from the capture interrupt handler.
Checks interrupt status, clears interrupt.
Definition at line 451 of file Stm32DCCDecoder.hxx.
|
inlinestatic |
Called from the timeout interrupt handler.
Checks interrupt status, clears timer expired interrupt.
Definition at line 496 of file Stm32DCCDecoder.hxx.
|
static |
Called inline with Device::disable().
Definition at line 428 of file Stm32DCCDecoder.hxx.
|
static |
Called inline with Device::enable().
Definition at line 348 of file Stm32DCCDecoder.hxx.
|
static |
Called once during construction time.
Definition at line 340 of file Stm32DCCDecoder.hxx.
|
inlinestatic |
Sets the timer to capture mode.
Needed for the digitization of DCC signal bits.
Definition at line 235 of file Stm32DCCDecoder.hxx.
|
inlinestatic |
Delays a given number of usec using the usec timer feature.
Needed for the timing of the railcom cutout. An rcom_interrupt shall be raised after this many usec.
| usec | how much to delay, with the measurement started from the set_cap_timer_time() call (or the previous edge captured before that by the capture timer). |
Definition at line 219 of file Stm32DCCDecoder.hxx.
|
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().
@TODO __HAL_TIM_DISABLE_IT(capture_timer_handle(), HW::CAPTURE_IF);
Definition at line 245 of file Stm32DCCDecoder.hxx.
|
inlinestaticprivate |
Definition at line 324 of file Stm32DCCDecoder.hxx.
|
inlinestatic |
Called once inline in an interrupt.
Signals that the delay timer is not needed anymore.
Definition at line 258 of file Stm32DCCDecoder.hxx.
|
inlinestatic |
How many usec later should the railcom cutout middle happen.
Definition at line 191 of file Stm32DCCDecoder.hxx.
|
inlinestatic |
How many usec later should the railcom cutout middle happen.
Definition at line 185 of file Stm32DCCDecoder.hxx.
|
inlinestatic |
How many usec later should the railcom cutout start happen.
Definition at line 179 of file Stm32DCCDecoder.hxx.
|
inlinestatic |
Calls a software interrupt.
Definition at line 149 of file Stm32DCCDecoder.hxx.
|
inlinestaticprivate |
Definition at line 307 of file Stm32DCCDecoder.hxx.
|
inlinestaticprivate |
Definition at line 313 of file Stm32DCCDecoder.hxx.
|
staticprivate |
Definition at line 265 of file Stm32DCCDecoder.hxx.
|
staticconstexpr |
Length of the device queue.
Definition at line 130 of file Stm32DCCDecoder.hxx.
|
staticconstexpr |
After how many timer counts we should take one sample for occupancy feedback.
Definition at line 128 of file Stm32DCCDecoder.hxx.
|
staticconstexpr |
This is the counter from which the timer starts counting down.
When the timer overflows, it starts from this value.
Definition at line 125 of file Stm32DCCDecoder.hxx.
|
staticprivate |
Definition at line 266 of file Stm32DCCDecoder.hxx.
|
staticprivate |
Holds the base value from where the usec timer should be counting down when the delay_usec call is invoked.
This is set from the last capture edge when the mode is switched to the usec timer.
Definition at line 270 of file Stm32DCCDecoder.hxx.