]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blobdiff - rpp-test-sw/commands/cmd_vbat.c
Change license to MIT
[pes-rpp/rpp-test-sw.git] / rpp-test-sw / commands / cmd_vbat.c
index e575a043e1665942cc99e9060b175be74e4285ab..339207bacba0d678b26a0ee706ae88cfe4ca7c64 100644 (file)
@@ -1,15 +1,31 @@
 /*
- * 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 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.
+ * 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:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * 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
  *
@@ -24,7 +40,6 @@
 #ifndef DOCGEN
 
 #include "rpp/rpp.h"
-#include "hal/hal.h"
 
 #define VBATPWM_PERIOD 400
 
@@ -51,25 +66,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_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++)))
                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++)
                                ;
                }
-       hal_gpio_pin_set_value(desc, 1);
+       if (rpp_gio_set(PIN_VBAT1EN, 1) == FAILURE) {
+               return -CMDERR_BADDIO;
+       }
        _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;
 }
 
 /**
@@ -84,8 +109,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(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);
 }
@@ -100,12 +130,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(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;
+       }
 
-       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);
 }