io: add I/O thread base

This commit is contained in:
Felix Kopp 2020-11-29 23:23:37 +01:00
parent dbda35d82a
commit e690a6824e
No known key found for this signature in database
GPG key ID: C478BA0A85F75728
5 changed files with 115 additions and 6 deletions

View file

@ -7,6 +7,11 @@
#include <ardix/ringbuf.h>
#include <toolchain.h>
#ifndef CONFIG_SERIAL_BAUD
/** serial baud rate */
#define CONFIG_SERIAL_BAUD 115200
#endif
#ifndef SERIAL_BUFSZ
/** size of a serial I/O buffer in bytes */
#define SERIAL_BUFSZ 256

View file

@ -25,6 +25,8 @@
ARDIX_KERNEL_PWD = $(PWD)/kernel
include $(ARDIX_KERNEL_PWD)/io/Makefile
ARDIX_SOURCES += \
$(ARDIX_KERNEL_PWD)/printk.c \
$(ARDIX_KERNEL_PWD)/ringbuf.c \

29
kernel/io/Makefile Normal file
View file

@ -0,0 +1,29 @@
#
# Copyright (c) 2020 Felix Kopp <sandtler@sandtler.club>
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
# 3. Neither the name of the copyright holder nor the names of its contributors may be
# used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
ARDIX_KERNEL_IO_PWD = $(ARDIX_KERNEL_PWD)/io
ARDIX_SOURCES += \
$(ARDIX_KERNEL_IO_PWD)/io.c

60
kernel/io/io.c Normal file
View file

@ -0,0 +1,60 @@
/* SPDX-License-Identifier: BSD-3-Clause */
/* See the end of this file for copyright, licensing, and warranty information. */
#include <arch/serial.h>
#include <ardix/io.h>
#include <ardix/sched.h>
#include <ardix/serial.h>
#include <toolchain.h>
__naked void io_thread_entry(void)
{
while (1) {
io_serial_buf_update(serial_default_interface);
sched_switch_early(PROC_QUEUE);
}
}
int io_init(void)
{
int ret;
struct process *proc;
ret = serial_init(serial_default_interface, CONFIG_SERIAL_BAUD);
if (ret)
return ret;
proc = sched_process_create(&io_thread_entry);
if (proc == NULL)
ret = -1;
return ret;
}
/*
* Copyright (c) 2020 Felix Kopp <sandtler@sandtler.club>
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

View file

@ -3,9 +3,10 @@
#include <ardix/ringbuf.h>
#include <ardix/serial.h>
#include <ardix/sched.h>
#include <arch/serial.h>
#include <arch/sched.h>
#include <arch/serial.h>
#include <stddef.h>
@ -58,13 +59,25 @@ ssize_t serial_read(void *dest, struct serial_interface *interface, size_t len)
ssize_t serial_write(struct serial_interface *interface, const void *data, size_t len)
{
ssize_t ret;
size_t ret = 0;
size_t tmp;
sched_atomic_enter();
ret = (ssize_t)ringbuf_write(interface->tx, data, len);
sched_atomic_leave();
while (1) {
sched_atomic_enter();
tmp = ringbuf_write(interface->tx, data, len);
sched_atomic_leave();
ret += tmp;
return ret;
if (ret != len) { /* buffer full, suspend until I/O is ready */
len -= tmp;
data += tmp;
sched_switch_early(PROC_IOWAIT);
} else {
break;
}
}
return (ssize_t)ret;
}
/*