From 50439eed0df5c61ecb70483ad7d999f0038f1b3d Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Mon, 26 Feb 2018 09:29:02 +0000 Subject: Added back missing revisions in trunk. git-svn-id: https://svn.code.sf.net/p/chibios/svn2/trunk@11544 110e8d01-0319-4d1e-a829-52ad28d1bb01 --- os/hal/include/hal.h | 1 + os/hal/include/hal_objects.h | 86 ++++++++++++++++++++++++++++++++++++++++++++ os/hal/include/hal_pal.h | 51 ++------------------------ os/hal/include/hal_streams.h | 6 +++- 4 files changed, 95 insertions(+), 49 deletions(-) create mode 100644 os/hal/include/hal_objects.h (limited to 'os/hal/include') diff --git a/os/hal/include/hal.h b/os/hal/include/hal.h index 337f85f6f..6eb7ccfb8 100644 --- a/os/hal/include/hal.h +++ b/os/hal/include/hal.h @@ -114,6 +114,7 @@ #include "hal_lld.h" /* Abstract interfaces.*/ +#include "hal_objects.h" #include "hal_streams.h" #include "hal_channels.h" #include "hal_files.h" diff --git a/os/hal/include/hal_objects.h b/os/hal/include/hal_objects.h new file mode 100644 index 000000000..59c3884da --- /dev/null +++ b/os/hal/include/hal_objects.h @@ -0,0 +1,86 @@ +/* + ChibiOS - Copyright (C) 2006..2018 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_objects.h + * @brief Base object. + * @details This header defines a base object that is the root for the + * inheritance system. + * + * @addtogroup HAL_BASE_OBJECT + * @details HAL uses concepts of Object Oriented Programming even if it + * is written in C. Things like simple inheritance, multiple + * inheritance and interfaces are used through the system. + * This module defines a "base object" that is the ancestor of + * all classes in the system. + * @{ + */ + +#ifndef HAL_OBJECTS_H +#define HAL_OBJECTS_H + +/** + * @brief @p BaseObject specific methods. + * @note This object defines no methods. + */ +#define _base_object_methods \ + /* Instance offset, used for multiple inheritance, normally zero. It + represents the offset between the current object and the container + object*/ \ + size_t instance_offset; + +/** + * @brief @p BaseObject specific data. + * @note This object defines no data. + */ +#define _base_object_data + +/** + * @brief @p BaseObject virtual methods table. + */ +struct BaseObjectVMT { + _base_object_methods +}; + +/** + * @brief Base stream class. + * @details This class represents a generic blocking unbuffered sequential + * data stream. + */ +typedef struct { + /** @brief Virtual Methods Table.*/ + const struct BaseObjectVMT *vmt; + _base_object_data +} BaseObject; + +/** + * @name Macro Functions (BaseObject) + * @{ + */ +/** + * @brief Returns the instance pointer starting from an interface pointer. + * + * @param[in] type the type of the instance pointer, it is used for casting + * @param[in] ip the interface pointer + * @return A pointer to the object implementing the interface + */ +#define objGetInstance(type, ip) \ + (type)(((size_t)(ip)) - (ip)->vmt->instance_offset) +/** @} */ + +#endif /* HAL_OBJECTS_H */ + +/** @} */ diff --git a/os/hal/include/hal_pal.h b/os/hal/include/hal_pal.h index a3c9818ce..86a4fe699 100644 --- a/os/hal/include/hal_pal.h +++ b/os/hal/include/hal_pal.h @@ -949,54 +949,6 @@ typedef struct { } while (false) #endif /* PAL_USE_CALLBACKS == TRUE */ -#if (PAL_USE_WAIT == TRUE) || defined(__DOXYGEN__) -/** - * @brief Waits for an edge on the specified port/pad. - * - * @param[in] port port identifier - * @param[in] pad pad number within the port - * @param[in] timeout the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @returns The operation state. - * @retval MSG_OK if an edge has been detected. - * @retval MSG_TIMEOUT if a timeout occurred before an edge cound be detected. - * @retval MSG_RESET if the event has been disabled while the thread was - * waiting for an edge. - * - * @api - */ -#define palWaitPadTimeout(port, pad, timeout) \ - do { \ - osalSysLock(); \ - palWaitPadTimeoutS(port, pad, timeout); \ - osalSysUnlock(); \ - } while (false) - - -/** - * @brief Waits for an edge on the specified line. - * - * @param[in] line line identifier - * @param[in] timeout operation timeout - * @returns The operation state. - * @retval MSG_OK if an edge has been detected. - * @retval MSG_TIMEOUT if a timeout occurred before an edge cound be detected. - * @retval MSG_RESET if the event has been disabled while the thread was - * waiting for an edge. - * - * @api - */ -#define palWaitLineTimeout(line, timeout) \ - do { \ - osalSysLock(); \ - palWaitLineTimeoutS(line, timeout); \ - osalSysUnlock(); \ - } while (false) -#endif /* PAL_USE_WAIT == TRUE */ - /** @} */ /*===========================================================================*/ @@ -1017,7 +969,10 @@ extern "C" { #if (PAL_USE_WAIT == TRUE) || defined(__DOXYGEN__) msg_t palWaitPadTimeoutS(ioportid_t port, iopadid_t pad, sysinterval_t timeout); + msg_t palWaitPadTimeout(ioportid_t port, iopadid_t pad, + sysinterval_t timeout); msg_t palWaitLineTimeoutS(ioline_t line, sysinterval_t timeout); + msg_t palWaitLineTimeout(ioline_t line, sysinterval_t timeout); #endif /* PAL_USE_WAIT == TRUE */ #ifdef __cplusplus } diff --git a/os/hal/include/hal_streams.h b/os/hal/include/hal_streams.h index 3e414ae04..bbdc65309 100644 --- a/os/hal/include/hal_streams.h +++ b/os/hal/include/hal_streams.h @@ -48,6 +48,7 @@ * @brief BaseSequentialStream specific methods. */ #define _base_sequential_stream_methods \ + _base_object_methods \ /* Stream write buffer method.*/ \ size_t (*write)(void *instance, const uint8_t *bp, size_t n); \ /* Stream read buffer method.*/ \ @@ -62,7 +63,8 @@ * @note It is empty because @p BaseSequentialStream is only an interface * without implementation. */ -#define _base_sequential_stream_data +#define _base_sequential_stream_data \ + _base_object_data /** * @brief @p BaseSequentialStream virtual methods table. @@ -72,6 +74,8 @@ struct BaseSequentialStreamVMT { }; /** + * @extends BaseObject + * * @brief Base stream class. * @details This class represents a generic blocking unbuffered sequential * data stream. -- cgit v1.2.3