]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blobdiff - rpp-test-sw/commands/cmd_lout.c
Merge branches 'master' and 'rm48/master'
[pes-rpp/rpp-test-sw.git] / rpp-test-sw / commands / cmd_lout.c
diff --git a/rpp-test-sw/commands/cmd_lout.c b/rpp-test-sw/commands/cmd_lout.c
new file mode 100644 (file)
index 0000000..6922fea
--- /dev/null
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2012-2013 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_lout.c
+ *
+ * Abstract:
+ *      This file contains commands for testing LOUT (8x100mA Digital output).
+ *
+ */
+
+
+#include "cmd_lout.h"
+#include "stdio.h"
+
+#ifndef DOCGEN
+
+#include "rpp/rpp.h"
+#include "cmdproc_utils.h"
+#include "drv/drv.h"
+
+/**
+ * @brief Set digital value to LOUT pin
+ *
+ * @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 lower than 0
+ */
+int cmd_do_lout_set(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+       int pin;
+       char *p = param[1];
+       char spareParams;
+       int val;
+       int ret;
+
+       if (sscanf(p, "%d %d %1s", &pin, &val, &spareParams) != 2)
+               return -CMDERR_BADPAR;
+       ret = rpp_lout_set(pin, val);
+       if (ret == -1) {
+               rpp_sci_printf("Pin out of range.");
+               return -CMDERR_BADPAR;
+       }
+
+       if (rpp_lout_update() == FAILURE) {
+               rpp_sci_printf("LOUT update failed.");
+               return -CMDERR_EIO;
+       }
+
+       return cmd_opchar_replong(cmd_io, param, val, 0, 10);
+}
+
+/**
+ * @brief Read digital diagnostic value from LOUT DIAG pin
+ *
+ * @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 lower than 0
+ */
+int cmd_do_lout_diag(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+       int pin;
+       char *p = param[1];
+       char spareParams;
+       int ret;
+
+       if (sscanf(p, "%d %1s", &pin, &spareParams) != 1)
+               return -CMDERR_BADPAR;
+
+       if (rpp_lout_update() == FAILURE) {
+               rpp_sci_printf("LOUT update failed.");
+               return -CMDERR_EIO;
+       }
+
+       ret = rpp_lout_diag(pin);
+       if (ret == -1) {
+               rpp_sci_printf("Pin out of range.");
+               return -CMDERR_BADPAR;
+       }
+
+       rpp_sci_printf("loutdiag%d=%d\n", pin, ret, ret);
+       return 0;
+}
+
+#endif  /* DOCGEN */
+
+/** Command descriptor for lout set port value */
+cmd_des_t const cmd_des_lout_set = {
+       0, 0,
+       "loutset*","Set a value of the LOUT pin",
+       "### Command syntax ###\n"
+       "\n"
+       "    loutset<PIN> <VALUE>\n"
+       "where\n"
+       "\n"
+       "- `<PIN>` is a number in range 1-8\n"
+       "- `<VALUE>` is a binary value to be set (0 or 1)\n"
+       "\n"
+       "### Description ###\n"
+       "\n"
+       "The command sets the digital value on the LOUT pin.\n"
+       "\n"
+       "### Example ###\n"
+       "\n"
+       "    --> loutset1 1\n"
+       "\n"
+       "Sets LOUT1 to 1.\n"
+       "\n"
+       "    --> loutset2 0\n"
+       "\n"
+       "Sets LOUT2 to 0.\n",
+       CMD_HANDLER(cmd_do_lout_set), (void *)&cmd_list_lout
+};
+
+/** Command descriptor for lout get pin diag value */
+cmd_des_t const cmd_des_lout_diag = {
+       0, 0,
+       "loutdiag*","Read a diagnostic value from an LOUT pin",
+       "### Command syntax ###\n"
+       "\n"
+       "    loutdiag<PIN>\n"
+       "\n"
+       "where `<PIN>` is a number in range 1-8\n"
+       "\n"
+       "### Description ###\n"
+       "\n"
+       "The command reads a logical value of the LOUT diagnostic signal.\n"
+       "\n"
+       "### Example ###\n"
+       "\n"
+       "    --> loutdiag1\n"
+       "\n"
+       "Reads value of the LOUT1 diagnostic signal.\n",
+       CMD_HANDLER(cmd_do_lout_diag), (void *)&cmd_list_lout
+};
+
+
+/** List of commands for hout, defined as external */
+cmd_des_t const *cmd_list_lout[] = {
+       &cmd_des_lout_set,
+       &cmd_des_lout_diag,
+       NULL
+};