git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8616 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
Giovanni Di Sirio 2015-12-17 16:11:31 +00:00
parent ad6437b784
commit f6616d5708
5 changed files with 241 additions and 2 deletions

View File

@ -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 \

View File

@ -39,6 +39,7 @@
#include "hal_mmcsd.h"
/* Shared headers.*/
#include "hal_buffers.h"
#include "hal_queues.h"
/* Normal drivers.*/

View File

@ -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_ */
/** @} */

View File

@ -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

86
os/hal/src/hal_buffers.c Normal file
View File

@ -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;
}
/** @} */