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
This commit is contained in:
barthess 2013-03-27 20:03:40 +00:00
parent ee1eb36086
commit f571b50713
3 changed files with 58 additions and 0 deletions

View File

@ -76,6 +76,23 @@ typedef void (*gptcallback_t)(GPTDriver *gptp);
/* Driver macros. */
/*===========================================================================*/
/**
* @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
*
* @iclass
*/
#define stm32_gptChangeIntervalI(gptp, interval) { \
gpt_lld_change_interval(gptp, interval); \
}
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
@ -89,6 +106,7 @@ extern "C" {
void gptStop(GPTDriver *gptp);
void gptStartContinuous(GPTDriver *gptp, gptcnt_t interval);
void gptStartContinuousI(GPTDriver *gptp, gptcnt_t interval);
void stm32_gptChangeInterval(GPTDriver *gptp, gptcnt_t interval);
void gptStartOneShot(GPTDriver *gptp, gptcnt_t interval);
void gptStartOneShotI(GPTDriver *gptp, gptcnt_t interval);
void gptStopTimer(GPTDriver *gptp);

View File

@ -267,6 +267,22 @@ struct GPTDriver {
/* Driver macros. */
/*===========================================================================*/
/**
* @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.
* @note The function has effect at the next cycle start.
*
* @param[in] gptp pointer to a @p GPTDriver object
* @param[in] interval new cycle time in timer ticks
* @notapi
*/
#define gpt_lld_change_interval(gptp, interval) \
((gptp)->tim->ARR = (uint16_t)((interval) - 1))
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/

View File

@ -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.
*