Callback-based drivers abstract class.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@16279 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
parent
746d8e1f21
commit
942ce8c780
|
@ -0,0 +1,58 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="http://www.chibios.org/xml/schema/ccode/modules.xsd"
|
||||
name="hal_cb_driver" descr="Callback Driver" editcode="false">
|
||||
<brief>Common ancestor of callback-based drivers</brief>
|
||||
<imports>
|
||||
<import>hal_base_driver.xml</import>
|
||||
</imports>
|
||||
<public>
|
||||
<types>
|
||||
<typedef name="hal_cb_t">
|
||||
<brief>Generic HAL notification callback type.</brief>
|
||||
<basetype ctype="void (*$N)(void *ip)" />
|
||||
</typedef>
|
||||
<class type="abstract" name="hal_cb_driver" namespace="cbdrv"
|
||||
ancestorname="hal_base_driver" descr="callback driver">
|
||||
<brief>Class of a callback-based driver.</brief>
|
||||
<fields>
|
||||
<field name="cb" ctype="hal_cb_t">
|
||||
<brief>Driver callback.</brief>
|
||||
<note>Can be @p NULL.</note>
|
||||
</field>
|
||||
</fields>
|
||||
<methods>
|
||||
<objinit callsuper="true">
|
||||
<implementation><![CDATA[
|
||||
self->cb = NULL;]]></implementation>
|
||||
</objinit>
|
||||
<dispose>
|
||||
<implementation><![CDATA[ ]]></implementation>
|
||||
</dispose>
|
||||
<inline>
|
||||
<method name="drvSetCallback" ctype="void">
|
||||
<brief>Associates a callback to the driver instance.</brief>
|
||||
<param name="cb" ctype="hal_cb_t">
|
||||
Callback function to be associated. Passing @p NULL disables the
|
||||
existing callback, if any.</param>
|
||||
<implementation><![CDATA[
|
||||
|
||||
self->cb = cb;]]></implementation>
|
||||
</method>
|
||||
<method name="drvGetCallback" ctype="hal_cb_t">
|
||||
<brief>Returns the callback associated to the driver instance.</brief>
|
||||
<implementation><![CDATA[
|
||||
|
||||
return self->cb;]]></implementation>
|
||||
</method>
|
||||
</inline>
|
||||
</methods>
|
||||
</class>
|
||||
</types>
|
||||
</public>
|
||||
<private>
|
||||
<includes_always>
|
||||
<include style="regular">hal.h</include>
|
||||
</includes_always>
|
||||
</private>
|
||||
</module>
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE doc [
|
||||
<!ENTITY hal_base_driver SYSTEM "hal_base_driver.xml">
|
||||
<!ENTITY hal_cb_driver SYSTEM "hal_cb_driver.xml">
|
||||
<!ENTITY hal_channels SYSTEM "hal_channels.xml">
|
||||
<!ENTITY hal_block_io SYSTEM "hal_block_io.xml">
|
||||
<!ENTITY hal_buffered_serial SYSTEM "hal_buffered_serial.xml">
|
||||
|
@ -13,6 +14,7 @@
|
|||
</paths>
|
||||
<modules>
|
||||
&hal_base_driver;
|
||||
&hal_cb_driver;
|
||||
&hal_channels;
|
||||
&hal_block_io;
|
||||
&hal_buffered_serial;
|
||||
|
|
|
@ -292,10 +292,8 @@ static inline halfreq_t halClockGetPointX(halclkpt_t clkpt) {
|
|||
#include "oop_base_interface.h"
|
||||
#include "oop_sequential_stream.h"
|
||||
#include "hal_base_driver.h"
|
||||
//#include "hal_objects.h"
|
||||
//#include "hal_streams.h"
|
||||
#include "hal_cb_driver.h"
|
||||
#include "hal_channels.h"
|
||||
//#include "hal_files.h"
|
||||
#include "hal_block_io.h"
|
||||
//#include "hal_mmcsd.h"
|
||||
//#include "hal_persistent.h"
|
||||
|
|
|
@ -0,0 +1,184 @@
|
|||
/*
|
||||
ChibiOS - Copyright (C) 2006..2023 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_cb_driver.h
|
||||
* @brief Generated Callback Driver header.
|
||||
* @note This is a generated file, do not edit directly.
|
||||
*
|
||||
* @addtogroup HAL_CB_DRIVER
|
||||
* @brief Common ancestor of callback-based drivers.
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef HAL_CB_DRIVER_H
|
||||
#define HAL_CB_DRIVER_H
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module constants. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module pre-compile time settings. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Derived constants and error checks. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module macros. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module data structures and types. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Generic HAL notification callback type.
|
||||
*/
|
||||
typedef void (*hal_cb_t)(void *ip);
|
||||
|
||||
/**
|
||||
* @class hal_cb_driver_c
|
||||
* @extends base_object_c, hal_base_driver_c.
|
||||
*
|
||||
* @brief Class of a callback-based driver.
|
||||
*
|
||||
* @name Class @p hal_cb_driver_c structures
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Type of a callback driver class.
|
||||
*/
|
||||
typedef struct hal_cb_driver hal_cb_driver_c;
|
||||
|
||||
/**
|
||||
* @brief Class @p hal_cb_driver_c virtual methods table.
|
||||
*/
|
||||
struct hal_cb_driver_vmt {
|
||||
/* From base_object_c.*/
|
||||
void (*dispose)(void *ip);
|
||||
/* From hal_base_driver_c.*/
|
||||
msg_t (*start)(void *ip);
|
||||
void (*stop)(void *ip);
|
||||
msg_t (*configure)(void *ip, const void *config);
|
||||
/* From hal_cb_driver_c.*/
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Structure representing a callback driver class.
|
||||
*/
|
||||
struct hal_cb_driver {
|
||||
/**
|
||||
* @brief Virtual Methods Table.
|
||||
*/
|
||||
const struct hal_cb_driver_vmt *vmt;
|
||||
/**
|
||||
* @brief Driver state.
|
||||
*/
|
||||
driver_state_t state;
|
||||
/**
|
||||
* @brief Driver argument.
|
||||
*/
|
||||
void *arg;
|
||||
#if (HAL_USE_MUTUAL_EXCLUSION == TRUE) || defined (__DOXYGEN__)
|
||||
/**
|
||||
* @brief Driver mutex.
|
||||
*/
|
||||
mutex_t mutex;
|
||||
#endif /* HAL_USE_MUTUAL_EXCLUSION == TRUE */
|
||||
#if (HAL_USE_REGISTRY == TRUE) || defined (__DOXYGEN__)
|
||||
/**
|
||||
* @brief Driver identifier.
|
||||
*/
|
||||
unsigned int id;
|
||||
/**
|
||||
* @brief Driver name.
|
||||
*/
|
||||
const char *name;
|
||||
/**
|
||||
* @brief Registry link structure.
|
||||
*/
|
||||
hal_regent_t regent;
|
||||
#endif /* HAL_USE_REGISTRY == TRUE */
|
||||
/**
|
||||
* @brief Driver callback.
|
||||
* @note Can be @p NULL.
|
||||
*/
|
||||
hal_cb_t cb;
|
||||
};
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* External declarations. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* Methods of hal_cb_driver_c.*/
|
||||
void *__cbdrv_objinit_impl(void *ip, const void *vmt);
|
||||
void __cbdrv_dispose_impl(void *ip);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module inline functions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @name Inline methods of hal_cb_driver_c
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @memberof hal_cb_driver_c
|
||||
* @public
|
||||
*
|
||||
* @brief Associates a callback to the driver instance.
|
||||
*
|
||||
* @param[in,out] ip Pointer to a @p hal_cb_driver_c instance.
|
||||
* @param cb Callback function to be associated. Passing @p
|
||||
* NULL disables the existing callback, if any.
|
||||
*/
|
||||
CC_FORCE_INLINE
|
||||
static inline void drvSetCallback(void *ip, hal_cb_t cb) {
|
||||
hal_cb_driver_c *self = (hal_cb_driver_c *)ip;
|
||||
|
||||
self->cb = cb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberof hal_cb_driver_c
|
||||
* @public
|
||||
*
|
||||
* @brief Returns the callback associated to the driver instance.
|
||||
*
|
||||
* @param[in,out] ip Pointer to a @p hal_cb_driver_c instance.
|
||||
*/
|
||||
CC_FORCE_INLINE
|
||||
static inline hal_cb_t drvGetCallback(void *ip) {
|
||||
hal_cb_driver_c *self = (hal_cb_driver_c *)ip;
|
||||
|
||||
return self->cb;
|
||||
}
|
||||
/** @} */
|
||||
|
||||
#endif /* HAL_CB_DRIVER_H */
|
||||
|
||||
/** @} */
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
ChibiOS - Copyright (C) 2006..2023 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_cb_driver.c
|
||||
* @brief Generated Callback Driver source.
|
||||
* @note This is a generated file, do not edit directly.
|
||||
*
|
||||
* @addtogroup HAL_CB_DRIVER
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "hal.h"
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module local definitions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module local macros. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module exported variables. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module local types. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module local variables. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module local functions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module exported functions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module class "hal_cb_driver_c" methods. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @name Methods implementations of hal_cb_driver_c
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @memberof hal_cb_driver_c
|
||||
* @protected
|
||||
*
|
||||
* @brief Implementation of object creation.
|
||||
* @note This function is meant to be used by derived classes.
|
||||
*
|
||||
* @param[out] ip Pointer to a @p hal_cb_driver_c instance to be
|
||||
* initialized.
|
||||
* @param[in] vmt VMT pointer for the new object.
|
||||
* @return A new reference to the object.
|
||||
*/
|
||||
void *__cbdrv_objinit_impl(void *ip, const void *vmt) {
|
||||
hal_cb_driver_c *self = (hal_cb_driver_c *)ip;
|
||||
|
||||
/* Initialization of the ancestors-defined parts.*/
|
||||
__drv_objinit_impl(self, vmt);
|
||||
|
||||
/* Initialization code.*/
|
||||
self->cb = NULL;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* @memberof hal_cb_driver_c
|
||||
* @protected
|
||||
*
|
||||
* @brief Implementation of object finalization.
|
||||
* @note This function is meant to be used by derived classes.
|
||||
*
|
||||
* @param[in,out] ip Pointer to a @p hal_cb_driver_c instance to be
|
||||
* disposed.
|
||||
*/
|
||||
void __cbdrv_dispose_impl(void *ip) {
|
||||
hal_cb_driver_c *self = (hal_cb_driver_c *)ip;
|
||||
|
||||
/* No finalization code.*/
|
||||
(void)self;
|
||||
|
||||
/* Finalization of the ancestors-defined parts.*/
|
||||
__drv_dispose_impl(self);
|
||||
}
|
||||
/** @} */
|
||||
|
||||
/** @} */
|
Loading…
Reference in New Issue