]> rtime.felk.cvut.cz Git - rpp-test-sw.git/blobdiff - rpp-test-sw/commands/_tms570_rpp/cmd_pin.c
Merge branches 'master' and 'rm48/master'
[rpp-test-sw.git] / rpp-test-sw / commands / _tms570_rpp / cmd_pin.c
diff --git a/rpp-test-sw/commands/_tms570_rpp/cmd_pin.c b/rpp-test-sw/commands/_tms570_rpp/cmd_pin.c
new file mode 100644 (file)
index 0000000..0d8edf4
--- /dev/null
@@ -0,0 +1,282 @@
+/*
+ * 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
+};