From b24866225a6301d3a663f874725e83c012dc25d3 Mon Sep 17 00:00:00 2001 From: Florent Duchon Date: Wed, 26 Dec 2012 17:36:00 +0100 Subject: digital/beacon: add bitcloud stack into common directory digital/zigbit --- .../stack/Components/HAL/avr/common/src/pwm.c | 165 +++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 digital/zigbit/bitcloud/stack/Components/HAL/avr/common/src/pwm.c (limited to 'digital/zigbit/bitcloud/stack/Components/HAL/avr/common/src/pwm.c') diff --git a/digital/zigbit/bitcloud/stack/Components/HAL/avr/common/src/pwm.c b/digital/zigbit/bitcloud/stack/Components/HAL/avr/common/src/pwm.c new file mode 100644 index 00000000..ad7b18a2 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/HAL/avr/common/src/pwm.c @@ -0,0 +1,165 @@ +/**************************************************************************//** + \file pwm.c + + \brief Implementation of PWM interface. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 10/11/08 A. Taradov - Created + 5/04/11 A.Razinkov - Refactored +*******************************************************************************/ +/****************************************************************************** + * WARNING: CHANGING THIS FILE MAY AFFECT CORE FUNCTIONALITY OF THE STACK. * + * EXPERT USERS SHOULD PROCEED WITH CAUTION. * + ******************************************************************************/ + +/****************************************************************************** + Includes section +******************************************************************************/ +#include +#include + +/****************************************************************************** + Defines section +******************************************************************************/ + +/****************************************************************************** + Constants section +******************************************************************************/ + +/****************************************************************************** + Global variables section +******************************************************************************/ + +/****************************************************************************** + Implementations section +******************************************************************************/ + +/**************************************************************************//** +\brief Initializes the PWM. + +\param [in] pwmUnit - PWM unit number. + Equal to ID of Timer/Counter witch serves PWM module. + +\return operation status +******************************************************************************/ +int HAL_OpenPwm(HAL_PwmUnit_t pwmUnit) +{ + /* Check PWM unit */ + if ((PWM_UNIT_1 == pwmUnit) || (PWM_UNIT_3 == pwmUnit)) + halOpenPwm(pwmUnit); + else + return PWM_INVALID_UNIT_STATUS; + + return PWM_SUCCESS_STATUS; +} + +/**************************************************************************//** +\brief Starts PWM on specified channel. + +\param [in] descriptor - PWM channel descriptor. + +\return operation status +******************************************************************************/ +int HAL_StartPwm(HAL_PwmDescriptor_t *descriptor) +{ + /* Invalid PWM channel specified */ + if (PWM_INVALID_CHANNEL <= descriptor->channel) + return PWM_INVALID_CHANNEL_STATUS; + /* Check PWM unit */ + if ((PWM_UNIT_1 == descriptor->unit) || (PWM_UNIT_3 == descriptor->unit)) + { + halPreparePwmChannelAccess(descriptor); + halStartPwm(descriptor); + } + else + return PWM_INVALID_UNIT_STATUS; + + return PWM_SUCCESS_STATUS; +} + +/**************************************************************************//** +\brief Stops PWM on specified channel. + +\param [in] descriptor - PWM channel descriptor. + +\return operation status +******************************************************************************/ +int HAL_StopPwm(HAL_PwmDescriptor_t *descriptor) +{ + /* Invalid PWM channel specified */ + if (PWM_INVALID_CHANNEL <= descriptor->channel) + return PWM_INVALID_CHANNEL_STATUS; + else + halStopPwm(descriptor); + + return PWM_SUCCESS_STATUS; +} + +/**************************************************************************//** +\brief Sets base frequency of module. Common for all module channels. + +\param [in] pwmUnit - PWM unit number. Equal to corresponding Timer/Counter ID. +\param [in] top - value for the TOP register. +\param [in] prescaler - clock prescaler. + +\return operation status +******************************************************************************/ +int HAL_SetPwmFrequency(HAL_PwmUnit_t pwmUnit, uint16_t top, HAL_PwmPrescaler_t prescaler) +{ + /* Check prescaler value */ + if (PWM_PRESCALER_INVALID <= prescaler) + return PWM_INVALID_PRESCALER_STATUS; + else halSetPwmFrequency(pwmUnit, top, prescaler); + + return PWM_SUCCESS_STATUS; +} + +/**************************************************************************//** +\brief Sets compare value for the PWM channel. + +\param [in] descriptor - PWM channel descriptor. + +\return operation status +******************************************************************************/ +int HAL_SetPwmCompareValue(HAL_PwmDescriptor_t *descriptor, uint16_t cmpValue) +{ + /* Invalid PWM channel specified */ + if (PWM_INVALID_CHANNEL <= descriptor->channel) + return PWM_INVALID_CHANNEL_STATUS; + /* Check PWM unit */ + if ((PWM_UNIT_1 == descriptor->unit) || (PWM_UNIT_3 == descriptor->unit)) + halSetPwmCompareValue(descriptor, cmpValue); + else + return PWM_INVALID_UNIT_STATUS; + + return PWM_SUCCESS_STATUS; +} + +/**************************************************************************//** +\brief Closes the PWM. + +\param [in] pwmUnit - PWM unit number. + Equal to ID of Timer/Counter witch serves PWM module. + +\return operation status +******************************************************************************/ +int HAL_ClosePwm(HAL_PwmUnit_t pwmUnit) +{ + /* Check PWM unit */ + if ((PWM_UNIT_1 == pwmUnit) || (PWM_UNIT_3 == pwmUnit)) + halClosePwm(pwmUnit); + else + return PWM_INVALID_UNIT_STATUS; + + return PWM_SUCCESS_STATUS; +} + +// eof pwm.c -- cgit v1.2.3