]> rtime.felk.cvut.cz Git - rpp-test-sw.git/blobdiff - rpp-test-sw/commands/cmd_mout.c
Add MOUT commands
[rpp-test-sw.git] / rpp-test-sw / commands / cmd_mout.c
diff --git a/rpp-test-sw/commands/cmd_mout.c b/rpp-test-sw/commands/cmd_mout.c
new file mode 100644 (file)
index 0000000..c8ab76a
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2012-2013, 2016 Czech Technical University in Prague
+ *
+ * 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_mout.c
+ *
+ * Abstract:
+ *      This file contains commands for testing MOUT
+ *
+ */
+
+
+#include "cmd_mout.h"
+#include "stdio.h"
+
+#ifndef DOCGEN
+
+#include "rpp/rpp.h"
+#include "cmdproc_utils.h"
+
+int cmd_do_mout_set(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+       int pin;
+       char *p = param[1];
+       char spareParams[2];
+       int val;
+       int ret;
+
+       if (sscanf(p, "%d %d %1s", &pin, &val, spareParams) != 2)
+               return -CMDERR_BADPAR;
+       ret = rpp_mout_set(pin, val);
+       if (ret == -1) {
+               rpp_sci_printf("Pin out of range.\n");
+               return -CMDERR_BADPAR;
+       }
+
+       if (ret != SUCCESS) {
+               rpp_sci_printf("MOUT set failed.\n");
+               return -CMDERR_EIO;
+       }
+
+       return cmd_opchar_replong(cmd_io, param, val, 0, 10);
+}
+
+int cmd_do_mout_diag(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+       int pin;
+       char *p = param[1];
+       char spareParams[2];
+       int ret;
+
+       if (sscanf(p, "%d %1s", &pin, spareParams) != 1)
+               return -CMDERR_BADPAR;
+
+       ret = rpp_mout_diag(pin);
+       if (ret < 0) {
+               rpp_sci_printf("Pin out of range.\n");
+               return -CMDERR_BADPAR;
+       }
+
+       rpp_sci_printf("moutdiag%d=%d\n", pin, ret);
+       return 0;
+}
+
+#endif  /* DOCGEN */
+
+/** Command descriptor for mout set port value */
+cmd_des_t const cmd_des_mout_set = {
+       0, 0,
+       "moutset*","Set a value of the MOUT pin",
+       "### Command syntax ###\n"
+       "\n"
+       "    moutset<PIN> <VALUE>\n"
+       "where\n"
+       "\n"
+       "- `<PIN>` is a number in range 1-6\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 MOUT pin.\n"
+       "\n"
+       "### Example ###\n"
+       "\n"
+       "    --> moutset1 1\n"
+       "    moutset1 =1\n"
+       "\n"
+       "Sets MOUT1 to 1.\n"
+       "\n"
+       "    --> moutset2 0\n"
+       "    moutset2 =0\n"
+       "\n"
+       "Sets MOUT2 to 0.\n",
+       CMD_HANDLER(cmd_do_mout_set), (void *)&cmd_list_mout
+};
+
+/** Command descriptor for mout get pin diag value */
+cmd_des_t const cmd_des_mout_diag = {
+       0, 0,
+       "moutdiag*","Read a diagnostic value from an MOUT pin",
+       "### Command syntax ###\n"
+       "\n"
+       "    moutdiag<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 MOUT diagnostic signal.\n"
+       "\n"
+       "### Example ###\n"
+       "\n"
+       "    --> moutdiag1\n"
+       "\n"
+       "Reads value of the MOUT1 diagnostic signal.\n",
+       CMD_HANDLER(cmd_do_mout_diag), (void *)&cmd_list_mout
+};
+
+
+/** List of commands for hout, defined as external */
+cmd_des_t const *cmd_list_mout[] = {
+       &cmd_des_mout_set,
+       &cmd_des_mout_diag,
+       NULL
+};