ChibiOS/RT Architecture - Reference Manual - Guides |
00001 /* 00002 ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. 00003 00004 This file is part of ChibiOS/RT. 00005 00006 ChibiOS/RT is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 ChibiOS/RT is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 00019 --- 00020 00021 A special exception to the GPL can be applied should you wish to distribute 00022 a combined work that includes ChibiOS/RT, without being obliged to provide 00023 the source code for any proprietary components. See the file exception.txt 00024 for full details of how and when the exception can be applied. 00025 */ 00026 00027 /** 00028 * @file pwm.c 00029 * @brief PWM Driver code. 00030 * @addtogroup PWM 00031 * @{ 00032 */ 00033 00034 #include "ch.h" 00035 #include "hal.h" 00036 00037 #if CH_HAL_USE_PWM || defined(__DOXYGEN__) 00038 00039 /*===========================================================================*/ 00040 /* Driver exported variables. */ 00041 /*===========================================================================*/ 00042 00043 /*===========================================================================*/ 00044 /* Driver local variables. */ 00045 /*===========================================================================*/ 00046 00047 /*===========================================================================*/ 00048 /* Driver local functions. */ 00049 /*===========================================================================*/ 00050 00051 /*===========================================================================*/ 00052 /* Driver exported functions. */ 00053 /*===========================================================================*/ 00054 00055 /** 00056 * @brief PWM Driver initialization. 00057 */ 00058 void pwmInit(void) { 00059 00060 pwm_lld_init(); 00061 } 00062 00063 /** 00064 * @brief Initializes the standard part of a @p PWMDriver structure. 00065 * 00066 * @param[in] pwmp pointer to a @p PWMDriver object 00067 */ 00068 void pwmObjectInit(PWMDriver *pwmp) { 00069 00070 pwmp->pd_state = PWM_STOP; 00071 pwmp->pd_config = NULL; 00072 } 00073 00074 /** 00075 * @brief Configures and activates the PWM peripheral. 00076 * 00077 * @param[in] pwmp pointer to a @p PWMDriver object 00078 * @param[in] config pointer to a @p PWMConfig object 00079 */ 00080 void pwmStart(PWMDriver *pwmp, const PWMConfig *config) { 00081 00082 chDbgCheck((pwmp != NULL) && (config != NULL), "pwmStart"); 00083 00084 chSysLock(); 00085 chDbgAssert((pwmp->pd_state == PWM_STOP) || (pwmp->pd_state == PWM_READY), 00086 "pwmStart(), #1", 00087 "invalid state"); 00088 pwmp->pd_config = config; 00089 pwm_lld_start(pwmp); 00090 pwmp->pd_state = PWM_READY; 00091 chSysUnlock(); 00092 } 00093 00094 /** 00095 * @brief Deactivates the PWM peripheral. 00096 * 00097 * @param[in] pwmp pointer to a @p PWMDriver object 00098 */ 00099 void pwmStop(PWMDriver *pwmp) { 00100 00101 chDbgCheck(pwmp != NULL, "pwmStop"); 00102 00103 chSysLock(); 00104 chDbgAssert((pwmp->pd_state == PWM_STOP) || (pwmp->pd_state == PWM_READY), 00105 "pwmStop(), #1", 00106 "invalid state"); 00107 pwm_lld_stop(pwmp); 00108 pwmp->pd_state = PWM_STOP; 00109 chSysUnlock(); 00110 } 00111 00112 /** 00113 * @brief Enables a PWM channel. 00114 * 00115 * @param[in] pwmp pointer to a @p PWMDriver object 00116 * @param[in] channel PWM channel identifier 00117 * @param[in] width PWM pulse width as clock pulses number 00118 */ 00119 void pwmEnableChannel(PWMDriver *pwmp, 00120 pwmchannel_t channel, 00121 pwmcnt_t width) { 00122 00123 chDbgCheck((pwmp != NULL) && (channel < PWM_CHANNELS), 00124 "pwmEnableChannel"); 00125 00126 chSysLock(); 00127 chDbgAssert(pwmp->pd_state == PWM_READY, 00128 "pwmEnableChannel(), #1", "invalid state"); 00129 pwm_lld_enable_channel(pwmp, channel, width); 00130 chSysUnlock(); 00131 } 00132 00133 /** 00134 * @brief Disables a PWM channel. 00135 * @details The channel is disabled and its output line returned to the 00136 * idle state. 00137 * 00138 * @param[in] pwmp pointer to a @p PWMDriver object 00139 * @param[in] channel PWM channel identifier 00140 */ 00141 void pwmDisableChannel(PWMDriver *pwmp, pwmchannel_t channel) { 00142 00143 chDbgCheck((pwmp != NULL) && (channel < PWM_CHANNELS), 00144 "pwmEnableChannel"); 00145 00146 chSysLock(); 00147 chDbgAssert(pwmp->pd_state == PWM_READY, 00148 "pwmDisableChannel(), #1", "invalid state"); 00149 pwm_lld_disable_channel(pwmp, channel); 00150 chSysUnlock(); 00151 } 00152 00153 #endif /* CH_HAL_USE_PWM */ 00154 00155 /** @} */