* 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.
- *
- * 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * This document contains proprietary information belonging to Czech
+ * Technical University in Prague. Passing on and copying of this
+ * document, and communication of its contents is not permitted
+ * without prior written authorization.
*
* 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
*
*/
#ifndef DOCGEN
#include "rpp/rpp.h"
-#include "hal/hal.h"
+#include "drv/digital_io_def.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
};
/**
*
* @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_set_output(DIO_PIN_NAME_VBAT1EN, 0) == 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_val(DIO_PIN_NAME_VBAT1EN, 1) == FAILURE) {
+ return -CMDERR_BADDIO;
+ }
for (j = 0; j < pwm; j++)
;
- hal_gpio_pin_set_value(desc, 0);
+ if (rpp_gio_set_val(DIO_PIN_NAME_VBAT1EN, 0) == FAILURE) {
+ return -CMDERR_BADDIO;
+ }
for (j = 0; j < VBATPWM_PERIOD - pwm; j++)
;
}
+ if (rpp_gio_set_val(DIO_PIN_NAME_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_val(DIO_PIN_NAME_VBAT1EN);
+ if (ret == FAILURE) {
+ return -CMDERR_BADDIO;
+ }
+ return ret;
}
/**
* @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_val(DIO_PIN_NAME_VBATEN, 1) == FAILURE) {
+ return -CMDERR_BADDIO;
+ }
+ ret = rpp_gio_get_val(DIO_PIN_NAME_VBATEN);
+ if (ret == FAILURE) {
+ return -CMDERR_BADDIO;
+ }
+ ret |= vbat1_pwm() << 1;
+ return cmd_opchar_replong(cmd_io, param, ret, 0, 0);
}
/**
* @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_val(DIO_PIN_NAME_VBAT1EN, 0) == FAILURE) {
+ return -CMDERR_BADDIO;
+ }
+ ret = rpp_gio_get_val(DIO_PIN_NAME_VBAT1EN);
+ if (ret == FAILURE) {
+ return -CMDERR_BADDIO;
+ }
+ if (rpp_gio_set_val(DIO_PIN_NAME_VBATEN, 0) == FAILURE) {
+ return -CMDERR_BADDIO;
+ }
+ ret = rpp_gio_get_val(DIO_PIN_NAME_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
};