36#ifndef _FREERTOS_DRIVERS_TI_TIVATESTPACKETSOURCE_HXX_
37#define _FREERTOS_DRIVERS_TI_TIVATESTPACKETSOURCE_HXX_
41#include <sys/select.h>
42#include "hardware.hxx"
43#include "driverlib/timer.h"
44#include "driverlib/interrupt.h"
45#include "inc/hw_ints.h"
68 static constexpr unsigned BANDWIDTH = 30000 * 29 / 7;
83 MAP_SysCtlPeripheralEnable(HW::TIMER_PERIPH);
84 MAP_TimerDisable(HW::TIMER_BASE, TIMER_A);
91 MAP_TimerIntClear(HW::TIMER_BASE, TIMER_TIMA_TIMEOUT);
93 if (HW::ENABLE_Pin::get() == HW::ENABLE_PIN_TRUE &&
110 MAP_SysCtlPeripheralEnable(HW::TIMER_PERIPH);
111 MAP_TimerDisable(HW::TIMER_BASE, TIMER_A);
113 MAP_TimerClockSourceSet(HW::TIMER_BASE, TIMER_CLOCK_SYSTEM);
114 MAP_TimerConfigure(HW::TIMER_BASE, TIMER_CFG_PERIODIC);
116 MAP_TimerLoadSet(HW::TIMER_BASE, TIMER_A, HW::TIMER_PERIOD);
118 MAP_IntDisable(HW::TIMER_INTERRUPT);
120 HW::TIMER_INTERRUPT, configKERNEL_INTERRUPT_PRIORITY);
121 MAP_TimerIntEnable(HW::TIMER_BASE, TIMER_TIMA_TIMEOUT);
122 MAP_TimerEnable(HW::TIMER_BASE, TIMER_A);
123 MAP_IntEnable(HW::TIMER_INTERRUPT);
129 MAP_TimerDisable(HW::TIMER_BASE, TIMER_A);
138 ssize_t
write(
File *,
const void *,
size_t len)
override
145 ssize_t
read(
File *file,
void *vtgt,
size_t len)
override
147 char *tgt = (
char *)vtgt;
153 if (file->
flags & O_NONBLOCK)
164 ::select(fd + 1, &fds, NULL, NULL, NULL);
166 portENTER_CRITICAL();
172 while (rd < len && bufferedBytes_ > 0)
204 portENTER_CRITICAL();
static int fd_lookup(File *file)
Looks up a file descriptor corresponding to a given File reference.
const char * name
device name
A dummy device driver that spews out a lot of GC packets when a button is held.
unsigned offset_
Which is the next byte from the INPUT_PACKET to send back.
unsigned cnt_
Index of the next packet.
TivaTestPacketSource(const char *name)
Constructor.
SelectInfo readSelect_
Helper structure for select() support.
void flush_buffers() override
Unused.
ssize_t read(File *file, void *vtgt, size_t len) override
Performs generating the fake data and/or blocking the caller as needed.
void enable() override
Turns on the device.
char packet_[40]
Text-rendered form of the next packet.
void timer_isr()
Call this function from extern "C" void timer3a_interrupt_handler()
void reset_packet()
Helper function to clear the input packet buffer and fill in with the next packet in line.
bool select(File *file, int mode) override
Implementation of device-specific select() functionality.
unsigned bufferedBytes_
How many bytes we have accumulated to send back.
uint32_t absoluteOffset_
How many bytes in total have been read from this driver since boot.
void disable() override
Turns off the device.
ssize_t write(File *, const void *, size_t len) override
Unused.
unsigned absolute_offset()
unsigned inputPacketLen_
Length of packet_;.
#define FWRITE
Workaround for missing header defines on some newlib versions.
#define FREAD
Workaround for missing header defines on some newlib versions.
Select wakeup information.
static void select_wakeup_from_isr(SelectInfo *info, int *woken)
Wakeup the list of clients needing woken.
static void select_insert(SelectInfo *info)
Add client to list of clients needing woken.
static void select_wakeup(SelectInfo *info)
Wakeup the list of clients needing woken.
Example hardware specification for the TivaTestPacketSource device driver.
static constexpr unsigned BANDWIDTH
Bytes/sec to generate in total as input.
static constexpr auto TIMER_PERIPH
Peripheral to enable the clock output to.
SW1_Pin ENABLE_Pin
GPIO pin structure that turns on the input feed.
static constexpr auto TIMER_BASE
Which timer resource to use.
static constexpr auto ENABLE_PIN_TRUE
Defines whether the enabe pin is active-high or active-low.
static constexpr unsigned TIMER_PERIOD
Number of clock cycles to wait between generating two packets.
static constexpr auto TIMER_INTERRUPT
Interrupt number of the timer resource.
static constexpr unsigned MAX_BUFFER_VALUE
How may bytes maximum can be accumulated as pending if the reader is not consuming data fast enough.
static constexpr unsigned PACKET_SIZE
How many bytes to generate in one go.