98 static constexpr unsigned Q_SIZE = HW::Q_SIZE;
103 return configCPU_CLOCK_HZ / 1000000;
118 MAP_IntPendSet(HW::OS_INTERRUPT);
124 HW::dcc_before_cutout_hook();
130 HW::dcc_packet_finished_hook();
136 HW::after_feedback_hook();
142 return HW::time_delta_railcom_pre_usec();
148 return HW::time_delta_railcom_mid_usec();
154 return HW::time_delta_railcom_end_usec();
179 Debug::DccPacketDelay::toggle();
180 uint32_t new_match_v = usec * 80;
181 MAP_TimerMatchSet(HW::TIMER_BASE, HW::RCOM_TIMER, 0xfffe - new_match_v);
182 MAP_TimerPrescaleMatchSet(HW::TIMER_BASE, HW::RCOM_TIMER, 0);
189 MAP_TimerDisable(HW::TIMER_BASE, HW::TIMER);
191 HW::TIMER_BASE, HW::TIMER_CAP_EVENT);
193 HW::TIMER_BASE, HW::TIMER_CAP_EVENT);
196 HW::TIMER_BASE, HW::CFG_TIM_CAPTURE | HW::CFG_RCOM_TIMER);
197 MAP_TimerControlEvent(
198 HW::TIMER_BASE, HW::TIMER, TIMER_EVENT_BOTH_EDGES);
199 MAP_TimerLoadSet(HW::TIMER_BASE, HW::TIMER, HW::TIMER_MAX_VALUE);
200 MAP_TimerPrescaleSet(HW::TIMER_BASE, HW::TIMER, HW::PS_MAX);
202 MAP_TimerIntEnable(HW::TIMER_BASE, HW::TIMER_CAP_EVENT);
203 MAP_TimerEnable(HW::TIMER_BASE, HW::TIMER);
211 MAP_TimerDisable(HW::TIMER_BASE, HW::RCOM_TIMER);
214 HW::TIMER_BASE, HW::TIMER_RCOM_MATCH);
216 HW::TIMER_BASE, HW::TIMER_RCOM_MATCH);
218 MAP_TimerLoadSet(HW::TIMER_BASE, HW::RCOM_TIMER, 0xfffe);
219 MAP_TimerPrescaleSet(HW::TIMER_BASE, HW::RCOM_TIMER, 0);
221 MAP_TimerIntEnable(HW::TIMER_BASE, HW::TIMER_RCOM_MATCH);
222 MAP_TimerEnable(HW::TIMER_BASE, HW::RCOM_TIMER);
229 MAP_TimerDisable(HW::TIMER_BASE, HW::RCOM_TIMER);
237 MAP_SysCtlPeripheralEnable(HW::TIMER_PERIPH);
238 MAP_GPIOPadConfigSet(HW::NRZ_Pin::GPIO_BASE, HW::NRZ_Pin::GPIO_PIN,
239 GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
244 MAP_TimerClockSourceSet(HW::TIMER_BASE, TIMER_CLOCK_SYSTEM);
245 MAP_TimerControlStall(HW::TIMER_BASE, HW::TIMER,
true);
247 set_cap_timer_capture();
249 MAP_TimerIntEnable(HW::TIMER_BASE, HW::TIMER_CAP_EVENT);
251 MAP_IntPrioritySet(HW::TIMER_INTERRUPT, 0x20);
252 MAP_IntPrioritySet(HW::RCOM_INTERRUPT, 0x20);
253 MAP_IntPrioritySet(HW::OS_INTERRUPT, configKERNEL_INTERRUPT_PRIORITY);
254 MAP_IntEnable(HW::OS_INTERRUPT);
255 MAP_IntEnable(HW::TIMER_INTERRUPT);
256 MAP_IntEnable(HW::RCOM_INTERRUPT);
261 MAP_IntDisable(HW::TIMER_INTERRUPT);
262 MAP_IntDisable(HW::RCOM_INTERRUPT);
263 MAP_IntDisable(HW::OS_INTERRUPT);
264 MAP_TimerDisable(HW::TIMER_BASE, HW::TIMER);
265 MAP_TimerDisable(HW::TIMER_BASE, HW::RCOM_TIMER);
272 auto status = MAP_TimerIntStatus(HW::TIMER_BASE,
true);
273 if (status & HW::TIMER_CAP_EVENT)
276 HW::cap_event_hook();
277 MAP_TimerIntClear(HW::TIMER_BASE, HW::TIMER_CAP_EVENT);
285 return MAP_TimerValueGet(HW::TIMER_BASE, HW::TIMER);
290 Debug::DccDecodeInterrupts::set(
true);
291 auto status = MAP_TimerIntStatus(HW::TIMER_BASE,
true);
292 if (status & HW::TIMER_RCOM_MATCH)
294 MAP_TimerIntClear(HW::TIMER_BASE, HW::TIMER_RCOM_MATCH);
Device driver for decoding a DCC signal using a Timer resource.
Device driver for decoding a DCC signal on a TI Tiva class microcontroller.
static void set_cap_timer_delay_usec(int usec)
Delays a give number of usec using the capture timer feature.
static void dcc_before_cutout_hook()
hook
static constexpr uint32_t SAMPLE_PERIOD_CLOCKS
After how many timer counts we should take one sample.
static void set_cap_timer_time()
Sets the timer to oneshot (timer) mode.
static uint32_t get_capture_counter()
Called from the interrupt handler if int_get_and_clear_capture_event said yes.
static void trigger_os_interrupt()
Calls a software interrupt.
typename HW::NRZ_Pin NRZ_Pin
Exports the input pin to the driver on the module interface.
static void set_cap_timer_capture()
Sets the timer to capture mode.
static void dcc_packet_finished_hook()
hook
static bool int_get_and_clear_delay_event()
Called from the timeout interrupt handler.
static void module_enable()
Called inline with Device::enable().
static bool int_get_and_clear_capture_event()
Called from the capture interrupt handler.
static constexpr uint32_t TIMER_MAX_VALUE
This is the counter from which the timer starts counting down.
static int time_delta_railcom_mid_usec()
How many usec later should the railcom cutout middle happen.
static void module_disable()
Called inline with Device::disable().
static uint32_t get_ticks_per_usec()
static void stop_cap_timer_time()
Called once inline in an interrupt.
static int time_delta_railcom_end_usec()
How many usec later should the railcom cutout middle happen.
static int time_delta_railcom_pre_usec()
How many usec later should the railcom cutout start happen.
static void module_init()
Called once during construction time.
static void after_feedback_hook()
hook
static constexpr unsigned Q_SIZE
Length of the device queue.
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.
GPIO Pin definition structure with no actual pin behind it.