diff options
author | Uladzimir Pylinski <barthess@yandex.ru> | 2016-02-18 20:51:06 +0300 |
---|---|---|
committer | Uladzimir Pylinski <barthess@yandex.ru> | 2016-02-18 20:51:06 +0300 |
commit | b634bd9beef41b5b141b994efa4ac3d55505d0c4 (patch) | |
tree | 38550a82a8a6a27ef1c6846ccf2594074e82dd2e /os/hal/include | |
parent | d56a6f02425c6b7780953dc99fb5d0966165ec59 (diff) | |
parent | 499335cd61ae6daadf828b2ab2b3f8b40c0f7c03 (diff) | |
download | ChibiOS-Contrib-b634bd9beef41b5b141b994efa4ac3d55505d0c4.tar.gz ChibiOS-Contrib-b634bd9beef41b5b141b994efa4ac3d55505d0c4.tar.bz2 ChibiOS-Contrib-b634bd9beef41b5b141b994efa4ac3d55505d0c4.zip |
Merge pull request #43 from fpoussin/timcap-pull
TIMCAP Driver
Merged pull request #43 from fpoussin/timcap-pull. Original driver: https://github.com/dsigma/ChibiOS/tree/master/demos/ARMCM4-STM32F407-WAVESHARE-OPEN-407I-C-TIM_CAP/timcap
Diffstat (limited to 'os/hal/include')
-rw-r--r-- | os/hal/include/hal_community.h | 1 | ||||
-rw-r--r-- | os/hal/include/timcap.h | 210 |
2 files changed, 211 insertions, 0 deletions
diff --git a/os/hal/include/hal_community.h b/os/hal/include/hal_community.h index 5ed561f..7c83078 100644 --- a/os/hal/include/hal_community.h +++ b/os/hal/include/hal_community.h @@ -33,6 +33,7 @@ #include "nand.h"
#include "eicu.h"
#include "usbh.h"
+#include "timcap.h"
/* Complex drivers.*/
#include "onewire.h"
diff --git a/os/hal/include/timcap.h b/os/hal/include/timcap.h new file mode 100644 index 0000000..a848783 --- /dev/null +++ b/os/hal/include/timcap.h @@ -0,0 +1,210 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011,2012,2013 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/** + * @file timcap.h + * @brief TIMCAP Driver macros and structures. + * + * @addtogroup TIMCAP + * @{ + */ + +#ifndef _TIMCAP_H_ +#define _TIMCAP_H_ + +#include "ch.h" +#include "hal.h" + +#ifndef HAL_USE_TIMCAP +#define HAL_USE_TIMCAP FALSE +#endif + +#if HAL_USE_TIMCAP || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver constants. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver pre-compile time settings. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver data structures and types. */ +/*===========================================================================*/ + +/** + * @brief Driver state machine possible states. + */ +typedef enum { + TIMCAP_UNINIT = 0, /**< Not initialized. */ + TIMCAP_STOP = 1, /**< Stopped. */ + TIMCAP_READY = 2, /**< Ready. */ + TIMCAP_WAITING = 3, /**< Waiting first edge. */ + TIMCAP_ACTIVE = 4, /**< Active cycle phase. */ + TIMCAP_IDLE = 5, /**< Idle cycle phase. */ +} timcapstate_t; + +/** + * @brief Type of a structure representing an TIMCAP driver. + */ +typedef struct TIMCAPDriver TIMCAPDriver; + + +/** + * @brief TIMCAP notification callback type. + * + * @param[in] timcapp pointer to a @p TIMCAPDriver object + */ +typedef void (*timcapcallback_t)(TIMCAPDriver *timcapp); + +#include "timcap_lld.h" + +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + +/** + * @name Macro Functions + * @{ + */ +/** + * @brief Enables the input capture. + * + * @param[in] timcapp pointer to the @p TIMCAPDriver object + * + * @iclass + */ +#define timcapEnableI(timcapp) timcap_lld_enable(timcapp) + +/** + * @brief Disables the input capture. + * + * @param[in] timcapp pointer to the @p TIMCAPDriver object + * + * @iclass + */ +#define timcapDisableI(timcapp) timcap_lld_disable(timcapp) + + + + +/** @} */ + +/** + * @name Low Level driver helper macros + * @{ + */ + + +/** + * @brief Common ISR code, TIMCAP channel 1 event. + * + * @param[in] timcapp pointer to the @p TIMCAPDriver object + * + * @notapi + */ +#define _timcap_isr_invoke_channel1_cb(timcapp) { \ + timcapstate_t previous_state = (timcapp)->state; \ + (timcapp)->state = TIMCAP_ACTIVE; \ + if (previous_state != TIMCAP_WAITING) \ + (timcapp)->config->capture_cb_array[0](timcapp); \ +} + +/** + * @brief Common ISR code, TIMCAP channel 2 event. + * + * @param[in] timcapp pointer to the @p TIMCAPDriver object + * + * @notapi + */ +#define _timcap_isr_invoke_channel2_cb(timcapp) { \ + timcapstate_t previous_state = (timcapp)->state; \ + (timcapp)->state = TIMCAP_ACTIVE; \ + if (previous_state != TIMCAP_WAITING) \ + (timcapp)->config->capture_cb_array[1](timcapp); \ +} + +/** + * @brief Common ISR code, TIMCAP channel 3 event. + * + * @param[in] timcapp pointer to the @p TIMCAPDriver object + * + * @notapi + */ +#define _timcap_isr_invoke_channel3_cb(timcapp) { \ + timcapstate_t previous_state = (timcapp)->state; \ + (timcapp)->state = TIMCAP_ACTIVE; \ + if (previous_state != TIMCAP_WAITING) \ + (timcapp)->config->capture_cb_array[2](timcapp); \ +} + +/** + * @brief Common ISR code, TIMCAP channel 4 event. + * + * @param[in] timcapp pointer to the @p TIMCAPDriver object + * + * @notapi + */ +#define _timcap_isr_invoke_channel4_cb(timcapp) { \ + timcapstate_t previous_state = (timcapp)->state; \ + (timcapp)->state = TIMCAP_ACTIVE; \ + if (previous_state != TIMCAP_WAITING) \ + (timcapp)->config->capture_cb_array[3](timcapp); \ +} + +/** + * @brief Common ISR code, TIMCAP timer overflow event. + * + * @param[in] timcapp pointer to the @p TIMCAPDriver object + * + * @notapi + */ +#define _timcap_isr_invoke_overflow_cb(timcapp) { \ + (timcapp)->config->overflow_cb(timcapp); \ +} +/** @} */ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + void timcapInit(void); + void timcapObjectInit(TIMCAPDriver *timcapp); + void timcapStart(TIMCAPDriver *timcapp, const TIMCAPConfig *config); + void timcapStop(TIMCAPDriver *timcapp); + void timcapEnable(TIMCAPDriver *timcapp); + void timcapDisable(TIMCAPDriver *timcapp); +#ifdef __cplusplus +} +#endif + +#endif /* HAL_USE_TIMCAP */ + +#endif /* _TIMCAP_H_ */ + +/** @} */ |