summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2015-05-18 01:31:58 +0200
committerMichal Idziorek <m.i@gmx.at>2015-05-18 01:31:58 +0200
commitfe79552d9fcfd60d8c2bb828c6b93cf471ef7b75 (patch)
tree7bf842857ce4f485101848292405a96f322fe374
parentdb22b587966b4a4eaa47536f32ca812532446bcb (diff)
fifo interface
-rw-r--r--fs/file.h3
-rw-r--r--fs/ringbuffer.c12
-rw-r--r--kernel/config.h2
-rw-r--r--kernel/fifo.c16
-rw-r--r--kernel/fifo.h25
-rw-r--r--kernel/kernel.c8
-rw-r--r--kernel/kernel.h7
-rw-r--r--kernel/syscalls.c2
-rw-r--r--lib/logger/log.c5
-rw-r--r--terminal/vt52.c3
-rw-r--r--terminal/vt52.h3
11 files changed, 65 insertions, 21 deletions
diff --git a/fs/file.h b/fs/file.h
index 241301f..7ecd9c8 100644
--- a/fs/file.h
+++ b/fs/file.h
@@ -5,10 +5,7 @@
typedef struct file_struct
{
- int fgetc();
- int fputc();
- void *opaque;
}file;
diff --git a/fs/ringbuffer.c b/fs/ringbuffer.c
index ca5870f..449ad88 100644
--- a/fs/ringbuffer.c
+++ b/fs/ringbuffer.c
@@ -1,13 +1,13 @@
-#define FOOLOS_MODULE_NAME "fifo"
+#define FOOLOS_MODULE_NAME "ringbuffer"
#include "lib/logger/log.h"
-#include "fifo.h"
+#include "ringbuffer.h"
static int sl=9;
-fifo fifo_init(uint32_t size)
+ringbuffer ringbuffer_init(uint32_t size)
{
- fifo f;
+ ringbuffer f;
f.data=kballoc(size);
f.size=size*4096;
f.front=f.size-1;
@@ -15,7 +15,7 @@ fifo fifo_init(uint32_t size)
return f;
}
-bool fifo_put(fifo* f,uint8_t c)
+bool ringbuffer_put(ringbuffer* f,uint8_t c)
{
x86_int_disable();
lock_spin(sl);
@@ -40,7 +40,7 @@ bool fifo_put(fifo* f,uint8_t c)
return true;
}
-uint8_t fifo_get(fifo* f) // blocking
+uint8_t ringbuffer_get(ringbuffer* f) // blocking
{
char c;
diff --git a/kernel/config.h b/kernel/config.h
index 0a6fd3c..c4f9af1 100644
--- a/kernel/config.h
+++ b/kernel/config.h
@@ -8,7 +8,7 @@
#define FOOLOS_CONFIG_H
#define FOOLOS_CONSOLE_AUTOBREAK // add newline automatically at end of line
-#define FOOLOS_LOG_OFF // do not log anything
+//#define FOOLOS_LOG_OFF // do not log anything
#define FOOLOS_CONSOLE // otherwise VESA will be used!
#define FOOLSOS_SHOW_VESAMODES
#define MEM_PRINT_MEMORYMAP
diff --git a/kernel/fifo.c b/kernel/fifo.c
new file mode 100644
index 0000000..abd6c46
--- /dev/null
+++ b/kernel/fifo.c
@@ -0,0 +1,16 @@
+#include "fifo.h"
+
+bool fifo_put(fifo* f,uint8_t c)
+{
+ return f->put(f->data,c);
+}
+
+uint8_t fifo_get(fifo* f)
+{
+ return f->get(f->data);
+}
+
+bool fifo_has(fifo* f)
+{
+ return f->has(f->data);
+}
diff --git a/kernel/fifo.h b/kernel/fifo.h
new file mode 100644
index 0000000..bae7d57
--- /dev/null
+++ b/kernel/fifo.h
@@ -0,0 +1,25 @@
+// SIMPLE FIFO DRIVER
+
+
+#ifndef FIFO_H
+#define FIFO_H
+
+#include <stdint.h>
+#include <stdbool.h>
+
+typedef struct fifo_struct
+{
+ bool (*put)(struct fifo_stuct*,uint8_t);
+ uint8_t (*get)(struct fifo_struct*);
+ bool (*has)(struct fifo_struct*);
+
+ void *data; // opaque! can be a vt52 or a ringbuffer..
+
+}fifo;
+
+bool fifo_put(fifo*,uint8_t);
+uint8_t fifo_get(fifo*);
+bool fifo_has(fifo*);
+
+
+#endif
diff --git a/kernel/kernel.c b/kernel/kernel.c
index 0fb337f..dd3f502 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -11,6 +11,7 @@
#include "types.h"
#include "lib/logger/log.h"
+#include "fifo.h"
#include "timer.h"
#include "mem.h"
#include "vmem.h"
@@ -28,7 +29,6 @@
#include "terminal/vt52.h"
#include "driver/console.h"
-#include "fs/fifo.h"
//
// The Foolish structure of Fool OS!
@@ -61,8 +61,7 @@ static void stdin_put_char(uint8_t c)
static void init_stdio()
{
- fifo in=fifo_init(1);
- fifo out=fifo_init(1);
+// get_fool().std_in
//
// Setup terminal output / input
@@ -75,8 +74,11 @@ static void init_stdio()
input.put_char=stdin_put_char;
tty1=vt52_init(&screen,&input);
+ get_fool()->std_out.data=&tty1;
+ get_fool()->std_out.put=vt52_put;
keyboard_init(put_kb);
+
}
diff --git a/kernel/kernel.h b/kernel/kernel.h
index fb4e44d..2929a28 100644
--- a/kernel/kernel.h
+++ b/kernel/kernel.h
@@ -3,12 +3,13 @@
#define KERNEL_VERSION "FoolOs 0.2.1"
-#include "fs/fifo.h";
+#include "fifo.h"
typedef struct fool_os_struct
{
- fifo fifo_stdin;
- fifo fifo_stdout;
+
+ fifo std_in;
+ fifo std_out;
}fool_os;
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index 9900567..cd54d7b 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -43,7 +43,7 @@ int syscall_write(int file, char *buf, int len)
//stderr and stdout go to console
for(int i=0;i<len;i++)
{
- fifo_put(&get_fool()->fifo_stdout,buf[i]);
+// fifo_put(&get_fool()->fifo_stdout,buf[i]);
}
lock_release(2);
//x86_int_enable();
diff --git a/lib/logger/log.c b/lib/logger/log.c
index 9348f01..daa3713 100644
--- a/lib/logger/log.c
+++ b/lib/logger/log.c
@@ -7,8 +7,8 @@
#include "kernel/kernel.h"
#include "kernel/config.h"
-#include "terminal/vt52.h"
#include "kernel/timer.h"
+#include "kernel/fifo.h"
static char buffer[LOG_BUF_SIZE];
@@ -21,7 +21,8 @@ static void log_string(char *str)
{
while(*str!=0)
{
- fifo_put(&get_fool()->fifo_stdout,*(str++));
+ fifo_put(&get_fool()->std_out,*(str++));
+
}
}
diff --git a/terminal/vt52.c b/terminal/vt52.c
index 3fa4137..66fd5f1 100644
--- a/terminal/vt52.c
+++ b/terminal/vt52.c
@@ -87,7 +87,7 @@ void vt52_kb(vt52_tty *tty, uint8_t c)
tty->input->put_char(c);
}
// send one ASCII character to the terminal
-void vt52_put(vt52_tty *tty, uint8_t c)
+bool vt52_put(vt52_tty *tty, uint8_t c)
{
if(c==VT52_ESC_1){escaping=1;return;}
if(c==VT52_ESC_2){if(escaping==1)escaping=2;return;}
@@ -192,5 +192,6 @@ void vt52_put(vt52_tty *tty, uint8_t c)
}
tty->screen->update_cursor(tty->x,tty->y);
+ return true;
}
diff --git a/terminal/vt52.h b/terminal/vt52.h
index 94502d1..9258cec 100644
--- a/terminal/vt52.h
+++ b/terminal/vt52.h
@@ -2,6 +2,7 @@
#define VT52_H
#include <stdint.h>
+#include <stdbool.h>
//
@@ -56,7 +57,7 @@ typedef struct vt52_tty_struct
}vt52_tty;
vt52_tty vt52_init(term_out *screen,term_in *input);
-void vt52_put(vt52_tty *tty, uint8_t c);
+bool vt52_put(vt52_tty *tty, uint8_t c);
void vt52_kb(vt52_tty *tty, uint8_t c);
#endif