]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blobdiff - rpp-test-sw/commands/cmd_spi.c
Update library
[pes-rpp/rpp-test-sw.git] / rpp-test-sw / commands / cmd_spi.c
index d09b4bac5f17e2b4fac7fab7974b8432e40a612c..23b8ff7af8c7f3a8bb03d9eb66e9e7629b327468 100644 (file)
@@ -1,29 +1,21 @@
 /*
- * Copyright (C) 2012-2013 Czech Technical University in Prague
+ * Copyright (C) 2012-2013, 2015 Czech Technical University in Prague
  *
  * Created on: 28.2.2013
  *
  * Authors:
  *     - Michal Horn
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * This document contains proprietary information belonging to Czech
+ * Technical University in Prague. Passing on and copying of this
+ * document, and communication of its contents is not permitted
+ * without prior written authorization.
  *
  * File : cmd_spi.c
  *
  * Abstract:
- *     Command for processing data from SPI and
- *     lowlevel command for sending data on SPI
+ *      Command for processing data from SPI and
+ *      lowlevel command for sending data on SPI
  *
  */
 
 #include "cmdproc_utils.h"
 #include "drv/drv.h"
 #include <_isfuncdcl.h>
+#include "spi_resp_transl.h"
 
 /**
- *     @brief  Translate SPI response according the command and peripheral type
+ *  @brief     Translate SPI response according the command and peripheral type
  *
  * @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_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;
+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) {
-                 return -CMDERR_BADPAR;
-         }
+       p = param[1];
+       if (sscanf(p, "%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_cmd_map_t *cmdDesc = cmdDesc = get_spi_cmd_map(peripheralName, -1, &numCmdDesc);
+       if (cmdDesc == 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 (param[2] != NULL) {         // More parameters expected
+               p = param[2];
+               if (sscanf(p, "%x %x %1s", &values[0], &values[1], &spareParams) != 2)
                        return -CMDERR_BADPAR;
-               }
                command = values[0];
                response = values[1];
 
-               const spitr_field_desc_tfieldDescs = get_spi_field_desc(cmdDesc, numCmdDesc, command, &numFieldDesc);
+               const spitr_field_desc_t *fieldDescs = get_spi_field_desc(cmdDesc, numCmdDesc, command, &numFieldDesc);
                if (fieldDescs == NULL)
                        return -CMDERR_BADPAR;
 
@@ -85,10 +77,9 @@ int cmd_do_spi_translate(cmd_io_t *cmd_io, const struct cmd_des *des, char *para
                        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);
-         }
-         else{
-                 return -CMDERR_BADPAR;
-         }
+       }
+       else
+               return -CMDERR_BADPAR;
 }
 
 
@@ -119,7 +110,7 @@ int spimst_print_rx(struct spi_drv *ifc, int status, int addr, uint8_t *buf)
 
 
 /**
- *     @brief  Send SPI command on SPI and receive response
+ *  @brief     Send SPI command on SPI and receive response
  *
  * @param[in]  cmd_io  Pointer to IO stack
  * @param[in]  des             Pointer to command descriptor
@@ -131,28 +122,25 @@ int cmd_do_spimst(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
        spi_drv_t *ifc;
        int i;
        char *p;
-       chartoken;
+       char *token;
        int ret;
        unsigned int addr;
        unsigned int rq_len;
        int spi;
        int values[MAX_PARAM_VALUES_NUM];
 
-       p=param[1];
-       if (sscanf(p, "%d", &spi) != 1) {
+       p = param[1];
+       if (sscanf(p, "%d", &spi) != 1)
                return -CMDERR_BADPAR;
-       }
-       p=param[2];
-       if (sscanf(p, " %d", &addr) != 1) {
+       p = param[2];
+       if (sscanf(p, " %d", &addr) != 1)
                return -CMDERR_BADPAR;
-       }
        token = strtok(p, " ");
        token = strtok(NULL, " ");
        i = 0;
        while (i < MAX_PARAM_VALUES_NUM && token != NULL) {
-               if (sscanf(token, "%x", &values[i]) == EOF) {
+               if (sscanf(token, "%x", &values[i]) == EOF)
                        break;
-               }
                token = strtok(NULL, " ");
                spi_test_buf_tx[i] = (uint8_t)values[i];
                i++;
@@ -163,10 +151,9 @@ int cmd_do_spimst(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
        if (ifc == NULL)
                return -CMDERR_NODEV;
 
-       if (!(ifc->flags & SPI_IFC_ON)) {
+       if (!(ifc->flags & SPI_IFC_ON))
                //if (spi_tms570_init(ifc) < 0)
                return -CMDERR_BADCFG;
-       }
 
        rq_len = i;
 
@@ -175,20 +162,21 @@ int cmd_do_spimst(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
        return 0;
 }
 
-#endif /* DOCGEN */
+#endif  /* DOCGEN */
 /** Command descriptor for SPI response translation */
-cmd_des_t const cmd_des_spi_translate={
+cmd_des_t const cmd_des_spi_translate = {
        0, CDESM_OPCHR|CDESM_RW,
        "spitr*","Translate response from an SPI peripheral",
-       "=== Command syntax ===\n"
+       "### Command syntax ###\n"
        "\n"
-       "   spitr<NAME> <CMD> <RESP>\n"
+       "    spitr<NAME> <CMD> <RESP>\n"
        "where\n"
-       "* <NAME> is a string specifying the name of the peripheral (one of DINSPI, LOUT, DAC12, DAC34, HBR, FRAY1 and FRAY2)\n"
-       "* <CMD> is a hexadecimal number in range 0 - FFFFFFFF\n"
-       "* <RESP> is a hexadecimal number in range 0 - FFFFFFFF\n"
        "\n"
-       "=== Description ===\n"
+       "- `<NAME>` is a string specifying the name of the peripheral (one of DINSPI, LOUT, DAC12, DAC34, HBR, FRAY1 and FRAY2)\n"
+       "- `<CMD>` is a hexadecimal number in range 0 - FFFFFFFF\n"
+       "- `<RESP>` is a hexadecimal number in range 0 - FFFFFFFF\n"
+       "\n"
+       "### Description ###\n"
        "\n"
        "This command translates a response from SPI from many different\n"
        "peripherals into a human readable form. The SPI response is in the\n"
@@ -197,35 +185,35 @@ cmd_des_t const cmd_des_spi_translate={
        "response, the name of the peripheral and translates the response into\n"
        "the attribute-value table.\n"
        "\n"
-       "=== Example ===\n"
-       "   --> portvalDINSPI 7F 00 00\n"
-       "   portvalDINSPI=AAC03F\n"
-       "   --> spitrDINSPI 7F0000 3FC0AA\n"
-       "   Thermal flag        : 0\n"
-       "   INT flag    : 0\n"
-       "   SP0  - DIN0 : 1\n"
-       "   SP1  - DIN1 : 1\n"
-       "   SP2  - DIN2 : 1\n"
-       "   SP3  - DIN3 : 1\n"
-       "   SP4  - DIN4 : 1\n"
-       "   SP5  - DIN5 : 1\n"
-       "   SP6  - DIN6 : 1\n"
-       "   SP7  - DIN7 : 1\n"
-       "   SG0  - DIN8 : 0\n"
-       "   SG1  - DIN9 : 1\n"
-       "   SG2  - DIN10        : 0\n"
-       "   SG3  - DIN11        : 1\n"
-       "   SG4  - DIN12        : 0\n"
-       "   SG5  - DIN13        : 1\n"
-       "   SG6  - DIN14        : 0\n"
-       "   SG7  - DIN15        : 1\n"
-       "   SG8  - NA   : 0\n"
-       "   SG9  - NA   : 0\n"
-       "   SG10 - NA   : 0\n"
-       "   SG11 - NA   : 0\n"
-       "   SG12 - NA   : 0\n"
-       "   SG13 - NA   : 0\n"
-       "   spitrDINSPI=24\n"
+       "### Example ###\n"
+       "    --> portvalDINSPI 7F 00 00\n"
+       "    portvalDINSPI=AAC03F\n"
+       "    --> spitrDINSPI 7F0000 3FC0AA\n"
+       "    Thermal flag       : 0\n"
+       "    INT flag   : 0\n"
+       "    SP0  - DIN0        : 1\n"
+       "    SP1  - DIN1        : 1\n"
+       "    SP2  - DIN2        : 1\n"
+       "    SP3  - DIN3        : 1\n"
+       "    SP4  - DIN4        : 1\n"
+       "    SP5  - DIN5        : 1\n"
+       "    SP6  - DIN6        : 1\n"
+       "    SP7  - DIN7        : 1\n"
+       "    SG0  - DIN8        : 0\n"
+       "    SG1  - DIN9        : 1\n"
+       "    SG2  - DIN10       : 0\n"
+       "    SG3  - DIN11       : 1\n"
+       "    SG4  - DIN12       : 0\n"
+       "    SG5  - DIN13       : 1\n"
+       "    SG6  - DIN14       : 0\n"
+       "    SG7  - DIN15       : 1\n"
+       "    SG8  - NA  : 0\n"
+       "    SG9  - NA  : 0\n"
+       "    SG10 - NA  : 0\n"
+       "    SG11 - NA  : 0\n"
+       "    SG12 - NA  : 0\n"
+       "    SG13 - NA  : 0\n"
+       "    spitrDINSPI=24\n"
        "\n"
        "Translates response 0x3FC0AA returned by command 0x7F0000 into a human\n"
        "readable form.\n"
@@ -238,32 +226,33 @@ cmd_des_t const cmd_des_spi_translate={
 cmd_des_t const cmd_des_spimst = {
        0, 0,
        "spimst*", "Request SPI master communication",
-       "=== Command syntax ===\n"
+       "### Command syntax ###\n"
        "\n"
-       "   spimst<SPI> <ADDR> <DATA>\n"
+       "    spimst<SPI> <ADDR> <DATA>\n"
        "where\n"
-       "* <SPI> is a number in range 0 - 4\n"
-       "* <ADDR> is a number in range 0 - 2\n"
-       "* <DATA> is a sequence of hexadecimal numbers, separated by spaces, e.g. 12 AA CD\n"
        "\n"
-       "=== Description ===\n"
+       "- `<SPI>` is a number in range 0 - 4\n"
+       "- `<ADDR>` is a number in range 0 - 2\n"
+       "- `<DATA>` is a sequence of hexadecimal numbers, separated by spaces, e.g. 12 AA CD\n"
+       "\n"
+       "### Description ###\n"
        "\n"
        "The command sends given data to the SPI peripheral and prints the\n"
        "response. The response contains the address and the received data in\n"
        "parentheses.\n"
        "\n"
-       "=== Example ===\n"
+       "### Example ###\n"
        "\n"
-       "   --> spimst1 0 7F 00 00\n"
-       "   spirx:0x0(0x3f,0xc0,0xff)\n"
+       "    --> spimst1 0 7F 00 00\n"
+       "    spirx:0x0(0x3f,0xc0,0xff)\n"
        "\n"
        "Sends reset command (0x7F0000) to the DIN peripheral.\n",
        CMD_HANDLER(cmd_do_spimst), (void *)&cmd_list_spi
 };
 
 /** List of commands for SPI, defined as external */
-cmd_des_t const *cmd_list_spi[]={
-  &cmd_des_spi_translate,
-  &cmd_des_spimst,
-  NULL
+cmd_des_t const *cmd_list_spi[] = {
+       &cmd_des_spi_translate,
+       &cmd_des_spimst,
+       NULL
 };