]> rtime.felk.cvut.cz Git - rpp-test-sw.git/commitdiff
The commands for port control tuned.
authorMichal Horn <hornmich@fel.cvut.cz>
Wed, 31 Jul 2013 15:50:11 +0000 (17:50 +0200)
committerMichal Horn <hornmich@fel.cvut.cz>
Wed, 31 Jul 2013 15:50:11 +0000 (17:50 +0200)
Portlist now prints the list of the ports in format PortName - Interface type (SPI, ADC, GPIO).
Portlist is now functional for all listed peripherals.
Commands help modified to reflex new features.

commands/cmd_port.c
rpp-lib

index 0da51c1bc17a4c12c792477d0b45d7b656913376..25cb249aed9adc82beb932cc550c7266e2941669 100644 (file)
 
 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;
-               rpp_sci_printf("%s\r\n", ports[i].name);
+               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;
 }
@@ -59,36 +68,56 @@ int cmd_do_port_list(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
  * @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 opchar;
-         int i;
-         port_desc_t* desc;
-         uint32_t ret;
-         uint32_t values[MAX_PARAM_VALUES_NUM];
-
-         if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
-
-         if((desc = hal_port_get_dsc(param[1], param[2]-param[1]))==NULL) return -CMDERR_BADREG;
-
-         if(opchar==':'){
-           p=param[3];
-               si_skspace(&p);
-               i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 16);
-               if (i < 0)
-                       return i;
-               if (i != desc->numValues)
-                       return -CMDERR_BADPAR;
-
-           ret = desc->port_setfnc_ptr(desc->config, desc->numValues, values);
-           return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
-         }
-         else{
-               ret = desc->port_getfnc_ptr(desc->config, desc->numValues, values);
-               for (i = 0; i < desc->numValues; i++) {
-                       rpp_sci_printf("%h\r\n", values[i]);
+  char *p;
+  int opchar;
+  int i;
+  port_desc_t* desc;
+  uint32_t ret;
+  uint32_t values[MAX_PARAM_VALUES_NUM];
+
+  if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
+
+  if((desc = hal_port_get_dsc(param[1], param[2]-param[1]))==NULL) return -CMDERR_BADREG;
+
+  if(opchar==':'){
+       p=param[3];
+       si_skspace(&p);
+       i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 16);
+       if (i < 0)
+               return i;
+       if (desc->port_setfnc_ptr == NULL) {
+               return -CMDERR_WRPERM;
+       }
+       else {
+               if (desc->interfaceType == PORT_INTERFACE_GPIO) {
+                       if (i != desc->numValues/8+1)   // Information about pin values are encoded as hexadecimal 8b value
+                               return -CMDERR_BADPAR;
+               }
+               else if (desc->interfaceType == PORT_INTERFACE_SPI) {
+                       if (i != desc->numValues)       // Commands are passed as bytes
+                               return -CMDERR_BADPAR;
+               }
+               else if (desc->interfaceType == PORT_INTERFACE_ADC) {
+                       return -CMDERR_BADPAR;  // ADC is read only and no other port is supported
+               }
+               if (desc->port_setfnc_ptr != NULL) {
+                       ret = desc->port_setfnc_ptr(desc->config, desc->numValues, values);
                }
-           return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
+       }
+       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]);
+                       }
          }
+         return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
+  }
 }
 
 #endif /* DOCGEN */
@@ -109,23 +138,47 @@ cmd_des_t const cmd_des_port_val={
     "=== Description ===\n"
     "\n"
     "This command sets or gets values of all pins on the specified port.\n"
-    "The lowest significant bit is assigned to the first pin, the second\n"
-    "bit is assigned to the second pin, etc.\n"
+    "If the port is connected to the GPIO interface of the MCU, then\n"
+    "when writting 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"
-    "Port names can be obtained with the portlist command.\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"
-    "=== Example ===\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"
-    "   --> portvalLOUT:(FA)\n"        /* FIXME: This example returns ERROR 20 */
-    "   LOUT1 = 0\n"
+    "Port names and interface type can be obtained with the portlist\n"
+    "command.\n"
     "\n"
-    "   LOUT2 = 1\n"
+    "NOTE: For successful communication with the HBR, HBR_EN pin must\n"
+    "be set first.\n"
     "\n"
-    "   LOUT3 = 0\n"
+    "=== Example ===\n"
     "\n"
-    "   LOUT4 = 1\n"
+    "   --> portvalMOUTIN:(3A)\n"
+    "   portvalMOUTIN=0\n"
+    "   --> portvalMOUTIN?\n"
+    "   0\n"
+    "   1\n"
+    "   0\n"
+    "   1\n"
+    "   1\n"
+    "   1\n"
     "\n"
-    "   LOUT5-8 = 1\n",
+    "This pair of commands sets:\nMOUT1IN"
+    "MOUT1IN=0\n"
+    "MOUT2IN=1\n"
+    "MOUT3IN=0\n"
+    "MOUT4IN=1\n"
+    "MOUT5IN=1\n"
+    "MOUT6IN=1\n"
+    "Which is shown in getter output\n",
     CMD_HANDLER(cmd_do_port_val), (void *)&cmd_list_port
 };
 
@@ -140,27 +193,30 @@ cmd_des_t const cmd_des_port_list={
     "=== Description ===\n"
     "\n"
     "This command prints the list of all defined ports accessible via the\n"
-    "portval command.\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"
-    "   DINMCU\n"
-    "   DINSPI\n"
-    "   HOUTDIAG\n"
-    "   HOUTIN\n"
-    "   HOUTIFBK\n"
-    "   ADC\n"
-    "   LOUT\n"
-    "   DAC12\n"
-    "   DAC34\n"
-    "   DACDREF\n"
-    "   HBR\n"
-    "   DAC12\n"
-    "   FRAY1\n"
-    "   FRAY2\n"
-    "   MOUTEN\n",
+    "   DINMCU, GPIO\n"
+    "   DINSPI, SPI\n"
+    "   HOUTDIAG, GPIO\n"
+    "   HOUTIN, GPIO\n"
+    "   HOUTIFBK, ADC\n"
+    "   ADC, ADC\n"
+    "   LOUT, SPI\n"
+    "   DAC12, SPI\n"
+    "   DAC34, SPI\n"
+    "   DACDREF, SPI\n"
+    "   HBR, SPI\n"
+    "   FRAY1, SPI\n"
+    "   FRAY2, SPI\n"
+    "   MOUTEN, GPIO\n"
+    "   MOUTIN, GPIO\n",
     CMD_HANDLER(cmd_do_port_list), (void *)&cmd_list_port
 };
 
diff --git a/rpp-lib b/rpp-lib
index bf03bedb2d6d9a8df678d752a30acf8d97b519cf..ca997bcd0a1b66daf3c217762b26af1b74c45c87 160000 (submodule)
--- a/rpp-lib
+++ b/rpp-lib
@@ -1 +1 @@
-Subproject commit bf03bedb2d6d9a8df678d752a30acf8d97b519cf
+Subproject commit ca997bcd0a1b66daf3c217762b26af1b74c45c87