]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blobdiff - rpp-test-sw/commands/cmd_pin.c
Change license to MIT
[pes-rpp/rpp-test-sw.git] / rpp-test-sw / commands / cmd_pin.c
index 9c1bbcf20fb3190b51cbf79434766f0ce93a850e..6816d50928662041a5805e1a82955357dde1ccd4 100644 (file)
@@ -1,31 +1,39 @@
 /*
- * Copyright (C) 2012-2013 Czech Technical University in Prague
+ * Copyright (C) 2012-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.
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
  *
  * 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
+ *      Commands for pin controlling
+ *          - Printing list of available pins
+ *          - Setting and getting value to pins
+ *          - Setting and getting pins direction
  */
 
 #include "cmd_pin.h"
@@ -35,7 +43,7 @@
 #ifndef DOCGEN
 
 #include "rpp/rpp.h"
-#include "hal/hal.h"
+#include "drv/gio_tab.h"
 #include "cmdproc_utils.h"
 
 /**
  * @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[]) {
+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");
-       }
+       for (i = 0; i < ARRAY_SIZE(gio_table); i++)
+               rpp_sci_printf("%s\r\n", gio_table[i].pin_name);
        return 1;
 }
 
+static enum pin_name pin_from_name(const char *pin_name)
+{
+       uint32_t i;
+
+       for (i = 0; i < ARRAY_SIZE(gio_table); i++)
+               if (strcmp(pin_name, gio_table[i].pin_name) == 0)
+                       return (enum pin_name)i;
+       return _PIN_INVALID;
+}
+
 /**
  * @brief      Set or get pin value
  *
@@ -65,35 +82,40 @@ int cmd_do_pin_list(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
  * @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];
+int cmd_do_pin_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+       char *p;
+       long val;
+       char spareParams;
+       char pinName[32];
 
-         p = param[1];
-         if (sscanf(p, "%31s ", pinName) != 1) {
-                 return -CMDERR_BADPAR;
-         }
+       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;
+       enum pin_name pin = pin_from_name(pinName);
+       if (pin == _PIN_INVALID)
+               return -CMDERR_BADPAR;
 
-         if(param[2] != NULL){         // More parameters = set values
-               p=param[2];
-               if (sscanf(p, "%d %1s", &val, &spareParams) != 1) {
+       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;
+               if (rpp_gio_set(pin, val) == FAILURE) {
+                       return -CMDERR_BADPAR;;
+               }
+               return cmd_opchar_replong(cmd_io, param, val, 0, 0);
+       }
+       else {  // No more parameters = get values
+               int pin_value = rpp_gio_get(pin);
+               if (pin_value == FAILURE) {
                        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;
-         }
+       }
 }
 
 /**
@@ -104,119 +126,116 @@ int cmd_do_pin_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
  * @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];
+int cmd_do_pin_dir(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+       char *p;
+       uint32_t val;
+       char spareParams;
+       char pinName[32];
 
-         p = param[1];
-         if (sscanf(p, "%31s ", pinName) != 1) {
-                 return -CMDERR_BADPAR;
-         }
+       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;
+       enum pin_name pin = pin_from_name(pinName);
+       if (pin == _PIN_INVALID)
+               return -CMDERR_BADPAR;
 
-         if(param[2] != NULL){         // More parameters = set values
-               p=param[2];
-               if (sscanf(p, "%d %1s", &val, &spareParams) != 1) {
+       if (param[2] != NULL) {     // More parameters = set values
+               p = param[2];
+               if (sscanf(p, "%u %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;
-           }
+               uint32_t pin_dsc = gio_table[pin].pin_dsc;
+
+               pin_dsc &= ~GIO_PIN_CONF_DIR_MASK;
+               pin_dsc |= val ? GIO_PIN_CONF_DIR_OUT : GIO_PIN_CONF_DIR_IN;
+
+               gio_setup(pin_dsc);
 
-           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 cmd_opchar_replong(cmd_io, param, val, 0, 0);
+       }
+       else {  // No more parameters = get values
+               int32_t pin_dir = 0/* rpp_gio_is_dir_output(pinName) */;
+/*             if (pin_dir == FAILURE) { */
+/*                     return -CMDERR_BADPAR; */
+/*             } */
+               rpp_sci_printf("pindir%s=%d FIXME not implemented\n", pinName, pin_dir);
                return 0;
-         }
+       }
 }
 
-#endif /* DOCGEN */
+#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"
-    "    FANCTRL\n"
-    "    ETHRST\n"
-    "    VBAT1EN\n"
-    "    VBAT2EN\n"
-    "    VBAT3EN\n"
-    "    VBATEN\n"
-    "    SPICSA\n"
-    "    SPICSB\n"
-    "    MOUT1EN\n"
-    "    MOUT2EN\n"
-    "    CANNSTB\n"
-    "    CANEN\n"
-    "    LIN2NSLP\n"
-    "    LIN1NSLP\n"
-    "    DININT\n"
-    "    DIN8\n"
-    "    DIN9\n"
-    "    DIN10\n"
-    "    DIN11\n"
-    "    DIN12\n"
-    "    DIN13\n"
-    "    DIN14\n"
-    "    DIN15\n"
-    "    MOUT6EN\n"
-    "    MOUT5EN\n"
-    "    MOUT6IN\n"
-    "    MOUT5IN\n"
-    "    MOUT4EN\n"
-    "    MOUT3EN\n"
-    "    MOUT4IN\n"
-    "    MOUT3IN\n"
-    "    HBREN\n"
-    "    HBRDIR\n"
-    "    HBRPWM\n"
-    "    MOUT1IN\n"
-    "    MOUT2IN\n"
-    "    HOUT1IN\n"
-    "    HOUT1DIAG\n"
-    "    HOUT2IN\n"
-    "    HOUT2DIAG\n"
-    "    HOUT3IN\n"
-    "    HOUT3DIAG\n"
-    "    HOUT4IN\n"
-    "    HOUT4DIAG\n"
-    "    HOUT5IN\n"
-    "    HOUT5DIAG\n"
-    "    HOUT6IN\n"
-    "    HOUT6DIAG\n",
-    CMD_HANDLER(cmd_do_pin_list), (void *)&cmd_list_pin
+       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={
+cmd_des_t const cmd_des_pin_val = {
        0, 0,
        "pinval*","Set or get the pin value",
        "### Command syntax ###\n"
@@ -234,27 +253,22 @@ cmd_des_t const cmd_des_pin_val={
        "\n"
        "The list of valid pin names can be obtained with pinlist command.\n"
        "\n"
-       "Most of the pins are accessible indirectly via other highlevel\n"
-       "commands. HBR_EN is, for example, controlled by the hbrenable command.\n"
-       "This command serves as supplement to highlevel commands for testing\n"
-       "purpose.\n"
-       "\n"
        "### Example ###\n"
        "\n"
-       "    --> pinvalHBREN 1\n"
-       "    pinvalHBREN=1\n"
+       "    --> pinvalGIOB0 1\n"
+       "    pinvalGIOB0=1\n"
        "\n"
-       "Sets the HBR_EN pin to 1.\n"
+       "Sets the GIOB0 pin to 1.\n"
        "\n"
-       "    --> pinvalHBREN\n"
-       "    pinvalHBREN=1\n"
+       "    --> pinvalGIOB0\n"
+       "    pinvalGIOB0=1\n"
        "\n"
-       "Gets a value of the HBR_EN pin.\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={
+cmd_des_t const cmd_des_pin_dir = {
        0, 0,
        "pindir*","Set the pin direction",
        "### Command syntax ###\n"
@@ -272,29 +286,24 @@ cmd_des_t const cmd_des_pin_dir={
        "\n"
        "The list of valid pin names can be obtained with pinlist command.\n"
        "\n"
-       "Most of the pins are accessible indirectly via other highlevel\n"
-       "commands HBR_EN is, for example, controlled by the hbrenable command.\n"
-       "This command serves as supplement to highlevel commands for testing\n"
-       "purpose.\n"
-       "\n"
        "### Example ###\n"
        "\n"
-       "    --> pindirHBREN 1\n"
-       "    pindirHBREN=1\n"
+       "    --> pindirGIOB0 1\n"
+       "    pindirGIOB0=1\n"
        "\n"
-       "Sets the HBR_EN pin as output.\n"
+       "Sets the GIOB0 pin as output.\n"
        "\n"
-       "    --> pindirHBREN\n"
-       "    pindirHBREN=1\n"
+       "    --> pindirGIOB0\n"
+       "    pindirGIOB0=1\n"
        "\n"
-       "Gets the direction of the HBR_EN pin.\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
+cmd_des_t const *cmd_list_pin[] = {
+       &cmd_des_pin_list,
+       &cmd_des_pin_val,
+       &cmd_des_pin_dir,
+       NULL
 };