]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blobdiff - rpp-test-sw/commands/cmd_pin.c
Port GPIO control commands
[pes-rpp/rpp-test-sw.git] / rpp-test-sw / commands / cmd_pin.c
index 9c1bbcf20fb3190b51cbf79434766f0ce93a850e..65fd0a245b7e3b683182f1411441705b1bb7275f 100644 (file)
@@ -6,26 +6,18 @@
  * 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_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"
  * @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;
@@ -65,35 +59,35 @@ 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;
+       uint32_t *desc;
+       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;
+       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 (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
+               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 +98,117 @@ 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;
+       long val;
+       uint32_t *desc;
+       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;
+       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 (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;
                }
-           if (val == 1) {
-               *desc |= PORT_CONF_SET_DIR;
-               *desc |= PORT_CONF_DIR_OUT;
-           }
-           else if (val == 0) {
-               *desc &= (~PORT_CONF_DIR_OUT);
+               else if (val == 0) {
+                       *desc &= (~PORT_CONF_DIR_OUT);
                        *desc |= PORT_CONF_SET_DIR;
-           }
-           else {
-                     return -CMDERR_BADPAR;
-           }
+               }
+               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
+               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 */
+#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 +226,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 +259,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
 };