]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/commitdiff
Update library
authorMichal Horn <hornmich@fel.cvut.cz>
Wed, 22 Jul 2015 07:29:57 +0000 (09:29 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 7 Aug 2015 13:24:50 +0000 (15:24 +0200)
22 files changed:
rpp-lib
rpp-test-sw/Makefile.var
rpp-test-sw/commands/_tms570_rpp/cmd.c [deleted file]
rpp-test-sw/commands/_tms570_rpp/cmd_adc.c [deleted file]
rpp-test-sw/commands/_tms570_rpp/cmd_pin.c [deleted file]
rpp-test-sw/commands/_tms570_rpp/cmd_port.c [deleted file]
rpp-test-sw/commands/cmd.c
rpp-test-sw/commands/cmd_adc.c
rpp-test-sw/commands/cmd_din.c
rpp-test-sw/commands/cmd_fr_basic_test.c
rpp-test-sw/commands/cmd_fray.c
rpp-test-sw/commands/cmd_hbr.c
rpp-test-sw/commands/cmd_hout.c
rpp-test-sw/commands/cmd_lin.c
rpp-test-sw/commands/cmd_lout.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 [new file with mode: 0644]
rpp-test-sw/commands/spi_resp_transl.h [new file with mode: 0644]

diff --git a/rpp-lib b/rpp-lib
index 431c0b06c0dee19050a859c5df020c44ac605072..7f527b541985dafbfdf9c0119f16dc12ed6c5c61 160000 (submodule)
--- a/rpp-lib
+++ b/rpp-lib
@@ -1 +1 @@
-Subproject commit 431c0b06c0dee19050a859c5df020c44ac605072
+Subproject commit 7f527b541985dafbfdf9c0119f16dc12ed6c5c61
index c33ba4d0d8ca8242c64801346a2f6de3520d8280..ec601a3eb2678a3148f596456ba20611a0de083d 100644 (file)
@@ -31,7 +31,9 @@ SOURCES_tms570_rpp = \
        commands/cmd_sdram.c \
        commands/cmd_spi.c \
        commands/cmd_vbat.c \
-       commands/cmd_echoserver.c
+       commands/cmd_echoserver.c \
+       commands/spi_resp_transl.c
+
 
 
 SOURCES += $(SOURCES_$(TARGET))
diff --git a/rpp-test-sw/commands/_tms570_rpp/cmd.c b/rpp-test-sw/commands/_tms570_rpp/cmd.c
deleted file mode 100644 (file)
index 8b8895b..0000000
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Copyright (C) 2012-2013 Czech Technical University in Prague
- *
- * Created on: 31.7.2012
- *
- * 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.
- *
- * File : cmd.c
- *
- * Abstract:
- *      This file contains root of the list of the commands.
- *
- */
-
-/* Include files */
-#include "cmdproc.h"
-#include "../cmd.h"
-#include "../cmd_adc.h"
-#include "../cmd_dac.h"
-#include "../cmd_emac.h"
-#include "../cmd_fray.h"
-#include "../cmd_can.h"
-#include "../cmd_din.h"
-#include "../cmd_hbr.h"
-#include "../cmd_hout.h"
-#include "../cmd_lin.h"
-#include "../cmd_lout.h"
-#include "../cmd_nc.h"
-#include "../cmd_netstats.h"
-#include "../cmd_pin.h"
-#include "../cmd_port.h"
-#include "../cmd_sdram.h"
-#include "../cmd_spi.h"
-#include "../cmd_vbat.h"
-#include "../cmd_motor_example.h"
-#include "../cmd_fr_basic_test.h"
-
-#ifndef DOCGEN
-
-#include "rpp/rpp.h"
-#include "hal/hal.h"
-
-
-/**
- *  @brief     Sleep the board
- *
- * @param[in]  cmd_io  Pointer to IO stack
- * @param[in]  des             Pointer to command descriptor
- * @param[in]  param   Parameters of command
- * @return     0 when OK or error code
- */
-int cmd_do_sleep(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
-       hal_gpio_pin_set_value(PIN_DSC_CANNSTB, 1);
-       hal_gpio_pin_set_value(PIN_DSC_CANEN, 1);
-       hal_gpio_pin_set_value(PIN_DSC_LIN2NSLP, 1);
-       hal_gpio_pin_set_value(PIN_DSC_LIN1NSLP, 1);
-       vTaskDelay(10/portTICK_RATE_MS);
-       hal_gpio_pin_set_value(PIN_DSC_LIN2NSLP, 0);
-       hal_gpio_pin_set_value(PIN_DSC_LIN1NSLP, 0);
-       hal_gpio_pin_set_value(PIN_DSC_CANNSTB, 0);
-       return 0;
-}
-
-#include <version.h>
-
-int cmd_do_version(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
-       rpp_sci_printf("version=%s\n", GIT_VERSION);
-       return 0;
-}
-
-#endif  /* DOCGEN */
-
-/** Root list in which commands are stored */
-cmd_des_t const **cmd_list;
-
-/** Command descriptor for sleep command */
-cmd_des_t const cmd_des_sleep = {
-       0, 0,
-       "sleep","Sleep the board",
-       "### Syntax ###\n"
-       "\n"
-       " sleep\n"
-       "\n"
-       "### Description ###\n"
-       "\n"
-       "This command configures the LIN and CAN peripherals to enter sleep mode\n"
-       "and turn the whole device into sleep mode. External signal on CAN or\n"
-       "LIN will wake the device up.\n",
-       CMD_HANDLER(cmd_do_sleep), (void *)&cmd_list
-};
-
-/** Command descriptor for show help command */
-cmd_des_t const cmd_des_help = {
-       0, 0,
-       "help","Print help for commands",
-       "### Syntax ###\n"
-       "\n"
-       " help [command]\n"
-       "\n"
-       "### Description ###\n"
-       "\n"
-       "This command without parameter prints the list of all available\n"
-       "commands with short help text for each of them. If a parameter is\n"
-       "provided, the command prints a long description for given command.\n",
-       CMD_HANDLER(cmd_do_help), (void *)&cmd_list
-};
-
-cmd_des_t const cmd_des_version = {
-       0, 0,
-       "version","Print version of the software",
-       "### Syntax ###\n"
-       "\n"
-       " version\n"
-       "\n"
-       "### Description ###\n"
-       "\n"
-       "This command prints the version of the test software. The version\n"
-       "number is the output of 'git describe' command, i.e. it is composed\n"
-       "from the last tag in the git repository, the number of commits since\n"
-       "the tag and the abbreviated commit hash.\n"
-       "\n"
-       "### Example ###\n"
-       "\n"
-       "    --> version\n"
-       "    version=v0.2-109-ga81a9dd\n",
-       CMD_HANDLER(cmd_do_version),
-};
-
-/*  ------------------------
- *  Command lists definitons
- *  ------------------------
- */
-
-/** @brief Main list of commands */
-cmd_des_t const *cmd_list_main[] = {
-       &cmd_des_help,
-       &cmd_des_sleep,
-       &cmd_des_version,
-       CMD_DES_INCLUDE_SUBLIST(cmd_list_adc),
-       CMD_DES_INCLUDE_SUBLIST(cmd_list_can),
-       CMD_DES_INCLUDE_SUBLIST(cmd_list_dac),
-       CMD_DES_INCLUDE_SUBLIST(cmd_list_din),
-       CMD_DES_INCLUDE_SUBLIST(cmd_list_emac),
-       CMD_DES_INCLUDE_SUBLIST(cmd_list_fray),
-       CMD_DES_INCLUDE_SUBLIST(cmd_list_hbr),
-       CMD_DES_INCLUDE_SUBLIST(cmd_list_hout),
-       CMD_DES_INCLUDE_SUBLIST(cmd_list_lin),
-       CMD_DES_INCLUDE_SUBLIST(cmd_list_lout),
-       CMD_DES_INCLUDE_SUBLIST(cmd_list_nc),
-       CMD_DES_INCLUDE_SUBLIST(cmd_list_netstats),
-       CMD_DES_INCLUDE_SUBLIST(cmd_list_pin),
-       CMD_DES_INCLUDE_SUBLIST(cmd_list_port),
-       CMD_DES_INCLUDE_SUBLIST(cmd_list_sdram),
-       CMD_DES_INCLUDE_SUBLIST(cmd_list_spi),
-       CMD_DES_INCLUDE_SUBLIST(cmd_list_vbat),
-       CMD_DES_INCLUDE_SUBLIST(cmd_list_motor_example),
-       CMD_DES_INCLUDE_SUBLIST(cmd_list_fr_basic_test),
-       NULL
-};
-
-/** Pointer to the root list */
-cmd_des_t const **cmd_list = cmd_list_main;
diff --git a/rpp-test-sw/commands/_tms570_rpp/cmd_adc.c b/rpp-test-sw/commands/_tms570_rpp/cmd_adc.c
deleted file mode 100644 (file)
index a9cf2e4..0000000
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * Copyright (C) 2012-2013 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.
- *
- * File : cmd_adc.c
- *
- * Abstract:
- *      This file contains command for reading adc port.
- *
- */
-
-#include "../cmd_adc.h"
-
-#ifndef DOCGEN
-
-#include "hal/hal.h"
-#include "rpp/rpp.h"
-#include <stdio.h>
-
-static double lsb2volts(unsigned lsb)
-{
-       return ((double)lsb + 0.0)*2.5/4095*10;
-}
-
-
-/**
- * @brief Read values from ADC port
- *
- * @param[in]  cmd_io  Pointer to IO stack
- * @param[in]  des             Pointer to command descriptor
- * @param[in]  param   Parameters of command
- * @return 0 when OK or error code lower than 0
- */
-int cmd_do_read_adc1_values(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
-       uint32_t i, min, max;   // Cycle control variable
-
-       rpp_adc_update();
-       if (param[1] == param[0] + 7) { /* Single pin variant */
-               if (sscanf(param[1], "%d", &min) != 1)
-                       return -CMDERR_BADPAR;
-               if (min < 1 || min > 12)
-                       return -CMDERR_NODEV;
-               max = min;
-       }
-       else {              /* All pins */
-               min = 1;
-               max = PORT_ADC_CHANNEL_NUM;
-       }
-       for (i = min-1; i < max; i++) {
-               unsigned d = rpp_adc_get(i+1);
-               double v = lsb2volts(d);
-               rpp_sci_printf("ADC%-2d %4d lsb ~ %5.2f V\n", i+1, d, v);
-       }
-       return 0;
-}
-
-int cmd_do_adc_watch(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
-       int i;
-
-       rpp_sci_printf("ADC Inputs Test [1-12]:\r\n");
-       rpp_sci_printf("=======================================================================\r\n");
-
-       for (i = 1; i < 13; i++)
-               rpp_sci_printf("%5d ", i);
-       rpp_sci_printf("\n");
-
-       // Calculate wait time in OS ticks
-       static const portTickType freq_ticks = 100 /* ms */ / portTICK_RATE_MS;
-       portTickType last_wake_time = xTaskGetTickCount();
-
-       while (cmd_io->getc(cmd_io) < 0) {
-
-               // Update inputs
-               rpp_adc_update();
-
-               for (i = 1; i < 13; i++)
-                       rpp_sci_printf("%5d ", rpp_adc_get(i));
-               rpp_sci_printf("lsb\n");
-               for (i = 1; i < 13; i++)
-                       rpp_sci_printf("%5.2f ", lsb2volts(rpp_adc_get(i)));
-               rpp_sci_printf("V\r\033[A"); /* Cursor up */
-
-
-               vTaskDelayUntil(&last_wake_time, freq_ticks);
-       }
-       rpp_sci_printf("\n\n");
-       return 0;
-}
-
-
-#endif  /* DOCGEN */
-
-/** Descriptor of command for adc port reading */
-cmd_des_t const cmd_des_read_adc1 = {
-       0, 0,
-       "adcread","Read values from ADC inputs",
-       "### Command syntax ###\n"
-       "\n"
-       "     adcread\n"
-       "\n"
-       "### Description ###\n"
-       "\n"
-       "This command reads values corresponding to analog voltages on ADC\n"
-       "inputs 1-12 and prints them as decimal numbers as well as converted to\n"
-       "Volts.\n"
-       "\n"
-       "### Example ###\n"
-       "\n"
-       "     --> adcread\n"
-       "     ADC1  2332 lsb ~ 11.66 V\n"
-       "     ADC2   107 lsb ~  0.54 V\n"
-       "     ADC3   108 lsb ~  0.54 V\n"
-       "     ADC4   107 lsb ~  0.54 V\n"
-       "     ADC5   108 lsb ~  0.54 V\n"
-       "     ADC6   111 lsb ~  0.56 V\n"
-       "     ADC7   110 lsb ~  0.55 V\n"
-       "     ADC8   109 lsb ~  0.55 V\n"
-       "     ADC9   107 lsb ~  0.54 V\n"
-       "     ADC10  107 lsb ~  0.54 V\n"
-       "     ADC11  110 lsb ~  0.55 V\n"
-       "     ADC12  108 lsb ~  0.54 V\n",
-       CMD_HANDLER(cmd_do_read_adc1_values), (void *)&cmd_list_adc
-};
-
-cmd_des_t const cmd_des_read_adc2 = {
-       0, 0,
-       "adcread*","Read a value from a single ADC input",
-       "### Command syntax ###\n"
-       "\n"
-       "    adcread<PIN>\n"
-       "\n"
-       "where `<PIN>` is a number in range 1 - 12.\n"
-       "\n"
-       "### Description ###\n"
-       "\n"
-       "This command reads the value corresponding to analog voltage on an ADC\n"
-       "input and prints it as decimal numbers as well as converted to Volts.\n"
-       "\n"
-       "### Example ###\n"
-       "\n"
-       "    --> adcread1\n"
-       "    ADC1  2331 lsb ~ 11.66 V\n",
-       CMD_HANDLER(cmd_do_read_adc1_values), (void *)&cmd_list_adc
-};
-
-cmd_des_t const cmd_des_adcwatch = {
-       0, 0,
-       "adcwatch","Watch the values from ADC inputs",
-       "### Command syntax ###\n"
-       "\n"
-       "    adcwatch\n"
-       "\n"
-       "### Description ###\n"
-       "\n"
-       "This command reads values corresponding to analog voltages on ADC\n"
-       "inputs 1-12 10 times per second and prints them as decimal numbers (in\n"
-       "lsb units) as well as converted to Volts. The command is ended by any\n"
-       "key.\n"
-       "\n"
-       "### Example ###\n"
-       "\n"
-       "    --> adcwatch\n"
-       "    ADC Inputs Test [1-12]:\n"
-       "    =======================================================================\n"
-       "        1     2     3     4     5     6     7     8     9    10    11    12\n"
-       "     2331   107   108   106   107   110   110   109   107   107   110   109 lsb\n"
-       "    11.66  0.54  0.54  0.53  0.54  0.55  0.55  0.55  0.54  0.54  0.55  0.55 V\n",
-       CMD_HANDLER(cmd_do_adc_watch), (void *)&cmd_list_adc
-};
-
-/** List of commands for adc, defined as external */
-cmd_des_t const *cmd_list_adc[] = {
-       &cmd_des_read_adc1,
-       &cmd_des_read_adc2,
-       &cmd_des_adcwatch,
-       NULL
-};
diff --git a/rpp-test-sw/commands/_tms570_rpp/cmd_pin.c b/rpp-test-sw/commands/_tms570_rpp/cmd_pin.c
deleted file mode 100644 (file)
index 0d8edf4..0000000
+++ /dev/null
@@ -1,282 +0,0 @@
-/*
- * Copyright (C) 2012-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.
- *
- * File : cmd_pin.c
- *
- * Abstract:
- *      Commands for pin controlling
- *          - Printing list of available pins
- *          - Setting and getting value to pins
- *          - Setting and getting pins direction
- */
-
-#include "../cmd_pin.h"
-#include "stdio.h"
-#include "string.h"
-
-#ifndef DOCGEN
-
-#include "rpp/rpp.h"
-#include "hal/hal.h"
-#include "cmdproc_utils.h"
-
-/**
- * @brief      Print list of pins
- *
- * @param[in]  cmd_io  Pointer to IO stack
- * @param[in]  des             Pointer to command descriptor
- * @param[in]  param   Parameters of command
- * @return     0 when OK or error code
- */
-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");
-       for (i = 0; i < MAX_PIN_CNT; i++) {
-               if (pin_map[i].pin_name == PIN_NAME_UNUSED) continue;
-               rpp_sci_printf(pin_map[i].pin_name);
-               rpp_sci_printf("\r\n");
-       }
-       return 1;
-}
-
-/**
- * @brief      Set or get pin value
- *
- * @param[in]  cmd_io  Pointer to IO stack
- * @param[in]  des             Pointer to command descriptor
- * @param[in]  param   Parameters of command
- * @return     0 when OK or error code
- */
-int cmd_do_pin_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
-       char *p;
-       long val;
-       uint32_t *desc;
-       char spareParams;
-       char pinName[32];
-
-       p = param[1];
-       if (sscanf(p, "%31s ", pinName) != 1)
-               return -CMDERR_BADPAR;
-
-       if ((desc = hal_gpio_pin_get_dsc(pinName, -1)) == NULL) return -CMDERR_BADREG;
-
-       if (param[2] != NULL) {     // More parameters = set values
-               p = param[2];
-               if (sscanf(p, "%d %1s", &val, &spareParams) != 1)
-                       return -CMDERR_BADPAR;
-               if (val != 0 && val != 1)
-                       return -CMDERR_BADPAR;
-               hal_gpio_pin_set_value(*desc, (uint32_t)val);
-               return cmd_opchar_replong(cmd_io, param, val, 0, 0);
-               ;
-       }
-       else {  // No more parameters = get values
-               uint32_t pin_value = hal_gpio_pin_get_value(*desc);
-               rpp_sci_printf("pinval%s=%d\n", pinName, pin_value);
-               return 0;
-       }
-}
-
-/**
- * @brief      Set or get pin direction
- *
- * @param[in]  cmd_io  Pointer to IO stack
- * @param[in]  des             Pointer to command descriptor
- * @param[in]  param   Parameters of command
- * @return     0 when OK or error code
- */
-int cmd_do_pin_dir(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
-       char *p;
-       long val;
-       uint32_t *desc;
-       char spareParams;
-       char pinName[32];
-
-       p = param[1];
-       if (sscanf(p, "%31s ", pinName) != 1)
-               return -CMDERR_BADPAR;
-
-       if ((desc = hal_gpio_pin_get_dsc(pinName, -1)) == NULL) return -CMDERR_BADREG;
-
-       if (param[2] != NULL) {     // More parameters = set values
-               p = param[2];
-               if (sscanf(p, "%d %1s", &val, &spareParams) != 1)
-                       return -CMDERR_BADPAR;
-               if (val == 1) {
-                       *desc |= PORT_CONF_SET_DIR;
-                       *desc |= PORT_CONF_DIR_OUT;
-               }
-               else if (val == 0) {
-                       *desc &= (~PORT_CONF_DIR_OUT);
-                       *desc |= PORT_CONF_SET_DIR;
-               }
-               else
-                       return -CMDERR_BADPAR;
-
-               hal_gpio_pin_conf(*desc);
-               return cmd_opchar_replong(cmd_io, param, val, 0, 0);
-       }
-       else {  // No more parameters = get values
-               uint32_t pin_dir = hal_gpio_pin_get_direction(*desc);
-               rpp_sci_printf("pindir%s=%d\n", pinName, pin_dir);
-               return 0;
-       }
-}
-
-#endif  /* DOCGEN */
-
-/** Command descriptor for pin list */
-cmd_des_t const cmd_des_pin_list = {
-       0, 0,
-       "pinlist","Print a list of all defined pins.",
-       "### Command syntax ###\n"
-       "\n"
-       "    pinlist\n"
-       "\n"
-       "### Description ###\n"
-       "\n"
-       "The command prints a list of all defined pins accessible by pinval and\n"
-       "pindir commands.\n"
-       "\n"
-       "### Example ###\n"
-       "\n"
-       "    --> pinlist\n"
-       "    List of all defined pins. Those names can be used by pinval command.\n"
-       "    GIOA0\n"
-       "    GIOA1\n"
-       "    GIOA2\n"
-       "    GIOA3\n"
-       "    GIOA4\n"
-       "    GIOA5\n"
-       "    GIOA6\n"
-       "    GIOA7\n"
-       "    GIOB0\n"
-       "    GIOB1\n"
-       "    GIOB2\n"
-       "    GIOB3\n"
-       "    GIOB4\n"
-       "    GIOB5\n"
-       "    GIOB6\n"
-       "    GIOB7\n"
-       "    NHET10\n"
-       "    NHET11\n"
-       "    NHET12\n"
-       "    NHET13\n"
-       "    NHET14\n"
-       "    NHET15\n"
-       "    NHET16\n"
-       "    NHET17\n"
-       "    NHET18\n"
-       "    NHET19\n"
-       "    NHET110\n"
-       "    NHET111\n"
-       "    NHET112\n"
-       "    NHET113\n"
-       "    NHET114\n"
-       "    NHET115\n"
-       "    NHET116\n"
-       "    NHET117\n"
-       "    NHET118\n"
-       "    NHET119\n"
-       "    NHET120\n"
-       "    NHET121\n"
-       "    NHET122\n"
-       "    NHET123\n"
-       "    NHET124\n"
-       "    NHET125\n"
-       "    NHET126\n"
-       "    NHET127\n"
-       "    NHET128\n"
-       "    NHET129\n"
-       "    NHET130\n"
-       "    NHET131\n",
-       CMD_HANDLER(cmd_do_pin_list), (void *)&cmd_list_pin
-};
-
-/** Command descriptor for pin get/set value */
-cmd_des_t const cmd_des_pin_val = {
-       0, 0,
-       "pinval*","Set or get the pin value",
-       "### Command syntax ###\n"
-       "\n"
-       "    pinval<NAME> <VAL>\n"
-       "    pinval<NAME>\n"
-       "where\n"
-       "\n"
-       "- `<NAME>` is a string identifying the pin\n"
-       "- `<VAL>` can be 0 or 1\n"
-       "\n"
-       "### Description ###\n"
-       "\n"
-       "This command is sets or gets a value of the particular pin.\n"
-       "\n"
-       "The list of valid pin names can be obtained with pinlist command.\n"
-       "\n"
-       "### Example ###\n"
-       "\n"
-       "    --> pinvalGIOB0 1\n"
-       "    pinvalGIOB0=1\n"
-       "\n"
-       "Sets the GIOB0 pin to 1.\n"
-       "\n"
-       "    --> pinvalGIOB0\n"
-       "    pinvalGIOB0=1\n"
-       "\n"
-       "Gets a value of the GIOB0 pin.\n",
-       CMD_HANDLER(cmd_do_pin_val), (void *)&cmd_list_pin
-};
-
-/** Command descriptor for pin get/set direction */
-cmd_des_t const cmd_des_pin_dir = {
-       0, 0,
-       "pindir*","Set the pin direction",
-       "### Command syntax ###\n"
-       "\n"
-       "    pindir<NAME> <DIR>\n"
-       "    pindir<NAME>\n"
-       "where\n"
-       "\n"
-       "- `<NAME>` is a string identifying the pin\n"
-       "- DIR is be either 0 (input) or 1 (output)\n"
-       "\n"
-       "### Description ###\n"
-       "\n"
-       "This command is used to set or get direction of the particular pin.\n"
-       "\n"
-       "The list of valid pin names can be obtained with pinlist command.\n"
-       "\n"
-       "### Example ###\n"
-       "\n"
-       "    --> pindirGIOB0 1\n"
-       "    pindirGIOB0=1\n"
-       "\n"
-       "Sets the GIOB0 pin as output.\n"
-       "\n"
-       "    --> pindirGIOB0\n"
-       "    pindirGIOB0=1\n"
-       "\n"
-       "Gets the direction of the GIOB0 pin.\n",
-       CMD_HANDLER(cmd_do_pin_dir), (void *)&cmd_list_pin
-};
-
-/** List of commands for pin, defined as external */
-cmd_des_t const *cmd_list_pin[] = {
-       &cmd_des_pin_list,
-       &cmd_des_pin_val,
-       &cmd_des_pin_dir,
-       NULL
-};
diff --git a/rpp-test-sw/commands/_tms570_rpp/cmd_port.c b/rpp-test-sw/commands/_tms570_rpp/cmd_port.c
deleted file mode 100644 (file)
index e25ec02..0000000
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * Copyright (C) 2012-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.
- *
- * File : cmd_port.c
- *
- * Abstract:
- *          Commands for port controlling
- *          - Printing list of available ports (not yet available)
- *          - Setting/getting port value*
- */
-
-#include "../cmd_port.h"
-#include "stdio.h"
-
-#ifndef DOCGEN
-
-#include "rpp/rpp.h"
-#include "hal/hal.h"
-#include "cmdproc_utils.h"
-
-
-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");
-       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)
-                       portInterface = "SPI";
-               else if (ports[i].desc->interfaceType == PORT_INTERFACE_GPIO)
-                       portInterface = "GPIO";
-               else if (ports[i].desc->interfaceType == PORT_INTERFACE_ADC)
-                       portInterface = "ADC";
-               else
-                       portInterface = "UNKNOWN";
-               rpp_sci_printf("%s, %s\r\n", ports[i].name, portInterface);
-       }
-       return 1;
-}
-
-
-
-/**
- * @brief      Read values from specified port
- *
- * @param[in]  cmd_io  Pointer to IO stack
- * @param[in]  des             Pointer to command descriptor
- * @param[in]  param   Parameters of command
- * @return     0 when OK or error code
- */
-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;
-       uint32_t values[MAX_PARAM_VALUES_NUM];
-       char portName[32];
-       char *token;
-       uint32_t numParams;
-
-       p = param[1];
-       if (sscanf(p, "%31s ", portName) != 1)
-               return -CMDERR_BADPAR;
-
-       if ((desc = hal_port_get_dsc(portName, -1)) == NULL) return -CMDERR_BADREG;
-
-       if (param[2] != NULL) { // More parameters = set values
-               p = param[2];
-               if (desc->port_setfnc_ptr == NULL)
-                       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)
-                       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]);
-                       }
-               }
-               rpp_sci_printf("portval%s=%x\n", portName, ret);
-               return 0;
-       }
-}
-
-#endif  /* DOCGEN */
-
-/** Command descriptor for read values from port command */
-cmd_des_t const cmd_des_port_val = {
-       0, 0,
-       "portval*","Read or write values from or to the port",
-       "### Command syntax ###\n"
-       "\n"
-       "     portval<NAME> <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"
-       "\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"
-       "\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"
-       "\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"
-       "\n"
-       "Port names and interface type can be obtained with the portlist\n"
-       "command.\n"
-       "\n"
-       "### Example ###\n"
-       "\n"
-       "     --> portvalGIOB 3A\n"
-       "     portvalGIOB=0\n"
-       "     --> portvalGIOB\n"
-       "     0\n"
-       "     1\n"
-       "     0\n"
-       "     1\n"
-       "     1\n"
-       "     1\n"
-       "\n"
-       "This pair of commands sets:\nGIOB"
-       "GIOB=0\n"
-       "GIOB=1\n"
-       "GIOB=0\n"
-       "GIOB=1\n"
-       "GIOB=1\n"
-       "GIOB=1\n"
-       "Which is shown in getter output\n",
-       CMD_HANDLER(cmd_do_port_val), (void *)&cmd_list_port
-};
-
-/** Command descriptor for port list printout */
-cmd_des_t const cmd_des_port_list = {
-       0, 0,
-       "portlist","Print a list of all port names",
-       "### Command syntax ###\n"
-       "\n"
-       "     portlist\n"
-       "\n"
-       "### Description ###\n"
-       "\n"
-       "This command prints the list of all defined ports accessible via the\n"
-       "portval command. Each record of the list is a couple of\n"
-       "PortName-PortInterface, where PortInterface is SPI, ADC or GPIO.\n"
-       "The type of the MCU<->port interface slightly modifies the meaning\n"
-       "of the portval command."
-       "\n"
-       "### Example ###\n"
-       "\n"
-       "     --> portlist\n"
-       "     List of all defined ports with its type. Those names can be used by portval command.\n"
-       "     GIOA, GPIO\n"
-       "     GIOB, GPIO\n"
-       "     NHET1, GPIO\n"
-       "     ADC, ADC\n",
-       CMD_HANDLER(cmd_do_port_list), (void *)&cmd_list_port
-};
-
-/** List of commands for port, defined as external */
-cmd_des_t const *cmd_list_port[] = {
-       &cmd_des_port_val,
-       &cmd_des_port_list,
-       NULL
-};
index b02c1e5b245c1d15c6d41329769187ffd324daf1..6a8e89fa920a82d3a1abf4759b8e55775e5334f7 100644 (file)
@@ -48,7 +48,7 @@
 #ifndef DOCGEN
 
 #include "rpp/rpp.h"
-#include "hal/hal.h"
+#include "drv/digital_io_def.h"
 
 
 #include <version.h>
@@ -68,14 +68,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
-       hal_gpio_pin_set_value(PIN_DSC_CANNSTB, 1);
-       hal_gpio_pin_set_value(PIN_DSC_CANEN, 1);
-       hal_gpio_pin_set_value(PIN_DSC_LIN2NSLP, 1);
-       hal_gpio_pin_set_value(PIN_DSC_LIN1NSLP, 1);
+       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;
        vTaskDelay(10/portTICK_RATE_MS);
-       hal_gpio_pin_set_value(PIN_DSC_LIN2NSLP, 0);
-       hal_gpio_pin_set_value(PIN_DSC_LIN1NSLP, 0);
-       hal_gpio_pin_set_value(PIN_DSC_CANNSTB, 0);
+       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;
 #endif
        return 0;
 }
index 4a389eabd95094c0572cb9e74be8ab6f0fefa1b2..333d37399271d5dfa84b7ebb5ed5f67be0e1b793 100644 (file)
@@ -22,7 +22,7 @@
 
 #ifndef DOCGEN
 
-#include "hal/hal.h"
+#include "drv/digital_io_def.h"
 #include "rpp/rpp.h"
 #include <stdio.h>
 
@@ -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 = PORT_ADC_CHANNEL_NUM-1;
+               max = rpp_port_get_pin_cnt(DIO_PORT_NAME_ADC)-1;
        }
        for (i = min; i <= max; i++) {
                unsigned d = rpp_adc_get(i+1);
index 624cb4c9a7dbde833c015586ba2d3fdc4f6dcbf5..d0a6528cd1232c057384ec016a1f75c2e8cb1816 100644 (file)
@@ -24,9 +24,7 @@
 #ifndef DOCGEN
 
 #include "cmdproc_utils.h"
-#include "drv/din.h"
 #include "rpp/rpp.h"
-#include "hal/hal.h"
 
 /**
  * @brief      Setup DIN pin parameters (pull up/down, tristate/active, IRQ and wakeup disable/enable
index 2f053a77d3ee4612f699ea9536bc5e5486f48f19..9c9fccca9b879c4d34eb5fbcdfa79e4c6edc7f47 100644 (file)
@@ -28,9 +28,7 @@
 
 #include <string.h>
 #include "cmdproc_utils.h"
-#include "drv/drv.h"
 #include "rpp/rpp.h"
-#include "hal/hal.h"
 #include "stdio.h"
 
 #define printf rpp_sci_printf
index f2e45624594bcbfb12e55113a92dd28ac686bc47..1bbf55629c087d7ff4c474a3b934898f9bc81601 100644 (file)
 #ifndef DOCGEN
 
 #include "rpp/rpp.h"
-#include "drv/fray.h"
 #include "cmdproc_utils.h"
-#include "hal/hal.h"
+#include "drv/digital_io_def.h"
 #include "cmdproc.h"
-#include "sys/ti_drv_fray.h"
-#include "hal/spi_resp_transl.h"
+#include "spi_resp_transl.h"
 
 /**
  * This structure contains global FlexRay configuration.
@@ -321,7 +319,7 @@ 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(PORT_NAME_FRAY1, -1, &numCmdDesc);
+       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);
index 1e60dce1385d2aae7145cfec3dd39ffed28485e7..e8934640e166c982316fcc2e6506ff06ca25230d 100644 (file)
@@ -25,7 +25,6 @@
 
 #include "rpp/rpp.h"
 #include "cmdproc_utils.h"
-#include "drv/drv.h"
 
 
 /**
index 40fd97ba3f13d5244edb6c064344f77b7c6d5f7f..cf19029c8d01a52da4ee7ff0e4eb836550d768e4 100644 (file)
@@ -24,8 +24,9 @@
 #ifndef DOCGEN
 
 #include "rpp/rpp.h"
-#include "hal/hal.h"
-#include "drv/drv.h"
+/* FIXME: remove hout.h */
+#include "drv/hout.h"
+#include "drv/digital_io_def.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
-       port_desc_t *desc;
-       uint32_t values[PORT_HOUTIFBK_CHANNEL_NUM*2];
+       uint32_t port_num_values = rpp_port_get_pin_cnt(DIO_PORT_NAME_HOUTIFBK);
+       uint32_t values[port_num_values*2];
        int ret;
 
-       desc = hal_port_get_dsc(PORT_NAME_HOUTIFBK, -1);
 
-       ret = desc->port_getfnc_ptr(desc->config, PORT_HOUTIFBK_CHANNEL_NUM, values);
+       ret = rpp_port_get_val(DIO_PORT_NAME_HOUTIFBK, port_num_values, values);
        if (ret < 0)
                return ret;
 
-       for (i = 0; i < PORT_HOUTIFBK_CHANNEL_NUM; i++) {
+       for (i = 0; i < port_num_values; i++) {
                rpp_sci_printf("HOUT%d: %d\n", i+1, values[i]);
        }
        return 0;
index 602ad7569ee60eb906bfd232fe0c50483f0d01ad..ec8ad32f355508226f00025fb1b6be15a41c103f 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "rpp/rpp.h"
 #include "sys/sys.h"
-#include "hal/hal.h"
+#include "drv/digital_io_def.h"
 
 /** Semaphore used to stop command, until message is received */
 extern xSemaphoreHandle linMsgReceived;
@@ -48,7 +48,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);
-       hal_gpio_pin_set_value(PIN_DSC_LIN1NSLP, 1);
+       rpp_gio_set_val(DIO_PIN_NAME_LIN1NSLP, 1);
        linIDReceived = xSemaphoreCreateCounting(1, 0);
        linMsgReceived = xSemaphoreCreateCounting(1, 0);
 
@@ -77,7 +77,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);
-       hal_gpio_pin_set_value(PIN_DSC_LIN1NSLP, 0);
+       rpp_gio_set_val(DIO_PIN_NAME_LIN1NSLP, 0);
        return 0;
 }
 
index 6922fea62b8553c59eb9bdb7d1d050eba6377c7a..c884b04ab4da0fb408f1c28bb5c4784dcc637c31 100644 (file)
@@ -26,7 +26,6 @@
 
 #include "rpp/rpp.h"
 #include "cmdproc_utils.h"
-#include "drv/drv.h"
 
 /**
  * @brief Set digital value to LOUT pin
index 475734feacf5339ceb535fead83e0deacce048b6..1c6a9e2c24e778feac0608542395cbbd37d7c011 100644 (file)
@@ -25,8 +25,7 @@
 #ifndef DOCGEN
 
 #include "rpp/rpp.h"
-#include "hal/hal.h"
-#include "drv/drv.h"
+#include "drv/digital_io_def.h"
 #include "cmdproc.h"
 
 #define ADC_MAX_VALUE 0x0983
@@ -320,8 +319,8 @@ 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[])
 {
-       port_desc_t *adc_desc;
-       uint32_t adc_values[PORT_ADC_CHANNEL_NUM*2];
+       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;
@@ -331,8 +330,6 @@ int cmd_do_control(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
        int dir_cnt = 0;            // Debounce counter for direction button
        uint32_t error;
 
-       adc_desc = hal_port_get_dsc(PORT_NAME_ADC, -1);
-
        if (rpp_din_setup(0, FALSE, TRUE, FALSE) == FAILURE) {  // For the red button, which is switch to battery
                rpp_sci_printf("Din 0 setup failed.\n");
                return -CMDERR_BADCFG;
@@ -370,7 +367,7 @@ int cmd_do_control(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 
        while (1) {
                vTaskDelay(10/portTICK_RATE_MS);
-               ret = adc_desc->port_getfnc_ptr(adc_desc->config, PORT_ADC_CHANNEL_NUM, adc_values);
+               ret = rpp_port_get_val(DIO_PORT_NAME_ADC, adc_num_values, adc_values);
                if (ret < 0) {
                        rpp_sci_printf("ADC read failed!\n");
                        break;
index a56cc504e606f595b21922c68c423d9b04bfec25..71ee438206c6fe2ae75754ec51ff1024b7120895 100644 (file)
@@ -27,7 +27,7 @@
 #ifndef DOCGEN
 
 #include "rpp/rpp.h"
-#include "hal/hal.h"
+#include "drv/digital_io_def.h"
 #include "cmdproc_utils.h"
 
 /**
@@ -43,9 +43,12 @@ 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");
-       for (i = 0; i < MAX_PIN_CNT; i++) {
-               if (pin_map[i].pin_name == PIN_NAME_UNUSED) continue;
-               rpp_sci_printf(pin_map[i].pin_name);
+       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");
        }
        return 1;
@@ -63,7 +66,6 @@ int cmd_do_pin_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 {
        char *p;
        long val;
-       uint32_t *desc;
        char spareParams;
        char pinName[32];
 
@@ -71,7 +73,6 @@ 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;
 
-       if ((desc = hal_gpio_pin_get_dsc(pinName, -1)) == NULL) return -CMDERR_BADREG;
 
        if (param[2] != NULL) {     // More parameters = set values
                p = param[2];
@@ -79,12 +80,16 @@ 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;
-               hal_gpio_pin_set_value(*desc, (uint32_t)val);
+               if (rpp_gio_set_val(pinName, val) == FAILURE) {
+                       return -CMDERR_BADPAR;;
+               }
                return cmd_opchar_replong(cmd_io, param, val, 0, 0);
-               ;
        }
        else {  // No more parameters = get values
-               uint32_t pin_value = hal_gpio_pin_get_value(*desc);
+               int32_t pin_value = rpp_gio_get_val(pinName);
+               if (pin_value == FAILURE) {
+                       return -CMDERR_BADPAR;
+               }
                rpp_sci_printf("pinval%s=%d\n", pinName, pin_value);
                return 0;
        }
@@ -101,8 +106,7 @@ int cmd_do_pin_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 int cmd_do_pin_dir(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 {
        char *p;
-       long val;
-       uint32_t *desc;
+       uint32_t val;
        char spareParams;
        char pinName[32];
 
@@ -110,28 +114,31 @@ 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;
 
-       if ((desc = hal_gpio_pin_get_dsc(pinName, -1)) == NULL) return -CMDERR_BADREG;
-
        if (param[2] != NULL) {     // More parameters = set values
                p = param[2];
-               if (sscanf(p, "%d %1s", &val, &spareParams) != 1)
+               if (sscanf(p, "%u %1s", &val, &spareParams) != 1)
                        return -CMDERR_BADPAR;
-               if (val == 1) {
-                       *desc |= PORT_CONF_SET_DIR;
-                       *desc |= PORT_CONF_DIR_OUT;
+               if (val == 0) {
+                       if (rpp_gio_set_input(pinName) == FAILURE) {
+                               return -CMDERR_BADPAR;
+                       }
                }
-               else if (val == 0) {
-                       *desc &= (~PORT_CONF_DIR_OUT);
-                       *desc |= PORT_CONF_SET_DIR;
+               else if (val == 1) {
+                       if (rpp_gio_set_output(pinName, 0) == FAILURE) {
+                               return -CMDERR_BADPAR;
+                       }
                }
-               else
+               else {
                        return -CMDERR_BADPAR;
+               }
 
-               hal_gpio_pin_conf(*desc);
                return cmd_opchar_replong(cmd_io, param, val, 0, 0);
        }
        else {  // No more parameters = get values
-               uint32_t pin_dir = hal_gpio_pin_get_direction(*desc);
+               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);
                return 0;
        }
index 88e159b3c093d2e76f8018dee5d393e44ba2a12e..6cb8ab4441a8226f010c4e7387bfe10d686299e2 100644 (file)
 
 #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;
index e1d1ca4a2c82544ba6b931dc0258b0a264cde4c9..23b8ff7af8c7f3a8bb03d9eb66e9e7629b327468 100644 (file)
@@ -28,8 +28,7 @@
 #include "cmdproc_utils.h"
 #include "drv/drv.h"
 #include <_isfuncdcl.h>
-#include "hal/spi.h"
-#include "hal/spi_resp_transl.h"
+#include "spi_resp_transl.h"
 
 /**
  *  @brief     Translate SPI response according the command and peripheral type
index e575a043e1665942cc99e9060b175be74e4285ab..98dfa8b9cb1c9ba8b026e3ca8269fe6d6204a3eb 100644 (file)
@@ -24,7 +24,7 @@
 #ifndef DOCGEN
 
 #include "rpp/rpp.h"
-#include "hal/hal.h"
+#include "drv/digital_io_def.h"
 
 #define VBATPWM_PERIOD 400
 
@@ -51,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;
 }
 
 /**
@@ -84,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);
 }
@@ -100,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);
 }
 
diff --git a/rpp-test-sw/commands/spi_resp_transl.c b/rpp-test-sw/commands/spi_resp_transl.c
new file mode 100644 (file)
index 0000000..a4a5799
--- /dev/null
@@ -0,0 +1,358 @@
+/* Copyright (C) 2012-2013, 2015 Czech Technical University in Prague
+ *
+ * Authors:
+ *     - Michal Horn <hornmich@fel.cvut.cz>
+ *
+ * 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 : spi_resp_transl.c
+ *
+ * Abstract:
+ *         This module provides the capability to translate pure SPI response into human readable form.
+ *
+ *      Some SPI peripherals provides simple responses, but some others provide responses depending
+ *      on previous command, they have obtained.
+ *
+ *      So we have a structure, that maps SPI peripheral names (spi port names) to arrays of another
+ *      structure, that maps spi commands to responses field descriptors.
+ *
+ *      Command to response field map consists of a command mask, command, pointer to field
+ *      descriptor and number of fields in field descriptor.
+ *
+ *      Each fields descriptor maps field name to field mask, that specifies the meaning of each
+ *      bit or group of bits in the response.
+ */
+
+#include "drv/digital_io.h"
+#include "drv/spi.h"
+#include "spi_resp_transl.h"
+
+// Field descriptors
+static const spitr_field_desc_t din_glob_field_descs[DIN_NUM_GLOB_FD] = {
+       { .field_name = "Thermal flag\t",           .mask = (1 << 23) },
+       { .field_name = "INT flag\t",               .mask = (1 << 22) },
+       { .field_name = "SP0  - DIN0\t",            .mask = (1 << 14) },
+       { .field_name = "SP1  - DIN1\t",            .mask = (1 << 15) },
+       { .field_name = "SP2  - DIN2\t",            .mask = (1 << 16) },
+       { .field_name = "SP3  - DIN3\t",            .mask = (1 << 17) },
+       { .field_name = "SP4  - DIN4\t",            .mask = (1 << 18) },
+       { .field_name = "SP5  - DIN5\t",            .mask = (1 << 19) },
+       { .field_name = "SP6  - DIN6\t",            .mask = (1 << 20) },
+       { .field_name = "SP7  - DIN7\t",            .mask = (1 << 21) },
+       { .field_name = "SG0  - DIN8\t",            .mask = (1 << 0) },
+       { .field_name = "SG1  - DIN9\t",            .mask = (1 << 1) },
+       { .field_name = "SG2  - DIN10\t",           .mask = (1 << 2) },
+       { .field_name = "SG3  - DIN11\t",           .mask = (1 << 3) },
+       { .field_name = "SG4  - DIN12\t",           .mask = (1 << 4) },
+       { .field_name = "SG5  - DIN13\t",           .mask = (1 << 5) },
+       { .field_name = "SG6  - DIN14\t",           .mask = (1 << 6) },
+       { .field_name = "SG7  - DIN15\t",           .mask = (1 << 7) },
+       { .field_name = "SG8  - NA\t",              .mask = (1 << 8) },
+       { .field_name = "SG9  - NA\t",              .mask = (1 << 9) },
+       { .field_name = "SG10 - NA\t",              .mask = (1 << 10) },
+       { .field_name = "SG11 - NA\t",              .mask = (1 << 11) },
+       { .field_name = "SG12 - NA\t",              .mask = (1 << 12) },
+       { .field_name = "SG13 - NA\t",              .mask = (1 << 13) }
+};
+
+static const spitr_field_desc_t lout_glob_field_descs[LOUT_NUM_GLOB_FD] = {
+       { .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) },
+       { .field_name = "U401 IN6 state",   .mask = (1 << 29) },
+       { .field_name = "U401 IN5 state",   .mask = (1 << 30) },
+       { .field_name = "U401 Driver 8 status", .mask = (uint32_t)(1 << 31) },
+       { .field_name = "U401 Driver 7 status", .mask = (1 << 16) },
+       { .field_name = "U401 Driver 6 status", .mask = (1 << 17) },
+       { .field_name = "U401 Driver 5 status", .mask = (1 << 18) },
+       { .field_name = "U401 Driver 4 status", .mask = (1 << 19) },
+       { .field_name = "U401 Driver 3 status", .mask = (1 << 20) },
+       { .field_name = "U401 Driver 2 status", .mask = (1 << 21) },
+       { .field_name = "U401 Driver 1 status", .mask = (1 << 22) },
+       { .field_name = "U401 Thermal warning", .mask = (1 << 23) },
+       { .field_name = "U404 VS PS M",     .mask = (1 << 8) },
+       { .field_name = "U404 IN8 state",   .mask = (1 << 11) },
+       { .field_name = "U404 IN7 state",   .mask = (1 << 12) },
+       { .field_name = "U404 IN6 state",   .mask = (1 << 13) },
+       { .field_name = "U404 IN5 state",   .mask = (1 << 14) },
+       { .field_name = "U404 Driver 8 status", .mask = (1 << 15) },
+       { .field_name = "U404 Driver 7 status", .mask = (1 << 0) },
+       { .field_name = "U404 Driver 6 status", .mask = (1 << 1) },
+       { .field_name = "U404 Driver 5 status", .mask = (1 << 2) },
+       { .field_name = "U404 Driver 4 status", .mask = (1 << 3) },
+       { .field_name = "U404 Driver 3 status", .mask = (1 << 4) },
+       { .field_name = "U404 Driver 2 status", .mask = (1 << 5) },
+       { .field_name = "U404 Driver 1 status", .mask = (1 << 6) },
+       { .field_name = "U404 Thermal warning", .mask = (1 << 7) }
+};
+
+static const spitr_field_desc_t dac_glob_field_descs[DAC_NUM_GLOB_FD] = {
+       { .field_name = "Provides no informations", .mask = 0 }
+};
+
+static const spitr_field_desc_t fray_glob_field_descs[FRAY_NUM_GLOB_FD] = {
+       { .field_name = "Parity bit",           .mask = (1 << 0) },
+       { .field_name = "SPI error",            .mask = (1 << 5) },
+       { .field_name = "UVVIO",                .mask = (1 << 6) },
+       { .field_name = "UVVCC",                .mask = (1 << 7) },
+       { .field_name = "TXEN clamped",         .mask = (1 << 8) },
+       { .field_name = "Temp high",            .mask = (1 << 9) },
+       { .field_name = "Bus error",            .mask = (1 << 10) },
+       { .field_name = "Pwon",                 .mask = (1 << 11) },
+       { .field_name = "BGE clamped",          .mask = (1 << 12) },
+       { .field_name = "Transmiter enabled",   .mask = (1 << 13) },
+       { .field_name = "Normal mode",          .mask = (1 << 14) },
+       { .field_name = "Bus wake",             .mask = (1 << 15) }
+};
+
+static const spitr_field_desc_t hbr_statreg0_field_descs[HBR_NUM_STATREG_FD] = {
+       { .field_name = "GL_ER",                .mask = (1 << 15) },
+       { .field_name = "Frame Error",          .mask = (1 << 14) },
+       { .field_name = "STK_RESET_Q",          .mask = (1 << 13) },
+       { .field_name = "TSD",                  .mask = (1 << 12) },
+       { .field_name = "TW",                   .mask = (1 << 11) },
+       { .field_name = "UV",                   .mask = (1 << 10) },
+       { .field_name = "OV",                   .mask = (1 << 9) },
+       { .field_name = "WDTO",                 .mask = (1 << 8) },
+       { .field_name = "DS_MON_3",             .mask = (1 << 7) },
+       { .field_name = "DS_MON_2",             .mask = (1 << 6) },
+       { .field_name = "DS_MON_1",             .mask = (1 << 5) },
+       { .field_name = "DS_MON_0",             .mask = (1 << 4) },
+       { .field_name = "OT_EXT",               .mask = (1 << 1) },
+       { .field_name = "CP_LOW",               .mask = (1 << 0) }
+};
+
+static const spitr_field_desc_t hbr_applreg1_field_descs[HBR_NUM_APPLREG1_FD] = {
+       { .field_name = "GL_ER",                .mask = (1 << 15) },
+       { .field_name = "Frame Error",          .mask = (1 << 14) },
+       { .field_name = "STK_RESET_Q",          .mask = (1 << 13) },
+       { .field_name = "TSD",                  .mask = (1 << 12) },
+       { .field_name = "TW",                   .mask = (1 << 11) },
+       { .field_name = "UV",                   .mask = (1 << 10) },
+       { .field_name = "OV",                   .mask = (1 << 9) },
+       { .field_name = "WDTO",                 .mask = (1 << 8) },
+       { .field_name = "RWD",                  .mask = (1 << 7) },
+       { .field_name = "FW_PAS",               .mask = (1 << 6) },
+       { .field_name = "OFF_CAL",              .mask = (1 << 5) },
+       { .field_name = "CLK_SPCTR",            .mask = (1 << 4) },
+       { .field_name = "OVT",                  .mask = (1 << 3) },
+       { .field_name = "OV_UV_RD",             .mask = (1 << 2) },
+       { .field_name = "DIAG",                 .mask = (3 << 0) }
+};
+
+static const spitr_field_desc_t hbr_applreg2_field_descs[HBR_NUM_APPLREG2_FD] = {
+       { .field_name = "GL_ER",                .mask = (1 << 15) },
+       { .field_name = "Frame Error",          .mask = (1 << 14) },
+       { .field_name = "STK_RESET_Q",          .mask = (1 << 13) },
+       { .field_name = "TSD",                  .mask = (1 << 12) },
+       { .field_name = "TW",                   .mask = (1 << 11) },
+       { .field_name = "UV",                   .mask = (1 << 10) },
+       { .field_name = "OV",                   .mask = (1 << 9) },
+       { .field_name = "WDTO",                 .mask = (1 << 8) },
+       { .field_name = "RWD",                  .mask = (1 << 7) },
+       { .field_name = "COPT",                 .mask = (7 << 4) },
+       { .field_name = "FW",                   .mask = (1 << 3) },
+       { .field_name = "MCSA",                 .mask = (1 << 2) },
+       { .field_name = "GCSA",                 .mask = (3 << 0) }
+};
+
+static const spitr_field_desc_t hbr_applreg3_field_descs[HBR_NUM_APPLREG3_FD] = {
+       { .field_name = "GL_ER",                .mask = (1 << 15) },
+       { .field_name = "Frame Error",          .mask = (1 << 14) },
+       { .field_name = "STK_RESET_Q",          .mask = (1 << 13) },
+       { .field_name = "TSD",                  .mask = (1 << 12) },
+       { .field_name = "TW",                   .mask = (1 << 11) },
+       { .field_name = "UV",                   .mask = (1 << 10) },
+       { .field_name = "OV",                   .mask = (1 << 9) },
+       { .field_name = "WDTO",                 .mask = (1 << 8) },
+       { .field_name = "RWD",                  .mask = (1 << 7) },
+       { .field_name = "EXT_TS",               .mask = (1 << 6) },
+       { .field_name = "EXT_TH_5",             .mask = (1 << 5) },
+       { .field_name = "EXT_TH_4",             .mask = (1 << 4) },
+       { .field_name = "EXT_TH_3",             .mask = (1 << 3) },
+       { .field_name = "EXT_TH_2",             .mask = (1 << 2) },
+       { .field_name = "EXT_TH_1",             .mask = (1 << 1) },
+       { .field_name = "EXT_TH_0",             .mask = (1 << 0) }
+};
+
+static const spitr_field_desc_t hbr_diaddr0_field_descs[HBR_NUM_DIADDR0_FD] = {
+       { .field_name = "GL_ER",                .mask = (1 << 15) },
+       { .field_name = "Frame Error",          .mask = (1 << 14) },
+       { .field_name = "STK_RESET_Q",          .mask = (1 << 13) },
+       { .field_name = "TSD",                  .mask = (1 << 12) },
+       { .field_name = "TW",                   .mask = (1 << 11) },
+       { .field_name = "UV",                   .mask = (1 << 10) },
+       { .field_name = "OV",                   .mask = (1 << 9) },
+       { .field_name = "WDTO",                 .mask = (1 << 8) },
+       { .field_name = "FAM",                  .mask = (3 << 6) },
+       { .field_name = "NR_PI",                .mask = (0x3F << 0) }
+};
+
+static const spitr_field_desc_t hbr_diaddr1_field_descs[HBR_NUM_DIADDR1_FD] = {
+       { .field_name = "GL_ER",                .mask = (1 << 15) },
+       { .field_name = "Frame Error",          .mask = (1 << 14) },
+       { .field_name = "STK_RESET_Q",          .mask = (1 << 13) },
+       { .field_name = "TSD",                  .mask = (1 << 12) },
+       { .field_name = "TW",                   .mask = (1 << 11) },
+       { .field_name = "UV",                   .mask = (1 << 10) },
+       { .field_name = "OV",                   .mask = (1 << 9) },
+       { .field_name = "WDTO",                 .mask = (1 << 8) },
+       { .field_name = "PRD_ID",               .mask = (0xFF << 0) }
+};
+
+static const spitr_field_desc_t hbr_diaddr2_field_descs[HBR_NUM_DIADDR2_FD] = {
+       { .field_name = "GL_ER",                .mask = (1 << 15) },
+       { .field_name = "Frame Error",          .mask = (1 << 14) },
+       { .field_name = "STK_RESET_Q",          .mask = (1 << 13) },
+       { .field_name = "TSD",                  .mask = (1 << 12) },
+       { .field_name = "TW",                   .mask = (1 << 11) },
+       { .field_name = "UV",                   .mask = (1 << 10) },
+       { .field_name = "OV",                   .mask = (1 << 9) },
+       { .field_name = "WDTO",                 .mask = (1 << 8) },
+       { .field_name = "PRD_ID",               .mask = (0xFF << 0) }
+};
+
+static const spitr_field_desc_t hbr_diaddr3_field_descs[HBR_NUM_DIADDR3_FD] = {
+       { .field_name = "GL_ER",                .mask = (1 << 15) },
+       { .field_name = "Frame Error",          .mask = (1 << 14) },
+       { .field_name = "STK_RESET_Q",          .mask = (1 << 13) },
+       { .field_name = "TSD",                  .mask = (1 << 12) },
+       { .field_name = "TW",                   .mask = (1 << 11) },
+       { .field_name = "UV",                   .mask = (1 << 10) },
+       { .field_name = "OV",                   .mask = (1 << 9) },
+       { .field_name = "WDTO",                 .mask = (1 << 8) },
+       { .field_name = "BR",                   .mask = (1 << 7) },
+       { .field_name = "AR5",                  .mask = (1 << 6) },
+       { .field_name = "AR4",                  .mask = (1 << 5) },
+       { .field_name = "AR3",                  .mask = (1 << 4) },
+       { .field_name = "32-bits",              .mask = (1 << 3) },
+       { .field_name = "24-bits",              .mask = (1 << 2) },
+       { .field_name = "16-bits",              .mask = (1 << 1) },
+       { .field_name = "8-bits",               .mask = (1 << 0) }
+};
+
+/* 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_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_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_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_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 },
+};
+
+/* 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 }
+};
+
+
+
+/**
+ *  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
+ */
+const spitr_cmd_map_t *get_spi_cmd_map(const char *spi_port_name, int len, uint32_t *num_cmdDesc)
+{
+       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;
+
+       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;
+               }
+       }
+       *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)
+{
+       if (cmd_map == NULL) {
+               *num_fdDesc = 0;
+               return NULL;
+       }
+
+       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;
+               }
+       }
+       *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)
+{
+       uint32_t 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);
+       }
+       table->num_rows = num_fields;
+       return i;
+}
diff --git a/rpp-test-sw/commands/spi_resp_transl.h b/rpp-test-sw/commands/spi_resp_transl.h
new file mode 100644 (file)
index 0000000..ff4ab5c
--- /dev/null
@@ -0,0 +1,73 @@
+/**
+ *
+ * @file spi_resp_transl.h
+ *
+ * @copyright Copyright (C) 2012-2013 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
+
+/*masked fields macros*/
+//#define __val2mfld(mask,val) (((mask)&~((mask)<<1))*(val)&(mask))
+//#define __mfld2val(mask,val) (((val)&(mask))/((mask)&~((mask)<<1)))
+
+
+typedef struct spitr_field_desc_st {
+       const char *field_name;
+       uint32_t mask;
+} spitr_field_desc_t;
+
+typedef struct spitr_cmd_map_st {
+       uint32_t cmd_msk;
+       uint32_t command;
+       const spitr_field_desc_t *field_desc;
+       uint32_t num_fields;
+} spitr_cmd_map_t;
+
+typedef struct spitr_name_map_st {
+       const char *spi_name;
+       const spitr_cmd_map_t *cmd_map;
+       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;
+
+
+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);
+
+#endif /* SPI_RESP_TRANSL_H_ */