]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blobdiff - rpp-test-sw/commands/cmd_port.c
Update library
[pes-rpp/rpp-test-sw.git] / rpp-test-sw / commands / cmd_port.c
index bbad320753b398492887b6fcebb17137adbd92a1..6cb8ab4441a8226f010c4e7387bfe10d686299e2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2013 Czech Technical University in Prague
+ * Copyright (C) 2012-2015 Czech Technical University in Prague
  *
  * Created on: 28.2.2013
  *
 
 #include "cmd_port.h"
 #include "stdio.h"
+#include "string.h"
 
 #ifndef DOCGEN
 
 #include "rpp/rpp.h"
-#include "hal/hal.h"
+#include "drv/digital_io_def.h"
 #include "cmdproc_utils.h"
 
 
@@ -35,19 +36,22 @@ int cmd_do_port_list(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
        char *portInterface;
 
        rpp_sci_printf("List of all defined ports with its type. Those names can be used by portval command.\r\n");
-       const port_def_t *ports = hal_port_get_definitions();
-
-       for (i = 0; i < PORT_CNT; i++) {
-               if (ports[i].name == PIN_NAME_UNUSED) continue;
-               if (ports[i].desc->interfaceType == PORT_INTERFACE_SPI)
+       uint32_t port_cnt = rpp_port_get_port_cnt();
+       const char* port_names[16];
+       rpp_port_get_port_names(port_names, port_cnt);
+
+       for (i = 0; i < port_cnt; i++) {
+               if (strcmp(port_names[i], DIO_PIN_NAME_UNUSED) == 0) continue;
+               int8_t port_interface = rpp_port_get_interface_type(port_names[i]);
+               if (port_interface == 2)
                        portInterface = "SPI";
-               else if (ports[i].desc->interfaceType == PORT_INTERFACE_GPIO)
+               else if (port_interface == 3)
                        portInterface = "GPIO";
-               else if (ports[i].desc->interfaceType == PORT_INTERFACE_ADC)
+               else if (port_interface == 1)
                        portInterface = "ADC";
                else
                        portInterface = "UNKNOWN";
-               rpp_sci_printf("%s, %s\r\n", ports[i].name, portInterface);
+               rpp_sci_printf("%s, %s\r\n", port_names[i], portInterface);
        }
        return 1;
 }
@@ -66,55 +70,55 @@ int cmd_do_port_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 {
        char *p;
        int i;
-       port_desc_t *desc;
-       uint32_t ret;
+       int32_t ret;
        uint32_t values[MAX_PARAM_VALUES_NUM];
        char portName[32];
        char *token;
        uint32_t numParams;
+       int32_t port_pin_cnt = rpp_port_get_pin_cnt(portName);
 
        p = param[1];
        if (sscanf(p, "%31s ", portName) != 1)
                return -CMDERR_BADPAR;
 
-       if ((desc = hal_port_get_dsc(portName, -1)) == NULL) return -CMDERR_BADREG;
+       int8_t port_interface = rpp_port_get_interface_type(portName);
+       if (port_interface == FAILURE) return -CMDERR_BADREG;
 
        if (param[2] != NULL) { // More parameters = set values
                p = param[2];
-               if (desc->port_setfnc_ptr == NULL)
+               if (port_interface == 3)
+                       // Information about pin values are encoded as hexadecimal 8b value
+                       numParams = port_pin_cnt/8+1;
+               else if (port_interface == 2)
+                       // Commands are passed as bytes
+                       numParams = port_pin_cnt;
+               else if (port_interface == 1)
+                       return -CMDERR_BADPAR;  // ADC is read only and no other port is supported
+               token = strtok(p, " ");
+               i = 0;
+               while (i < numParams && token != NULL) {
+                       if (sscanf(token, "%x", &values[i]) == EOF)
+                               break;
+                       token = strtok(NULL, " ");
+                       i++;
+               }
+
+               if (i != numParams || token != NULL)
+                       return -CMDERR_BADPAR;
+               ret = rpp_port_set_val(portName, port_pin_cnt, values);
+               if (ret == FAILURE) {
                        return -CMDERR_WRPERM;
-               else {
-                       if (desc->interfaceType == PORT_INTERFACE_GPIO)
-                               // Information about pin values are encoded as hexadecimal 8b value
-                               numParams = desc->numValues/8+1;
-                       else if (desc->interfaceType == PORT_INTERFACE_SPI)
-                               // Commands are passed as bytes
-                               numParams = desc->numValues;
-                       else if (desc->interfaceType == PORT_INTERFACE_ADC)
-                               return -CMDERR_BADPAR;  // ADC is read only and no other port is supported
-                       token = strtok(p, " ");
-                       i = 0;
-                       while (i < numParams && token != NULL) {
-                               if (sscanf(token, "%x", &values[i]) == EOF)
-                                       break;
-                               token = strtok(NULL, " ");
-                               i++;
-                       }
-
-                       if (i != numParams || token != NULL)
-                               return -CMDERR_BADPAR;
-                       ret = desc->port_setfnc_ptr(desc->config, desc->numValues, values);
                }
+
                return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
        }
        else {
-               if (desc->port_getfnc_ptr == NULL)
+               ret = rpp_port_get_val(portName, port_pin_cnt, values);
+               if (ret == FAILURE) {
                        return -CMDERR_RDPERM;
-               else {
-                       ret = desc->port_getfnc_ptr(desc->config, desc->numValues, values);
-                       for (i = 0; i < desc->numValues; i++) {
-                               rpp_sci_printf("%d\r\n", values[i]);
-                       }
+               }
+               for (i = 0; i < port_pin_cnt; i++) {
+                       rpp_sci_printf("%d\r\n", values[i]);
                }
                rpp_sci_printf("portval%s=%x\n", portName, ret);
                return 0;