]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/commitdiff
Update to the reworked gio and port in the rpp-lib
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 26 Jul 2015 21:31:19 +0000 (23:31 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 7 Aug 2015 18:02:31 +0000 (20:02 +0200)
Also simplify spi_resp_transl.

13 files changed:
rpp-lib
rpp-test-sw/commands/cmd.c
rpp-test-sw/commands/cmd_adc.c
rpp-test-sw/commands/cmd_fray.c
rpp-test-sw/commands/cmd_hout.c
rpp-test-sw/commands/cmd_lin.c
rpp-test-sw/commands/cmd_motor_example.c
rpp-test-sw/commands/cmd_pin.c
rpp-test-sw/commands/cmd_port.c
rpp-test-sw/commands/cmd_spi.c
rpp-test-sw/commands/cmd_vbat.c
rpp-test-sw/commands/spi_resp_transl.c
rpp-test-sw/commands/spi_resp_transl.h

diff --git a/rpp-lib b/rpp-lib
index 7f527b541985dafbfdf9c0119f16dc12ed6c5c61..a51911e6286f0aa67562634cab9db68620e7cc89 160000 (submodule)
--- a/rpp-lib
+++ b/rpp-lib
@@ -1 +1 @@
-Subproject commit 7f527b541985dafbfdf9c0119f16dc12ed6c5c61
+Subproject commit a51911e6286f0aa67562634cab9db68620e7cc89
index 6a8e89fa920a82d3a1abf4759b8e55775e5334f7..8326d5b97caace3556da35771ea77449ffea8ded 100644 (file)
@@ -48,8 +48,6 @@
 #ifndef DOCGEN
 
 #include "rpp/rpp.h"
-#include "drv/digital_io_def.h"
-
 
 #include <version.h>
 
@@ -68,14 +66,14 @@ cmd_des_t const **cmd_list;
 int cmd_do_sleep(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 {
 #ifndef DOCGEN
-       if (rpp_gio_set_val(DIO_PIN_NAME_CANNSTB, 1) == FAILURE) return -CMDERR_BADDIO;
-       if (rpp_gio_set_val(DIO_PIN_NAME_CANEN, 1) == FAILURE) return -CMDERR_BADDIO;
-       if (rpp_gio_set_val(DIO_PIN_NAME_LIN2NSLP, 1) == FAILURE) return -CMDERR_BADDIO;
-       if (rpp_gio_set_val(DIO_PIN_NAME_LIN1NSLP, 1) == FAILURE) return -CMDERR_BADDIO;
+       if (rpp_gio_set(PIN_CANNSTB, 1) == FAILURE) return -CMDERR_BADDIO;
+       if (rpp_gio_set(PIN_CANEN, 1) == FAILURE) return -CMDERR_BADDIO;
+       if (rpp_gio_set(PIN_LIN2NSLP, 1) == FAILURE) return -CMDERR_BADDIO;
+       if (rpp_gio_set(PIN_LIN1NSLP, 1) == FAILURE) return -CMDERR_BADDIO;
        vTaskDelay(10/portTICK_RATE_MS);
-       if (rpp_gio_set_val(DIO_PIN_NAME_LIN2NSLP, 0) == FAILURE) return -CMDERR_BADDIO;
-       if (rpp_gio_set_val(DIO_PIN_NAME_LIN1NSLP, 0) == FAILURE) return -CMDERR_BADDIO;
-       if (rpp_gio_set_val(DIO_PIN_NAME_CANNSTB, 0) == FAILURE) return -CMDERR_BADDIO;
+       if (rpp_gio_set(PIN_LIN2NSLP, 0) == FAILURE) return -CMDERR_BADDIO;
+       if (rpp_gio_set(PIN_LIN1NSLP, 0) == FAILURE) return -CMDERR_BADDIO;
+       if (rpp_gio_set(PIN_CANNSTB, 0) == FAILURE) return -CMDERR_BADDIO;
 #endif
        return 0;
 }
index 333d37399271d5dfa84b7ebb5ed5f67be0e1b793..5c88ff6c029f104b4df39ae73a87e5df55076d83 100644 (file)
@@ -22,9 +22,9 @@
 
 #ifndef DOCGEN
 
-#include "drv/digital_io_def.h"
 #include "rpp/rpp.h"
 #include <stdio.h>
+#include "drv/port.h"
 
 static double lsb2volts(unsigned lsb)
 {
@@ -54,7 +54,7 @@ int cmd_do_read_adc1_values(cmd_io_t *cmd_io, const struct cmd_des *des, char *p
        }
        else {              /* All pins */
                min = 0;
-               max = rpp_port_get_pin_cnt(DIO_PORT_NAME_ADC)-1;
+               max = port_desc[PORT_ID_ADC].numchn - 1;
        }
        for (i = min; i <= max; i++) {
                unsigned d = rpp_adc_get(i+1);
index 1bbf55629c087d7ff4c474a3b934898f9bc81601..27a455e7f2cf5027633e70530ff0967eab79c7fd 100644 (file)
@@ -31,9 +31,9 @@
 
 #ifndef DOCGEN
 
+#include "drv/port_def.h"
 #include "rpp/rpp.h"
 #include "cmdproc_utils.h"
-#include "drv/digital_io_def.h"
 #include "cmdproc.h"
 #include "spi_resp_transl.h"
 
@@ -306,9 +306,6 @@ int cmd_do_fray_status(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[
 {
        char *p;
        int pin;
-       uint32_t numCmdDesc;
-       int i;
-       uint32_t numFieldDesc;
 
        p = param[1];
        if (sscanf(p, "%d", &pin) != 1)
@@ -318,19 +315,14 @@ int cmd_do_fray_status(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[
 
        if (Fr_spi_transfer(pin) != 0) return -CMDERR_BADDIO;
 
-       spitr_reg_translate_table_t translatedData;
-       const spitr_cmd_map_t *cmdDesc = get_spi_cmd_map(DIO_PORT_NAME_FRAY1, -1, &numCmdDesc);
-       if (cmdDesc == NULL) return -CMDERR_BADREG;
-
-       const spitr_field_desc_t *fieldDescs = get_spi_field_desc(cmdDesc, numCmdDesc, Fr_spi_get_cmd(pin), &numFieldDesc);
-       if (fieldDescs == NULL)
+       const spitr_cmd_desc_t *cmd_desc = get_spi_cmd_desc(&spitr_port_cmds[PORT_ID_FRAY1],
+                                                                                                               Fr_spi_get_cmd(pin));
+       if (cmd_desc == NULL)
                return -CMDERR_BADPAR;
        uint32_t fr_spi_response = Fr_spi_response(pin);
        uint32_t lsbResponse = 0 | ((fr_spi_response & 0xFF) << 8) | ((fr_spi_response & 0xFF00) >> 8);
-       spitr_fill_tr_table(fieldDescs, numFieldDesc, lsbResponse, &translatedData);
-       for (i = 0; i < translatedData.num_rows; i++) {
-               rpp_sci_printf("%s: %x\r\n", translatedData.row[i].field_name, translatedData.row[i].value);
-       }
+
+       spitr_print_resp(cmd_desc, lsbResponse);
        return 0;
 }
 
index cf19029c8d01a52da4ee7ff0e4eb836550d768e4..be5bf4bdb65efd849f7e086691f526dd58237809 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2013 Czech Technical University in Prague
+ * Copyright (C) 2012-2013, 2015 Czech Technical University in Prague
  *
  * Created on: 28.2.2013
  *
@@ -26,7 +26,7 @@
 #include "rpp/rpp.h"
 /* FIXME: remove hout.h */
 #include "drv/hout.h"
-#include "drv/digital_io_def.h"
+#include "drv/port.h"                  /* TODO: Use rpp/port.h */
 #include "cmdproc_utils.h"
 
 
  */
 int cmd_do_read_hout_ifbk_values(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 {
-       uint32_t i;                     // Cycle control variable
-       uint32_t port_num_values = rpp_port_get_pin_cnt(DIO_PORT_NAME_HOUTIFBK);
-       uint32_t values[port_num_values*2];
+       uint32_t i;
+       const struct port_desc *port = &port_desc[PORT_ID_HOUTIFBK];
+       uint16_t values[port->numchn];
        int ret;
 
 
-       ret = rpp_port_get_val(DIO_PORT_NAME_HOUTIFBK, port_num_values, values);
+       ret = port->get(port, values, sizeof(values));
        if (ret < 0)
                return ret;
 
-       for (i = 0; i < port_num_values; i++) {
+       for (i = 0; i < port->numchn; i++) {
                rpp_sci_printf("HOUT%d: %d\n", i+1, values[i]);
        }
        return 0;
index ec8ad32f355508226f00025fb1b6be15a41c103f..661b62e29239db862c98362d242566f68a1417bf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2013 Czech Technical University in Prague
+ * Copyright (C) 2012-2013, 2015 Czech Technical University in Prague
  *
  * Created on: 28.2.2013
  *
@@ -25,7 +25,6 @@
 
 #include "rpp/rpp.h"
 #include "sys/sys.h"
-#include "drv/digital_io_def.h"
 
 /** Semaphore used to stop command, until message is received */
 extern xSemaphoreHandle linMsgReceived;
@@ -48,7 +47,7 @@ int cmd_do_lin_loop_back(cmd_io_t *cmd_io, const struct cmd_des *des, char *para
        uint8_t rxID = 0;
 
        linEnableLoopback(linREG, Digital);
-       rpp_gio_set_val(DIO_PIN_NAME_LIN1NSLP, 1);
+       rpp_gio_set(PIN_LIN1NSLP, 1);
        linIDReceived = xSemaphoreCreateCounting(1, 0);
        linMsgReceived = xSemaphoreCreateCounting(1, 0);
 
@@ -77,7 +76,7 @@ int cmd_do_lin_loop_back(cmd_io_t *cmd_io, const struct cmd_des *des, char *para
                rpp_sci_printf("FAILED: Sent and Received ID does not match.");
        vSemaphoreDelete(linIDReceived);
        vSemaphoreDelete(linMsgReceived);
-       rpp_gio_set_val(DIO_PIN_NAME_LIN1NSLP, 0);
+       rpp_gio_set(PIN_LIN1NSLP, 0);
        return 0;
 }
 
index 1c6a9e2c24e778feac0608542395cbbd37d7c011..703f3b62f62d23d7499b18798d4954d835fd3b3a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2013 Czech Technical University in Prague
+ * Copyright (C) 2012-2013, 2015 Czech Technical University in Prague
  *
  * Created on: 16.5.2013
  *
@@ -25,8 +25,8 @@
 #ifndef DOCGEN
 
 #include "rpp/rpp.h"
-#include "drv/digital_io_def.h"
 #include "cmdproc.h"
+#include "drv/port.h"
 
 #define ADC_MAX_VALUE 0x0983
 #define RX_ERROR_MAX 100
@@ -319,8 +319,6 @@ int receive_control_data(int *enable, int *direction, int *duty)
  */
 int cmd_do_control(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 {
-       uint32_t adc_num_values = rpp_port_get_pin_cnt(DIO_PORT_NAME_ADC);
-       uint32_t adc_values[adc_num_values*2];
        int ret;
        int duty = 0;
        int button = 0;
@@ -366,8 +364,11 @@ int cmd_do_control(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
        rpp_sci_printf("Connected.\r\n");
 
        while (1) {
+               const struct port_desc *port = &port_desc[PORT_ID_ADC];
+               uint16_t adc_values[port->numchn];
                vTaskDelay(10/portTICK_RATE_MS);
-               ret = rpp_port_get_val(DIO_PORT_NAME_ADC, adc_num_values, adc_values);
+
+               ret = port->get(port, adc_values, sizeof(adc_values));
                if (ret < 0) {
                        rpp_sci_printf("ADC read failed!\n");
                        break;
index 71ee438206c6fe2ae75754ec51ff1024b7120895..ad2081b73c86572824127b10f3237ed7fea1009a 100644 (file)
@@ -27,7 +27,7 @@
 #ifndef DOCGEN
 
 #include "rpp/rpp.h"
-#include "drv/digital_io_def.h"
+#include "drv/gio_tab.h"
 #include "cmdproc_utils.h"
 
 /**
@@ -43,17 +43,21 @@ int cmd_do_pin_list(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
        uint32_t i;
 
        rpp_sci_printf("List of all defined pins. Those names can be used by pinval command.\r\n");
-       uint32_t pin_cnt = rpp_gio_get_pin_cnt();
-       const char* pin_names[128];
-       rpp_gio_get_pin_names(pin_names, pin_cnt);
-       for (i = 0; i < pin_cnt; i++) {
-               if (strcmp(pin_names[i], DIO_PIN_NAME_UNUSED) == 0) continue;
-               rpp_sci_printf(pin_names[i]);
-               rpp_sci_printf("\r\n");
-       }
+       for (i = 0; i < ARRAY_SIZE(gio_table); i++)
+               rpp_sci_printf("%s\r\n", gio_table[i].pin_name);
        return 1;
 }
 
+static enum pin_name pin_from_name(const char *pin_name)
+{
+       uint32_t i;
+
+       for (i = 0; i < ARRAY_SIZE(gio_table); i++)
+               if (strcmp(pin_name, gio_table[i].pin_name) == 0)
+                       return (enum pin_name)i;
+       return _PIN_INVALID;
+}
+
 /**
  * @brief      Set or get pin value
  *
@@ -73,6 +77,9 @@ int cmd_do_pin_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
        if (sscanf(p, "%31s ", pinName) != 1)
                return -CMDERR_BADPAR;
 
+       enum pin_name pin = pin_from_name(pinName);
+       if (pin == _PIN_INVALID)
+               return -CMDERR_BADPAR;
 
        if (param[2] != NULL) {     // More parameters = set values
                p = param[2];
@@ -80,13 +87,13 @@ int cmd_do_pin_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
                        return -CMDERR_BADPAR;
                if (val != 0 && val != 1)
                        return -CMDERR_BADPAR;
-               if (rpp_gio_set_val(pinName, val) == FAILURE) {
+               if (rpp_gio_set(pin, val) == FAILURE) {
                        return -CMDERR_BADPAR;;
                }
                return cmd_opchar_replong(cmd_io, param, val, 0, 0);
        }
        else {  // No more parameters = get values
-               int32_t pin_value = rpp_gio_get_val(pinName);
+               int pin_value = rpp_gio_get(pin);
                if (pin_value == FAILURE) {
                        return -CMDERR_BADPAR;
                }
@@ -114,32 +121,29 @@ int cmd_do_pin_dir(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
        if (sscanf(p, "%31s ", pinName) != 1)
                return -CMDERR_BADPAR;
 
+       enum pin_name pin = pin_from_name(pinName);
+       if (pin == _PIN_INVALID)
+               return -CMDERR_BADPAR;
+
        if (param[2] != NULL) {     // More parameters = set values
                p = param[2];
                if (sscanf(p, "%u %1s", &val, &spareParams) != 1)
                        return -CMDERR_BADPAR;
-               if (val == 0) {
-                       if (rpp_gio_set_input(pinName) == FAILURE) {
-                               return -CMDERR_BADPAR;
-                       }
-               }
-               else if (val == 1) {
-                       if (rpp_gio_set_output(pinName, 0) == FAILURE) {
-                               return -CMDERR_BADPAR;
-                       }
-               }
-               else {
-                       return -CMDERR_BADPAR;
-               }
+               uint32_t pin_dsc = gio_table[pin].pin_dsc;
+
+               pin_dsc &= ~GIO_PIN_CONF_DIR_MASK;
+               pin_dsc |= val ? GIO_PIN_CONF_DIR_OUT : GIO_PIN_CONF_DIR_IN;
+
+               gio_setup(pin_dsc);
 
                return cmd_opchar_replong(cmd_io, param, val, 0, 0);
        }
        else {  // No more parameters = get values
-               int32_t pin_dir = rpp_gio_is_dir_output(pinName);
-               if (pin_dir == FAILURE) {
-                       return -CMDERR_BADPAR;
-               }
-               rpp_sci_printf("pindir%s=%d\n", pinName, pin_dir);
+               int32_t pin_dir = 0/* rpp_gio_is_dir_output(pinName) */;
+/*             if (pin_dir == FAILURE) { */
+/*                     return -CMDERR_BADPAR; */
+/*             } */
+               rpp_sci_printf("pindir%s=%d FIXME not implemented\n", pinName, pin_dir);
                return 0;
        }
 }
index 6cb8ab4441a8226f010c4e7387bfe10d686299e2..eb7c02ced97ea41a7a10a3c1be854af2ccfbfa93 100644 (file)
 #ifndef DOCGEN
 
 #include "rpp/rpp.h"
-#include "drv/digital_io_def.h"
+#include "drv/port.h"
+#ifdef TARGET_HAS_SPI
+#include "drv/spi.h"
+#endif
 #include "cmdproc_utils.h"
 
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
 
 int cmd_do_port_list(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 {
        uint32_t i;
-       char *portInterface;
 
        rpp_sci_printf("List of all defined ports with its type. Those names can be used by portval command.\r\n");
-       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 (port_interface == 3)
-                       portInterface = "GPIO";
-               else if (port_interface == 1)
-                       portInterface = "ADC";
-               else
-                       portInterface = "UNKNOWN";
-               rpp_sci_printf("%s, %s\r\n", port_names[i], portInterface);
+
+       for (i = 0; i < ARRAY_SIZE(port_desc); i++) {
+               const struct port_desc *port = &port_desc[i];
+               const char *type = "";
+#ifdef TARGET_HAS_SPI
+               if (port->set == port_spi_set)
+                       type = "SPI";
+#endif
+               rpp_sci_printf("%s %dx%db%s%s%s\r\n",
+                                          port->name, port->numchn, port->bpch,
+                                          *type ? " (": "",
+                                          type,
+                                          *type ? ")" : "");
        }
        return 1;
 }
 
+static const struct port_desc *port_from_name(const char *port_name)
+{
+       uint32_t i;
 
+       for (i = 0; i < ARRAY_SIZE(port_desc); i++)
+               if (strcmp(port_name, port_desc[i].name) == 0)
+                       return &port_desc[i];
+       return NULL;
+}
 
 /**
  * @brief      Read values from specified port
@@ -68,59 +76,108 @@ int cmd_do_port_list(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
  */
 int cmd_do_port_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 {
-       char *p;
-       int i;
        int32_t ret;
-       uint32_t values[MAX_PARAM_VALUES_NUM];
+       int i;
        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)
+       if (sscanf(param[1], "%31s ", portName) != 1)
                return -CMDERR_BADPAR;
 
-       int8_t port_interface = rpp_port_get_interface_type(portName);
-       if (port_interface == FAILURE) return -CMDERR_BADREG;
+       const struct port_desc *port = port_from_name(portName);
+       if (!port)
+               return -CMDERR_BADPAR;
 
        if (param[2] != NULL) { // More parameters = set values
-               p = param[2];
-               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) {
+               if (!port->set)
                        return -CMDERR_WRPERM;
-               }
 
-               return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
-       }
-       else {
-               ret = rpp_port_get_val(portName, port_pin_cnt, values);
-               if (ret == FAILURE) {
+               switch (port->bpch) {
+               case 1:
+               case 32:
+               {
+                       uint32_t value;
+                       ret = sscanf(param[2], "%i", &value);
+                       if (ret == EOF || ret == 0)
+                               return -CMDERR_BADPAR;
+
+                       ret = port->set(port, &value, sizeof(value));
+                       if (ret == FAILURE)
+                               return -CMDERR_WRPERM;
+                       return cmd_opchar_replong(cmd_io, param, value, 0, 16);
+               }
+               case 8: {
+                       uint8_t values[16] = {0};
+                       if (port->numchn > ARRAY_SIZE(values))
+                               return -CMDERR_BADCFG;
+                       for (i = 0; i < port->numchn; i++) {
+                               ret = sscanf(param[2+i], "%hhi", &values[i]);
+                               if (ret == EOF || ret == 0)
+                                       break;
+                       }
+                       ret = port->set(port, &values, sizeof(values));
+                       if (ret == FAILURE)
+                               return -CMDERR_WRPERM;
+                       return cmd_opchar_replong(cmd_io, param, values[0], 0, 16);
+               }
+               case 16: {
+                       uint16_t values[16] = {0};
+                       if (port->numchn > ARRAY_SIZE(values))
+                               return -CMDERR_BADCFG;
+                       for (i = 0; i < port->numchn; i++) {
+                               ret = sscanf(param[2+i], "%hi", &values[i]);
+                               if (ret == EOF || ret == 0)
+                                       break;
+                       }
+                       ret = port->set(port, &values, sizeof(values));
+                       if (ret == FAILURE)
+                               return -CMDERR_WRPERM;
+                       return cmd_opchar_replong(cmd_io, param, values[0], 0, 16);
+               }
+               default:
+                       rpp_sci_printf("Unsupported bits-per-channel value: %d\n", port->bpch);
+                       return -CMDERR_NODEV;
+               }
+       } else { /* Get values from port */
+               if (!port->get)
                        return -CMDERR_RDPERM;
+
+               switch (port->bpch) {
+               case 1: {
+                       uint32_t value = 0;
+                       ret = port->get(port, &value, sizeof(value));
+                       if (ret == FAILURE)
+                               return -CMDERR_RDPERM;
+                       rpp_sci_printf("0x%x\n", value);
+                       break;
+               }
+               case 8: {
+                       uint8_t values[16] = {0};
+                       if (port->numchn > ARRAY_SIZE(values))
+                               return -CMDERR_BADCFG;
+                       ret = port->get(port, &values, sizeof(values));
+                       if (ret == FAILURE)
+                               return -CMDERR_RDPERM;
+                       for (i = 0; i < port->numchn; i++)
+                               rpp_sci_printf(" %hhd", values[i]);
+                       rpp_sci_printf("\n");
+                       break;
                }
-               for (i = 0; i < port_pin_cnt; i++) {
-                       rpp_sci_printf("%d\r\n", values[i]);
+               case 16: {
+                       uint16_t values[16] = {0};
+                       if (port->numchn > ARRAY_SIZE(values))
+                               return -CMDERR_BADCFG;
+                       ret = port->get(port, &values, sizeof(values));
+                       if (ret == FAILURE)
+                               return -CMDERR_RDPERM;
+                       for (i = 0; i < port->numchn; i++)
+                               rpp_sci_printf(" %hd", values[i]);
+                       rpp_sci_printf("\n");
+                       break;
+               }
+               default:
+                       rpp_sci_printf("Unsupported bits-per-channel value: %d\n", port->bpch);
+                       return -CMDERR_NODEV;
                }
-               rpp_sci_printf("portval%s=%x\n", portName, ret);
                return 0;
        }
 }
@@ -133,27 +190,24 @@ cmd_des_t const cmd_des_port_val = {
        "portval*","Read or write values from or to the port",
        "### Command syntax ###\n"
        "\n"
-       "     portval<NAME> <VAL>\n"
+       "     portval<NAME> <VAL> [<VAL> ...]\n"
        "     portval<NAME>\n"
        "where\n"
        "\n"
        "- `<NAME>` is a string specifying the name of the port\n"
-       "- `<VAL>` is a sequence of hexadecimal numbers, separated by spaces, e.g. 12 AA CD\n\n"
+       "- `<VAL>` is decimal, hexdecimal (0x) or octal (0) number\n"
        "\n"
        "### Description ###\n"
        "\n"
        "This command sets or gets values of all pins on the specified port.\n"
-       "If the port is connected to the GPIO interface of the MCU, then\n"
-       "when writing the value, the lowest significant bit of the argument\n"
-       "is assigned to the first pin, the second bit is assigned to the\n"
-       "second pin, etc. The command returns zero.\n"
-       "When reading from the port, the command returns values for each pin.\n"
+       "For digital IO ports, the least significant bit of the VAL corresponds\n"
+       "to the first pin, the second bit to the second pin, etc. The command\n"
+       "returns zero. When reading from the port, the command returns values\n"
+       "for each pin.\n"
        "\n"
-       "If the port is connected to the SPI interface of the MCU, then\n"
-       "it is write only and the argument is interpreted as a command for\n"
-       "the port controller. The command returns the response from the\n"
-       "port controller.\n"
-       "For command examples please refer to the project wiki\n"
+       "If the port represents an SPI interface of the MCU, then it is write\n"
+       "only and the argument is interpreted as a command for the port\n"
+       "controller. The command returns the response from the port controller.\n"
        "\n"
        "If the port is connected to the ADC interface of the MCU, then\n"
        "it is read only and returns values for each ADC pin.\n"
@@ -163,16 +217,10 @@ cmd_des_t const cmd_des_port_val = {
        "\n"
        "### Example ###\n"
        "\n"
-       "     --> portvalGIOB 3A\n"
+       "     --> portvalGIOB 0x3A\n"
        "     portvalGIOB=0\n"
        "     --> portvalGIOB\n"
-       "     0\n"
-       "     1\n"
-       "     0\n"
-       "     1\n"
-       "     1\n"
-       "     1\n"
-       "\n"
+       "        0x3a\n"
        "This pair of commands sets:\nGIOB"
        "GIOB=0\n"
        "GIOB=1\n"
index 23b8ff7af8c7f3a8bb03d9eb66e9e7629b327468..6ad57a90628e2d5fe8df37e01ddf873880b2ccb8 100644 (file)
  */
 int cmd_do_spi_translate(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 {
-       char *p;
-       int i;
-       uint32_t ret;
-       uint32_t values[MAX_PARAM_VALUES_NUM];
-       uint32_t numFieldDesc;
-       uint32_t numCmdDesc;
        uint32_t command;
        uint32_t response;
-       spitr_reg_translate_table_t translatedData;
        char peripheralName[32];
        char spareParams;
 
-       p = param[1];
-       if (sscanf(p, "%31s ", peripheralName) != 1)
+       if (sscanf(param[1], "%31s ", peripheralName) != 1)
                return -CMDERR_BADPAR;
 
-       const spitr_cmd_map_t *cmdDesc = cmdDesc = get_spi_cmd_map(peripheralName, -1, &numCmdDesc);
-       if (cmdDesc == NULL) return -CMDERR_BADREG;
+       const spitr_port_cmds_t *cmds = spitr_get_cmds_by_port_name(peripheralName);
+       if (cmds == NULL) return -CMDERR_BADREG;
 
 
        if (param[2] != NULL) {         // More parameters expected
-               p = param[2];
-               if (sscanf(p, "%x %x %1s", &values[0], &values[1], &spareParams) != 2)
+               if (sscanf(param[2], "%x %x %1s", &command, &response, &spareParams) != 2)
                        return -CMDERR_BADPAR;
-               command = values[0];
-               response = values[1];
 
-               const spitr_field_desc_t *fieldDescs = get_spi_field_desc(cmdDesc, numCmdDesc, command, &numFieldDesc);
-               if (fieldDescs == NULL)
-                       return -CMDERR_BADPAR;
+               const spitr_cmd_desc_t *cmd_desc = get_spi_cmd_desc(cmds, command);
+               if (!cmd_desc)
+                       return -CMDERR_BADCMD;
 
-               ret = spitr_fill_tr_table(fieldDescs, numFieldDesc, response, &translatedData);
+               spitr_print_resp(cmd_desc, response);
 
-               for (i = 0; i < translatedData.num_rows; i++) {
-                       rpp_sci_printf("%s: %x\r\n", translatedData.row[i].field_name, translatedData.row[i].value);
-               }
-               return cmd_opchar_replong(cmd_io, param, ret, 0, 10);
+               return cmd_opchar_replong(cmd_io, param, 0, 0, 10);
        }
        else
                return -CMDERR_BADPAR;
index 98dfa8b9cb1c9ba8b026e3ca8269fe6d6204a3eb..4e7494d011305379bc445c1188c1c135a7c1029c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2013 Czech Technical University in Prague
+ * Copyright (C) 2012-2013, 2015 Czech Technical University in Prague
  *
  * Created on: 28.2.2013
  *
@@ -24,7 +24,6 @@
 #ifndef DOCGEN
 
 #include "rpp/rpp.h"
-#include "drv/digital_io_def.h"
 
 #define VBATPWM_PERIOD 400
 
@@ -52,7 +51,7 @@ int vbat1_pwm()
        int i, j;
        int pulse_cnt = 100;
 
-       if (rpp_gio_set_output(DIO_PIN_NAME_VBAT1EN, 0) == FAILURE) {
+       if (rpp_gio_setup(PIN_VBAT1EN, RPP_GIO_IN, RPP_GIO_MODE_PULLDIS, false) == FAILURE) {
                return -CMDERR_BADDIO;
        }
 
@@ -60,22 +59,22 @@ int vbat1_pwm()
        _disable_IRQ();
        while ((pwm = *(ppwm++)))
                for (i = 0; i < pulse_cnt; i++) {
-                       if (rpp_gio_set_val(DIO_PIN_NAME_VBAT1EN, 1) == FAILURE) {
+                       if (rpp_gio_set(PIN_VBAT1EN, 1) == FAILURE) {
                                return -CMDERR_BADDIO;
                        }
                        for (j = 0; j < pwm; j++)
                                ;
-                       if (rpp_gio_set_val(DIO_PIN_NAME_VBAT1EN, 0) == FAILURE) {
+                       if (rpp_gio_set(PIN_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) {
+       if (rpp_gio_set(PIN_VBAT1EN, 1) == FAILURE) {
                return -CMDERR_BADDIO;
        }
        _enable_IRQ();
-       int32_t ret = rpp_gio_get_val(DIO_PIN_NAME_VBAT1EN);
+       int32_t ret = rpp_gio_get(PIN_VBAT1EN);
        if (ret == FAILURE) {
                return -CMDERR_BADDIO;
        }
@@ -94,10 +93,10 @@ int cmd_do_power_on(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 {
        int ret = 0;
 
-       if (rpp_gio_set_val(DIO_PIN_NAME_VBATEN, 1) == FAILURE) {
+       if (rpp_gio_set(PIN_VBATEN, 1) == FAILURE) {
                return -CMDERR_BADDIO;
        }
-       ret = rpp_gio_get_val(DIO_PIN_NAME_VBATEN);
+       ret = rpp_gio_get(PIN_VBATEN);
        if (ret == FAILURE) {
                return -CMDERR_BADDIO;
        }
@@ -117,17 +116,17 @@ 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) {
+       if (rpp_gio_set(PIN_VBAT1EN, 0) == FAILURE) {
                return -CMDERR_BADDIO;
        }
-       ret = rpp_gio_get_val(DIO_PIN_NAME_VBAT1EN);
+       ret = rpp_gio_get(PIN_VBAT1EN);
        if (ret == FAILURE) {
                return -CMDERR_BADDIO;
        }
-       if (rpp_gio_set_val(DIO_PIN_NAME_VBATEN, 0) == FAILURE) {
+       if (rpp_gio_set(PIN_VBATEN, 0) == FAILURE) {
                return -CMDERR_BADDIO;
        }
-       ret = rpp_gio_get_val(DIO_PIN_NAME_VBATEN);
+       ret = rpp_gio_get(PIN_VBATEN);
        if (ret == FAILURE) {
                return -CMDERR_BADDIO;
        }
index a4a5799319bcda77897d2072a1436f1a0eb8483e..84cee92e990a97833c7121173c4846723c25bd65 100644 (file)
  *      bit or group of bits in the response.
  */
 
-#include "drv/digital_io.h"
+#include "rpp/sci.h"
+#include "drv/gio.h"
 #include "drv/spi.h"
 #include "spi_resp_transl.h"
+#include "drv/port.h"
 
 // Field descriptors
-static const spitr_field_desc_t din_glob_field_descs[DIN_NUM_GLOB_FD] = {
+static const spitr_field_desc_t din_glob_field_descs[] = {
        { .field_name = "Thermal flag\t",           .mask = (1 << 23) },
        { .field_name = "INT flag\t",               .mask = (1 << 22) },
        { .field_name = "SP0  - DIN0\t",            .mask = (1 << 14) },
@@ -58,7 +60,7 @@ static const spitr_field_desc_t din_glob_field_descs[DIN_NUM_GLOB_FD] = {
        { .field_name = "SG13 - NA\t",              .mask = (1 << 13) }
 };
 
-static const spitr_field_desc_t lout_glob_field_descs[LOUT_NUM_GLOB_FD] = {
+static const spitr_field_desc_t lout_glob_field_descs[] = {
        { .field_name = "U401 VS PS M",     .mask = (1 << 24) },
        { .field_name = "U401 IN8 state",   .mask = (1 << 27) },
        { .field_name = "U401 IN7 state",   .mask = (1 << 28) },
@@ -89,11 +91,11 @@ static const spitr_field_desc_t lout_glob_field_descs[LOUT_NUM_GLOB_FD] = {
        { .field_name = "U404 Thermal warning", .mask = (1 << 7) }
 };
 
-static const spitr_field_desc_t dac_glob_field_descs[DAC_NUM_GLOB_FD] = {
+static const spitr_field_desc_t dac_glob_field_descs[] = {
        { .field_name = "Provides no informations", .mask = 0 }
 };
 
-static const spitr_field_desc_t fray_glob_field_descs[FRAY_NUM_GLOB_FD] = {
+static const spitr_field_desc_t fray_glob_field_descs[] = {
        { .field_name = "Parity bit",           .mask = (1 << 0) },
        { .field_name = "SPI error",            .mask = (1 << 5) },
        { .field_name = "UVVIO",                .mask = (1 << 6) },
@@ -108,7 +110,7 @@ static const spitr_field_desc_t fray_glob_field_descs[FRAY_NUM_GLOB_FD] = {
        { .field_name = "Bus wake",             .mask = (1 << 15) }
 };
 
-static const spitr_field_desc_t hbr_statreg0_field_descs[HBR_NUM_STATREG_FD] = {
+static const spitr_field_desc_t hbr_statreg0_field_descs[] = {
        { .field_name = "GL_ER",                .mask = (1 << 15) },
        { .field_name = "Frame Error",          .mask = (1 << 14) },
        { .field_name = "STK_RESET_Q",          .mask = (1 << 13) },
@@ -125,7 +127,7 @@ static const spitr_field_desc_t hbr_statreg0_field_descs[HBR_NUM_STATREG_FD] = {
        { .field_name = "CP_LOW",               .mask = (1 << 0) }
 };
 
-static const spitr_field_desc_t hbr_applreg1_field_descs[HBR_NUM_APPLREG1_FD] = {
+static const spitr_field_desc_t hbr_applreg1_field_descs[] = {
        { .field_name = "GL_ER",                .mask = (1 << 15) },
        { .field_name = "Frame Error",          .mask = (1 << 14) },
        { .field_name = "STK_RESET_Q",          .mask = (1 << 13) },
@@ -143,7 +145,7 @@ static const spitr_field_desc_t hbr_applreg1_field_descs[HBR_NUM_APPLREG1_FD] =
        { .field_name = "DIAG",                 .mask = (3 << 0) }
 };
 
-static const spitr_field_desc_t hbr_applreg2_field_descs[HBR_NUM_APPLREG2_FD] = {
+static const spitr_field_desc_t hbr_applreg2_field_descs[] = {
        { .field_name = "GL_ER",                .mask = (1 << 15) },
        { .field_name = "Frame Error",          .mask = (1 << 14) },
        { .field_name = "STK_RESET_Q",          .mask = (1 << 13) },
@@ -159,7 +161,7 @@ static const spitr_field_desc_t hbr_applreg2_field_descs[HBR_NUM_APPLREG2_FD] =
        { .field_name = "GCSA",                 .mask = (3 << 0) }
 };
 
-static const spitr_field_desc_t hbr_applreg3_field_descs[HBR_NUM_APPLREG3_FD] = {
+static const spitr_field_desc_t hbr_applreg3_field_descs[] = {
        { .field_name = "GL_ER",                .mask = (1 << 15) },
        { .field_name = "Frame Error",          .mask = (1 << 14) },
        { .field_name = "STK_RESET_Q",          .mask = (1 << 13) },
@@ -178,7 +180,7 @@ static const spitr_field_desc_t hbr_applreg3_field_descs[HBR_NUM_APPLREG3_FD] =
        { .field_name = "EXT_TH_0",             .mask = (1 << 0) }
 };
 
-static const spitr_field_desc_t hbr_diaddr0_field_descs[HBR_NUM_DIADDR0_FD] = {
+static const spitr_field_desc_t hbr_diaddr0_field_descs[] = {
        { .field_name = "GL_ER",                .mask = (1 << 15) },
        { .field_name = "Frame Error",          .mask = (1 << 14) },
        { .field_name = "STK_RESET_Q",          .mask = (1 << 13) },
@@ -191,7 +193,7 @@ static const spitr_field_desc_t hbr_diaddr0_field_descs[HBR_NUM_DIADDR0_FD] = {
        { .field_name = "NR_PI",                .mask = (0x3F << 0) }
 };
 
-static const spitr_field_desc_t hbr_diaddr1_field_descs[HBR_NUM_DIADDR1_FD] = {
+static const spitr_field_desc_t hbr_diaddr1_field_descs[] = {
        { .field_name = "GL_ER",                .mask = (1 << 15) },
        { .field_name = "Frame Error",          .mask = (1 << 14) },
        { .field_name = "STK_RESET_Q",          .mask = (1 << 13) },
@@ -203,7 +205,7 @@ static const spitr_field_desc_t hbr_diaddr1_field_descs[HBR_NUM_DIADDR1_FD] = {
        { .field_name = "PRD_ID",               .mask = (0xFF << 0) }
 };
 
-static const spitr_field_desc_t hbr_diaddr2_field_descs[HBR_NUM_DIADDR2_FD] = {
+static const spitr_field_desc_t hbr_diaddr2_field_descs[] = {
        { .field_name = "GL_ER",                .mask = (1 << 15) },
        { .field_name = "Frame Error",          .mask = (1 << 14) },
        { .field_name = "STK_RESET_Q",          .mask = (1 << 13) },
@@ -215,7 +217,7 @@ static const spitr_field_desc_t hbr_diaddr2_field_descs[HBR_NUM_DIADDR2_FD] = {
        { .field_name = "PRD_ID",               .mask = (0xFF << 0) }
 };
 
-static const spitr_field_desc_t hbr_diaddr3_field_descs[HBR_NUM_DIADDR3_FD] = {
+static const spitr_field_desc_t hbr_diaddr3_field_descs[] = {
        { .field_name = "GL_ER",                .mask = (1 << 15) },
        { .field_name = "Frame Error",          .mask = (1 << 14) },
        { .field_name = "STK_RESET_Q",          .mask = (1 << 13) },
@@ -235,124 +237,88 @@ static const spitr_field_desc_t hbr_diaddr3_field_descs[HBR_NUM_DIADDR3_FD] = {
 };
 
 /* Map register descriptors to spi commands */
-static const spitr_cmd_map_t din_cmd_map[DIN_NUM_CMD_D] = {
-       { .cmd_msk = 0,     .command = 0,   .field_desc = din_glob_field_descs, .num_fields = DIN_NUM_GLOB_FD}
+static const spitr_cmd_desc_t din_cmds[] = {
+       { .cmd_msk = 0,     .command = 0,   .field_desc = din_glob_field_descs, .num_fields = ARRAY_SIZE(din_glob_field_descs) }
 };
 
-static const spitr_cmd_map_t lout_cmd_map[LOUT_NUM_CMD_D] = {
-       { .cmd_msk = 0,     .command = 0,   .field_desc = lout_glob_field_descs, .num_fields = LOUT_NUM_GLOB_FD }
+static const spitr_cmd_desc_t lout_cmds[] = {
+       { .cmd_msk = 0,     .command = 0,   .field_desc = lout_glob_field_descs, .num_fields = ARRAY_SIZE(lout_glob_field_descs) }
 };
 
-static const spitr_cmd_map_t dac_cmd_map[DAC_NUM_CMD_D] = {
-       { .cmd_msk = 0,     .command = 0,   .field_desc = dac_glob_field_descs, .num_fields = DAC_NUM_GLOB_FD }
+static const spitr_cmd_desc_t dac_cmds[] = {
+       { .cmd_msk = 0,     .command = 0,   .field_desc = dac_glob_field_descs, .num_fields = ARRAY_SIZE(dac_glob_field_descs) }
 };
 
-static const spitr_cmd_map_t fray_cmd_map[FRAY_NUM_CMD_D] = {
-       { .cmd_msk = 0,     .command = 0,   .field_desc = fray_glob_field_descs, .num_fields = FRAY_NUM_GLOB_FD }
+static const spitr_cmd_desc_t fray_cmds[] = {
+       { .cmd_msk = 0,     .command = 0,   .field_desc = fray_glob_field_descs, .num_fields = ARRAY_SIZE(fray_glob_field_descs) }
 };
 
-static const spitr_cmd_map_t hbr_cmd_map[HBR_NUM_CMD_D] = {
-       { .cmd_msk = 0x0000FF00, .command = 0xC000, .field_desc = hbr_diaddr0_field_descs, .num_fields = HBR_NUM_DIADDR0_FD },
-       { .cmd_msk = 0x0000FF00, .command = 0xC100, .field_desc = hbr_diaddr1_field_descs, .num_fields = HBR_NUM_DIADDR1_FD },
-       { .cmd_msk = 0x0000FF00, .command = 0xC200, .field_desc = hbr_diaddr2_field_descs, .num_fields = HBR_NUM_DIADDR2_FD },
-       { .cmd_msk = 0x0000FF00, .command = 0xC300, .field_desc = hbr_diaddr3_field_descs, .num_fields = HBR_NUM_DIADDR3_FD },
-       { .cmd_msk = 0x0000FF00, .command = 0x8000, .field_desc = hbr_statreg0_field_descs, .num_fields = HBR_NUM_STATREG_FD },
-       { .cmd_msk = 0x0000FF00, .command = 0x4000, .field_desc = hbr_statreg0_field_descs, .num_fields = HBR_NUM_STATREG_FD },
-       { .cmd_msk = 0x0000FF00, .command = 0x4100, .field_desc = hbr_applreg1_field_descs, .num_fields = HBR_NUM_APPLREG1_FD },
-       { .cmd_msk = 0x0000FF00, .command = 0x4200, .field_desc = hbr_applreg2_field_descs, .num_fields = HBR_NUM_APPLREG2_FD },
-       { .cmd_msk = 0x0000FF00, .command = 0x4300, .field_desc = hbr_applreg3_field_descs, .num_fields = HBR_NUM_APPLREG3_FD },
-       { .cmd_msk = 0x0000FF00, .command = 0x0100, .field_desc = hbr_applreg1_field_descs, .num_fields = HBR_NUM_APPLREG1_FD },
-       { .cmd_msk = 0x0000FF00, .command = 0x0200, .field_desc = hbr_applreg2_field_descs, .num_fields = HBR_NUM_APPLREG2_FD },
-       { .cmd_msk = 0x0000FF00, .command = 0x0300, .field_desc = hbr_applreg3_field_descs, .num_fields = HBR_NUM_APPLREG3_FD },
+static const spitr_cmd_desc_t hbr_cmds[] = {
+       { .cmd_msk = 0x0000FF00, .command = 0xC000, .field_desc = hbr_diaddr0_field_descs, .num_fields = ARRAY_SIZE(hbr_diaddr0_field_descs) },
+       { .cmd_msk = 0x0000FF00, .command = 0xC100, .field_desc = hbr_diaddr1_field_descs, .num_fields = ARRAY_SIZE(hbr_diaddr1_field_descs) },
+       { .cmd_msk = 0x0000FF00, .command = 0xC200, .field_desc = hbr_diaddr2_field_descs, .num_fields = ARRAY_SIZE(hbr_diaddr2_field_descs) },
+       { .cmd_msk = 0x0000FF00, .command = 0xC300, .field_desc = hbr_diaddr3_field_descs, .num_fields = ARRAY_SIZE(hbr_diaddr3_field_descs) },
+       { .cmd_msk = 0x0000FF00, .command = 0x8000, .field_desc = hbr_statreg0_field_descs, .num_fields = ARRAY_SIZE(hbr_statreg0_field_descs) },
+       { .cmd_msk = 0x0000FF00, .command = 0x4000, .field_desc = hbr_statreg0_field_descs, .num_fields = ARRAY_SIZE(hbr_statreg0_field_descs) },
+       { .cmd_msk = 0x0000FF00, .command = 0x4100, .field_desc = hbr_applreg1_field_descs, .num_fields = ARRAY_SIZE(hbr_applreg1_field_descs) },
+       { .cmd_msk = 0x0000FF00, .command = 0x4200, .field_desc = hbr_applreg2_field_descs, .num_fields = ARRAY_SIZE(hbr_applreg2_field_descs) },
+       { .cmd_msk = 0x0000FF00, .command = 0x4300, .field_desc = hbr_applreg3_field_descs, .num_fields = ARRAY_SIZE(hbr_applreg3_field_descs) },
+       { .cmd_msk = 0x0000FF00, .command = 0x0100, .field_desc = hbr_applreg1_field_descs, .num_fields = ARRAY_SIZE(hbr_applreg1_field_descs) },
+       { .cmd_msk = 0x0000FF00, .command = 0x0200, .field_desc = hbr_applreg2_field_descs, .num_fields = ARRAY_SIZE(hbr_applreg2_field_descs) },
+       { .cmd_msk = 0x0000FF00, .command = 0x0300, .field_desc = hbr_applreg3_field_descs, .num_fields = ARRAY_SIZE(hbr_applreg3_field_descs) },
 };
 
 /* Map command maps to SPI peripheral name */
-static const spitr_name_map_t spitr_map[NUM_SPI_DEVICES] = {
-       { .spi_name = DIO_PORT_NAME_DINSPI,     .cmd_map = din_cmd_map,     .num_cmd = DIN_NUM_CMD_D},
-       { .spi_name = DIO_PORT_NAME_LOUT,       .cmd_map = lout_cmd_map,    .num_cmd = LOUT_NUM_CMD_D },
-       { .spi_name = DIO_PORT_NAME_DAC1_2,     .cmd_map = dac_cmd_map,     .num_cmd = DAC_NUM_CMD_D },
-       { .spi_name = DIO_PORT_NAME_DAC3_4,     .cmd_map = dac_cmd_map,     .num_cmd = DAC_NUM_CMD_D },
-       { .spi_name = DIO_PORT_NAME_HBR,        .cmd_map = hbr_cmd_map,     .num_cmd = HBR_NUM_CMD_D },
-       { .spi_name = DIO_PORT_NAME_FRAY1,      .cmd_map = fray_cmd_map,    .num_cmd = FRAY_NUM_CMD_D },
-       { .spi_name = DIO_PORT_NAME_FRAY2,      .cmd_map = fray_cmd_map,    .num_cmd = FRAY_NUM_CMD_D }
+const spitr_port_cmds_t spitr_port_cmds[] = {
+       [PORT_ID_DINSPI] = { .cmd_desc = din_cmds,     .num_cmd = ARRAY_SIZE(din_cmds) },
+       [PORT_ID_LOUT]   = { .cmd_desc = lout_cmds,    .num_cmd = ARRAY_SIZE(lout_cmds) },
+       [PORT_ID_DAC1_2] = { .cmd_desc = dac_cmds,     .num_cmd = ARRAY_SIZE(dac_cmds) },
+       [PORT_ID_DAC3_4] = { .cmd_desc = dac_cmds,     .num_cmd = ARRAY_SIZE(dac_cmds) },
+       [PORT_ID_HBR]    = { .cmd_desc = hbr_cmds,     .num_cmd = ARRAY_SIZE(hbr_cmds) },
+       [PORT_ID_FRAY1]  = { .cmd_desc = fray_cmds,    .num_cmd = ARRAY_SIZE(fray_cmds) },
+       [PORT_ID_FRAY2]  = { .cmd_desc = fray_cmds,    .num_cmd = ARRAY_SIZE(fray_cmds) }
 };
 
-
-
 /**
- *  Get the map spi command to spi response.
- *  @param[in] spi_port_name    String of the port name
- *  @param[in] len  Length of the port name string, if terminated by '/0', then len = -1
- *  @param[out] num_cmdDesc returns number of command->fieldDesc fields assigned to the map
- *  @return command to field_desc map or NULL if not found
+ *  Get fields descriptor according to the field descriptor map and command.
+ *  @param[in] cmds  pointer to structure, that maps commands to their field descriptors
+ *  @param[in] num_cmd  Number of fields in the cmds
+ *  @param[in] cmd      Command used as a key value in the cmds. We are searching for the field descriptors assigned to this command
+ *  @param[out] num_fdDesc  Number of fields in field descriptors structure, that was found
+ *  @return pointer to the structure that maps field names to field masks or NULL, when not found
  */
-const spitr_cmd_map_t *get_spi_cmd_map(const char *spi_port_name, int len, uint32_t *num_cmdDesc)
+const spitr_cmd_desc_t *get_spi_cmd_desc(const spitr_port_cmds_t *cmds, uint32_t cmd)
 {
-       uint32_t i;
-       const char *spi_port_name_ptr;
-       char port_name_term[32];
-
-       if (len != -1) {    // port name not terminated by '\0'
-               strncpy(port_name_term, spi_port_name, len);
-               port_name_term[len] = '\0';
-               spi_port_name_ptr = port_name_term;
-       }
-       else spi_port_name_ptr = spi_port_name;
+       if (cmds == NULL)
+               return NULL;
 
-       for (i = 0; i < NUM_SPI_DEVICES; i++) {
-               if (strcmp(spi_port_name_ptr, spitr_map[i].spi_name) == 0) {
-                       *num_cmdDesc = spitr_map[i].num_cmd;
-                       return spitr_map[i].cmd_map;
-               }
+       uint32_t i;
+       for (i = 0; i < cmds->num_cmd; i++) {
+               const spitr_cmd_desc_t *cd = &cmds->cmd_desc[i];
+               if ((cmd & cd->cmd_msk) == cd->command)
+                       return cd;
        }
-       *num_cmdDesc = 0;
        return NULL;
 }
 
-/**
- *  Get fields descriptor according to the field descriptor map and command.
- *  @param[in] cmd_map  pointer to structure, that maps commands to their field descriptors
- *  @param[in] num_cmd  Number of fields in the cmd_map
- *  @param[in] cmd      Command used as a key value in the cmd_map. We are searching for the field descriptors assigned to this command
- *  @param[out] num_fdDesc  Number of fields in field descriptors structure, that was found
- *  @return pointer to the structure that maps field names to field masks or NULL, when not found
- */
-const spitr_field_desc_t *get_spi_field_desc(const spitr_cmd_map_t *cmd_map, uint32_t num_cmd, uint32_t cmd, uint32_t *num_fdDesc)
+const spitr_port_cmds_t *spitr_get_cmds_by_port_name(const char *name)
 {
-       if (cmd_map == NULL) {
-               *num_fdDesc = 0;
-               return NULL;
-       }
+       int i;
 
-       uint32_t i;
-       for (i = 0; i < num_cmd; i++) {
-               uint32_t mskcmd = cmd & cmd_map[i].cmd_msk;
-               uint32_t tmpCmd = cmd_map[i].command;
-               if (mskcmd == tmpCmd) {
-                       *num_fdDesc = cmd_map[i].num_fields;
-                       return cmd_map[i].field_desc;
-               }
+       for (i = 0; i < _PORT_COUNT; i++) {
+               if (strcmp(name, port_desc[i].name) == 0)
+                       return &spitr_port_cmds[i];
        }
-       *num_fdDesc = cmd_map[i].num_fields;
        return NULL;
 }
 
-/**
- *  Translate spi response into human readable form
- *  @param[in] fd           Pointer to structure that maps Field names to field value masks
- *  @param[in] num_fields   Number of fields in fd
- *  @param[in] value        spi response to be traslated
- *  @param[out] table       The result is stored in this table, where each row consists of the value name and the value
- *  @return number of rows in the translated table
- */
-int spitr_fill_tr_table(const spitr_field_desc_t *fd, uint32_t num_fields, uint32_t value, spitr_reg_translate_table_t *table)
+
+void spitr_print_resp(const spitr_cmd_desc_t *cmd_desc, uint32_t resp)
 {
-       uint32_t i;
+       int i;
 
-       for (i = 0; i < num_fields; i++) {
-               table->row[i].field_name = fd[i].field_name;
-               table->row[i].value = __mfld2val(fd[i].mask, value);
+       for (i = 0; i < cmd_desc->num_fields; i++) {
+               const spitr_field_desc_t *fd = &cmd_desc->field_desc[i];
+               rpp_sci_printf("%s: 0x%x\r\n", fd->field_name, __mfld2val(fd->mask, resp));
        }
-       table->num_rows = num_fields;
-       return i;
 }
index ff4ab5c51a00f425963696aa42d072a8d262560a..293d9a21ddde57cb1329ec9375e93828ec6fd7c8 100644 (file)
@@ -2,7 +2,7 @@
  *
  * @file spi_resp_transl.h
  *
- * @copyright Copyright (C) 2012-2013 Czech Technical University in Prague
+ * @copyright Copyright (C) 2012-2013, 2015 Czech Technical University in Prague
  *
  * @author Michal Horn <hornmich@fel.cvut.cz>
  */
 #ifndef SPI_RESP_TRANSL_H_
 #define SPI_RESP_TRANSL_H_
 
-#define NUM_SPI_DEVICES 7
-#define DIN_NUM_GLOB_FD     24
-#define LOUT_NUM_GLOB_FD    28
-#define DAC_NUM_GLOB_FD     1
-#define FRAY_NUM_GLOB_FD    12
-#define HBR_NUM_STATREG_FD  14
-#define HBR_NUM_APPLREG1_FD 15
-#define HBR_NUM_APPLREG2_FD 13
-#define HBR_NUM_APPLREG3_FD 16
-#define HBR_NUM_DIADDR0_FD 10
-#define HBR_NUM_DIADDR1_FD 9
-#define HBR_NUM_DIADDR2_FD 9
-#define HBR_NUM_DIADDR3_FD 16
-
-#define DIN_NUM_CMD_D   1
-#define LOUT_NUM_CMD_D  1
-#define DAC_NUM_CMD_D   1
-#define FRAY_NUM_CMD_D  1
-#define HBR_NUM_CMD_D   12
-
-#define MAX_NUM_ROWS    32
+#include "drv/port_def.h"
 
 /*masked fields macros*/
 //#define __val2mfld(mask,val) (((mask)&~((mask)<<1))*(val)&(mask))
@@ -42,32 +22,22 @@ typedef struct spitr_field_desc_st {
        uint32_t mask;
 } spitr_field_desc_t;
 
-typedef struct spitr_cmd_map_st {
+typedef struct spitr_cmd_desc_st {
        uint32_t cmd_msk;
        uint32_t command;
        const spitr_field_desc_t *field_desc;
        uint32_t num_fields;
-} spitr_cmd_map_t;
+} spitr_cmd_desc_t;
 
-typedef struct spitr_name_map_st {
-       const char *spi_name;
-       const spitr_cmd_map_t *cmd_map;
+typedef struct spitr_port_cmds_st {
+       const spitr_cmd_desc_t *cmd_desc;
        uint32_t num_cmd;
-} spitr_name_map_t;
-
-typedef struct spitr_reg_translate_table_row_st {
-       const char *field_name;
-       uint32_t value;
-} spitr_reg_translate_table_row_t;
-
-typedef struct spitr_reg_translate_table_st {
-       spitr_reg_translate_table_row_t row[MAX_NUM_ROWS];
-       uint32_t num_rows;
-} spitr_reg_translate_table_t;
+} spitr_port_cmds_t;
 
+extern const spitr_port_cmds_t spitr_port_cmds[_PORT_COUNT];
 
-const spitr_cmd_map_t *get_spi_cmd_map(const char *spi_port_name, int len, uint32_t *num_cmdDesc);
-const spitr_field_desc_t *get_spi_field_desc(const spitr_cmd_map_t *cmd_map, uint32_t num_cmd, uint32_t cmd, uint32_t *num_fdDesc);
-int spitr_fill_tr_table(const spitr_field_desc_t *fd, uint32_t num_fields, uint32_t value, spitr_reg_translate_table_t *table);
+const spitr_port_cmds_t *spitr_get_cmds_by_port_name(const char *name);
+const spitr_cmd_desc_t *get_spi_cmd_desc(const spitr_port_cmds_t *cmds, uint32_t cmd);
+void spitr_print_resp(const spitr_cmd_desc_t *cmd_desc, uint32_t resp);
 
 #endif /* SPI_RESP_TRANSL_H_ */