4 * Created on: 28.2.2013
9 #include "cmdio_tisci.h"
12 #include "hal_gpio_tms570.h"
17 * @brief Reads values from HOUT_IFBK pins (subset of ADC)
19 * Command syntax: readhifbk
21 * @param[in] cmd_io Pointer to IO stack
22 * @param[in] des Pointer to command descriptor
23 * @param[in] param Parameters of command
24 * @return 0 when OK or error code
26 int cmd_do_read_hout_ifbk_values(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
28 char numBuf[32]; // Buffer used for i2str conversion
29 uint32_t i; // Cycle control variable
31 uint32_t values[PORT_HOUTIFBK_CHANNEL_NUM*2];
34 desc = port_get_dsc(PORT_NAME_HOUTIFBK, -1);
36 ret = desc->port_getfnc_ptr(desc->config, PORT_HOUTIFBK_CHANNEL_NUM, values);
40 print((uint8_t *)"\r\nHOUT_IFBK: values: ");
41 /* conversion results : */
42 for (i = 0; i < PORT_HOUTIFBK_CHANNEL_NUM; i++) {
43 print((uint8_t *)"\r\nChannel: ");
44 i2str(numBuf, values[i+PORT_HOUTIFBK_CHANNEL_NUM], 1, 10);
45 print((uint8_t *)numBuf);
46 print((uint8_t *)"\tvalue: ");
47 i2str(numBuf, values[i], 1, 10);
48 print((uint8_t *)numBuf);
49 print((uint8_t *)" 0x");
50 i2str(numBuf, values[i], 1, 16);
51 print((uint8_t *)numBuf);
56 //TODO: Repair this function - HOUT_DIAG id periodicaly shorted to ground and each 2ms
58 * @brief Runs test of HOUT. Test, weather HOUT is in fault state, which means that HOUT_DIAG is shorted to ground
60 * Command syntax: houtfail
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[])
69 print((uint8_t *)"Testing fault state of HOUT port:");
71 uint32_t values[] = {1, 1, 1, 1, 1, 1};
73 port_desc_t* inDesc = port_get_dsc(PORT_NAME_HOUTIN, -1);
74 port_desc_t* diagDesc = port_get_dsc(PORT_NAME_HOUTDIAG, -1);
76 inDesc->port_setfnc_ptr(inDesc->config, inDesc->numValues, values);
77 vTaskDelay(100/portTICK_RATE_MS);
78 for (i = 0; i < inDesc->numValues; i++) {
79 if (hal_gpio_get_value(diagDesc->config[i]) == values[i]) {
80 print((uint8_t *)"\r\nOK");
83 print((uint8_t *)"\r\nFAIL");
87 inDesc->port_setfnc_ptr(inDesc->config, inDesc->numValues, values);
92 * @brief Set or get actual pwm parameters
94 * Command syntax: houtpwm:(p,d) - set p as a period in us and D as duty cycle in % of the period.
95 * houtpwm? - Get actual PWM parameters, period in us and duty cycle in % of the period.
97 * @param[in] cmd_io Pointer to IO stack
98 * @param[in] des Pointer to command descriptor
99 * @param[in] param Parameters of command
100 * @return 0 when OK or error code
102 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];
111 if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
114 if(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
116 if (pin < 0 || pin > 5) return -CMDERR_BADPAR;
121 i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 10);
125 return -CMDERR_BADPAR;
126 if (values[0] < 1 || values[1] > 100) return -CMDERR_BADPAR;
127 hout_pwm_set_signal(pin, (double)values[0], values[1]);
131 double period = hout_pwm_get_period(pin);
132 uint32_t duty = hout_pwm_get_duty(pin);
134 print((uint8_t *)"hout");
135 i2str(buf, pin, 0, 10);
136 print((uint8_t *)"_pwm_period: ");
137 i2str(buf, period, 0, 10);
138 print((uint8_t *)buf);
139 print((uint8_t *)"\r\nhout");
140 i2str(buf, pin, 0, 10);
141 print((uint8_t *)"_pwm_duty: ");
142 i2str(buf, duty, 0, 10);
143 print((uint8_t *)buf);
144 print((uint8_t *)"%");
150 * @brief Start PWM, if it was previously set by houtpwm command
152 * Command syntax: houtpwmstart
154 * @param[in] cmd_io Pointer to IO stack
155 * @param[in] des Pointer to command descriptor
156 * @param[in] param Parameters of command
157 * @return 0 when OK or error code
159 int cmd_do_hout_pwm_start(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
165 if(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
167 if (pin < 0 || pin > 5) return -CMDERR_BADPAR;
168 int ret = hout_pwm_start(pin);
170 print((uint8_t*)"PWM was not initialized.\r\n");
171 return -CMDERR_BADCFG;
181 * Command syntax: houtpwmstop
183 * @param[in] cmd_io Pointer to IO stack
184 * @param[in] des Pointer to command descriptor
185 * @param[in] param Parameters of command
186 * @return 0 when OK or error code
188 int cmd_do_hout_pwm_stop(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
194 if(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
196 if (pin < 0 || pin > 5) return -CMDERR_BADPAR;
200 /** Command descriptor for test hout fault state command */
201 cmd_des_t const cmd_des_test_hout_fail = {
203 "houtfail","Test if some HOUT port is in fault state",
204 cmd_do_test_hout_fault, (void *)&cmd_list_hout
207 /** Command descriptor for hout read IFBK command */
208 cmd_des_t const cmd_des_read_hifbk={
210 "readhifbk","Reads values from HOUT IFBK",
211 cmd_do_read_hout_ifbk_values, (void *)&cmd_list_hout
214 /** Command descriptor for HBR set PWM command */
215 cmd_des_t const cmd_des_hout_pwm={
216 0, CDESM_OPCHR|CDESM_RW,
217 "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.",
218 cmd_do_hout_pwm, (void *)&cmd_list_hout
221 /** Command descriptor for PWM start command */
222 cmd_des_t const cmd_des_hout_pwm_start={
224 "houtpwmstart#","\t- houtpwmstartX - Start generating of pwm signal on HOUTX",
225 cmd_do_hout_pwm_start, (void *)&cmd_list_hout
228 /** Command descriptor for PWM stop command */
229 cmd_des_t const cmd_des_hout_pwm_stop={
231 "houtpwmstop#","\t- houtpwmstopX - Stop generating of pwm signal on HOUTX",
232 cmd_do_hout_pwm_stop, (void *)&cmd_list_hout
235 /** List of commands for hout, defined as external */
236 cmd_des_t const *cmd_list_hout[]={
237 &cmd_des_test_hout_fail,
240 &cmd_des_hout_pwm_start,
241 &cmd_des_hout_pwm_stop,