]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blob - rpp-test-sw/commands/cmd_lout.c
5a7333e89872523d8a0e024697cdf96b42987444
[pes-rpp/rpp-test-sw.git] / rpp-test-sw / commands / cmd_lout.c
1 /*
2  * Copyright (C) 2012-2013 Czech Technical University in Prague
3  *
4  * Created on: 28.2.2013
5  *
6  * Authors:
7  *     - Michal Horn
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * File : cmd_lout.c
23  *
24  * Abstract:
25  *      This file contains commands for testing LOUT (8x100mA Digital output).
26  *
27  */
28
29
30 #include "cmd_lout.h"
31 #include "stdio.h"
32
33 #ifndef DOCGEN
34
35 #include "rpp/rpp.h"
36 #include "cmdproc_utils.h"
37 #include "drv/drv.h"
38
39 /**
40  * @brief Set digital value to LOUT pin
41  *
42  * @param[in]   cmd_io  Pointer to IO stack
43  * @param[in]   des             Pointer to command descriptor
44  * @param[in]   param   Parameters of command
45  * @return 0 when OK or error code lower than 0
46  */
47 int cmd_do_lout_set(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
48 {
49         int pin;
50         char *p = param[1];
51         char spareParams;
52         int val;
53         int ret;
54
55         if (sscanf(p, "%d %d %1s", &pin, &val, &spareParams) != 2)
56                 return -CMDERR_BADPAR;
57         ret = rpp_lout_set(pin, val);
58         if (ret == -1) {
59                 rpp_sci_printf("Pin out of range.");
60                 return -CMDERR_BADPAR;
61         }
62
63         if (rpp_lout_update() == FAILURE) {
64                 rpp_sci_printf("LOUT update failed.");
65                 return -CMDERR_EIO;
66         }
67
68         return cmd_opchar_replong(cmd_io, param, val, 0, 10);
69 }
70
71 /**
72  * @brief Read digital diagnostic value from LOUT DIAG pin
73  *
74  * @param[in]   cmd_io  Pointer to IO stack
75  * @param[in]   des             Pointer to command descriptor
76  * @param[in]   param   Parameters of command
77  * @return 0 when OK or error code lower than 0
78  */
79 int cmd_do_lout_diag(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
80 {
81         int pin;
82         char *p = param[1];
83         char spareParams;
84         int ret;
85
86         if (sscanf(p, "%d %1s", &pin, &spareParams) != 1)
87                 return -CMDERR_BADPAR;
88
89         if (rpp_lout_update() == FAILURE) {
90                 rpp_sci_printf("LOUT update failed.");
91                 return -CMDERR_EIO;
92         }
93
94         ret = rpp_lout_diag(pin);
95         if (ret == -1) {
96                 rpp_sci_printf("Pin out of range.");
97                 return -CMDERR_BADPAR;
98         }
99
100         rpp_sci_printf("loutdiag%d=%d\n", pin, ret, ret);
101         return 0;
102 }
103
104 #endif  /* DOCGEN */
105
106 /** Command descriptor for lout set port value */
107 cmd_des_t const cmd_des_lout_set = {
108         0, 0,
109         "loutset*","Set a value of the LOUT pin",
110         "### Command syntax ###\n"
111         "\n"
112         "    loutset<PIN> <VALUE>\n"
113         "where\n"
114         "\n"
115         "- `<PIN>` is a number in range 1-8\n"
116         "- `<VALUE>` is a binary value to be set (0 or 1)\n"
117         "\n"
118         "### Description ###\n"
119         "\n"
120         "The command sets the digital value on the LOUT pin.\n"
121         "\n"
122         "### Example ###\n"
123         "\n"
124         "    --> loutset1 1\n"
125         "\n"
126         "Sets LOUT1 to 1.\n"
127         "\n"
128         "    --> loutset2 0\n"
129         "\n"
130         "Sets LOUT2 to 0.\n",
131         CMD_HANDLER(cmd_do_lout_set), (void *)&cmd_list_lout
132 };
133
134 /** Command descriptor for lout get pin diag value */
135 cmd_des_t const cmd_des_lout_diag = {
136         0, 0,
137         "loutdiag*","Read a diagnostic value from an LOUT pin",
138         "### Command syntax ###\n"
139         "\n"
140         "    loutdiag<PIN>\n"
141         "\n"
142         "where `<PIN>` is a number in range 1-8\n"
143         "\n"
144         "### Description ###\n"
145         "\n"
146         "The command reads a logical value of the LOUT diagnostic signal.\n"
147         "\n"
148         "### Example ###\n"
149         "\n"
150         "    --> loutdiag1\n"
151         "\n"
152         "Reads value of the LOUT1 diagnostic signal.\n",
153         CMD_HANDLER(cmd_do_lout_diag), (void *)&cmd_list_lout
154 };
155
156
157 /** List of commands for hout, defined as external */
158 cmd_des_t const *cmd_list_lout[] = {
159         &cmd_des_lout_set,
160         &cmd_des_lout_diag,
161         NULL
162 };