summaryrefslogtreecommitdiff
path: root/cesar/hal/arch/io.h
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/hal/arch/io.h')
-rw-r--r--cesar/hal/arch/io.h87
1 files changed, 87 insertions, 0 deletions
diff --git a/cesar/hal/arch/io.h b/cesar/hal/arch/io.h
new file mode 100644
index 0000000000..5e66f59b3a
--- /dev/null
+++ b/cesar/hal/arch/io.h
@@ -0,0 +1,87 @@
+#ifndef hal_arch_io_h
+#define hal_arch_io_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file hal/arch/io.h
+ * \brief Architecture dependent basic input output services.
+ * \ingroup hal_arch
+ *
+ * The services in this file offer the added value that they should depend of
+ * almost nothing in order to work, enabling use from debugger or fatal error
+ * state.
+ */
+
+/**
+ * Basic output, output a single char.
+ * \param c the char to output
+ *
+ * \note Actually implemented as macro.
+ */
+void
+arch_io_write_char (char c);
+
+/**
+ * Basic output, output a null terminated string.
+ * \param s the string to output
+ *
+ * \note Actually implemented as macro.
+ */
+void
+arch_io_write_string (const char *s);
+
+/**
+ * Basic output, output a text buffer.
+ * \param text text buffer start address
+ * \param text_size number of characters to output
+ *
+ * \note Actually implemented as macro.
+ */
+void
+arch_io_write (const char *text, uint text_size);
+
+#if defined (ECOS) && ECOS
+
+# include <cyg/infra/diag.h>
+
+# define arch_io_write_char diag_write_char
+
+# define arch_io_write_string diag_write_string
+
+# define arch_io_write(text, text_size) do { \
+ const char *iter_ = (text); \
+ const char *end_ = iter_ + (text_size); \
+ for (; iter_ != end_; iter_++) \
+ { \
+ arch_io_write_char (*iter_); \
+ } \
+} while (0)
+
+#else /* !(defined (ECOS) && ECOS) */
+
+# include <unistd.h>
+# include <string.h>
+
+# define arch_io_write_char(c) do { \
+ char c_ = (c); \
+ arch_io_write (&c_, 1); \
+} while (0)
+
+# define arch_io_write_string(s) do { \
+ const char *s_ = (s); \
+ uint size_ = strlen (s_); \
+ arch_io_write (s_, size_); \
+} while (0)
+
+# define arch_io_write(text, text_size) do { \
+ write (1, (text), (text_size)); \
+} while (0)
+
+#endif /* !(defined (ECOS) && ECOS) */
+
+#endif /* hal_arch_io_h */