57#ifndef _FREERTOS_DRIVERS_COMMON_RAILCOMIMPL_HXX_
58#define _FREERTOS_DRIVERS_COMMON_RAILCOMIMPL_HXX_
104 static uint8_t sample() {
106 if (!CH1_Pin::get()) ret |= 1;
107 if (!CH2_Pin::get()) ret |= 2;
108 if (!CH3_Pin::get()) ret |= 4;
109 if (!CH4_Pin::get()) ret |= 8;
114// The weak attribute is needed if the definition is put into a header file.
115const uint32_t RailcomHw::UART_BASE[] __attribute__((weak)) = {UART4_BASE, UART3_BASE, UART2_BASE, UART7_BASE};
116const uint32_t RailcomHw::UART_PERIPH[]
117__attribute__((weak)) = {SYSCTL_PERIPH_UART4, SYSCTL_PERIPH_UART3, SYSCTL_PERIPH_UART2, SYSCTL_PERIPH_UART7};
174 int ioctl(
File *file,
unsigned long int key,
unsigned long data)
override
185 portENTER_CRITICAL();
219 n->notify_from_isr();
220 os_isr_exit_yield_test(
true);
254 if (sample < 0)
return;
256 extern uint32_t feedback_sample_overflow_count;
257 ++feedback_sample_overflow_count;
263 uint32_t tick_timer = HW::get_timer_tick();
const char * name
device name
This structure is safe to use from an interrupt context and a regular context at the same time,...
void increment_front()
Removes the head of the FIFO from the queue.
bool has_noncommit_space()
void increment_back()
Commits the element at back() into the queue.
T & front()
Returns the head of the FIFO (next element to read).
T & back()
Returns the space to write the next element to.
void noncommit_back()
Increments the back pointer without committing the entry into the queue.
OSMutex lock_
protects internal structures.
An object that can schedule itself on an executor to run.
virtual void notify()=0
Generic callback.
Class to allow convenient locking and unlocking of mutexes in a C context.
Base class for railcom drivers.
Notifiable * readableNotifiable_
Notify this when we have data in our buffers.
void os_interrupt_handler()
Implementation of the interrupt handler running at the kernel interrupt priority.
RailcomDriverBase(const char *name)
Constructor.
dcc::Feedback * returnedPackets_[HW::CHANNEL_COUNT]
Stores pointers to packets we are filling right now, one for each channel.
uint32_t feedbackKey_
Stores the key for the next packets to read.
ssize_t read(File *file, void *buf, size_t count) OVERRIDE
Read from a file or device.
void flush_buffers() OVERRIDE
Instructs the device driver to drop all TX and RX queues.
dcc::Feedback * alloc_new_packet(uint8_t channel)
Takes a new empty packet at the front of the queue, fills in feedback key and channel information.
void set_feedback_key(uint32_t key) OVERRIDE
Specifies the feedback key to write into the received railcom data packets.
int ioctl(File *file, unsigned long int key, unsigned long data) override
Request an ioctl transaction.
virtual void int_set_pending(unsigned int_nr)=0
Sets a given software interrupt pending.
void add_sample(int sample)
Adds a sample for a preamble bit.
FixedQueue< dcc::Feedback, HW::Q_SIZE > feedbackQueue_
The packets we have read so far.
ssize_t write(File *, const void *, size_t) OVERRIDE
Write to a file or device.
Abstract base class for railcom drivers.
#define CAN_IOC_READ_ACTIVE
read active ioctl.
#define NOTIFIABLE_TYPE
ioctl minor type used for the read/write active notifiable integration.
#define CAN_IOC_MAGIC
Magic number for this driver's ioctl calls.
#define IOC_SIZE(_num)
Decode ioctl size.
#define IOC_TYPE(_num)
Decode ioctl type.
#define OVERRIDE
Function attribute for virtual functions declaring that this funciton is overriding a funciton that s...
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
uint8_t channel
Used by multi-channel railcom receiver drivers.
uint8_t ch2Data[6]
Payload of channel 2.
Structure used for reading (railcom) feedback data from DCC / Railcom device drivers.
void reset(uint32_t feedback_key)
Clears the structure and sets the feedback key to a specific value.
void add_ch1_data(uint8_t data)
Appends a byte to the channel 1 payload.