2009-12-07 16:13:01 +00:00
|
|
|
/*
|
2013-03-30 10:32:37 +00:00
|
|
|
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
|
2009-12-07 16:13:01 +00:00
|
|
|
|
2013-03-30 10:32:37 +00:00
|
|
|
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
|
2009-12-07 16:13:01 +00:00
|
|
|
|
2013-03-30 10:32:37 +00:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2009-12-07 16:13:01 +00:00
|
|
|
|
2013-03-30 10:32:37 +00:00
|
|
|
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.
|
2009-12-07 16:13:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-02-07 11:11:45 +00:00
|
|
|
* @file templates/pwm_lld.c
|
|
|
|
* @brief PWM Driver subsystem low level driver source template.
|
|
|
|
*
|
2010-10-25 18:48:13 +00:00
|
|
|
* @addtogroup PWM
|
2009-12-07 16:13:01 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ch.h"
|
|
|
|
#include "hal.h"
|
|
|
|
|
2010-11-01 17:29:56 +00:00
|
|
|
#if HAL_USE_PWM || defined(__DOXYGEN__)
|
|
|
|
|
2011-08-26 13:47:22 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local definitions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-12-07 16:13:01 +00:00
|
|
|
/*===========================================================================*/
|
2009-12-29 11:12:05 +00:00
|
|
|
/* Driver exported variables. */
|
2009-12-07 16:13:01 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
/**
|
|
|
|
* @brief PWM1 driver identifier.
|
|
|
|
*/
|
|
|
|
#if PLATFORM_PWM_USE_PWM1 || defined(__DOXYGEN__)
|
|
|
|
PWMDriver PWMD1;
|
|
|
|
#endif
|
|
|
|
|
2009-12-07 16:13:01 +00:00
|
|
|
/*===========================================================================*/
|
2013-02-28 16:23:19 +00:00
|
|
|
/* Driver local variables and types. */
|
2009-12-07 16:13:01 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
2009-12-29 11:12:05 +00:00
|
|
|
/* Driver local functions. */
|
2009-12-07 16:13:01 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
2009-12-29 11:12:05 +00:00
|
|
|
/* Driver interrupt handlers. */
|
2009-12-07 16:13:01 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
2009-12-29 11:12:05 +00:00
|
|
|
/* Driver exported functions. */
|
2009-12-07 16:13:01 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
2010-02-07 11:11:45 +00:00
|
|
|
* @brief Low level PWM driver initialization.
|
2010-10-04 17:16:18 +00:00
|
|
|
*
|
|
|
|
* @notapi
|
2009-12-07 16:13:01 +00:00
|
|
|
*/
|
|
|
|
void pwm_lld_init(void) {
|
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
#if PLATFORM_PWM_USE_PWM1
|
|
|
|
/* Driver initialization.*/
|
|
|
|
pwmObjectInit(&PWMD1);
|
|
|
|
#endif /* PLATFORM_PWM_USE_PWM1 */
|
2009-12-07 16:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-02-07 11:11:45 +00:00
|
|
|
* @brief Configures and activates the PWM peripheral.
|
2009-12-07 16:13:01 +00:00
|
|
|
*
|
2010-02-07 11:11:45 +00:00
|
|
|
* @param[in] pwmp pointer to the @p PWMDriver object
|
2010-10-04 17:16:18 +00:00
|
|
|
*
|
|
|
|
* @notapi
|
2009-12-07 16:13:01 +00:00
|
|
|
*/
|
|
|
|
void pwm_lld_start(PWMDriver *pwmp) {
|
|
|
|
|
2011-03-08 10:09:57 +00:00
|
|
|
if (pwmp->state == PWM_STOP) {
|
2013-02-27 10:42:09 +00:00
|
|
|
/* Enables the peripheral.*/
|
2013-02-25 13:10:39 +00:00
|
|
|
#if PLATFORM_PWM_USE_PWM1
|
|
|
|
if (&PWMD1 == pwmp) {
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif /* PLATFORM_PWM_USE_PWM1 */
|
2009-12-07 16:13:01 +00:00
|
|
|
}
|
2013-02-25 13:10:39 +00:00
|
|
|
/* Configures the peripheral.*/
|
|
|
|
|
2009-12-07 16:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-02-07 11:11:45 +00:00
|
|
|
* @brief Deactivates the PWM peripheral.
|
2009-12-07 16:13:01 +00:00
|
|
|
*
|
2010-02-07 11:11:45 +00:00
|
|
|
* @param[in] pwmp pointer to the @p PWMDriver object
|
2010-10-04 17:16:18 +00:00
|
|
|
*
|
|
|
|
* @notapi
|
2009-12-07 16:13:01 +00:00
|
|
|
*/
|
|
|
|
void pwm_lld_stop(PWMDriver *pwmp) {
|
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
if (pwmp->state == PWM_READY) {
|
|
|
|
/* Resets the peripheral.*/
|
|
|
|
|
|
|
|
/* Disables the peripheral.*/
|
|
|
|
#if PLATFORM_PWM_USE_PWM1
|
|
|
|
if (&PWMD1 == pwmp) {
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif /* PLATFORM_PWM_USE_PWM1 */
|
|
|
|
}
|
2009-12-07 16:13:01 +00:00
|
|
|
}
|
|
|
|
|
2009-12-08 07:42:49 +00:00
|
|
|
/**
|
2011-03-31 10:21:52 +00:00
|
|
|
* @brief Changes the period the PWM peripheral.
|
|
|
|
* @details This function changes the period of a PWM unit that has already
|
|
|
|
* been activated using @p pwmStart().
|
|
|
|
* @pre The PWM unit must have been activated using @p pwmStart().
|
|
|
|
* @post The PWM unit period is changed to the new value.
|
2011-04-05 18:21:00 +00:00
|
|
|
* @note The function has effect at the next cycle start.
|
|
|
|
* @note If a period is specified that is shorter than the pulse width
|
|
|
|
* programmed in one of the channels then the behavior is not
|
|
|
|
* guaranteed.
|
2009-12-08 07:42:49 +00:00
|
|
|
*
|
2011-03-31 10:21:52 +00:00
|
|
|
* @param[in] pwmp pointer to a @p PWMDriver object
|
2011-04-01 13:14:47 +00:00
|
|
|
* @param[in] period new cycle time in ticks
|
2010-10-04 17:16:18 +00:00
|
|
|
*
|
2011-04-05 18:21:00 +00:00
|
|
|
* @notapi
|
2009-12-08 07:42:49 +00:00
|
|
|
*/
|
2011-03-31 10:21:52 +00:00
|
|
|
void pwm_lld_change_period(PWMDriver *pwmp, pwmcnt_t period) {
|
2009-12-08 07:42:49 +00:00
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
(void)pwmp;
|
|
|
|
(void)period;
|
|
|
|
|
2009-12-08 07:42:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-11-21 21:31:35 +00:00
|
|
|
* @brief Enables a PWM channel.
|
2011-03-31 10:21:52 +00:00
|
|
|
* @pre The PWM unit must have been activated using @p pwmStart().
|
|
|
|
* @post The channel is active using the specified configuration.
|
|
|
|
* @note Depending on the hardware implementation this function has
|
|
|
|
* effect starting on the next cycle (recommended implementation)
|
|
|
|
* or immediately (fallback implementation).
|
2009-12-08 07:42:49 +00:00
|
|
|
*
|
2010-11-21 13:45:22 +00:00
|
|
|
* @param[in] pwmp pointer to a @p PWMDriver object
|
|
|
|
* @param[in] channel PWM channel identifier (0...PWM_CHANNELS-1)
|
2010-11-21 21:31:35 +00:00
|
|
|
* @param[in] width PWM pulse width as clock pulses number
|
2010-10-04 17:16:18 +00:00
|
|
|
*
|
|
|
|
* @notapi
|
2009-12-08 07:42:49 +00:00
|
|
|
*/
|
2010-11-21 21:31:35 +00:00
|
|
|
void pwm_lld_enable_channel(PWMDriver *pwmp,
|
|
|
|
pwmchannel_t channel,
|
|
|
|
pwmcnt_t width) {
|
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
(void)pwmp;
|
|
|
|
(void)channel;
|
|
|
|
(void)width;
|
|
|
|
|
2010-11-21 21:31:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Disables a PWM channel.
|
2011-03-31 10:21:52 +00:00
|
|
|
* @pre The PWM unit must have been activated using @p pwmStart().
|
|
|
|
* @post The channel is disabled and its output line returned to the
|
2010-11-21 21:31:35 +00:00
|
|
|
* idle state.
|
2011-03-31 10:21:52 +00:00
|
|
|
* @note Depending on the hardware implementation this function has
|
|
|
|
* effect starting on the next cycle (recommended implementation)
|
|
|
|
* or immediately (fallback implementation).
|
2010-11-21 21:31:35 +00:00
|
|
|
*
|
|
|
|
* @param[in] pwmp pointer to a @p PWMDriver object
|
|
|
|
* @param[in] channel PWM channel identifier (0...PWM_CHANNELS-1)
|
2011-03-31 10:21:52 +00:00
|
|
|
*
|
|
|
|
* @notapi
|
2010-11-21 21:31:35 +00:00
|
|
|
*/
|
|
|
|
void pwm_lld_disable_channel(PWMDriver *pwmp, pwmchannel_t channel) {
|
2009-12-08 07:42:49 +00:00
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
(void)pwmp;
|
|
|
|
(void)channel;
|
|
|
|
|
2009-12-08 07:42:49 +00:00
|
|
|
}
|
|
|
|
|
2010-11-01 17:29:56 +00:00
|
|
|
#endif /* HAL_USE_PWM */
|
|
|
|
|
2009-12-07 16:13:01 +00:00
|
|
|
/** @} */
|