]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blob - rpp-test-sw/commands/cmd_lout.c
6922fea62b8553c59eb9bdb7d1d050eba6377c7a
[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 document contains proprietary information belonging to Czech
10  * Technical University in Prague. Passing on and copying of this
11  * document, and communication of its contents is not permitted
12  * without prior written authorization.
13  *
14  * File : cmd_lout.c
15  *
16  * Abstract:
17  *      This file contains commands for testing LOUT (8x100mA Digital output).
18  *
19  */
20
21
22 #include "cmd_lout.h"
23 #include "stdio.h"
24
25 #ifndef DOCGEN
26
27 #include "rpp/rpp.h"
28 #include "cmdproc_utils.h"
29 #include "drv/drv.h"
30
31 /**
32  * @brief Set digital value to LOUT pin
33  *
34  * @param[in]   cmd_io  Pointer to IO stack
35  * @param[in]   des             Pointer to command descriptor
36  * @param[in]   param   Parameters of command
37  * @return 0 when OK or error code lower than 0
38  */
39 int cmd_do_lout_set(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
40 {
41         int pin;
42         char *p = param[1];
43         char spareParams;
44         int val;
45         int ret;
46
47         if (sscanf(p, "%d %d %1s", &pin, &val, &spareParams) != 2)
48                 return -CMDERR_BADPAR;
49         ret = rpp_lout_set(pin, val);
50         if (ret == -1) {
51                 rpp_sci_printf("Pin out of range.");
52                 return -CMDERR_BADPAR;
53         }
54
55         if (rpp_lout_update() == FAILURE) {
56                 rpp_sci_printf("LOUT update failed.");
57                 return -CMDERR_EIO;
58         }
59
60         return cmd_opchar_replong(cmd_io, param, val, 0, 10);
61 }
62
63 /**
64  * @brief Read digital diagnostic value from LOUT DIAG pin
65  *
66  * @param[in]   cmd_io  Pointer to IO stack
67  * @param[in]   des             Pointer to command descriptor
68  * @param[in]   param   Parameters of command
69  * @return 0 when OK or error code lower than 0
70  */
71 int cmd_do_lout_diag(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
72 {
73         int pin;
74         char *p = param[1];
75         char spareParams;
76         int ret;
77
78         if (sscanf(p, "%d %1s", &pin, &spareParams) != 1)
79                 return -CMDERR_BADPAR;
80
81         if (rpp_lout_update() == FAILURE) {
82                 rpp_sci_printf("LOUT update failed.");
83                 return -CMDERR_EIO;
84         }
85
86         ret = rpp_lout_diag(pin);
87         if (ret == -1) {
88                 rpp_sci_printf("Pin out of range.");
89                 return -CMDERR_BADPAR;
90         }
91
92         rpp_sci_printf("loutdiag%d=%d\n", pin, ret, ret);
93         return 0;
94 }
95
96 #endif  /* DOCGEN */
97
98 /** Command descriptor for lout set port value */
99 cmd_des_t const cmd_des_lout_set = {
100         0, 0,
101         "loutset*","Set a value of the LOUT pin",
102         "### Command syntax ###\n"
103         "\n"
104         "    loutset<PIN> <VALUE>\n"
105         "where\n"
106         "\n"
107         "- `<PIN>` is a number in range 1-8\n"
108         "- `<VALUE>` is a binary value to be set (0 or 1)\n"
109         "\n"
110         "### Description ###\n"
111         "\n"
112         "The command sets the digital value on the LOUT pin.\n"
113         "\n"
114         "### Example ###\n"
115         "\n"
116         "    --> loutset1 1\n"
117         "\n"
118         "Sets LOUT1 to 1.\n"
119         "\n"
120         "    --> loutset2 0\n"
121         "\n"
122         "Sets LOUT2 to 0.\n",
123         CMD_HANDLER(cmd_do_lout_set), (void *)&cmd_list_lout
124 };
125
126 /** Command descriptor for lout get pin diag value */
127 cmd_des_t const cmd_des_lout_diag = {
128         0, 0,
129         "loutdiag*","Read a diagnostic value from an LOUT pin",
130         "### Command syntax ###\n"
131         "\n"
132         "    loutdiag<PIN>\n"
133         "\n"
134         "where `<PIN>` is a number in range 1-8\n"
135         "\n"
136         "### Description ###\n"
137         "\n"
138         "The command reads a logical value of the LOUT diagnostic signal.\n"
139         "\n"
140         "### Example ###\n"
141         "\n"
142         "    --> loutdiag1\n"
143         "\n"
144         "Reads value of the LOUT1 diagnostic signal.\n",
145         CMD_HANDLER(cmd_do_lout_diag), (void *)&cmd_list_lout
146 };
147
148
149 /** List of commands for hout, defined as external */
150 cmd_des_t const *cmd_list_lout[] = {
151         &cmd_des_lout_set,
152         &cmd_des_lout_diag,
153         NULL
154 };