151 MAP_SysCtlPeripheralEnable(HW::TIMER_PERIPH);
152 MAP_SysCtlPeripheralEnable(HW::NRZPIN_PERIPH);
153 MAP_GPIOPinConfigure(HW::NRZPIN_CONFIG);
154 MAP_GPIOPinTypeTimer(HW::NRZPIN_BASE, HW::NRZPIN_PIN);
162 MAP_TimerClockSourceSet(HW::TIMER_BASE, TIMER_CLOCK_SYSTEM);
163 MAP_TimerConfigure(HW::TIMER_BASE, HW::CFG_CAP_TIME_UP);
164 MAP_TimerControlStall(HW::TIMER_BASE, HW::TIMER,
true);
165 MAP_TimerControlEvent(HW::TIMER_BASE, HW::TIMER, TIMER_EVENT_BOTH_EDGES);
166 MAP_TimerLoadSet(HW::TIMER_BASE, HW::TIMER, HW::TIMER_MAX_VALUE);
167 MAP_TimerPrescaleSet(HW::TIMER_BASE, HW::TIMER, HW::PS_MAX);
172 MAP_TimerIntEnable(HW::TIMER_BASE, HW::TIMER_CAP_EVENT);
173 MAP_TimerIntEnable(HW::TIMER_BASE, HW::TIMER_TIM_TIMEOUT);
175 MAP_IntPrioritySet(HW::TIMER_INTERRUPT, 0);
176 MAP_IntPrioritySet(HW::OS_INTERRUPT, configKERNEL_INTERRUPT_PRIORITY);
177 MAP_IntEnable(HW::OS_INTERRUPT);
178 MAP_IntEnable(HW::TIMER_INTERRUPT);
180 MAP_TimerEnable(HW::TIMER_BASE, HW::TIMER);
185 MAP_IntDisable(HW::TIMER_INTERRUPT);
186 MAP_IntDisable(HW::OS_INTERRUPT);
187 MAP_TimerDisable(HW::TIMER_BASE, HW::TIMER);
191__attribute__((optimize(
"-O3"))) void
TivaNRZ<HW>::interrupt_handler()
194 auto status = MAP_TimerIntStatus(HW::TIMER_BASE,
true);
195 if (status & HW::TIMER_TIM_TIMEOUT)
199 MAP_TimerIntClear(HW::TIMER_BASE, HW::TIMER_TIM_TIMEOUT);
204 if (status & HW::TIMER_CAP_EVENT)
206 MAP_TimerIntClear(HW::TIMER_BASE, HW::TIMER_CAP_EVENT);
207 MAP_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_0, 0);
208 static uint32_t raw_new_value;
209 raw_new_value = MAP_TimerValueGet(HW::TIMER_BASE, HW::TIMER);
210 static uint32_t new_value;
211 new_value = raw_new_value;
212 while (reloadCount_ > 0)
214 new_value += HW::TIMER_MAX_VALUE;
218 new_value -= lastTimerValue_;
219 if (!inputData_.full())
221 inputData_.back() = overflowed_ ? 3 : new_value;
223 inputData_.increment_back();
227 lastTimerValue_ = raw_new_value;
228 MAP_IntPendSet(HW::OS_INTERRUPT);
233__attribute__((optimize(
"-O3"))) void
TivaNRZ<HW>::os_interrupt_handler()
235 if (!inputData_.empty())
238 readableNotifiable_ =
nullptr;
240 n->notify_from_isr();
241 os_isr_exit_yield_test(
true);
256 if (inputData_.empty())
258 portENTER_CRITICAL();
259 if (inputData_.empty())
267 std::swap(n, readableNotifiable_);
296 portENTER_CRITICAL();
297 if (inputData_.empty()) {
301 uint32_t v =
reinterpret_cast<uint32_t
>(buf);
303 uint32_t* pv =
static_cast<uint32_t*
>(buf);
304 *pv = inputData_.front();
305 inputData_.increment_front();
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.
An object that can schedule itself on an executor to run.
virtual void notify()=0
Generic callback.
Protocol-independent driver for decoding NRZ codes using a TI Tiva class microcontroller.
FixedQueue< uint32_t, HW::Q_SIZE > inputData_
Data to send measurements back to the application level.
bool overflowed_
Flags when we lost data due to buffer overrun.
void disable()
function to disable device
ssize_t read(File *file, void *buf, size_t count) OVERRIDE
Read from a file or device.
unsigned lastLevel_
unused.
void os_interrupt_handler()
Handles a software interrupt to FreeRTOS.
void interrupt_handler()
Handles a raw interrupt.
void flush_buffers()
Discards all pending buffers.
uint32_t lastTimerValue_
Free running timer's last value.
ssize_t write(File *file, const void *buf, size_t count) OVERRIDE
Write to a file or device.
int ioctl(File *file, unsigned long int key, unsigned long data) OVERRIDE
Request an ioctl transaction.
Notifiable * readableNotifiable_
Notifiable for asynchronous support.
TivaNRZ(const char *name)
Constructor.
void enable()
function to enable device
uint32_t reloadCount_
How many times the free running timer overflowed.
#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.
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.