[freenos] r410 committed - Modified the serial port server to demonstrate system calls.

  • From: freenos@xxxxxxxxxxxxxx
  • To: freenos@xxxxxxxxxxxxx
  • Date: Tue, 19 Oct 2010 21:48:52 +0000

Revision: 410
Author: nieklinnenbank
Date: Tue Oct 19 14:41:22 2010
Log: Modified the serial port server to demonstrate system calls.

http://code.google.com/p/freenos/source/detail?r=410

Added:
 /branches/scratch/server/serial/i8250.h
Modified:
 /branches/scratch/server/serial/main.c

=======================================
--- /dev/null
+++ /branches/scratch/server/serial/i8250.h     Tue Oct 19 14:41:22 2010
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2010 Niek Linnenbank
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __I8250_H
+#define __I8250_H
+
+/** I/O port of the first serial UART. */
+#define UART0      0x3f8
+
+/** UART Status register. */
+#define LINESTATUS 5
+
+/** UART Status Ready Flag. */
+#define TXREADY    0x20
+
+#endif /* __I8250_H */
=======================================
--- /branches/scratch/server/serial/main.c      Mon Oct 18 17:03:00 2010
+++ /branches/scratch/server/serial/main.c      Tue Oct 19 14:41:22 2010
@@ -15,11 +15,35 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */

+#include <FreeNOS/api.h>
+#include <stdio.h>
 #include <string.h>
 #include <unistd.h>
+#include "i8250.h"
+
+result_t serial_write(char *buffer, size_t count)
+{
+    size_t bytes = 0;
+
+    /* Write as much bytes as possible. */
+    while (api_io_read(UART0 + LINESTATUS, sizeof(u8)) & TXREADY
+       && bytes < count)
+    {
+       api_io_write(UART0, buffer[bytes++], sizeof(u8));
+    }
+    return bytes;
+}

 int main(void)
 {
+    char buf[1024];
+
+    /* Write a debug message. */
+    snprintf(buf, sizeof(buf), "serial: running as PID %u\r\n",
+            getpid());
+    serial_write(buf, strlen(buf));
+
+    /* Loop forever. */
     for (;;);
     return 0;
 }

Other related posts:

  • » [freenos] r410 committed - Modified the serial port server to demonstrate system calls. - freenos