aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2015-12-17 16:11:31 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2015-12-17 16:11:31 +0000
commitf6616d570865fce92ae7a669611e495038e9c111 (patch)
tree652e55d2c8a112304df967218fd77f887214352e
parentad6437b7847e7a5c4948b3a18d055a78d7c84dce (diff)
downloadChibiOS-f6616d570865fce92ae7a669611e495038e9c111.tar.gz
ChibiOS-f6616d570865fce92ae7a669611e495038e9c111.tar.bz2
ChibiOS-f6616d570865fce92ae7a669611e495038e9c111.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8616 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r--os/hal/hal.mk2
-rw-r--r--os/hal/include/hal.h1
-rw-r--r--os/hal/include/hal_buffers.h150
-rw-r--r--os/hal/include/hal_queues.h4
-rw-r--r--os/hal/src/hal_buffers.c86
5 files changed, 241 insertions, 2 deletions
diff --git a/os/hal/hal.mk b/os/hal/hal.mk
index 53da28525..ed2ac4d03 100644
--- a/os/hal/hal.mk
+++ b/os/hal/hal.mk
@@ -5,6 +5,7 @@ HALCONF := $(strip $(shell cat halconf.h | egrep -e "define"))
HALSRC := $(CHIBIOS)/os/hal/src/hal.c \
$(CHIBIOS)/os/hal/src/st.c \
+ $(CHIBIOS)/os/hal/src/hal_buffers.c \
$(CHIBIOS)/os/hal/src/hal_queues.c \
$(CHIBIOS)/os/hal/src/hal_mmcsd.c
ifneq ($(findstring HAL_USE_ADC TRUE,$(HALCONF)),)
@@ -69,6 +70,7 @@ HALSRC += $(CHIBIOS)/os/hal/src/wdg.c
endif
else
HALSRC = $(CHIBIOS)/os/hal/src/hal.c \
+ $(CHIBIOS)/os/hal/src/hal_buffers.c \
$(CHIBIOS)/os/hal/src/hal_queues.c \
$(CHIBIOS)/os/hal/src/hal_mmcsd.c \
$(CHIBIOS)/os/hal/src/adc.c \
diff --git a/os/hal/include/hal.h b/os/hal/include/hal.h
index 89ef9e08d..48d0a4031 100644
--- a/os/hal/include/hal.h
+++ b/os/hal/include/hal.h
@@ -39,6 +39,7 @@
#include "hal_mmcsd.h"
/* Shared headers.*/
+#include "hal_buffers.h"
#include "hal_queues.h"
/* Normal drivers.*/
diff --git a/os/hal/include/hal_buffers.h b/os/hal/include/hal_buffers.h
new file mode 100644
index 000000000..02f21f5cd
--- /dev/null
+++ b/os/hal/include/hal_buffers.h
@@ -0,0 +1,150 @@
+/*
+ ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+/**
+ * @file hal_buffers.h
+ * @brief I/O Buffers macros and structures.
+ *
+ * @addtogroup HAL_BUFFERS
+ * @{
+ */
+
+#ifndef _HAL_BUFFERS_H_
+#define _HAL_BUFFERS_H_
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+#define HAL_BUFFERS_QUEUE_SIZE 2
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Type of an I/O buffer.
+ */
+typedef struct hal_buffer io_buffer_t;
+
+/**
+ * @brief Structure of a generic buffer.
+ */
+struct hal_buffer {
+ /**
+ * @brief Pointer to the buffer in memory.
+ */
+ uint8_t *buffer;
+ /**
+ * @brief Pointer to the first non-used location in the buffer.
+ */
+ uint8_t *limit;
+ /**
+ * @brief Pointer to the buffer boundary.
+ */
+ uint8_t *top;
+};
+
+/**
+ * @brief Type of a generic double buffer.
+ */
+typedef struct io_double_buffer io_double_buffer_t;
+
+/**
+ * @brief Double buffer notification callback type.
+ *
+ * @param[in] iodbp the double buffer pointer
+ */
+typedef void (*dbnotify_t)(io_double_buffer_t *iodbp);
+
+/**
+ * @brief Structure of a generic double buffer.
+ */
+struct io_double_buffer {
+ /**
+ * @brief Queue of waiting threads.
+ */
+ threads_queue_t waiting;
+ /**
+ * @brief Active buffers counter.
+ */
+ volatile size_t counter;
+ /**
+ * @brief Buffer write pointer.
+ */
+ io_buffer_t *bwrptr;
+ /**
+ * @brief Buffer read pointer.
+ */
+ io_buffer_t *brdptr;
+ /**
+ * @brief Pointer for R/W sequential access.
+ */
+ uint8_t *ptr;
+ /**
+ * @brief Queue of buffer objects.
+ */
+ io_buffer_t buffers[HAL_BUFFERS_QUEUE_SIZE];
+ /**
+ * @brief Data notification callback.
+ */
+ dbnotify_t notify;
+ /**
+ * @brief Application defined field.
+ */
+ void *link;
+};
+
+/**
+ * @brief Type of an input double buffer.
+ */
+typedef io_double_buffer_t input_double_buffer_t;
+
+/**
+ * @brief Type of an output double buffer.
+ */
+typedef io_double_buffer_t output_double_buffer_t;
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void iobInit(io_buffer_t *iobp, uint8_t *bp, size_t size);
+ void idbObjectInit(input_double_buffer_t *idbp,
+ uint8_t *b1p, uint8_t *b2p, size_t size,
+ dbnotify_t infy, void *link);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _HAL_BUFFERS_H_ */
+
+/** @} */
diff --git a/os/hal/include/hal_queues.h b/os/hal/include/hal_queues.h
index c8c664ddc..da76aac8f 100644
--- a/os/hal/include/hal_queues.h
+++ b/os/hal/include/hal_queues.h
@@ -49,7 +49,7 @@ typedef struct io_queue io_queue_t;
/**
* @brief Queue notification callback type.
*
- * @param[in] qp the queue pointer.
+ * @param[in] qp the queue pointer
*/
typedef void (*qnotify_t)(io_queue_t *qp);
@@ -62,7 +62,7 @@ typedef void (*qnotify_t)(io_queue_t *qp);
* lock zone and is non-blocking.
*/
struct io_queue {
- threads_queue_t q_waiting; /**< @brief Waiting thread. */
+ threads_queue_t q_waiting; /**< @brief Queue of waiting threads. */
volatile size_t q_counter; /**< @brief Resources counter. */
uint8_t *q_buffer; /**< @brief Pointer to the queue buffer.*/
uint8_t *q_top; /**< @brief Pointer to the first
diff --git a/os/hal/src/hal_buffers.c b/os/hal/src/hal_buffers.c
new file mode 100644
index 000000000..62d1dbbb4
--- /dev/null
+++ b/os/hal/src/hal_buffers.c
@@ -0,0 +1,86 @@
+/*
+ ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+/**
+ * @file hal_buffers.c
+ * @brief I/O Buffers code.
+ *
+ * @addtogroup HAL_BUFFERS
+ * @{
+ */
+
+#include "hal.h"
+
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver exported variables. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver local variables and types. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver exported functions. */
+/*===========================================================================*/
+
+/**
+ * @brief Initializes an I/O buffer object.
+ *
+ * @param[out] iobp pointer to the @p input_double_buffer_t object
+ * @param[in] bp pointer to a memory area allocated as buffer
+ * @param[in] size size of the buffers
+ *
+ * @init
+ */
+void iobInit(io_buffer_t *iobp, uint8_t *bp, size_t size) {
+
+ iobp->buffer = bp;
+ iobp->limit = bp;
+ iobp->top = bp + size;
+}
+
+/**
+ * @brief Initializes an input double buffer object.
+ *
+ * @param[out] idbp pointer to the @p input_double_buffer_t object
+ * @param[in] b1p pointer to a memory area allocated as buffer 1
+ * @param[in] b2p pointer to a memory area allocated as buffer 2
+ * @param[in] size size of the buffers
+ *
+ * @init
+ */
+void idbObjectInit(input_double_buffer_t *idbp,
+ uint8_t *b1p, uint8_t *b2p, size_t size,
+ dbnotify_t infy, void *link) {
+
+ iobInit(&idbp->buffers[0], b1p, size);
+ iobInit(&idbp->buffers[1], b2p, size);
+ idbp->counter = 0;
+ idbp->brdptr = &idbp->buffers[0];
+ idbp->bwrptr = &idbp->buffers[0];
+ idbp->notify = infy;
+ idbp->link = link;
+}
+
+/** @} */