]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blobdiff - rpp-test-sw/commands/cmd_vbat.c
Update library
[pes-rpp/rpp-test-sw.git] / rpp-test-sw / commands / cmd_vbat.c
index 5f6b897ec7abac539ed5750d526c91a44896e53d..98dfa8b9cb1c9ba8b026e3ca8269fe6d6204a3eb 100644 (file)
@@ -6,18 +6,10 @@
  * 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
  *
@@ -32,7 +24,7 @@
 #ifndef DOCGEN
 
 #include "rpp/rpp.h"
-#include "hal/hal.h"
+#include "drv/digital_io_def.h"
 
 #define VBATPWM_PERIOD 400
 
@@ -59,25 +51,35 @@ int vbat1_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++)))
                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++)
                                ;
                }
-       hal_gpio_pin_set_value(desc, 1);
+       if (rpp_gio_set_val(DIO_PIN_NAME_VBAT1EN, 1) == FAILURE) {
+               return -CMDERR_BADDIO;
+       }
        _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;
 }
 
 /**
@@ -92,8 +94,13 @@ 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);
+       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);
 }
@@ -108,12 +115,24 @@ int cmd_do_power_on(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
  */
 int cmd_do_power_off(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 {
-       int ret = 0;
+       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;
+       }
 
-       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;
+       ret |= ret2 << 1;
        return cmd_opchar_replong(cmd_io, param, ret, 0, 0);
 }