]> rtime.felk.cvut.cz Git - rpp-test-sw.git/blob - rpp-test-sw/commands/cmd_lout.c
Change license to MIT
[rpp-test-sw.git] / rpp-test-sw / commands / cmd_lout.c
1 /*
2  * Copyright (C) 2012-2013, 2016 Czech Technical University in Prague
3  *
4  * Created on: 28.2.2013
5  *
6  * Authors:
7  *     - Michal Horn
8  *
9  * Permission is hereby granted, free of charge, to any person
10  * obtaining a copy of this software and associated documentation
11  * files (the "Software"), to deal in the Software without
12  * restriction, including without limitation the rights to use,
13  * copy, modify, merge, publish, distribute, sublicense, and/or sell
14  * copies of the Software, and to permit persons to whom the
15  * Software is furnished to do so, subject to the following
16  * conditions:
17  *
18  * The above copyright notice and this permission notice shall be
19  * included in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28  * OTHER DEALINGS IN THE SOFTWARE.
29  *
30  * File : cmd_lout.c
31  *
32  * Abstract:
33  *      This file contains commands for testing LOUT (8x100mA Digital output).
34  *
35  */
36
37
38 #include "cmd_lout.h"
39 #include "stdio.h"
40
41 #ifndef DOCGEN
42
43 #include "rpp/rpp.h"
44 #include "cmdproc_utils.h"
45
46 /**
47  * @brief Set digital value to LOUT pin
48  *
49  * @param[in]   cmd_io  Pointer to IO stack
50  * @param[in]   des             Pointer to command descriptor
51  * @param[in]   param   Parameters of command
52  * @return 0 when OK or error code lower than 0
53  */
54 int cmd_do_lout_set(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
55 {
56         int pin;
57         char *p = param[1];
58         char spareParams[2];
59         int val;
60         int ret;
61
62         if (sscanf(p, "%d %d %1s", &pin, &val, spareParams) != 2)
63                 return -CMDERR_BADPAR;
64         ret = rpp_lout_set(pin, val);
65         if (ret == -1) {
66                 rpp_sci_printf("Pin out of range.\n");
67                 return -CMDERR_BADPAR;
68         }
69
70         if (rpp_lout_update() == FAILURE) {
71                 rpp_sci_printf("LOUT update failed.\n");
72                 return -CMDERR_EIO;
73         }
74
75         return cmd_opchar_replong(cmd_io, param, val, 0, 10);
76 }
77
78 /**
79  * @brief Read digital diagnostic value from LOUT DIAG pin
80  *
81  * @param[in]   cmd_io  Pointer to IO stack
82  * @param[in]   des             Pointer to command descriptor
83  * @param[in]   param   Parameters of command
84  * @return 0 when OK or error code lower than 0
85  */
86 int cmd_do_lout_diag(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
87 {
88         int pin;
89         char *p = param[1];
90         char spareParams[2];
91         int ret;
92
93         if (sscanf(p, "%d %1s", &pin, spareParams) != 1)
94                 return -CMDERR_BADPAR;
95
96         if (rpp_lout_update() == FAILURE) {
97                 rpp_sci_printf("LOUT update failed.\n");
98                 return -CMDERR_EIO;
99         }
100
101         ret = rpp_lout_diag(pin);
102         if (ret == -1) {
103                 rpp_sci_printf("Pin out of range.\n");
104                 return -CMDERR_BADPAR;
105         }
106
107         rpp_sci_printf("loutdiag%d=%d\n", pin, ret, ret);
108         return 0;
109 }
110
111 #endif  /* DOCGEN */
112
113 /** Command descriptor for lout set port value */
114 cmd_des_t const cmd_des_lout_set = {
115         0, 0,
116         "loutset*","Set a value of the LOUT pin",
117         "### Command syntax ###\n"
118         "\n"
119         "    loutset<PIN> <VALUE>\n"
120         "where\n"
121         "\n"
122         "- `<PIN>` is a number in range 1-8\n"
123         "- `<VALUE>` is a binary value to be set (0 or 1)\n"
124         "\n"
125         "### Description ###\n"
126         "\n"
127         "The command sets the digital value on the LOUT pin.\n"
128         "\n"
129         "### Example ###\n"
130         "\n"
131         "    --> loutset1 1\n"
132         "    loutset1 =1\n"
133         "\n"
134         "Sets LOUT1 to 1.\n"
135         "\n"
136         "    --> loutset2 0\n"
137         "    loutset2 =0\n"
138         "\n"
139         "Sets LOUT2 to 0.\n",
140         CMD_HANDLER(cmd_do_lout_set), (void *)&cmd_list_lout
141 };
142
143 /** Command descriptor for lout get pin diag value */
144 cmd_des_t const cmd_des_lout_diag = {
145         0, 0,
146         "loutdiag*","Read a diagnostic value from an LOUT pin",
147         "### Command syntax ###\n"
148         "\n"
149         "    loutdiag<PIN>\n"
150         "\n"
151         "where `<PIN>` is a number in range 1-8\n"
152         "\n"
153         "### Description ###\n"
154         "\n"
155         "The command reads a logical value of the LOUT diagnostic signal.\n"
156         "\n"
157         "### Example ###\n"
158         "\n"
159         "    --> loutdiag1\n"
160         "\n"
161         "Reads value of the LOUT1 diagnostic signal.\n",
162         CMD_HANDLER(cmd_do_lout_diag), (void *)&cmd_list_lout
163 };
164
165
166 /** List of commands for hout, defined as external */
167 cmd_des_t const *cmd_list_lout[] = {
168         &cmd_des_lout_set,
169         &cmd_des_lout_diag,
170         NULL
171 };