aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-05-02 09:45:24 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-05-02 09:45:24 +0000
commite1301550bccc67c25fa9581da3b18cfefc4c601c (patch)
tree2801bda8500133fdcdc3b30eaa4f17f1d6f48d26 /src
parent5557c78ea373a8520b5ca75c687152e973216dd1 (diff)
downloadChibiOS-e1301550bccc67c25fa9581da3b18cfefc4c601c.tar.gz
ChibiOS-e1301550bccc67c25fa9581da3b18cfefc4c601c.tar.bz2
ChibiOS-e1301550bccc67c25fa9581da3b18cfefc4c601c.zip
Some work done on abstract I/O channels.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@931 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'src')
-rw-r--r--src/include/ch.h1
-rw-r--r--src/include/channels.h117
2 files changed, 118 insertions, 0 deletions
diff --git a/src/include/ch.h b/src/include/ch.h
index fa11c169b..bbc0c8eb4 100644
--- a/src/include/ch.h
+++ b/src/include/ch.h
@@ -80,6 +80,7 @@
#include "threads.h"
#include "inline.h"
#include "queues.h"
+#include "channels.h"
#include "serial.h"
#include "debug.h"
diff --git a/src/include/channels.h b/src/include/channels.h
new file mode 100644
index 000000000..deb01f433
--- /dev/null
+++ b/src/include/channels.h
@@ -0,0 +1,117 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT 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.
+
+ ChibiOS/RT 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/>.
+*/
+
+/**
+ * @file channels.h
+ * @brief I/O channels
+ * @addtogroup Channels
+ * @{
+ */
+
+#ifndef _CHANNELS_H_
+#define _CHANNELS_H_
+
+/**
+ * @brief Virtual methods table for base channels.
+ */
+struct _base_channel_vmt {
+ /**
+ * Channel synchronous put method.
+ */
+ msg_t (*put)(void *instance, uint8_t b, systime_t timeout);
+ /**
+ * Channel synchronous get method.
+ */
+ msg_t (*get)(void *instance, systime_t timeout);
+};
+
+/**
+ * @brief Base channels data.
+ * @note It is empty because @p BaseChannel is only an interface without
+ * implementation.
+ */
+struct _base_channel_data {
+};
+
+/**
+ * @brief Base channel class.
+ * @details This class represents a generic, synchronous, byte-wide,
+ * I/O channel.
+ */
+typedef struct _base_channel {
+ struct _base_channel_vmt *vmt; /**< Virtual Methods Table. */
+ struct _base_channel_data d0; /**< Class data. */
+} BaseChannel;
+
+#if CH_USE_EVENTS
+/**
+ * @brief Virtual methods table for base asynchronous channels.
+ */
+struct _base_asynchronous_channel_vmt {
+ /**
+ * Channel synchronous put method.
+ */
+ msg_t (*put)(void *instance, uint8_t b, systime_t timeout);
+ /**
+ * Channel synchronous get method.
+ */
+ msg_t (*get)(void *instance, systime_t timeout);
+ /**
+ * Channel asynchronous write method.
+ */
+ size_t (*write)(void *instance, uint8_t *bp, size_t n);
+ /**
+ * Channel asynchronous read method.
+ */
+ size_t (*read)(void *instance, uint8_t *bp, size_t n);
+};
+
+/**
+ * @brief Base asynchronous channels data.
+ */
+struct _base_asynchronous_channel_data {
+ /**
+ * Data Available @p EventSource. This event is generated when some incoming
+ * data is inserted in the input queue.
+ */
+ EventSource ievent;
+ /**
+ * Data Transmitted @p EventSource. This event is generated when the
+ * output queue is empty.
+ */
+ EventSource oevent;
+};
+
+/**
+ * @extends BaseChannel
+ *
+ * @brief Base asynchronous channel class.
+ * @details This class extends @p BaseChannel by adding methods for
+ * asynchronous I/O in an event-driven environment.
+ */
+typedef struct {
+ struct _base_asynchronous_channel_vmt *vmt; /**< Virtual Methods Table. */
+ struct _base_channel_data d0; /**< Super class data. */
+ struct _base_asynchronous_channel_data d1; /**< Class data. */
+} BaseAsynchronousChannel;
+#endif /* CH_USE_EVENTS */
+
+#endif /* _CHANNELS_H_ */
+
+/** @} */