diff options
author | Fabien Poussin <fabien.poussin@gmail.com> | 2019-01-08 20:02:45 +0100 |
---|---|---|
committer | Fabien Poussin <fabien.poussin@gmail.com> | 2019-01-08 20:02:45 +0100 |
commit | 91e635b08a57e44ce1f7deb0328a5ae78117f8d4 (patch) | |
tree | 23cb783d26ded78d5a759f39c1f917c5b9178979 /os/hal/src | |
parent | 5af099c3665e49ce9323fa79c56a51bf67b9ebab (diff) | |
download | ChibiOS-Contrib-91e635b08a57e44ce1f7deb0328a5ae78117f8d4.tar.gz ChibiOS-Contrib-91e635b08a57e44ce1f7deb0328a5ae78117f8d4.tar.bz2 ChibiOS-Contrib-91e635b08a57e44ce1f7deb0328a5ae78117f8d4.zip |
Adding rudimentary OPAMP Driver
Diffstat (limited to 'os/hal/src')
-rw-r--r-- | os/hal/src/hal_opamp.c | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/os/hal/src/hal_opamp.c b/os/hal/src/hal_opamp.c new file mode 100644 index 0000000..ba718a7 --- /dev/null +++ b/os/hal/src/hal_opamp.c @@ -0,0 +1,155 @@ +/* + ChibiOS - Copyright (C) 2006..2019 Giovanni Di Sirio + Copyright (C) 2019 Fabien Poussin (fabien.poussin (at) google's mail) + + 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_opamp.c + * @brief OPAMP Driver code. + * + * @addtogroup OPAMP + * @{ + */ + +#include "hal_opamp.h" + +#if HAL_USE_OPAMP || defined(__DOXYGEN__) + + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables and types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief OPAMP Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. + * + * @init + */ +void opampInit(void) { + + opamp_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p OPAMPDriver structure. + * + * @param[out] opampp pointer to the @p OPAMPDriver object + * + * @init + */ +void opampObjectInit(OPAMPDriver *opampp) { + + opampp->state = OPAMP_STOP; + opampp->config = NULL; +} + +/** + * @brief Configures and activates the OPAMP peripheral. + * + * @param[in] opampp pointer to the @p OPAMPDriver object + * @param[in] config pointer to the @p OPAMPConfig object + * + * @api + */ +void opampStart(OPAMPDriver *opampp, const OPAMPConfig *config) { + + osalDbgCheck((opampp != NULL) && (config != NULL)); + + osalSysLock(); + osalDbgAssert((opampp->state == OPAMP_STOP) || (opampp->state == OPAMP_READY), + "invalid state"); + opampp->config = config; + opamp_lld_start(opampp); + opampp->state = OPAMP_READY; + osalSysUnlock(); +} + +/** + * @brief Deactivates the OPAMP peripheral. + * + * @param[in] opampp pointer to the @p OPAMPDriver object + * + * @api + */ +void opampStop(OPAMPDriver *opampp) { + + osalDbgCheck(opampp != NULL); + + osalSysLock(); + osalDbgAssert((opampp->state == OPAMP_STOP) || (opampp->state == OPAMP_READY), + "invalid state"); + opamp_lld_stop(opampp); + opampp->state = OPAMP_STOP; + osalSysUnlock(); +} + +/** + * @brief Activates the opamp. + * + * @param[in] opampp pointer to the @p OPAMPDriver object + * + * @api + */ +void opampEnable(OPAMPDriver *opampp) { + + osalDbgCheck(opampp != NULL); + + osalSysLock(); + osalDbgAssert(opampp->state == OPAMP_READY, "invalid state"); + opamp_lld_enable(opampp); + opampp->state = OPAMP_ACTIVE; + osalSysUnlock(); +} + +/** + * @brief Deactivates the opamp. + * + * @param[in] opampp pointer to the @p OPAMPDriver object + * + * @api + */ +void opampDisable(OPAMPDriver *opampp) { + + osalDbgCheck(opampp != NULL); + + osalSysLock(); + osalDbgAssert((opampp->state == OPAMP_READY) || (opampp->state == OPAMP_ACTIVE), + "invalid state"); + opamp_lld_disable(opampp); + opampp->state = OPAMP_READY; + osalSysUnlock(); +} + +#endif /* HAL_USE_OPAMP */ + +/** @} */ |