diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2010-01-05 17:14:09 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2010-01-05 17:14:09 +0000 |
commit | 855fe2391d07c5dab27129ad626541482fe8d782 (patch) | |
tree | 93d4213cd7de59ab0d1b930e653d60fbf8914dc4 /os/hal | |
parent | de95f94fbeb425a7e36e664181824db6ed021ccc (diff) | |
download | ChibiOS-855fe2391d07c5dab27129ad626541482fe8d782.tar.gz ChibiOS-855fe2391d07c5dab27129ad626541482fe8d782.tar.bz2 ChibiOS-855fe2391d07c5dab27129ad626541482fe8d782.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1501 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal')
-rw-r--r-- | os/hal/hal.dox | 12 | ||||
-rw-r--r-- | os/hal/include/serial.h | 83 | ||||
-rw-r--r-- | os/hal/src/serial.c | 31 |
3 files changed, 100 insertions, 26 deletions
diff --git a/os/hal/hal.dox b/os/hal/hal.dox index 81b5a148d..657185f8e 100644 --- a/os/hal/hal.dox +++ b/os/hal/hal.dox @@ -26,17 +26,17 @@ * - High Level Device Driver (<b>HLD</b>). This layer contains the definitions
* of the driver's APIs and the platform independent part of the driver.<br>
* An HLD is composed by two files:
- * - @<driver@>.c, the high level implementation file. This file must be
+ * - @<driver@>.c, the HLD implementation file. This file must be
* included in the Makefile in order to use the driver.
- * - @<driver@>.h, the high level header file. This file must be included
- * by the application code in order to access the driver's APIs.
+ * - @<driver@>.h, the HLD header file. This file is implicitly
+ * included by the HAL header file @p hal.h.
* .
* - Low Level Device Driver (<b>LLD</b>). This layer contains the platform
* dependent part of the driver.<br>
* A LLD is composed by two files:
- * - @<driver@>_lld.c, the low level implementation file. This file must be
+ * - @<driver@>_lld.c, the LLD implementation file. This file must be
* included in the Makefile in order to use the driver.
- * - @<driver@>_lld.h, the high level header file. This file is implicitly
+ * - @<driver@>_lld.h, the LLD header file. This file is implicitly
* included by the HLD header file.
* .
* The LLD may be not present in those drivers that do not access the
@@ -174,7 +174,7 @@ * @dot
digraph example {
rankdir="LR";
- node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.75", height="0.75"];
+ node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.8", height="0.8"];
edge [fontname=Helvetica, fontsize=8];
uninit [label="SPI_UNINIT", style="bold"];
stop [label="SPI_STOP\nLow Power"];
diff --git a/os/hal/include/serial.h b/os/hal/include/serial.h index c24ac3994..3f4a1a8ca 100644 --- a/os/hal/include/serial.h +++ b/os/hal/include/serial.h @@ -108,6 +108,10 @@ struct _serial_driver_methods { */
struct SerialDriverVMT {
/**
+ * @p BaseSequentialStream class inherited methods.
+ */
+ struct _base_sequental_stream_methods bss;
+ /**
* @p BaseChannel class inherited methods.
*/
struct _base_channel_methods bc;
@@ -134,6 +138,10 @@ struct _SerialDriver { */
const struct SerialDriverVMT *vmt;
/**
+ * @p BaseSequentialStream class inherited data.
+ */
+ struct _base_sequental_stream_data bss;
+ /**
* @p BaseChannel class inherited data.
*/
struct _base_channel_data bc;
@@ -170,7 +178,7 @@ struct _SerialDriver { #define sdGetWouldBlock(sdp) chIQIsEmpty(&(sdp)->sd.iqueue)
/**
- * @brief Direct blocking write to a @p SerialDriver.
+ * @brief Direct write to a @p SerialDriver.
* @details This function bypasses the indirect access to the channel and
* writes directly on the output queue. This is faster but cannot
* be used to write to different channels implementations.
@@ -179,8 +187,7 @@ struct _SerialDriver { #define sdPut(sdp, b) chOQPut(&(sdp)->sd.oqueue, b)
/**
- * @brief Direct blocking write on a @p SerialDriver with timeout
- * specification.
+ * @brief Direct write to a @p SerialDriver with timeout specification.
* @details This function bypasses the indirect access to the channel and
* writes directly on the output queue. This is faster but cannot
* be used to write to different channels implementations.
@@ -189,7 +196,7 @@ struct _SerialDriver { #define sdPutTimeout(sdp, b, t) chOQPutTimeout(&(sdp)->sd.iqueue, b, t)
/**
- * @brief Direct blocking read from a @p SerialDriver.
+ * @brief Direct read from a @p SerialDriver.
* @details This function bypasses the indirect access to the channel and
* reads directly from the input queue. This is faster but cannot
* be used to read from different channels implementations.
@@ -198,8 +205,7 @@ struct _SerialDriver { #define sdGet(sdp) chIQGet(&(sdp)->sd.iqueue)
/**
- * @brief Direct blocking read from a @p SerialDriver with timeout
- * specification.
+ * @brief Direct read from a @p SerialDriver with timeout specification.
* @details This function bypasses the indirect access to the channel and
* reads directly from the input queue. This is faster but cannot
* be used to read from different channels implementations.
@@ -208,22 +214,77 @@ struct _SerialDriver { #define sdGetTimeout(sdp, t) chIQGetTimeout(&(sdp)->sd.iqueue, t)
/**
+ * @brief Direct blocking write to a @p SerialDriver.
+ * @details This function bypasses the indirect access to the channel and
+ * writes directly to the output queue. This is faster but cannot
+ * be used to write from different channels implementations.
+ * @see chIOWriteTimeout()
+ */
+#define sdWrite(sdp, b, n) \
+ chOQWriteTimeout(&(sdp)->sd.oqueue, b, n, TIME_INFINITE)
+
+/**
+ * @brief Direct blocking write to a @p SerialDriver with timeout
+ * specification.
+ * @details This function bypasses the indirect access to the channel and
+ * writes directly to the output queue. This is faster but cannot
+ * be used to write from different channels implementations.
+ * @see chIOWriteTimeout()
+ */
+#define sdWriteTimeout(sdp, b, n, t) \
+ chOQWriteTimeout(&(sdp)->sd.oqueue, b, n, t)
+
+/**
* @brief Direct non-blocking write to a @p SerialDriver.
* @details This function bypasses the indirect access to the channel and
* writes directly to the output queue. This is faster but cannot
* be used to write from different channels implementations.
- * @see chIOWrite()
+ * @see chIOWriteTimeout()
*/
-#define sdWrite(sdp, b, n) chOQWrite(&(sdp)->sd.oqueue, b, n)
+#define sdAsynchronousWrite(sdp, b, n) \
+ chOQWriteTimeout(&(sdp)->sd.oqueue, b, n, TIME_IMMEDIATE)
/**
- * @brief Direct non-blocking read on a @p SerialDriver.
+ * @brief Direct blocking read from a @p SerialDriver.
+ * @details This function bypasses the indirect access to the channel and
+ * reads directly from the input queue. This is faster but cannot
+ * be used to read from different channels implementations.
+ * @see chIOReadTimeout()
+ */
+#define sdRead(sdp, b, n) \
+ chIQReadTimeout(&(sdp)->sd.iqueue, b, n, TIME_INFINITE)
+
+/**
+ * @brief Direct blocking read from a @p SerialDriver with timeout
+ * specification.
* @details This function bypasses the indirect access to the channel and
* reads directly from the input queue. This is faster but cannot
* be used to read from different channels implementations.
- * @see chIORead()
+ * @see chIOReadTimeout()
+ */
+#define sdReadTimeout(sdp, b, n, t) \
+ chIQReadTimeout(&(sdp)->sd.iqueue, b, n, t)
+
+/**
+ * @brief Direct non-blocking read from a @p SerialDriver.
+ * @details This function bypasses the indirect access to the channel and
+ * reads directly from the input queue. This is faster but cannot
+ * be used to read from different channels implementations.
+ * @see chIOReadTimeout()
+ */
+#define sdAsynchronousRead(sdp, b, n) \
+ chIQReadTimeout(&(sdp)->sd.iqueue, b, n, TIME_IMMEDIATE)
+
+/**
+ * @brief Returns the status change event source.
+ * @details The status change event source is broadcasted when the channel
+ * status is updated, the status flags can then be fetched and
+ * cheared by using @p sdGetAndClearFlags().
+ *
+ * @param[in] ip pointer to a @p SerialDriver object
+ * @return A pointer to an @p EventSource object.
*/
-#define sdRead(sdp, b, n) chIQRead(&(sdp)->sd.iqueue, b, n)
+#define sdGetStatusChangeEventSource(ip) (&((ip)->vmt->sd.sevent))
/*===========================================================================*/
/* External declarations. */
diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index 4c2cb71c9..54db8e95d 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -45,6 +45,19 @@ * Interface implementation, the following functions just invoke the equivalent
* queue-level function or macro. */
+
+static size_t writes(void *ip, const uint8_t *bp, size_t n) {
+
+ return chOQWriteTimeout(&((SerialDriver *)ip)->sd.oqueue, bp,
+ n, TIME_INFINITE);
+}
+
+static size_t reads(void *ip, uint8_t *bp, size_t n) {
+
+ return chIQReadTimeout(&((SerialDriver *)ip)->sd.iqueue, bp,
+ n, TIME_INFINITE);
+}
+
static bool_t putwouldblock(void *ip) {
return chOQIsFull(&((SerialDriver *)ip)->sd.oqueue);
@@ -55,29 +68,29 @@ static bool_t getwouldblock(void *ip) { return chIQIsEmpty(&((SerialDriver *)ip)->sd.iqueue);
}
-static msg_t put(void *ip, uint8_t b, systime_t timeout) {
+static msg_t putt(void *ip, uint8_t b, systime_t timeout) {
return chOQPutTimeout(&((SerialDriver *)ip)->sd.oqueue, b, timeout);
}
-static msg_t get(void *ip, systime_t timeout) {
+static msg_t gett(void *ip, systime_t timeout) {
return chIQGetTimeout(&((SerialDriver *)ip)->sd.iqueue, timeout);
}
-static size_t write(void *ip, uint8_t *buffer, size_t n) {
+static size_t writet(void *ip, const uint8_t *bp, size_t n, systime_t time) {
- return chOQWrite(&((SerialDriver *)ip)->sd.oqueue, buffer, n);
+ return chOQWriteTimeout(&((SerialDriver *)ip)->sd.oqueue, bp, n, time);
}
-static size_t read(void *ip, uint8_t *buffer, size_t n) {
+static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) {
- return chIQRead(&((SerialDriver *)ip)->sd.iqueue, buffer, n);
+ return chIQReadTimeout(&((SerialDriver *)ip)->sd.iqueue, bp, n, time);
}
static const struct SerialDriverVMT vmt = {
- {putwouldblock, getwouldblock, put, get},
- {write, read},
+ {writes, reads},
+ {putwouldblock, getwouldblock, putt, gett, writet, readt},
{}
};
@@ -112,10 +125,10 @@ void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) { chEvtInit(&sdp->bac.ievent);
chEvtInit(&sdp->bac.oevent);
chEvtInit(&sdp->sd.sevent);
+ sdp->sd.state = SD_STOP;
sdp->sd.flags = SD_NO_ERROR;
chIQInit(&sdp->sd.iqueue, sdp->sd.ib, SERIAL_BUFFERS_SIZE, inotify);
chOQInit(&sdp->sd.oqueue, sdp->sd.ob, SERIAL_BUFFERS_SIZE, onotify);
- sdp->sd.state = SD_STOP;
}
/**
|