simulator: Rework dummy simulator code to user timer_irq / serial_irq
Change the simulator to use the generic timer_irq.c and serial_irq.c code for (dummy) timer and io handling. This is just to make the code a better example for other developers (most micro-controllers will use the timer_irq.c and serial_irq.c code). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
43
src/simulator/serial.c
Normal file
43
src/simulator/serial.c
Normal file
@@ -0,0 +1,43 @@
|
||||
// Example code for interacting with serial_irq.c
|
||||
//
|
||||
// Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
|
||||
//
|
||||
// This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
|
||||
#include <fcntl.h> // fcntl
|
||||
#include <unistd.h> // STDIN_FILENO
|
||||
#include "board/serial_irq.h" // serial_get_tx_byte
|
||||
#include "sched.h" // DECL_INIT
|
||||
|
||||
void
|
||||
serial_init(void)
|
||||
{
|
||||
// Make stdin/stdout non-blocking
|
||||
fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL, 0) | O_NONBLOCK);
|
||||
fcntl(STDOUT_FILENO, F_SETFL, fcntl(STDOUT_FILENO, F_GETFL, 0) | O_NONBLOCK);
|
||||
}
|
||||
DECL_INIT(serial_init);
|
||||
|
||||
static void
|
||||
do_uart(void)
|
||||
{
|
||||
for (;;) {
|
||||
uint8_t data;
|
||||
int ret = serial_get_tx_byte(&data);
|
||||
if (ret)
|
||||
break;
|
||||
else
|
||||
write(STDOUT_FILENO, &data, sizeof(data));
|
||||
|
||||
// XXX - Normally the code would check if input data is
|
||||
// available and call serial_rx_byte()
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
serial_enable_tx_irq(void)
|
||||
{
|
||||
// Normally this would enable the hardware irq, but we just call
|
||||
// do_uart() directly in this demo code.
|
||||
do_uart();
|
||||
}
|
||||
Reference in New Issue
Block a user