X-Git-Url: http://rtime.felk.cvut.cz/gitweb/pes-rpp/rpp-test-sw.git/blobdiff_plain/9a505b7a1923b903d8b49fc96a2d8c57785dc742..9c52fa3be093456e383bb5fc96c7282ddae64b56:/rpp-test-sw/commands/cmd_vbat.c diff --git a/rpp-test-sw/commands/cmd_vbat.c b/rpp-test-sw/commands/cmd_vbat.c index 7695a8d..339207b 100644 --- a/rpp-test-sw/commands/cmd_vbat.c +++ b/rpp-test-sw/commands/cmd_vbat.c @@ -1,29 +1,37 @@ /* - * Copyright (C) 2012-2013 Czech Technical University in Prague + * Copyright (C) 2012-2013, 2015 Czech Technical University in Prague * * Created on: 28.2.2013 * * Authors: * - Michal Horn * - * This program 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 2 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: * - * This program 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. + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. * * File : cmd_vbat.c * * Abstract: - * Commands for VBAT control - * - Power VBAT1 on and off using PWM to charge capacitors + * Commands for VBAT control + * - Power VBAT1 on and off using PWM to charge capacitors * */ @@ -32,19 +40,18 @@ #ifndef DOCGEN #include "rpp/rpp.h" -#include "hal/hal.h" #define VBATPWM_PERIOD 400 /** Delay between set and clear vbat */ static int vbatPwmRampProfile[] = { - 19, - 20, - 21, - 23, - 27, - 30, - 0 + 19, + 20, + 21, + 23, + 27, + 30, + 0 }; /** @@ -52,32 +59,42 @@ static int vbatPwmRampProfile[] = { * * @return value on VBAT port */ -int vbat1_pwm() { +int vbat1_pwm() +{ int *ppwm = vbatPwmRampProfile; int pwm; volatile uint8_t val = 1; int i, j; int pulse_cnt = 100; - uint32_t desc; - desc = PIN_DSC_VBAT1EN; - hal_gpio_pin_set_value(desc, 0); - hal_gpio_pin_direction_output(desc, 0); + if (rpp_gio_setup(PIN_VBAT1EN, RPP_GIO_IN, RPP_GIO_MODE_PULLDIS, false) == FAILURE) { + return -CMDERR_BADDIO; + } + vTaskDelay(10/portTICK_RATE_MS+2); _disable_IRQ(); - while((pwm = *(ppwm++))) { + while ((pwm = *(ppwm++))) for (i = 0; i < pulse_cnt; i++) { - hal_gpio_pin_set_value(desc, 1); + if (rpp_gio_set(PIN_VBAT1EN, 1) == FAILURE) { + return -CMDERR_BADDIO; + } for (j = 0; j < pwm; j++) ; - hal_gpio_pin_set_value(desc, 0); + if (rpp_gio_set(PIN_VBAT1EN, 0) == FAILURE) { + return -CMDERR_BADDIO; + } for (j = 0; j < VBATPWM_PERIOD - pwm; j++) ; } + if (rpp_gio_set(PIN_VBAT1EN, 1) == FAILURE) { + return -CMDERR_BADDIO; } - hal_gpio_pin_set_value(desc, 1); _enable_IRQ(); - return hal_gpio_pin_get_value(desc); + int32_t ret = rpp_gio_get(PIN_VBAT1EN); + if (ret == FAILURE) { + return -CMDERR_BADDIO; + } + return ret; } /** @@ -88,12 +105,19 @@ int vbat1_pwm() { * @param[in] param Parameters of command * @return value on VBAT port */ -int cmd_do_power_on(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) { +int cmd_do_power_on(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) +{ int ret = 0; - hal_gpio_pin_set_value(PIN_DSC_VBATEN, 1); - ret = hal_gpio_pin_get_value(PIN_DSC_VBATEN); - ret |= vbat1_pwm() << 1; - return cmd_opchar_replong(cmd_io, param, ret, 0, 0); + + if (rpp_gio_set(PIN_VBATEN, 1) == FAILURE) { + return -CMDERR_BADDIO; + } + ret = rpp_gio_get(PIN_VBATEN); + if (ret == FAILURE) { + return -CMDERR_BADDIO; + } + ret |= vbat1_pwm() << 1; + return cmd_opchar_replong(cmd_io, param, ret, 0, 0); } /** @@ -104,61 +128,75 @@ int cmd_do_power_on(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) * @param[in] param Parameters of command * @return value on VBAT port */ -int cmd_do_power_off(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) { - int ret = 0; - hal_gpio_pin_set_value(PIN_DSC_VBAT1EN, 0); - ret = hal_gpio_pin_get_value(PIN_DSC_VBAT1EN); - hal_gpio_pin_set_value(PIN_DSC_VBATEN, 0); - ret |= hal_gpio_pin_get_value(PIN_DSC_VBATEN) << 1; - return cmd_opchar_replong(cmd_io, param, ret, 0, 0); +int cmd_do_power_off(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) +{ + int ret, ret2 = 0; + + if (rpp_gio_set(PIN_VBAT1EN, 0) == FAILURE) { + return -CMDERR_BADDIO; + } + ret = rpp_gio_get(PIN_VBAT1EN); + if (ret == FAILURE) { + return -CMDERR_BADDIO; + } + if (rpp_gio_set(PIN_VBATEN, 0) == FAILURE) { + return -CMDERR_BADDIO; + } + ret = rpp_gio_get(PIN_VBATEN); + if (ret == FAILURE) { + return -CMDERR_BADDIO; + } + + ret |= ret2 << 1; + return cmd_opchar_replong(cmd_io, param, ret, 0, 0); } -#endif /* DOCGEN */ +#endif /* DOCGEN */ /** Command descriptor for poweron */ cmd_des_t const cmd_des_power_on = { - 0, 0, - "poweron","Enable VBATEN and VBAT1EN power supply by using PWM hack", - "### Command syntax ###\n" - "\n" - " poweron\n" - "\n" - "### Description ###\n" - "\n" - "This command tries to work around error on VBAT power supply wiring\n" - "and attempts to switch the power supply on.\n" - "\n" - "It turns on the VBAT voltage by slowly charging the capacitors\n" - "connected to the VBAT1 signal by using the software-generated PWM\n" - "signal with increasing duty cycle.\n" - "\n" - "The poweron command has to be launched before any access to any SPI\n" - "peripherals, otherwise they will not work (or the power supply has to\n" - "be electrically bypassed).\n" - "\n" - "Please note that parameters for the PWM signal may change from device\n" - "to device and it might be necessary to tune them (in source code) for\n" - "each device.\n", - CMD_HANDLER(cmd_do_power_on), (void *)&cmd_list_vbat + 0, 0, + "poweron","Enable VBATEN and VBAT1EN power supply by using PWM hack", + "### Command syntax ###\n" + "\n" + " poweron\n" + "\n" + "### Description ###\n" + "\n" + "This command tries to work around error on VBAT power supply wiring\n" + "and attempts to switch the power supply on.\n" + "\n" + "It turns on the VBAT voltage by slowly charging the capacitors\n" + "connected to the VBAT1 signal by using the software-generated PWM\n" + "signal with increasing duty cycle.\n" + "\n" + "The poweron command has to be launched before any access to any SPI\n" + "peripherals, otherwise they will not work (or the power supply has to\n" + "be electrically bypassed).\n" + "\n" + "Please note that parameters for the PWM signal may change from device\n" + "to device and it might be necessary to tune them (in source code) for\n" + "each device.\n", + CMD_HANDLER(cmd_do_power_on), (void *)&cmd_list_vbat }; /** Command descriptor for poweroff */ cmd_des_t const cmd_des_power_off = { - 0, 0, - "poweroff","Disables VBATEN and VBAT1EN power supply", - "### Command syntax ###\n" - "\n" - " poweroff\n" - "\n" - "### Description ###\n" - "\n" - "This command turns off VBAT and VBAT1 voltages.\n", - CMD_HANDLER(cmd_do_power_off), (void *)&cmd_list_vbat + 0, 0, + "poweroff","Disables VBATEN and VBAT1EN power supply", + "### Command syntax ###\n" + "\n" + " poweroff\n" + "\n" + "### Description ###\n" + "\n" + "This command turns off VBAT and VBAT1 voltages.\n", + CMD_HANDLER(cmd_do_power_off), (void *)&cmd_list_vbat }; /** List of commands for vbat, defined as external */ -cmd_des_t const *cmd_list_vbat[]={ - &cmd_des_power_on, - &cmd_des_power_off, - NULL +cmd_des_t const *cmd_list_vbat[] = { + &cmd_des_power_on, + &cmd_des_power_off, + NULL };