2 * Copyright (C) 2012-2013, 2015 Czech Technical University in Prague
4 * Created on: 28.2.2013
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.
17 * This file contains commands for HOUT control.
27 /* FIXME: remove hout.h */
29 #include "drv/port.h" /* TODO: Use rpp/port.h */
30 #include "cmdproc_utils.h"
34 * @brief Reads values from HOUT_IFBK pins (subset of ADC)
36 * @param[in] cmd_io Pointer to IO stack
37 * @param[in] des Pointer to command descriptor
38 * @param[in] param Parameters of command
39 * @return 0 when OK or error code
41 int cmd_do_read_hout_ifbk_values(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
44 const struct port_desc *port = &port_desc[PORT_ID_HOUTIFBK];
45 uint16_t values[port->numchn];
49 ret = port->get(port, values, sizeof(values));
53 for (i = 0; i < port->numchn; i++) {
54 rpp_sci_printf("HOUT%d: %d\n", i+1, values[i]);
60 * @brief Runs test of selected HOUT pin.
62 * @param[in] cmd_io Pointer to IO stack
63 * @param[in] des Pointer to command descriptor
64 * @param[in] param Parameters of command
65 * @return 0 when OK or error code
67 int cmd_do_test_hout_fault(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
73 if (sscanf(p, "%d %1s", &pin, &spareParams) != 1)
74 return -CMDERR_BADPAR;
76 if (pin < 0 || pin > 5) return -CMDERR_BADPAR;
78 switch (hout_fail(pin)) {
83 rpp_sci_printf("FAIL");
86 rpp_sci_printf("NOT RUNNING");
89 rpp_sci_printf("Bad pin selected");
97 * @brief Set or get actual pwm parameters
99 * @param[in] cmd_io Pointer to IO stack
100 * @param[in] des Pointer to command descriptor
101 * @param[in] param Parameters of command
102 * @return 0 when OK or error code
104 int cmd_do_hout_pwm(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
107 uint32_t values[MAX_PARAM_VALUES_NUM];
112 if (sscanf(p, "%d", &pin) != 1)
113 return -CMDERR_BADPAR;
115 if (pin < 0 || pin > 5) return -CMDERR_BADPAR;
117 if (param[2] != NULL) { // More parameters = set values
119 if (sscanf(p, "%d %d %1s", &values[0], &values[1], &spareParams) != 2)
120 return -CMDERR_BADPAR;
121 if (values[1] > 100) return -CMDERR_BADPAR;
122 hout_pwm_set_signal(pin, (double)values[0], values[1]);
125 else { // No more parameters = get values
126 double period = hout_pwm_get_period(pin);
127 uint32_t duty = hout_pwm_get_duty(pin);
129 rpp_sci_printf("houtpwm%d_period=%g\r\nhoutpwm%d_duty=%u%%", pin+1, period, pin+1, duty);
135 * @brief Start PWM, if it was previously set by houtpwm command
137 * @param[in] cmd_io Pointer to IO stack
138 * @param[in] des Pointer to command descriptor
139 * @param[in] param Parameters of command
140 * @return 0 when OK or error code
142 int cmd_do_hout_pwm_start(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
148 if (sscanf(p, "%d %1s", &pin, &spareParams) != 1)
149 return -CMDERR_BADPAR;
151 if (pin < 0 || pin > 5) return -CMDERR_BADPAR;
152 int ret = hout_pwm_start(pin);
154 rpp_sci_printf("PWM was not initialized.\r\n");
155 return -CMDERR_BADCFG;
164 * @param[in] cmd_io Pointer to IO stack
165 * @param[in] des Pointer to command descriptor
166 * @param[in] param Parameters of command
167 * @return 0 when OK or error code
169 int cmd_do_hout_pwm_stop(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
175 if (sscanf(p, "%d %1s", &pin, &spareParams) != 1)
176 return -CMDERR_BADPAR;
178 if (pin < 0 || pin > 5) return -CMDERR_BADPAR;
185 /** Command descriptor for test hout fault state command */
186 cmd_des_t const cmd_des_test_hout_fail = {
188 "houtfail*","Test if some HOUT pin is in the fault state",
189 "### Command syntax ###\n"
192 "where `<PIN>` is in range 1-6\n"
194 "### Description ###\n"
196 "This command tests, if HOUT pin is in a good condition. When the\n"
197 "circuit controlling HOUT pin detects some failure, it signals that on\n"
198 "HOUT_DIAG output. This command is supposed to read this output and\n"
201 "Possible outputs of this command:\n"
203 "- OK - no failure detected\n"
204 "- FAIL - a failure detected\n"
205 "- NOT RUNNING - PWM was set set up and started\n"
207 "Note: Before using this command, houtpwmstart and houtpwm commands\n"
208 "should be called.\n"
212 " --> houtpwm6 1000 25\n"
213 " --> houtpwmstart6\n"
217 "Detects the state of the HOUT1 and prints OK, FAIL or NOT RUNNING.\n",
218 CMD_HANDLER(cmd_do_test_hout_fault), (void *)&cmd_list_hout
221 /** Command descriptor for hout read IFBK command */
222 cmd_des_t const cmd_des_read_hifbk = {
224 "houtifbk","Read values from HOUT current feedback",
225 "### Command syntax ###\n"
229 "### Description ###\n"
231 "The command reads analog values from HOUT_IFBK pins and prints\n"
238 " HOUT2: 134223784\n"
239 " HOUT3: 134223784\n"
242 " HOUT6: 1342231444\n",
243 CMD_HANDLER(cmd_do_read_hout_ifbk_values), (void *)&cmd_list_hout
246 /** Command descriptor for HOUT set PWM command */
247 cmd_des_t const cmd_des_hout_pwm = {
249 "houtpwm*","Set or get actual PWM parameters",
250 "### Command syntax ###\n"
252 " houtpwm<PIN> <PER> <DUTY>\n"
256 "- `<PIN>` is a number in range 1-6\n"
257 "- `<PER>` is a length of the PWM period in microseconds\n"
258 "- `<DUTY>` is a the PWM duty cycle in percent (0-100)\n"
260 "### Description ###\n"
262 "This command can be used to set or get HOUT PWM parameters.\n"
266 " --> houtpwm1 1000 25\n"
268 "HOUT1 PWM will have the period of 1ms and will be active for 25% of\n"
272 " houtpwm1_period=1000\n"
273 " houtpwm1_duty=25\n"
275 "Prints the actual period of HOUT1 PWM in microseconds and the duty\n"
276 "cycle in percents.\n",
277 CMD_HANDLER(cmd_do_hout_pwm), (void *)&cmd_list_hout
280 /** Command descriptor for PWM start command */
281 cmd_des_t const cmd_des_hout_pwm_start = {
283 "houtstartpwm*","Start generating PWM signal on HOUT",
284 "### Command syntax ###\n"
286 " houtstartpwm<PIN>\n"
287 "where `<PIN>` is a number in range 1-6\n"
289 "### Description ###\n"
291 "This command starts to generate the PWM signal on the specified HOUT\n"
292 "pin. The HOUT PWM has to be previously set by the houtpwm command,\n"
293 "otherwise an error is printed.\n"
297 " --> houtpwm1 1000 25\n"
298 " --> houtstartpwm1\n"
300 "HOUT1 PWM generation will be started.\n",
301 CMD_HANDLER(cmd_do_hout_pwm_start), (void *)&cmd_list_hout
304 /** Command descriptor for PWM stop command */
305 cmd_des_t const cmd_des_hout_pwm_stop = {
307 "houtstoppwm*","Stop generating of PWM signal on HOUT",
308 "### Command syntax ###\n"
310 " houtstoppwm<PIN>\n"
311 "where `<PIN>` is a number in range 1-6\n"
313 "### Description ###\n"
315 "This command stops generating the PWM signal on the selected pin.\n"
319 " --> houtstoppwm1\n"
321 "HOUT1 PWM generation will be deactivated.\n",
322 CMD_HANDLER(cmd_do_hout_pwm_stop), (void *)&cmd_list_hout
325 /** List of commands for hout, defined as external */
326 cmd_des_t const *cmd_list_hout[] = {
327 &cmd_des_test_hout_fail,
330 &cmd_des_hout_pwm_start,
331 &cmd_des_hout_pwm_stop,