]> rtime.felk.cvut.cz Git - rpp-test-sw.git/blob - rpp-test-sw/commands/cmd_lout.c
Merge branch 'can' of rtime.felk.cvut.cz:rpp-test-sw
[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         int pin;
49         char *p=param[1];
50         char spareParams;
51         int val;
52         int ret;
53
54         if (sscanf(p, "%d %d %1s", &pin, &val, &spareParams) != 2) {
55                 return -CMDERR_BADPAR;
56         }
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         int pin;
81         char *p=param[1];
82         char spareParams;
83         int ret;
84
85         if (sscanf(p, "%d %1s", &pin, &spareParams) != 1) {
86                 return -CMDERR_BADPAR;
87         }
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         "* <PIN> is a number in range 1-8\n"
115         "* <VALUE> is a binary value to be set (0 or 1)\n"
116         "\n"
117         "=== Description ===\n"
118         "\n"
119         "The command sets the digital value on the LOUT pin.\n"
120         "\n"
121         "=== Example ===\n"
122         "\n"
123         "   --> loutset1 1\n"
124         "\n"
125         "Sets LOUT1 to 1.\n"
126         "\n"
127         "   --> loutset2 0\n"
128         "\n"
129         "Sets LOUT2 to 0.\n",
130         CMD_HANDLER(cmd_do_lout_set), (void *)&cmd_list_lout
131 };
132
133 /** Command descriptor for lout get pin diag value */
134 cmd_des_t const cmd_des_lout_diag={
135         0, 0,
136         "loutdiag*","Read a diagnostic value from an LOUT pin",
137         "=== Command syntax ===\n"
138         "\n"
139         "   loutdiag<PIN>\n"
140         "\n"
141         "where <PIN> is a number in range 1-8\n"
142         "\n"
143         "=== Description ===\n"
144         "\n"
145         "The command reads a logical value of the LOUT diagnostic signal.\n"
146         "\n"
147         "=== Example ===\n"
148         "\n"
149         "   --> loutdiag1\n"
150         "\n"
151         "Reads value of the LOUT1 diagnostic signal.\n",
152         CMD_HANDLER(cmd_do_lout_diag), (void *)&cmd_list_lout
153 };
154
155
156 /** List of commands for hout, defined as external */
157 cmd_des_t const *cmd_list_lout[]={
158   &cmd_des_lout_set,
159   &cmd_des_lout_diag,
160   NULL
161 };