From 6b5ddb71fcb396ec826a283427b4771018d193e8 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 28 Feb 2011 18:44:46 +0000 Subject: GPT driver model, STM32 GPT driver implementation, not tested, documentation not done yet. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2779 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/gpt.c | 228 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 228 insertions(+) create mode 100644 os/hal/src/gpt.c (limited to 'os/hal/src/gpt.c') diff --git a/os/hal/src/gpt.c b/os/hal/src/gpt.c new file mode 100644 index 000000000..5027079cf --- /dev/null +++ b/os/hal/src/gpt.c @@ -0,0 +1,228 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 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 . +*/ + +/** + * @file gpt.c + * @brief GPT Driver code. + * + * @addtogroup GPT + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if HAL_USE_GPT || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief GPT Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. + * + * @init + */ +void gptInit(void) { + + gpt_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p GPTDriver structure. + * + * @param[out] gptp pointer to the @p GPTDriver object + * + * @init + */ +void gptObjectInit(GPTDriver *gptp) { + + gptp->state = GPT_STOP; + gptp->config = NULL; +} + +/** + * @brief Configures and activates the GPT peripheral. + * + * @param[in] gptp pointer to the @p GPTDriver object + * @param[in] config pointer to the @p GPTConfig object + * + * @api + */ +void gptStart(GPTDriver *gptp, const GPTConfig *config) { + + chDbgCheck((gptp != NULL) && (config != NULL), "ptStart"); + + chSysLock(); + chDbgAssert((gptp->state == GPT_STOP) || (gptp->state == GPT_READY), + "gptStart(), #1", "invalid state"); + gptp->config = config; + gpt_lld_start(gptp); + gptp->state = GPT_READY; + chSysUnlock(); +} + +/** + * @brief Deactivates the GPT peripheral. + * + * @param[in] gptp pointer to the @p GPTDriver object + * + * @api + */ +void gptStop(GPTDriver *gptp) { + + chDbgCheck(gptp != NULL, "gptStop"); + + chSysLock(); + chDbgAssert((gptp->state == GPT_STOP) || (gptp->state == GPT_READY), + "gptStop(), #1", "invalid state"); + gpt_lld_stop(gptp); + gptp->state = GPT_STOP; + chSysUnlock(); +} + +/** + * @brief Starts the timer in continuous mode. + * + * @param[in] gptp pointer to the @p GPTDriver object + * @param[in] interval period in ticks + * + * @api + */ +void gptStartContinuous(GPTDriver *gptp, gptcnt_t interval) { + + chSysLock(); + gptStartContinuousI(gptp, interval); + chSysUnlock(); +} + +/** + * @brief Starts the timer in continuous mode. + * + * @param[in] gptp pointer to the @p GPTDriver object + * @param[in] interval period in ticks + * + * @iclass + */ +void gptStartContinuousI(GPTDriver *gptp, gptcnt_t interval) { + + chDbgAssert(gptp->state == GPT_READY, + "gptStartContinuousI(), #1", "invalid state"); + gptp->state = GPT_CONTINUOUS; + gpt_lld_start_timer(gptp, interval); +} + +/** + * @brief Starts the timer in one shot mode. + * + * @param[in] gptp pointer to the @p GPTDriver object + * @param[in] interval time interval in ticks + * + * @api + */ +void gptStartOneShot(GPTDriver *gptp, gptcnt_t interval) { + + chSysLock(); + gptStartOneShotI(gptp, interval); + chSysUnlock(); +} + +/** + * @brief Starts the timer in one shot mode. + * + * @param[in] gptp pointer to the @p GPTDriver object + * @param[in] interval time interval in ticks + * + * @api + */ +void gptStartOneShotI(GPTDriver *gptp, gptcnt_t interval) { + + chDbgAssert(gptp->state == GPT_READY, + "gptStartOneShotI(), #1", "invalid state"); + gptp->state = GPT_ONESHOT; + gpt_lld_start_timer(gptp, interval); +} + +/** + * @brief Stops the timer. + * + * @param[in] gptp pointer to the @p GPTDriver object + * + * @api + */ +void gptStopTimer(GPTDriver *gptp) { + + chSysLock(); + gptStopTimerI(gptp); + chSysUnlock(); +} + +/** + * @brief Stops the timer. + * + * @param[in] gptp pointer to the @p GPTDriver object + * + * @api + */ +void gptStopTimerI(GPTDriver *gptp) { + + chDbgAssert((gptp->state == GPT_READY) || (gptp->state == GPT_CONTINUOUS) || + (gptp->state == GPT_ONESHOT), + "gptStopTimerI(), #1", "invalid state"); + gptp->state = GPT_READY; + gpt_lld_stop_timer(gptp); +} + +/** + * @brief Starts the timer in one shot mode and waits for completion. + * @details This function specifically polls the timer waiting for completion + * in order to not have extra delays caused by interrupt servicing, + * this function is only recommended for short delays. + * @note The configured callback is not invoked when using this function. + * + * @param[in] gptp pointer to the @p GPTDriver object + * @param[in] interval time interval in ticks + * + * @api + */ +void gptPolledDelay(GPTDriver *gptp, gptcnt_t interval) { + + chDbgAssert(gptp->state == GPT_READY, + "gptPolledDelay(), #1", "invalid state"); + gptp->state = GPT_ONESHOT; + gpt_lld_polled_delay(gptp, interval); +} + +#endif /* HAL_USE_GPT */ + +/** @} */ -- cgit v1.2.3 From e7e79a6ccb4f3e320b2b8b7bad1b14d65218641d Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 18 Mar 2011 18:38:08 +0000 Subject: License updated. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2827 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/gpt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'os/hal/src/gpt.c') diff --git a/os/hal/src/gpt.c b/os/hal/src/gpt.c index 5027079cf..e90a8911a 100644 --- a/os/hal/src/gpt.c +++ b/os/hal/src/gpt.c @@ -1,5 +1,6 @@ /* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3 From f23670b728189b4549091d355e38218b31c0a0ad Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 21 Aug 2011 13:19:48 +0000 Subject: Added I-class function checks to HAL APIs. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3244 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/gpt.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'os/hal/src/gpt.c') diff --git a/os/hal/src/gpt.c b/os/hal/src/gpt.c index e90a8911a..5f424453d 100644 --- a/os/hal/src/gpt.c +++ b/os/hal/src/gpt.c @@ -137,8 +137,11 @@ void gptStartContinuous(GPTDriver *gptp, gptcnt_t interval) { */ void gptStartContinuousI(GPTDriver *gptp, gptcnt_t interval) { + chDbgCheckClassI(); + chDbgCheck(gptp != NULL, "gptStartContinuousI"); chDbgAssert(gptp->state == GPT_READY, "gptStartContinuousI(), #1", "invalid state"); + gptp->state = GPT_CONTINUOUS; gpt_lld_start_timer(gptp, interval); } @@ -168,8 +171,11 @@ void gptStartOneShot(GPTDriver *gptp, gptcnt_t interval) { */ void gptStartOneShotI(GPTDriver *gptp, gptcnt_t interval) { + chDbgCheckClassI(); + chDbgCheck(gptp != NULL, "gptStartOneShotI"); chDbgAssert(gptp->state == GPT_READY, "gptStartOneShotI(), #1", "invalid state"); + gptp->state = GPT_ONESHOT; gpt_lld_start_timer(gptp, interval); } @@ -197,9 +203,12 @@ void gptStopTimer(GPTDriver *gptp) { */ void gptStopTimerI(GPTDriver *gptp) { + chDbgCheckClassI(); + chDbgCheck(gptp != NULL, "gptStopTimerI"); chDbgAssert((gptp->state == GPT_READY) || (gptp->state == GPT_CONTINUOUS) || (gptp->state == GPT_ONESHOT), "gptStopTimerI(), #1", "invalid state"); + gptp->state = GPT_READY; gpt_lld_stop_timer(gptp); } @@ -220,6 +229,7 @@ void gptPolledDelay(GPTDriver *gptp, gptcnt_t interval) { chDbgAssert(gptp->state == GPT_READY, "gptPolledDelay(), #1", "invalid state"); + gptp->state = GPT_ONESHOT; gpt_lld_polled_delay(gptp, interval); } -- cgit v1.2.3 From fe0093f795b6c88db8f12e2f7e45e11355fc3340 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 26 Aug 2011 13:47:22 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3254 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/gpt.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'os/hal/src/gpt.c') diff --git a/os/hal/src/gpt.c b/os/hal/src/gpt.c index 5f424453d..c677f5284 100644 --- a/os/hal/src/gpt.c +++ b/os/hal/src/gpt.c @@ -31,6 +31,10 @@ #if HAL_USE_GPT || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + /*===========================================================================*/ /* Driver exported variables. */ /*===========================================================================*/ -- cgit v1.2.3 From bae85ff69f0037ae22bb9bf1fada5762f7db4292 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 19 Sep 2011 12:54:13 +0000 Subject: Fixed problem in gptPolledDelay(). git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3350 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/gpt.c | 1 + 1 file changed, 1 insertion(+) (limited to 'os/hal/src/gpt.c') diff --git a/os/hal/src/gpt.c b/os/hal/src/gpt.c index c677f5284..726936ca8 100644 --- a/os/hal/src/gpt.c +++ b/os/hal/src/gpt.c @@ -236,6 +236,7 @@ void gptPolledDelay(GPTDriver *gptp, gptcnt_t interval) { gptp->state = GPT_ONESHOT; gpt_lld_polled_delay(gptp, interval); + gptp->state = GPT_READY; } #endif /* HAL_USE_GPT */ -- cgit v1.2.3 From de5dcbba856524599a8f06d3a9bdbf1b01db44c2 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 21 Jan 2012 14:29:42 +0000 Subject: License text updated with new year. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3846 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/gpt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src/gpt.c') diff --git a/os/hal/src/gpt.c b/os/hal/src/gpt.c index 726936ca8..a0745da93 100644 --- a/os/hal/src/gpt.c +++ b/os/hal/src/gpt.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3 From 184a71345c6a36a9a8664eda8fbcc3ea728267a8 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 2 Feb 2013 10:58:09 +0000 Subject: Updated license years. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5102 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/gpt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src/gpt.c') diff --git a/os/hal/src/gpt.c b/os/hal/src/gpt.c index a0745da93..a4baf7146 100644 --- a/os/hal/src/gpt.c +++ b/os/hal/src/gpt.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3 From 01f971ba1d63d8568789adf51cde22fb35f69e73 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 28 Feb 2013 16:23:19 +0000 Subject: Adjusted C file templates. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5339 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/gpt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src/gpt.c') diff --git a/os/hal/src/gpt.c b/os/hal/src/gpt.c index a4baf7146..48db68174 100644 --- a/os/hal/src/gpt.c +++ b/os/hal/src/gpt.c @@ -40,7 +40,7 @@ /*===========================================================================*/ /*===========================================================================*/ -/* Driver local variables. */ +/* Driver local variables and types. */ /*===========================================================================*/ /*===========================================================================*/ -- cgit v1.2.3 From f571b507132cc77e401dee68535c2b9f3370c60c Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 27 Mar 2013 20:03:40 +0000 Subject: STM32. GPT. Added abillity to change interval of running GPT unit on the fly. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5510 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/gpt.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'os/hal/src/gpt.c') diff --git a/os/hal/src/gpt.c b/os/hal/src/gpt.c index 48db68174..9b7c0d9a6 100644 --- a/os/hal/src/gpt.c +++ b/os/hal/src/gpt.c @@ -116,6 +116,30 @@ void gptStop(GPTDriver *gptp) { chSysUnlock(); } +/** + * @brief Changes the interval of GPT peripheral. + * @details This function changes the interval of a running GPT unit. + * @pre The GPT unit must have been activated using @p gptStart(). + * @pre The GPT unit must have been running in continuous mode using + * @p gptStartContinuous(). + * @post The GPT unit interval is changed to the new value. + * + * @param[in] gptp pointer to a @p GPTDriver object + * @param[in] interval new cycle time in timer ticks + * + * @api + */ +void stm32_gptChangeInterval(GPTDriver *gptp, gptcnt_t interval) { + + chDbgCheck(gptp != NULL, "gptChangeInterval"); + + chSysLock(); + chDbgAssert(gptp->state == GPT_CONTINUOUS, + "gptChangeInterval(), #1", "invalid state"); + stm32_gptChangeIntervalI(gptp, interval); + chSysUnlock(); +} + /** * @brief Starts the timer in continuous mode. * -- cgit v1.2.3 From 042c2ddba82250d60de4882ae7b0293666747d2d Mon Sep 17 00:00:00 2001 From: barthess Date: Fri, 29 Mar 2013 19:27:32 +0000 Subject: STM32. GPT. Removed prefix "stm32" from names of functions changing interval. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5518 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/gpt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src/gpt.c') diff --git a/os/hal/src/gpt.c b/os/hal/src/gpt.c index 9b7c0d9a6..e37e1a5d8 100644 --- a/os/hal/src/gpt.c +++ b/os/hal/src/gpt.c @@ -129,14 +129,14 @@ void gptStop(GPTDriver *gptp) { * * @api */ -void stm32_gptChangeInterval(GPTDriver *gptp, gptcnt_t interval) { +void gptChangeInterval(GPTDriver *gptp, gptcnt_t interval) { chDbgCheck(gptp != NULL, "gptChangeInterval"); chSysLock(); chDbgAssert(gptp->state == GPT_CONTINUOUS, "gptChangeInterval(), #1", "invalid state"); - stm32_gptChangeIntervalI(gptp, interval); + gptChangeIntervalI(gptp, interval); chSysUnlock(); } -- cgit v1.2.3