2 * Copyright (C) 2012-2013 Czech Technical University in Prague
4 * Created on: 28.2.2013
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.
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.
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/>.
25 * This file contains commands for HOUT control.
36 #include "cmdproc_utils.h"
40 * @brief Reads values from HOUT_IFBK pins (subset of ADC)
42 * Command syntax: readhifbk
44 * @param[in] cmd_io Pointer to IO stack
45 * @param[in] des Pointer to command descriptor
46 * @param[in] param Parameters of command
47 * @return 0 when OK or error code
49 int cmd_do_read_hout_ifbk_values(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
51 uint32_t i; // Cycle control variable
53 uint32_t values[PORT_HOUTIFBK_CHANNEL_NUM*2];
56 desc = hal_port_get_dsc(PORT_NAME_HOUTIFBK, -1);
58 ret = desc->port_getfnc_ptr(desc->config, PORT_HOUTIFBK_CHANNEL_NUM, values);
62 rpp_sci_printf("HOUT_IFBK: values: ");
63 /* conversion results : */
64 for (i = 0; i < PORT_HOUTIFBK_CHANNEL_NUM; i++) {
65 rpp_sci_printf("\r\nChannel: %d\tvalue: %d %h", i+1, values[i], values[i]);
71 * @brief Runs test of selected HOUT pin.
73 * This command runs a test to check if HOUT pin is in good or fault condition.
74 * When HOUT is OK, HOUT_DIAG pin has the same value as HOUT_IN pin.
75 * When HOUT is in fault state, HOUT_DIAG periodically follows HOUT_PIN for 2ms and shorts to ground for 2ms.
77 * Command syntax: houtfail#
79 * @param[in] cmd_io Pointer to IO stack
80 * @param[in] des Pointer to command descriptor
81 * @param[in] param Parameters of command
82 * @return 0 when OK or error code
84 int cmd_do_test_hout_fault(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
88 if(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
90 if (pin < 0 || pin > 5) return -CMDERR_BADPAR;
92 switch (hout_fail(pin)) {
97 rpp_sci_printf("FAIL");
100 rpp_sci_printf("NOT RUNNING");
103 rpp_sci_printf("Bad pin selected");
110 * @brief Set or get actual pwm parameters
112 * Command syntax: houtpwm:(p,d) - set p as a period in us and D as duty cycle in % of the period.
113 * houtpwm? - Get actual PWM parameters, period in us and duty cycle in % of the period.
115 * @param[in] cmd_io Pointer to IO stack
116 * @param[in] des Pointer to command descriptor
117 * @param[in] param Parameters of command
118 * @return 0 when OK or error code
120 int cmd_do_hout_pwm(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
125 uint32_t values[MAX_PARAM_VALUES_NUM];
128 if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
131 if(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
133 if (pin < 0 || pin > 5) return -CMDERR_BADPAR;
138 i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 10);
142 return -CMDERR_BADPAR;
143 if (values[0] < 1 || values[1] > 100) return -CMDERR_BADPAR;
144 hout_pwm_set_signal(pin, (double)values[0], values[1]);
148 double period = hout_pwm_get_period(pin);
149 uint32_t duty = hout_pwm_get_duty(pin);
151 rpp_sci_printf("hout%d_pwm_period: %d\r\nhout%d_pwm_duty: %d/%", pin, period, pin, duty);
157 * @brief Start PWM, if it was previously set by houtpwm command
159 * Command syntax: houtpwmstart
161 * @param[in] cmd_io Pointer to IO stack
162 * @param[in] des Pointer to command descriptor
163 * @param[in] param Parameters of command
164 * @return 0 when OK or error code
166 int cmd_do_hout_pwm_start(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
172 if(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
174 if (pin < 0 || pin > 5) return -CMDERR_BADPAR;
175 int ret = hout_pwm_start(pin);
177 rpp_sci_printf("PWM was not initialized.\r\n");
178 return -CMDERR_BADCFG;
188 * Command syntax: houtpwmstop
190 * @param[in] cmd_io Pointer to IO stack
191 * @param[in] des Pointer to command descriptor
192 * @param[in] param Parameters of command
193 * @return 0 when OK or error code
195 int cmd_do_hout_pwm_stop(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
201 if(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
203 if (pin < 0 || pin > 5) return -CMDERR_BADPAR;
210 /** Command descriptor for test hout fault state command */
211 cmd_des_t const cmd_des_test_hout_fail = {
213 "houtfail","Test if some HOUT port is in fault state",
214 "=== Description ===\n"
216 "This command tests, if HOUT pin is in good condition. When a circuit,\n"
217 "controlling HOUT pin, detects some fault, it starts to generate signal\n"
218 "on HOUT_DIAG pin.\n"
220 "=== Command syntax ===\n"
222 " --> houtfail pin\n"
223 "where pin is in range 1-6\n",
224 CMD_HANDLER(cmd_do_test_hout_fault), (void *)&cmd_list_hout
227 /** Command descriptor for hout read IFBK command */
228 cmd_des_t const cmd_des_read_hifbk={
230 "readhifbk","Reads values from HOUT IFBK",
231 "=== Description ===\n"
233 "Command reads analog values on HOUT_IFBK pins.\n"
236 "=== Command syntax ===\n"
239 CMD_HANDLER(cmd_do_read_hout_ifbk_values), (void *)&cmd_list_hout
242 /** Command descriptor for HBR set PWM command */
243 cmd_des_t const cmd_des_hout_pwm={
244 0, CDESM_OPCHR|CDESM_RW,
245 "houtpwm*","Set or get actual PWM parameters",
246 "=== Description ===\n"
248 "This command can be used for setting or getting HOUT PWM parameters.\n"
249 "Command expects HOUT pin number as first parameter, operation\n"
250 "character : (setter) or ? (getter) and in case of setter, another two\n"
251 "parameters are mandatory. The first one is PWM period in us, the\n"
252 "second one is duty cycle in % of the period.\n"
254 "=== Command syntax ===\n"
256 " --> houtpwmPIN[:|?][(PER,DUTY)]\n"
258 "* PIN is in range 1-6\n"
259 "* : means set parameters and parameters in brackets are mandatory, ? means get parameters\n"
260 "* PER is greater than 0\n"
261 "* DUTY is in range 0-100\n"
265 " --> houtpwm1:(1000,25)\n"
267 "HOUT1 PWM will have period 1ms and will be active for 25% of this\n"
272 "Actual period of HOUT1 PWM in us and duty cycle in % will be printed.\n",
273 CMD_HANDLER(cmd_do_hout_pwm), (void *)&cmd_list_hout
276 /** Command descriptor for PWM start command */
277 cmd_des_t const cmd_des_hout_pwm_start={
279 "houtpwmstart#","houtpwmstartX - Start generating of pwm signal on HOUTX",
280 "=== Description ===\n"
282 "If HOUT PWM was previously set by houtpwm command, this command starts\n"
283 "generating PWM signal on specified pin.\n"
285 "=== Command syntax ===\n"
287 " --> houtpwmstartPIN\n"
288 "where PIN is in range 1-6\n",
289 CMD_HANDLER(cmd_do_hout_pwm_start), (void *)&cmd_list_hout
292 /** Command descriptor for PWM stop command */
293 cmd_des_t const cmd_des_hout_pwm_stop={
295 "houtpwmstop#","houtpwmstopX - Stop generating of pwm signal on HOUTX",
296 "=== Description ===\n"
298 "This command stops generating PWM signal on selected pin.\n"
300 "=== Command syntax ===\n"
302 " --> houtpwmstopPIN\n"
303 "where PIN is in range 1-6\n",
304 CMD_HANDLER(cmd_do_hout_pwm_stop), (void *)&cmd_list_hout
307 /** List of commands for hout, defined as external */
308 cmd_des_t const *cmd_list_hout[]={
309 &cmd_des_test_hout_fail,
312 &cmd_des_hout_pwm_start,
313 &cmd_des_hout_pwm_stop,