2 * @brief Command definitions file
5 * Command is defined by its function. The function and others parameters are stored as list element.
6 * All commands represented as elements are stored in lists connected into one main list.
11 #include "sys_common.h"
12 #include "cmdio_tisci.h"
23 /** @brief Count of AD channels in ADC1
25 #define ADC1_CHANNEL_COUNT 12
26 /** @brief Count of AD channels in HOUT port
28 #define HOUT_IFBK_CHANNEL_COUNT 6
30 /** @brief List in which commands are stored */
31 cmd_des_t const **cmd_list;
32 /** @brief Semaphore blocking task when it waits for interrupt signaling message receive */
33 xSemaphoreHandle canMsgReceived;
34 xSemaphoreHandle canMsgSent;
36 /** @brief Semaphore blocking task when it waits for interrupt signaling end of the conversion */
37 xSemaphoreHandle adcDataConverted;
38 /** @brief Data structure containing converted data from ADC */
41 /** @brief Set of port adresses for each din pin
44 extern gioPORT_t * dinPorts[8];
45 /** @brief Set of port adresses for each mout pin
47 * Defined in mout.c */
48 extern gioPORT_t * moutPorts[12];
49 /** @brief Set of port adresses for each hout pin
51 * Defined in hout.c */
52 extern gioPORT_t * houtPorts[12];
54 /** @brief Set of bit indexes for each din pin
56 * Each element stores index of a bit in register assigned to din pin.
58 extern uint8_t dinBits[8];
59 /** @brief Set of bit indexes for each mout pin
61 * Each element stores index of a bit in register assigned to mout pin.
63 extern uint8_t moutBits[12];
64 /** @brief Set of bit indexes for each hout pin
66 * Each element stores index of a bit in register assigned to hout pin.
68 extern uint8_t houtBits[12];
69 /** @brief Set of bit indexes for each v_bat pin
71 * Each element stores index of a bit in register assigned to v_bat pin.
72 * Defined in vbat.c */
73 extern uint8_t vbatBits[4];
80 /* ------------------------------
81 * User defined command functions
82 * ------------------------------
85 int cmd_do_vbat_set(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
86 vbatSetBit(NULL, vbatBits[0], 1);
87 print((uint8_t *)"V_BAT_EN set.");
91 int cmd_do_vbat_clr(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
92 vbatSetBit(NULL, vbatBits[0], 0);
93 print((uint8_t *)"V_BAT_EN cleared.");
96 int cmd_do_vbat_get(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
97 uint32_t value = vbatGetBit(vbatBits[0]);
99 print((uint8_t *)"1\r\n");
102 print((uint8_t *)"0\r\n");
107 /** Tests the capacity of connected SDRAM
108 * @param[in] cmd_io Pointer to IO stack
109 * @param[in] des Pointer to command descriptor
110 * @param[in] param Parameters of command
111 * @return 0 when OK or error code
113 int cmd_do_test_ram(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
114 volatile uint32_t* addrPtr = (uint32_t*)0x80000000U;
115 volatile uint32_t* endAddr = (uint32_t*)0x87FFFFFFU;
116 uint32_t pattern = 0x55555555U;
119 uint32_t readVal = 0;
121 while (addrPtr <= endAddr) {
123 pattern += 0x55555555U;
127 addrPtr = (uint32_t *)0x80000000U;
128 pattern = 0x55555555U;
129 while (addrPtr <= endAddr) {
131 if (pattern == readVal) cnt++;
132 else if(errCnt++ <= 10) {
133 print((uint8_t *)"Error at 0x");
135 i2str(numBuf, (long)addrPtr, 1, 16);
136 print((uint8_t *)numBuf);
137 print((uint8_t *)"\r\n");
140 pattern += 0x55555555U;
144 cnt /= (sizeof(uint32_t)*1000000);
146 print((uint8_t*)"SDRAM not connected.\r\n");
150 i2str(numBuf, cnt, 1, 10);
151 print((uint8_t*)"SDRAM installed: ");
152 print((uint8_t*)numBuf);
153 print((uint8_t*)" MB\r\n");
159 /** Reads values from MOUT_EN pins and prints them
160 * @param[in] cmd_io Pointer to IO stack
161 * @param[in] des Pointer to command descriptor
162 * @param[in] param Parameters of command
163 * @return 0 when OK or error code
165 int cmd_do_read_mout_values(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
166 print((uint8_t *)"\r\nValues from MOUT_EN:");
167 uint32_t portVal = moutGetPort();
168 print((uint8_t *)"\r\npin\t|\tvalue");
170 for (i = 6, portVal = portVal>>6; i < 12; i++, portVal = portVal>>1) {
171 uint8_t bit = portVal&1;
173 i2str(numBuf, i-5, 1, 10);
174 print((uint8_t *)"\r\n");
175 print((uint8_t *)numBuf);
176 print((uint8_t *)"\t|\t");
178 print((uint8_t *)"1");
181 print((uint8_t *)"0");
187 /** Reads values from DIN pins and prints them
188 * @param[in] cmd_io Pointer to IO stack
189 * @param[in] des Pointer to command descriptor
190 * @param[in] param Parameters of command
191 * @return 0 when OK or error code
193 int cmd_do_read_din_values(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
194 print((uint8_t *)"\r\nValues from DIN:");
195 uint32_t portVal = dinGetPort();
196 print((uint8_t *)"\r\npin\t|\tvalue");
198 for (i = 0; i < 8; i++,portVal = portVal>>1) {
199 uint8_t bit = portVal&1;
200 print((uint8_t *)"\r\n");
202 i2str(numBuf, i+8, 1, 10);
203 print((uint8_t *)numBuf);
204 print((uint8_t *)"\t|\t");
206 print((uint8_t *)"1");
209 print((uint8_t *)"0");
215 /** Reads values from HOUT_DIAG pins and prints them
216 * @param[in] cmd_io Pointer to IO stack
217 * @param[in] des Pointer to command descriptor
218 * @param[in] param Parameters of command
219 * @return 0 when OK or error code
221 int cmd_do_read_hout_diag_values(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
222 print((uint8_t *)"\r\nValues from HOUT_DIAG:");
223 uint32_t portVal = houtGetPort();
224 print((uint8_t *)"\r\npin\t|\tvalue");
226 for (i = 0, portVal = portVal>>6; i < 6; i++,portVal = portVal>>1) {
227 uint8_t bit = portVal&1;
228 print((uint8_t *)"\r\n");
230 i2str(numBuf, i+1, 1, 10);
231 print((uint8_t *)numBuf);
232 print((uint8_t *)"\t|\t");
234 print((uint8_t *)"1");
237 print((uint8_t *)"0");
243 /** Reads values from ADC and stores them to ADCData structure defined as global.
244 * ADCData structure must be defined properly before this function is called.
245 * @param[in] adc Pointer to ADC base register
246 * @param[in] group ADC group selector
247 * @return 0 when OK or error code
249 int read_adc(adcBASE_t* adc, uint32_t group) {
250 if (adcData.adc_data == NULL) {
253 adcDataConverted = xSemaphoreCreateCounting(1, 0);
254 adcEnableNotification(adc, group);
256 adcMidPointCalibration(adc);
258 adcStartConversion(adc, group);
259 xSemaphoreTake(adcDataConverted, portMAX_DELAY);
261 if (adcData.flags & BAD_CHANNELS_COUNT) {
262 print((uint8_t *)"\r\nERROR: Bad count of channels was read! Can not proceed.");
263 adcData.flags &= ~BAD_CHANNELS_COUNT;
264 adcDisableNotification(adc, group);
265 vSemaphoreDelete(canMsgReceived);
268 if (adcData.flags & MEM_OVERRUN) {
269 print((uint8_t *)"\r\nWARNING: ADC Memory overrun detected. Values can be imprecise.");
270 adcData.flags &= ~MEM_OVERRUN;
272 adcDisableNotification(adc, group);
273 vSemaphoreDelete(canMsgReceived);
277 /** Reads values from HOUT_IFBK pins (subset of ADC)
278 * @param[in] cmd_io Pointer to IO stack
279 * @param[in] des Pointer to command descriptor
280 * @param[in] param Parameters of command
281 * @return 0 when OK or error code
283 int cmd_do_read_hout_ifbk_values(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
285 char numBuf[4]; // Buffer used for i2str conversion
286 uint32_t i; // Cycle control variable
288 // ADCData structure initialization
289 adcData_t adc_data_origin[HOUT_IFBK_CHANNEL_COUNT];
290 adcData.adc_data = adc_data_origin;
291 adcData.ch_count = HOUT_IFBK_CHANNEL_COUNT;
293 print((uint8_t *)"\r\nRead HOUT_IFBK values.");
294 if (read_adc(adcREG2, adcGROUP1) == 1)
296 /* conversion results */
297 for (i = 0; i < adcData.ch_count; i++) {
298 print((uint8_t *)"\r\nHOUT: ");
299 i2str(numBuf, adcData.adc_data[i].id-1, 1, 10);
300 print((uint8_t *)numBuf);
301 print((uint8_t *)"\tvalue: ");
302 i2str(numBuf, adcData.adc_data[i].value, 1, 10);
303 print((uint8_t *)numBuf);
304 print((uint8_t *)" 0x");
305 i2str(numBuf, adcData.adc_data[i].value, 1, 16);
306 print((uint8_t *)numBuf);
308 adcData.adc_data = NULL;
312 /** Reads values from ADC1 pins
313 * @param[in] cmd_io Pointer to IO stack
314 * @param[in] des Pointer to command descriptor
315 * @param[in] param Parameters of command
316 * @return 0 when OK or error code
318 int cmd_do_read_adc1_values(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
320 char numBuf[4]; // Buffer used for i2str conversion
321 uint32_t i; // Cycle control variable
323 /* ADCData structure initialization */
324 adcData_t adc_data_origin[ADC1_CHANNEL_COUNT];
325 adcData.adc_data = adc_data_origin;
326 adcData.ch_count = ADC1_CHANNEL_COUNT;
328 print((uint8_t *)"\r\nADC1 values:");
329 if (read_adc(adcREG1, adcGROUP1) == 1)
332 /* conversion results : */
333 for (i = 0; i < adcData.ch_count; i++) {
334 print((uint8_t *)"\r\nChannel: ");
335 i2str(numBuf, adcData.adc_data[i].id, 1, 10);
336 print((uint8_t *)numBuf);
337 print((uint8_t *)"\tvalue: ");
338 i2str(numBuf, adcData.adc_data[i].value, 1, 10);
339 print((uint8_t *)numBuf);
340 print((uint8_t *)" 0x");
341 i2str(numBuf, adcData.adc_data[i].value, 1, 16);
342 print((uint8_t *)numBuf);
344 adcData.adc_data = NULL;
348 /** Read values general command function. According the suffix switch to appropriate reading procedure.
349 * @param[in] cmd_io Pointer to IO stack
350 * @param[in] des Pointer to command descriptor
351 * @param[in] param Parameters of command
352 * @return 0 when OK or error code
354 int cmd_do_read_values(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
358 if ((token = strtok(param[1], " ")) == NULL) {
359 print((uint8_t *)"ERROR: No suffix!");
363 if (!strcmp(token, "ADC1"))
365 else if (!strcmp(token, "DIN"))
367 else if (!strcmp(token, "MOUTE"))
369 else if (!strcmp(token, "HOUTD"))
371 else if (!strcmp(token, "HOUTF"))
374 print((uint8_t *)"ERROR: Wrong suffix!");
379 ret = cmd_do_read_adc1_values(cmd_io, des, param);
382 ret = cmd_do_read_din_values(cmd_io, des, param);
385 ret = cmd_do_read_mout_values(cmd_io, des, param);
388 ret = cmd_do_read_hout_diag_values(cmd_io, des, param);
391 ret = cmd_do_read_hout_ifbk_values(cmd_io, des, param);
400 /** Set value general command function. According the suffix sets given bit to given value to appropriate port pin.
401 * @param[in] cmd_io Pointer to IO stack
402 * @param[in] des Pointer to command descriptor
403 * @param[in] param Parameters of command
404 * @return 0 when OK or error code
406 int cmd_do_set_pin(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
407 void (*setBit)(gioPORT_t *, uint32_t, uint32_t) = NULL;
408 gioPORT_t * port = NULL;
416 if ((token = strtok(param[1], " ")) == NULL) {
417 print((uint8_t *)"ERROR: No suffix!");
420 if (!strcmp(token, "MOUTI"))
422 else if (!strcmp(token, "HOUTI")) {
425 else if (!strcmp(token, "VBAT")) {
430 print((uint8_t *)"ERROR: Wrong suffix!");
433 // Get index of the bit
434 if ((token = strtok(param[2], " ")) == NULL) {
435 print((uint8_t *)"ERROR: Parameter 1 expected.");
438 if (EOF == sscanf(token, "%d", &pin)){
439 print((uint8_t *)"ERROR: unsigned number expected as param 1!");
443 if ((token = strtok(NULL, " ")) == NULL) {
444 print((uint8_t *)"ERROR: Parameter 2 expected.");
447 if (EOF == sscanf(token, "%d", &value)){
448 print((uint8_t *)"ERROR: unsigned number expected as param 2!");
451 if ((token = strtok(NULL, " ")) != NULL) {
452 print((uint8_t *)"ERROR: More than 2 parameters detected!");
459 if (pin < 1 || pin > 6) {
460 print((uint8_t *)"ERROR: 1st parameter out of range <1;6>!");
463 if (value != 1 && value != 0) {
464 print((uint8_t *)"ERROR: 2nd parameter out of range <0;1>!");
467 port = moutPorts[pin-1];
468 bit = moutBits[pin-1];
472 if (pin < 1 || pin > 6) {
473 print((uint8_t *)"ERROR: 1st parameter out of range <1;6>!");
476 if (value != 1 && value != 0) {
477 print((uint8_t *)"ERROR: 2nd parameter out of range <0;1>!");
480 port = houtPorts[pin-1];
481 bit = houtBits[pin-1];
484 setBit=&vbatSetBitAndDir;
485 if (pin < 1 || pin > 3) {
486 print((uint8_t *)"ERROR: 1st parameter out of range <1;3>!");
489 if (value != 1 && value != 0) {
490 print((uint8_t *)"ERROR: 2nd parameter out of range <0;1>!");
497 setBit(port, bit, value);
498 print((uint8_t *)"Bit has been set.");
502 /** Get value general command function. According the suffix gets given bit of appropriate port pin.
503 * @param[in] cmd_io Pointer to IO stack
504 * @param[in] des Pointer to command descriptor
505 * @param[in] param Parameters of command
506 * @return 0 when OK or error code
508 int cmd_do_get_pin(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
513 uint32_t suffix = 100;
515 if ((token = strtok(param[1], " ")) == NULL) {
516 print((uint8_t *)"ERROR: No suffix!");
519 if (!strcmp(token, "ADC1"))
521 else if (!strcmp(token, "DIN"))
523 else if (!strcmp(token, "MOUTE"))
525 else if (!strcmp(token, "HOUTD"))
527 else if (!strcmp(token, "HOUTF"))
529 else if (!strcmp(token, "VBAT"))
532 print((uint8_t *)"ERROR: Wrong suffix!");
536 if ((token = strtok(param[2], " ")) == NULL) {
537 print((uint8_t *)"ERROR: Parameter 1 expected.");
540 if (EOF == sscanf(token, "%d", &pin)){
541 print((uint8_t *)"ERROR: unsigned number expected as param 1!");
544 if ((token = strtok(NULL, " ")) != NULL) {
545 print((uint8_t *)"ERROR: More than 1 parameters detected!");
553 print((uint8_t *)"ERROR: 1st parameter out of range <0;11>!");
557 adcData_t adc_data_origin[ADC1_CHANNEL_COUNT];
558 adcData.adc_data = adc_data_origin;
559 adcData.ch_count = ADC1_CHANNEL_COUNT;
560 if (read_adc(adcREG1, adcGROUP1) == 1)
562 value = adcData.adc_data[pin].value;
563 adcData.adc_data = NULL;
568 if (pin < 1 || pin > 8) {
569 print((uint8_t *)"ERROR: 1st parameter out of range <8;15>!");
572 value = gioGetBit(dinPorts[pin-1], dinBits[pin-1]);
575 if (pin < 1 || pin > 6) {
576 print((uint8_t *)"ERROR: 1st parameter out of range <1;6>!");
579 value = gioGetBit(moutPorts[pin-1], moutBits[pin-1]);
582 if (pin < 1 || pin > 6) {
583 print((uint8_t *)"ERROR: 1st parameter out of range <1;6>!");
586 value = gioGetBit(houtPorts[pin-1], houtBits[pin-1]);
590 if (pin < 1 || pin > 6) {
591 print((uint8_t *)"ERROR: 1st parameter out of range <1;6>!");
594 adcData_t adc_data_origin[HOUT_IFBK_CHANNEL_COUNT];
595 adcData.adc_data = adc_data_origin;
596 adcData.ch_count = HOUT_IFBK_CHANNEL_COUNT;
597 if (read_adc(adcREG2, adcGROUP1) == 1)
599 value = adcData.adc_data[pin].value;
600 adcData.adc_data = NULL;
605 if (pin < 1 || pin > 3) {
606 print((uint8_t *)"ERROR: 1st parameter out of range <1;3>!");
609 value = vbatGetBit(vbatBits[pin]);
613 i2str(numBuf, value, 1, 10);
614 print((uint8_t *)numBuf);
618 /** Runs test of ADC1. Test each channel if it is shorted to REFLO or REFHI
619 * @param[in] cmd_io Pointer to IO stack
620 * @param[in] des Pointer to command descriptor
621 * @param[in] param Parameters of command
622 * @return 0 when OK or error code
624 int cmd_do_test_adc1_connection(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
626 uint32_t Vn[ADC1_CHANNEL_COUNT]; // Nominal value, converted from ADC
627 uint32_t Vu[ADC1_CHANNEL_COUNT]; // Upper bound
628 uint32_t Vd[ADC1_CHANNEL_COUNT]; // Lower bound
629 uint32_t* Vptr; // Pointer to value (used in cycle)
630 uint8_t j; // Cycle control variable
631 uint32_t i; // Cycle control variable
632 char numBuf[2]; // Buffer used for i2str conversion
634 // Initialize ADCData structure
635 adcData_t adc_data_origin[ADC1_CHANNEL_COUNT];
636 adcData.adc_data = adc_data_origin;
637 adcData.ch_count = ADC1_CHANNEL_COUNT;
639 print((uint8_t *)"\r\nTesting ADC1 connection.");
641 // Read and store Nominal voltage, Lowest voltage Highest voltage in that order
642 for (j = 0; j < 3; j++) {
650 adcREG1->CALCR |= (1 << 24);
655 adcREG1->CALCR |= (1 << 8);
660 if (read_adc(adcREG2, adcGROUP1) == 1)
663 for (i = 0; i < ADC1_CHANNEL_COUNT; i++) {
664 Vptr[i] = adcData.adc_data[i].value;
668 print((uint8_t *)"\r\n|\tChannel\t|\tStatus");
669 for (i = 0; i < ADC1_CHANNEL_COUNT; i++) {
670 i2str(numBuf, i, 2, 10);
671 print((uint8_t *)"\r\n|\t");
672 print((uint8_t *)numBuf);
673 print((uint8_t *)"\t|\t");
677 print((uint8_t *)"shorted with REFLO");
680 print((uint8_t *)"shorted with REFHI");
684 print((uint8_t *)"GOOD");
688 adcData.adc_data = NULL;
693 /** Runs test of CAN loopback. Send message from CAN1 and receive it on CAN2.
694 * @param[in] cmd_io Pointer to IO stack
695 * @param[in] des Pointer to command descriptor
696 * @param[in] param Parameters of command
697 * @return 0 when OK or error code
699 int cmd_do_test_can_loopback(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
702 canBASE_t *canBases[3] = {canREG1, canREG2, canREG3};
703 uint32_t canMailBoxes[3] = {canMESSAGE_BOX1, canMESSAGE_BOX2, canMESSAGE_BOX3};
705 uint32_t txTimeOutCnt = 0;
706 uint32_t rxTimeOutCnt = 0;
707 uint32_t messagesTransmitted = 0;
708 uint32_t messagesReceived = 0;
710 uint8_t tx_data[8] = {'T', 'E', 'S', 'T', ' ', 'C', 'A', 'N'};
711 uint8_t rx_data[8] = {0, 0, 0, 0, 0, 0, 0, 0 };
714 if ((token = strtok(param[1], " ")) == NULL) {
716 print((uint8_t *)"ERROR: Parameter 1 expected.");
719 if (EOF == sscanf(token, "%d", &can[0])){
720 print((uint8_t *)"ERROR: unsigned number expected as param 1!");
724 if ((token = strtok(NULL, " ")) == NULL) {
725 print((uint8_t *)"ERROR: Parameter 2 expected.");
728 if (EOF == sscanf(token, "%d", &can[1])){
729 print((uint8_t *)"ERROR: unsigned number expected as param 2!");
732 if ((token = strtok(NULL, " ")) != NULL) {
733 print((uint8_t *)"ERROR: More than 2 parameters detected!");
736 if (can[0] == can[1]) {
737 print((uint8_t *)"ERROR: Destination equals source!);");
740 if (can[0] < 1 | can[1] > 3) {
741 print((uint8_t *)"Parameter out of range <1;3>!");
744 canSrc = canBases[can[0]-1];
745 canDst = canBases[can[1]-1];
746 canMsgBox = canMailBoxes[can[0]-1];
747 canMsgReceived = xSemaphoreCreateCounting(1, 0);
748 canMsgSent = xSemaphoreCreateCounting(1, 0);
750 print((uint8_t *)"\r\nTesting CAN loopback\r\n");
751 i = canSrc->ES; // Reset error flag
752 i = canDst->ES; // Reset error flag
753 canEnableErrorNotification(canDst);
754 canEnableErrorNotification(canSrc);
756 for (i = 0; i < 100; i++) { // Send 100 times the message
757 if (canGetErrorLevel(canSrc) != canLEVEL_ACTIVE) {
758 print((uint8_t*)"TX: CAN is not active.\r\n");
761 canTransmit(canSrc, canMsgBox, tx_data);
762 if (xSemaphoreTake(canMsgSent, 100/portTICK_RATE_MS) == pdFALSE) {
766 if (canGetErrorLevel(canSrc) & canLEVEL_BUS_OFF) {
767 print((uint8_t *)"TX: CAN bus is off.\r\n");
770 else if (canGetErrorLevel(canSrc) & canLEVEL_PASSIVE) {
771 print((uint8_t *)"TX: CAN bus in passive mode.\r\n");
774 else if (canGetErrorLevel(canSrc) & canLEVEL_WARNING) {
775 print((uint8_t *)"TX: CAN bus error counter warning.\r\n");
779 messagesTransmitted++;
780 if (xSemaphoreTake(canMsgReceived, 100/portTICK_RATE_MS) == pdFALSE) {
784 if (canGetData(canDst, canMsgBox, rx_data))
787 if (canGetErrorLevel(canDst) & canLEVEL_BUS_OFF) {
788 print((uint8_t *)"RX: CAN bus is off.\r\n");
791 else if (canGetErrorLevel(canDst) & canLEVEL_PASSIVE) {
792 print((uint8_t *)"RX: CAN bus in passive mode.\r\n");
795 else if (canGetErrorLevel(canDst) & canLEVEL_WARNING) {
796 print((uint8_t *)"RX: CAN bus error counter reached warning level.\r\n");
803 print((uint8_t *)"Messages transmitted: ");
805 i2str(errBuf, messagesTransmitted, 1, 10);
806 print((uint8_t *)errBuf);
807 print((uint8_t *)"/100\r\n");
809 print((uint8_t *)"Messages received: ");
810 i2str(errBuf, messagesReceived, 1, 10);
811 print((uint8_t *)errBuf);
812 print((uint8_t *)"/100\r\n");
814 print((uint8_t *)"TX timeouts: ");
815 i2str(errBuf, txTimeOutCnt, 1, 10);
816 print((uint8_t *)errBuf);
817 print((uint8_t *)"\r\n");
819 print((uint8_t *)"RX timeouts: ");
820 i2str(errBuf, rxTimeOutCnt, 1, 10);
821 print((uint8_t *)errBuf);
822 print((uint8_t *)"\r\n");
824 print((uint8_t *)"TX error counter: ");
825 uint32_t errCnt = canSrc->EERC & 0xFFU;
826 i2str(errBuf, errCnt, 1, 10);
827 print((uint8_t *)errBuf);
828 print((uint8_t *)"\r\n");
830 print((uint8_t *)"RX error counter: ");
831 errCnt = canSrc->EERC & 0xFF00U;
832 i2str(errBuf, errCnt, 1, 10);
833 print((uint8_t *)errBuf);
834 print((uint8_t *)"\r\n");
836 canDisableErrorNotification(canDst);
837 canDisableErrorNotification(canSrc);
838 vSemaphoreDelete(canMsgReceived);
839 vSemaphoreDelete(canMsgSent);
843 /** Runs test of HOUT. Test, weather HOUT is in fault state, which means that HOUT_DIAG is shorted to ground
844 * @param[in] cmd_io Pointer to IO stack
845 * @param[in] des Pointer to command descriptor
846 * @param[in] param Parameters of command
847 * @return 0 when OK or error code
849 int cmd_do_test_hout_fault(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
851 print((uint8_t *)"Testing fault state of HOUT port:");
853 for (i = 0; i < 6; i++) {
854 HOUTSetBit(houtPorts[i], houtBits[i], 1);
855 vTaskDelay(100/portTICK_RATE_MS);
856 if (HOUTGetBit(houtPorts[i+6], houtBits[i+6]) == 1) {
857 print((uint8_t *)"\r\nOK");
860 print((uint8_t *)"\r\nFAIL");
862 HOUTSetBit(houtPorts[i], houtBits[i], 0);
867 /** Runs test of MOUT. Test, weather MOUT is in fault state, which means that MOUT_EN is shorted to ground
868 * @param[in] cmd_io Pointer to IO stack
869 * @param[in] des Pointer to command descriptor
870 * @param[in] param Parameters of command
871 * @return 0 when OK or error code
873 int cmd_do_test_mout_fault(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
875 print((uint8_t *)"Testing fault state of MOUT port:");
877 for (i = 0; i < 6; i++) {
878 MOUTSetBit(moutPorts[i], moutBits[i], 1);
879 vTaskDelay(100/portTICK_RATE_MS);
880 if (MOUTGetBit(moutPorts[i+6], moutBits[i+6]) == 1) {
881 print((uint8_t *)"\r\nOK");
884 print((uint8_t *)"\r\nFAIL");
886 MOUTSetBit(moutPorts[i], moutBits[i], 0);
891 /* ------------------------------
892 * User defined command variables
893 * ------------------------------
896 /* -------------------
897 * Command definitions
898 * -------------------
901 cmd_des_t const cmd_des_vbat_set={
903 "VBATSET","Set V_BAT_EN.",
904 cmd_do_vbat_set, (void *)&cmd_list
907 cmd_des_t const cmd_des_vbat_clr={
909 "VBATCLR","Clear V_BAT_EN.",
910 cmd_do_vbat_clr, (void *)&cmd_list
913 /** @brief command descriptor for test SDRAM */
914 cmd_des_t const cmd_des_vbat_get={
916 "VBATGET","Get value from V_BAT_EN.",
917 cmd_do_vbat_get, (void *)&cmd_list
920 /** @brief command descriptor for test SDRAM */
921 cmd_des_t const cmd_des_test_sdram={
923 "TESTSDRAM","Test if SDRAM module is connected and if it is, measure capacity",
924 cmd_do_test_ram, (void *)&cmd_list
926 /** @brief command descriptor for get value of pin command */
927 cmd_des_t const cmd_des_get_pin={
929 "GETPIN*","Get value of pin at port given as suffix\r\n\t"
930 "-suffix ADC1 pin<0;11> - read value from ADC1[pin]\r\n\t"
931 "-suffix DIN pin<8;15> - read values from DIN[pin]\r\n\t"
932 "-suffix HOUTD pin<1;6> - read values from HOUT_DIAG[pin]\r\n\t"
933 "-suffix HOUTF pin<1;6> - read values from HOUT_IFBK[pin]\r\n\t"
934 "-suffix MOUTE pin<1;6> - read values from MOUT_EN[pin]\r\n\t"
935 "-suffix VBAT pin<1;3> - reads values from V_BAT_[pin]_EN.",
936 cmd_do_get_pin, (void *)&cmd_list
938 /** @brief command descriptor for set value to pin command */
939 cmd_des_t const cmd_des_set_pin={
941 "SETPIN*","Set value to pin at port given as suffix\r\n\t"
942 "-suffix: MOUTI pin<1;6> value <0;1> - MOUT[pin]_IN <- value\r\n\t"
943 "-suffix: HOUTI pin<1;6> value <0;1> - HOUT[pin]_IN <- value\r\n\t"
944 "-suffix: VBAT id<1;3> value <0;1> - V_BAT_[id]_EN <- value\r\n\t\t"
945 "iff value = 1 then V_Bat is set as an input and value to log 1\r\n\t\t"
946 "iff value = 0 than V_Bat is set as an output and value to log 0",
947 cmd_do_set_pin, (void *)&cmd_list
949 /** @brief command descriptor for read values from port command */
950 cmd_des_t const cmd_des_read={
952 "READVAL*","Read values from port\r\n\t"
953 "-suffix ADC1 - read values from ADC1\r\n\t"
954 "-suffix DIN - read values from DIN\r\n\t"
955 "-suffix HOUTD - read values from HOUT_DIAG\r\n\t"
956 "-suffix HOUTF - read values from HOUT_IFBK\r\n\t"
957 "-suffix MOUTE - read values from MOUT_EN",
958 cmd_do_read_values, (void *)&cmd_list
960 /** @brief command descriptor for test ADC connection command */
961 cmd_des_t const cmd_des_test_adc_connetion={
963 "ADCCON","Test fitness of each ADC channel connection",
964 cmd_do_test_adc1_connection, (void *)&cmd_list
966 /** @brief command descriptor for test CAN loopback command */
967 cmd_des_t const cmd_des_test_can_loopback={
969 "CANLOOPBACK","Test CAN loopback",
970 cmd_do_test_can_loopback, (void *)&cmd_list
972 /** @brief command descriptor for test mout fault state command */
973 cmd_des_t const cmd_des_test_mout_fail={
975 "MOUTFAIL","Test if some MOUT port is in fault state",
976 cmd_do_test_mout_fault, (void *)&cmd_list
978 /** @brief command descriptor for test hout fault state command */
979 cmd_des_t const cmd_des_test_hout_fail={
981 "HOUTFAIL","Test if some HOUT port is in fault state",
982 cmd_do_test_hout_fault, (void *)&cmd_list
984 /** @brief command descriptor for show help command */
985 cmd_des_t const cmd_des_help={
987 "HELP","prints help for commands\r\n",
988 cmd_do_help, (void *)&cmd_list
991 /* ------------------------
992 * Command lists definitons
993 * ------------------------
995 /** @brief Main list of commands */
996 cmd_des_t const *cmd_list_main[]={
1004 &cmd_des_test_adc_connetion,
1005 &cmd_des_test_can_loopback,
1006 &cmd_des_test_hout_fail,
1007 &cmd_des_test_mout_fail,
1008 &cmd_des_test_sdram,
1012 /** @brief pointer to the main list */
1013 cmd_des_t const **cmd_list = cmd_list_main;