4 * Created on: 28.2.2013
8 #include "commands/cmd_hout.h"
12 #include "cmdproc_utils.h"
16 * @brief Reads values from HOUT_IFBK pins (subset of ADC)
18 * Command syntax: readhifbk
20 * @param[in] cmd_io Pointer to IO stack
21 * @param[in] des Pointer to command descriptor
22 * @param[in] param Parameters of command
23 * @return 0 when OK or error code
25 int cmd_do_read_hout_ifbk_values(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
27 uint32_t i; // Cycle control variable
29 uint32_t values[PORT_HOUTIFBK_CHANNEL_NUM*2];
32 desc = hal_port_get_dsc(PORT_NAME_HOUTIFBK, -1);
34 ret = desc->port_getfnc_ptr(desc->config, PORT_HOUTIFBK_CHANNEL_NUM, values);
38 rpp_sci_printf("HOUT_IFBK: values: ");
39 /* conversion results : */
40 for (i = 0; i < PORT_HOUTIFBK_CHANNEL_NUM; i++) {
41 rpp_sci_printf("\r\nChannel: %d\tvalue: %d %h", i+1, values[i], values[i]);
47 * @brief Runs test of selected HOUT pin.
49 * This command runs a test to check if HOUT pin is in good or fault condition.
50 * When HOUT is OK, HOUT_DIAG pin has the same value as HOUT_IN pin.
51 * When HOUT is in fault state, HOUT_DIAG periodically follows HOUT_PIN for 2ms and shorts to ground for 2ms.
53 * Command syntax: houtfail#
55 * @param[in] cmd_io Pointer to IO stack
56 * @param[in] des Pointer to command descriptor
57 * @param[in] param Parameters of command
58 * @return 0 when OK or error code
60 int cmd_do_test_hout_fault(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
64 if(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
66 if (pin < 0 || pin > 5) return -CMDERR_BADPAR;
68 switch (hout_fail(pin)) {
73 rpp_sci_printf("FAIL");
76 rpp_sci_printf("NOT RUNNING");
79 rpp_sci_printf("Bad pin selected");
86 * @brief Set or get actual pwm parameters
88 * Command syntax: houtpwm:(p,d) - set p as a period in us and D as duty cycle in % of the period.
89 * houtpwm? - Get actual PWM parameters, period in us and duty cycle in % of the period.
91 * @param[in] cmd_io Pointer to IO stack
92 * @param[in] des Pointer to command descriptor
93 * @param[in] param Parameters of command
94 * @return 0 when OK or error code
96 int cmd_do_hout_pwm(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
101 uint32_t values[MAX_PARAM_VALUES_NUM];
104 if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
107 if(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
109 if (pin < 0 || pin > 5) return -CMDERR_BADPAR;
114 i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 10);
118 return -CMDERR_BADPAR;
119 if (values[0] < 1 || values[1] > 100) return -CMDERR_BADPAR;
120 hout_pwm_set_signal(pin, (double)values[0], values[1]);
124 double period = hout_pwm_get_period(pin);
125 uint32_t duty = hout_pwm_get_duty(pin);
127 rpp_sci_printf("hout%d_pwm_period: %d\r\nhout%d_pwm_duty: %d/%", pin, period, pin, duty);
133 * @brief Start PWM, if it was previously set by houtpwm command
135 * Command syntax: houtpwmstart
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(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
150 if (pin < 0 || pin > 5) return -CMDERR_BADPAR;
151 int ret = hout_pwm_start(pin);
153 rpp_sci_printf("PWM was not initialized.\r\n");
154 return -CMDERR_BADCFG;
164 * Command syntax: houtpwmstop
166 * @param[in] cmd_io Pointer to IO stack
167 * @param[in] des Pointer to command descriptor
168 * @param[in] param Parameters of command
169 * @return 0 when OK or error code
171 int cmd_do_hout_pwm_stop(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
177 if(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
179 if (pin < 0 || pin > 5) return -CMDERR_BADPAR;
183 /** Command descriptor for test hout fault state command */
184 cmd_des_t const cmd_des_test_hout_fail = {
186 "houtfail","Test if some HOUT port is in fault state",
187 cmd_do_test_hout_fault, (void *)&cmd_list_hout
190 /** Command descriptor for hout read IFBK command */
191 cmd_des_t const cmd_des_read_hifbk={
193 "readhifbk","Reads values from HOUT IFBK",
194 cmd_do_read_hout_ifbk_values, (void *)&cmd_list_hout
197 /** Command descriptor for HBR set PWM command */
198 cmd_des_t const cmd_des_hout_pwm={
199 0, CDESM_OPCHR|CDESM_RW,
200 "houtpwm*","\t- houtpwmX:(period,duty) set pwm period in us and duty in % of period\r\n\t\thoutpwmX? read period in us and duty in % of period from HOUTX.",
201 cmd_do_hout_pwm, (void *)&cmd_list_hout
204 /** Command descriptor for PWM start command */
205 cmd_des_t const cmd_des_hout_pwm_start={
207 "houtpwmstart#","\t- houtpwmstartX - Start generating of pwm signal on HOUTX",
208 cmd_do_hout_pwm_start, (void *)&cmd_list_hout
211 /** Command descriptor for PWM stop command */
212 cmd_des_t const cmd_des_hout_pwm_stop={
214 "houtpwmstop#","\t- houtpwmstopX - Stop generating of pwm signal on HOUTX",
215 cmd_do_hout_pwm_stop, (void *)&cmd_list_hout
218 /** List of commands for hout, defined as external */
219 cmd_des_t const *cmd_list_hout[]={
220 &cmd_des_test_hout_fail,
223 &cmd_des_hout_pwm_start,
224 &cmd_des_hout_pwm_stop,