2 * Copyright (C) 2012-2014 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 CAN test
30 * Error codes definitions for RPP CAN functions tests.
32 #define ERR_CCT_HW_OBJ 0x0001 /**< Wrong HW object passed to the RPP CAN function. */
33 #define ERR_CCT_MSG_MISMATCH 0x0010 /**< Received message does not match to the sent message. */
34 #define ERR_CCT_RX_IND_NOT_CLEARED 0x0020 /**< Message received indicator was not cleared by the rpp_can_read function. */
35 #define ERR_CCT_RX_IND_SET_NO_MSG_REC 0x0040 /**< Message received indicator is set, but no message could be retrieved by the rpp_can_read function. */
36 #define ERR_CCT_RECV_TIMEOUT 0x0100 /**< Message receive timeout reached. */
37 #define ERR_CCT_CLEAR_TX_PEND_TO 0x0200 /**< Timeout reached for waiting for the clearance of the transmission request flag. */
38 #define ERR_CCT_SET_TX_PEND_TO 0x0400 /**< Timeout reached for waiting until the transmission request flag is set after the request is posted. */
39 #define ERR_CCT_INIT 0x1000 /**< Error while initializing the CAN bus. */
40 #define ERR_CCT_SEND 0x2000 /**< Error while sending a CAN message. */
41 #define ERR_CCT_RCV 0x4000 /**< Error while receiving a CAN message */
42 #define ERR_CCT_UNEXPECTED_RETVAL 0x0008 /**< Unexpected return value has been returned from some RPP CAN function. */
44 #define CCT_TIMEOUT 100000 /**< Timeout for RPP CAN test steps. */
46 static int can_inited = 0;
48 /* Default CAN timing set to 500kb */
49 static struct rpp_can_timing_cfg can_timing[] = {
74 static struct rpp_can_ctrl_config ctrl_config[] = {
78 .timing_calc_method = RPP_CAN_TIMING_CALC_AUTO,
84 .timing_calc_method = RPP_CAN_TIMING_CALC_AUTO,
90 .timing_calc_method = RPP_CAN_TIMING_CALC_AUTO,
95 static struct rpp_can_tx_config tx_config[] = {
97 .type = RPP_CAN_EXTENDED,
102 .type = RPP_CAN_EXTENDED,
107 .type = RPP_CAN_EXTENDED,
113 static struct rpp_can_rx_config rx_config[] = {
115 .type = RPP_CAN_MIXED,
122 .type = RPP_CAN_MIXED,
129 .type = RPP_CAN_MIXED,
137 struct rpp_can_config can_config = {
140 .tx_config = tx_config,
141 .rx_config = rx_config,
146 * Structures for RPP CAN functions tests.
150 * CAN test bit timings configurations.
152 struct rpp_can_timing_cfg can_test_timing[] = {
177 * CAN test controllers configurations.
179 struct rpp_can_ctrl_config can_test_ctrl_cfg[] = {
183 .timing_calc_method = RPP_CAN_TIMING_CALC_MANUAL,
184 .timing_config = &can_test_timing[0]
189 .timing_calc_method = RPP_CAN_TIMING_CALC_MANUAL,
190 .timing_config = &can_test_timing[1]
195 .timing_calc_method = RPP_CAN_TIMING_CALC_MANUAL,
196 .timing_config = &can_test_timing[2]
201 * CAN test TX configuration.
203 struct rpp_can_tx_config can_test_tx_cfg[] = {
205 .type = RPP_CAN_STANDARD,
212 * CAN test RX configuration.
214 struct rpp_can_rx_config can_test_rx_cfg[] = {
216 .type = RPP_CAN_STANDARD,
225 * Root CAN test configuration structure
227 struct rpp_can_config can_test_cfg = {
230 .tx_config = can_test_tx_cfg,
231 .rx_config = can_test_rx_cfg,
232 .ctrl = can_test_ctrl_cfg
236 * Compare two CAN messages.
238 * @param[in] pdu1 CAN message 1
239 * @param[in] pdu2 CAN message 2
240 * @return TRUE, if the two CAN messages are equal.
242 boolean_t cmd_can_messages_equal(const struct rpp_can_pdu *pdu1, const struct rpp_can_pdu *pdu2)
244 boolean_t pdus_equal = TRUE;
246 if (pdu1->id != pdu2->id ||
247 pdu1->dlc != pdu2->dlc)
251 for (i = 0; i < pdu1->dlc; i++) {
252 if (pdu1->data[i] != pdu1->data[i]) {
262 * Initialize the CAN bus driver for tests.
264 * @param[in] timing_calc Select RPP_CAN_TIMING_CALC_AUTO for automatic CAN bit timing calculation
265 * for a baudrate specified by desired_baudrate. Select RPP_CAN_TIMING_CALC_MANUAL for configuring the
266 * CAN bus to 500kbits/sec with verified bit timing parameters generated by HALCoGen.
268 * @return SUCCESS if the test passed, FAILURE otherwise.
270 int cmd_can_test_init(enum rpp_can_timing_calculation timing_calc, uint32_t desired_baudrate)
272 can_test_cfg.ctrl[0].baudrate = desired_baudrate;
273 can_test_cfg.ctrl[0].timing_calc_method = timing_calc;
274 can_test_cfg.ctrl[1].baudrate = desired_baudrate;
275 can_test_cfg.ctrl[1].timing_calc_method = timing_calc;
276 can_test_cfg.ctrl[2].baudrate = desired_baudrate;
277 can_test_cfg.ctrl[2].timing_calc_method = timing_calc;
279 if (rpp_can_init(&can_test_cfg) == SUCCESS)
286 * General test for receiving of message.
288 * This function verifies that the rpp_can_read() function is working
289 * properly and that the CAN driver behaves as expected.
291 * This is a blocking function that tries to receive a CAN message. The reception
292 * has to finish until specified timeout is reached.
293 * The received message is compared with the transmitted one.
295 * @param[in] can_tx_pdu A message pattern, which should be received. Used for RX
296 * and TX equality verification.
297 * @param[in] timeout How long should the test wait for the message.
298 * @return SUCCESS if the test passed, error code otherwise.
300 int cmd_can_test_recv(const struct rpp_can_pdu *can_tx_pdu, uint32_t timeout)
302 boolean_t msg_received = FALSE;
303 volatile uint32_t rec_time = 0;
304 struct rpp_can_pdu can_rx_pdu;
306 while (!msg_received) {
307 int ret = rpp_can_read(0, &can_rx_pdu);
310 return ERR_CCT_HW_OBJ;
312 if (++rec_time >= CCT_TIMEOUT)
313 return ERR_CCT_RECV_TIMEOUT;
316 if (!cmd_can_messages_equal(&can_rx_pdu, can_tx_pdu))
317 return ERR_CCT_MSG_MISMATCH;
322 return ERR_CCT_UNEXPECTED_RETVAL;
329 * General test of sending a message.
331 * This function verifies that the rpp_can_write() function is working
332 * properly and that the CAN driver behaves as expected.
334 * @param[in] can_tx_msg A message for transmission.
335 * @return SUCCESS if the test passed, error code otherwise.
337 int cmd_can_test_send(const struct rpp_can_pdu *can_tx_msg)
339 if (rpp_can_write(0, can_tx_msg) != SUCCESS)
340 return ERR_CCT_HW_OBJ;
345 * General test of sending and receiving mechanism.
347 * This function verifies that the rpp_can_write() and rpp_can_read() functions
348 * are working properly and that the CAN driver behaves as expected.
350 * The message specified as a parameter is sent on the CAN bus and received to
351 * another mailbox. The received message is compared with the sent one.
353 * @param[in] can_tx_msg A message used to testing
354 * @return SUCCESS if the test passed, error code otherwise.
356 int cmd_can_test_simple_send_recv(const struct rpp_can_pdu *can_tx_msg)
360 if ((ret_val = cmd_can_test_send(can_tx_msg)) != SUCCESS)
361 return ERR_CCT_SEND|ret_val;
362 else if ((ret_val = cmd_can_test_recv(can_tx_msg, CCT_TIMEOUT)) != SUCCESS)
363 return ERR_CCT_RCV|ret_val;
369 * Test automatic CAN bit timing calculation for the specified baudrate.
371 * @param[in] tested_baudrate Desired baudrate.
372 * @param[in] can_tx_msg A message used to testing.
373 * @return SUCCESS if the test passed, error code otherwise.
376 int cmd_can_test_baudrate_calc(uint32_t tested_baudrate,const struct rpp_can_pdu *can_tx_msg)
380 if ((ret_val = cmd_can_test_init(RPP_CAN_TIMING_CALC_AUTO, 125000)) != SUCCESS)
381 return ERR_CCT_INIT|ret_val;
382 else if ((ret_val = cmd_can_test_simple_send_recv(can_tx_msg)) != SUCCESS)
389 * Test behavioral of two consecutive TX requests posting.
391 * This function verifies that the rpp_can_write() function is working properly and
392 * that the CAN driver behaves as expected.
394 * According to the behavioral defined by tha Autosar, the rpp_can_write() should not fail when
395 * new transmission request comes before the previous one has been processed. The function should
396 * overwrite the old request and only the new one should be transmitted.
398 * @param[in] can_tx_msg1 A message which transmission is requested foremost.
399 * @param[in] can_tx_msg2 A message, which transmission is requested right after the can_tx_msg1
400 * @return SUCCESS if the test passed, error code otherwise.
402 int cmd_can_test_tx_request_replace(const struct rpp_can_pdu *can_tx_msg1, const struct rpp_can_pdu *can_tx_msg2)
406 if ((ret_val = cmd_can_test_send(can_tx_msg1)) != SUCCESS)
408 else if ((ret_val = cmd_can_test_simple_send_recv(can_tx_msg2)) != SUCCESS)
415 * Test the TX request flag.
417 * This function verifies that the rpp_can_check_tx_pend() function is working properly and
418 * that the CAN driver behaves as expected.
420 * The TX request flag should be clear if no transmission request is pending. Once a rpp_can_write()
421 * is called a new transmission requst is posted and the TX request flag should be set, until the CAN
422 * bus driver sends the message. After the transmission is finished, the flag should be cleared.
424 * @param[in] rpp_can_pdu A message which used to testing.
425 * @param[out] time Measured time between posting the transmission request and setting the TX request flag.
426 * @return SUCCESS if the test passed, error code otherwise.
428 int cmd_can_test_tx_request_flag(const struct rpp_can_pdu *can_tx_msg, uint32_t *time)
431 uint32_t timeout = 0;
432 boolean_t tx_pend = FALSE;
434 if ((ret_val = cmd_can_test_send(can_tx_msg)) != SUCCESS)
437 /* Wait for the flag to be set */
439 if (++timeout > CCT_TIMEOUT)
440 return ERR_CCT_SET_TX_PEND_TO;
441 if (rpp_can_check_tx_pend(0, &tx_pend) == FAILURE)
442 return ERR_CCT_HW_OBJ;
446 if (rpp_can_check_tx_pend(0, &tx_pend) == FAILURE)
447 return ERR_CCT_HW_OBJ;
449 if (++timeout > CCT_TIMEOUT)
450 return ERR_CCT_CLEAR_TX_PEND_TO;
452 if ((ret_val = cmd_can_test_recv(can_tx_msg, CCT_TIMEOUT)) != SUCCESS)
453 return ERR_CCT_RCV|ret_val;
460 * Test the RX indicator.
462 * This function verifies that the rpp_can_check_rx_ind() function is working properly and
463 * that the CAN driver behaves as expected.
465 * The RX indicator should be set whenever new CAN message is received and remains set, until
466 * rpp_can_read() is called in order to retrieve the message.
468 * @param[in] rpp_can_pdu A message which used to testing.
469 * @param[out] time Measured time between posting the transmission request and setting the RX flag.
470 * @return SUCCESS if the test passed, error code otherwise.
472 int cmd_can_test_rx_indicator(const struct rpp_can_pdu *can_tx_msg, uint32_t *time)
475 volatile uint32_t timeout = 0;
476 boolean_t rx_ind = FALSE;
478 struct rpp_can_pdu can_rx_pdu;
480 if ((ret_val = cmd_can_test_send(can_tx_msg)) != SUCCESS)
483 /* Wait for the flag to be set */
485 if (rpp_can_check_rx_ind(0, &rx_ind) == FAILURE)
486 return ERR_CCT_HW_OBJ;
488 if (++timeout > CCT_TIMEOUT)
489 return ERR_CCT_SET_TX_PEND_TO;
492 if ((ret_val = rpp_can_read(0, &can_rx_pdu)) != SUCCESS) {
495 return ERR_CCT_RX_IND_SET_NO_MSG_REC;
497 return ERR_CCT_HW_OBJ;
499 return ERR_CCT_UNEXPECTED_RETVAL;
503 if (!cmd_can_messages_equal(&can_rx_pdu, can_tx_msg))
504 return ERR_CCT_MSG_MISMATCH;
506 if (rpp_can_check_rx_ind(0, &rx_ind) == FAILURE)
507 return ERR_CCT_HW_OBJ;
509 return ERR_CCT_RX_IND_NOT_CLEARED;
518 * Test CAN functions from RPP library.
520 * This is a complex test command for verification of automatic CAN bit timing
521 * calculation for baudrates 125k, 250k and 500kbits/sec and for checking RPP
526 * - rpp_can_check_rx_ind()
527 * - rpp_can_check_tx_pend()
529 * @return always SUCCESS
531 int cmd_do_can_test_functions(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
533 struct rpp_can_pdu can_tx_msg1 = {
536 .data = {'H', 'E', 'L', 'L', 'O', '0', '0', '1'}
539 struct rpp_can_pdu can_tx_msg2 = {
542 .data = {'H', 'E', 'L', 'L', 'O', '0', '0', '2'}
545 rpp_sci_printf("This is a test for RPP CAN library functions:\n");
547 * Simple send and receive a message with CAN bit time parameters for 500 kb/sec, picked
548 * from HALCoGen, which are proven to be functional.
550 rpp_sci_printf("Test of simple message transmission and reception.\n");
552 rpp_sci_printf("\tCAN bus Initialization: ");
553 if ((ret_val = cmd_can_test_init(RPP_CAN_TIMING_CALC_MANUAL, 500000)) != SUCCESS)
554 rpp_sci_printf("failed: error: 0x%X.\n", ret_val);
556 rpp_sci_printf("OK\n");
557 rpp_sci_printf("\tTransmission and reception...");
558 if ((ret_val = cmd_can_test_simple_send_recv(&can_tx_msg1)) != SUCCESS)
559 rpp_sci_printf("failed: error: 0x%X.\n", ret_val);
561 rpp_sci_printf("OK\n");
563 rpp_sci_printf("---\n");
564 /* Baudrate calculation testing
566 * Based on EATON requirements for baudrates: 125k, 250k, 500k
567 * - calculate bit timing parameters,
568 * - initialize the CAN bus,
570 * - receive a message
571 * - test if the received message is OK.
573 uint32_t baudrates[] = {125000, 250000, 500000};
574 uint8_t num_baudrates = 3;
576 rpp_sci_printf("Test of automatic CAN bit timing calculation.\n");
578 for (i = 0; i < num_baudrates; i++) {
579 rpp_sci_printf("\tBaudrate: %d: ", baudrates[i]);
580 if ((ret_val = cmd_can_test_baudrate_calc(baudrates[i], &can_tx_msg1)) != SUCCESS)
581 rpp_sci_printf("failed: error: 0x%X.\n", ret_val);
583 rpp_sci_printf("OK\n");
585 rpp_sci_printf("---\n");
588 * Test the behavioral when a new message replaces the actually pending message.
590 * - Send a request for message A transmission,
591 * - right after that, send a request for another message B transmission,
592 * - receive a message, which should be the message B.
594 rpp_sci_printf("Test of transmission request rewritting.\n");
595 rpp_sci_printf("\tCAN bus Initialization: ");
596 if ((ret_val = cmd_can_test_init(RPP_CAN_TIMING_CALC_MANUAL, 500000)) != SUCCESS)
597 rpp_sci_printf("failed: error: 0x%X.\n", ret_val);
599 rpp_sci_printf("OK\n");
600 rpp_sci_printf("\tTX request rewritting...");
601 if ((ret_val = cmd_can_test_tx_request_replace(&can_tx_msg1, &can_tx_msg2)) != SUCCESS)
602 rpp_sci_printf("failed: error: 0x%X.\n", ret_val);
604 rpp_sci_printf("OK\n");
606 rpp_sci_printf("---\n");
609 * Test the tx_pending flag detection
610 * - Send a request for a message transmission request,
611 * - Wait while the flag is reset, which means that the message has been received
612 * by another node, while measuring the time between the sending the request and
613 * resetting the flag.
614 * - Read the message to check that it has been already received.
617 rpp_sci_printf("Test of TX request pending flag detection.\n");
618 rpp_sci_printf("\tCAN bus Initialization: ");
619 if ((ret_val = cmd_can_test_init(RPP_CAN_TIMING_CALC_MANUAL, 500000)) != SUCCESS)
620 rpp_sci_printf("failed: error: 0x%X.\n", ret_val);
622 rpp_sci_printf("OK\n");
624 rpp_sci_printf("\tTX request pending flag behavioral: ");
625 if ((ret_val = cmd_can_test_tx_request_flag(&can_tx_msg1, &time)) != SUCCESS)
626 rpp_sci_printf("failed: error: 0x%X.\n", ret_val);
628 rpp_sci_printf("OK, time: %d cycles.\n", time);
630 rpp_sci_printf("---\n");
633 * Test the rx_ind flag
635 * - Wait for setting the rx_ind flag
636 * - Try to read the message.
638 rpp_sci_printf("Test of RX indicator.\n");
639 rpp_sci_printf("\tCAN bus Initialization: ");
640 if ((ret_val = cmd_can_test_init(RPP_CAN_TIMING_CALC_MANUAL, 500000)) != SUCCESS)
641 rpp_sci_printf("failed: error: 0x%X.\n", ret_val);
643 rpp_sci_printf("OK\n");
645 rpp_sci_printf("\tRX indicator behavioral: ");
646 if ((ret_val = cmd_can_test_rx_indicator(&can_tx_msg1, &time)) != SUCCESS)
647 rpp_sci_printf("failed: error: 0x%X.\n", ret_val);
649 rpp_sci_printf("OK, time: %d cycles.\n", time);
651 rpp_sci_printf("---\n");
654 * Reset the CAN bus to a determined state
657 rpp_sci_printf("Reset the CAN bus.\n");
658 rpp_sci_printf("\tCAN bus Initialization: ");
659 if ((ret_val = cmd_can_test_init(RPP_CAN_TIMING_CALC_MANUAL, 500000)) != SUCCESS)
660 rpp_sci_printf("failed: error: 0x%X.\n", ret_val);
662 rpp_sci_printf("OK\n");
666 int cmd_do_can_init(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
668 can_inited = (rpp_can_init(&can_config) == SUCCESS ? 1 : 0);
669 return (can_inited ? 0 : 1);
673 int cmd_do_can_send(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
675 uint32_t controller_id;
678 struct rpp_can_pdu pdu;
682 rpp_sci_printf("CAN is not initialized\n");
683 return -CMDERR_NODEV;
687 ret = sscanf(p, "%i %i%n", &controller_id, &pdu.id, &l);
689 rpp_sci_printf("Cannot parse parameter %d\n", ret+1);
690 return -CMDERR_BADPAR;
697 ret = sscanf(p, "%2hx%n", &data, &l);
699 pdu.data[i] = data & 0xff;
707 if (rpp_can_write(controller_id-1, &pdu) == SUCCESS) {
708 rpp_sci_printf("Sent: can%u\t%X\t[%u]\t", controller_id, pdu.id, pdu.dlc);
709 for (i = 0; i < pdu.dlc; i++) {
710 rpp_sci_printf("%X ", pdu.data[i]);
714 rpp_sci_printf("Error: rpp_can_write");
715 rpp_sci_printf("\n");
722 int cmd_do_can_dump(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
724 uint32_t controller_id = 0;
726 struct rpp_can_pdu pdu;
731 rpp_sci_printf("CAN is not initialized\n");
732 return -CMDERR_NODEV;
735 if (!(sscanf(param[1], "%u", &controller_id) == 1)) {
736 rpp_sci_printf("Unable to parse controller ID\n");
740 if (controller_id < 1 || controller_id > 3) {
741 rpp_sci_printf("Invalid controller ID\n");
742 return -CMDERR_NODEV;
745 rpp_can_init(&can_config);
747 while (cmd_io->getc(cmd_io) < 0) {
748 rpp_can_check_rx_ind(controller_id-1, &rx_ind);
750 if (rpp_can_read(controller_id-1, &pdu) == SUCCESS) {
751 if (pdu.id & CAN_EFF_FLAG)
752 rpp_sci_printf("can%u %08X [%u] ", controller_id & (~CAN_EFF_FLAG), pdu.id, pdu.dlc);
754 rpp_sci_printf("can%u %03X [%u] ", controller_id, pdu.id, pdu.dlc);
756 for (i = 0; i < pdu.dlc; i++) {
757 rpp_sci_printf("%X ", pdu.data[i]);
759 rpp_sci_printf("\n");
762 rpp_sci_printf("Error rpp_can_read\n");
770 int cmd_do_can_change_baudrate(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
773 uint32_t controller_id, baudrate;
775 if ((opchar = cmd_opchar_check(cmd_io, des, param)) < 0)
779 if (!(sscanf(param[1], "%u:%u", &controller_id, &baudrate) == 2)) {
780 rpp_sci_printf("Unable to parse arguments\n");
784 if (controller_id < 1 || controller_id > 3)
785 return -CMDERR_BADPAR;
787 can_config.ctrl[controller_id-1].baudrate = baudrate;
788 can_config.ctrl[controller_id-1].timing_config = NULL;
789 can_config.ctrl[controller_id-1].timing_calc_method = RPP_CAN_TIMING_CALC_AUTO;
793 if (!(sscanf(param[1], "%u", &controller_id) == 1))
795 if (controller_id < 1 || controller_id > 3)
796 return -CMDERR_BADPAR;
798 cmd_opchar_replong(cmd_io, param, can_config.ctrl[controller_id-1].baudrate, 0, 10);
804 int cmd_do_can_change_timing(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
807 uint32_t controller_id, brp, prop_seg, phase_seg1, phase_seg2, sjw;
809 if ((opchar = cmd_opchar_check(cmd_io, des, param)) < 0)
813 if (!(sscanf(param[1], "%u:%u %u %u %u %u", &controller_id, &brp, &prop_seg, &phase_seg1, &phase_seg2, &sjw) == 6)) {
814 rpp_sci_printf("Unable to parse arguments\n");
818 if (controller_id < 1 || controller_id > 3)
819 return -CMDERR_BADPAR;
821 can_config.ctrl[controller_id-1].baudrate = 0;
822 can_config.ctrl[controller_id-1].timing_config = &can_timing[controller_id-1];
823 can_config.ctrl[controller_id-1].timing_config->brp = brp;
824 can_config.ctrl[controller_id-1].timing_config->phase_seg1 = phase_seg1;
825 can_config.ctrl[controller_id-1].timing_config->phase_seg2 = phase_seg2;
826 can_config.ctrl[controller_id-1].timing_config->prop_seg = prop_seg;
827 can_config.ctrl[controller_id-1].timing_config->sjw = sjw;
828 can_config.ctrl[controller_id-1].timing_calc_method = RPP_CAN_TIMING_CALC_MANUAL;
832 if (!(sscanf(param[1], "%u", &controller_id) == 1))
834 if (controller_id < 1 || controller_id > 3)
835 return -CMDERR_BADPAR;
837 if (can_config.ctrl[controller_id-1].timing_config != NULL)
838 rpp_sci_printf("brp: %u\r\nprop_seg: %u tQ\r\nphase_seg1: %u tQ\r\nphase_seg2: %u tQ\r\nsjw: %u tQ\r\n",
839 can_config.ctrl[controller_id-1].timing_config->brp,
840 can_config.ctrl[controller_id-1].timing_config->prop_seg,
841 can_config.ctrl[controller_id-1].timing_config->phase_seg1,
842 can_config.ctrl[controller_id-1].timing_config->phase_seg2,
843 can_config.ctrl[controller_id-1].timing_config->sjw
847 rpp_sci_printf("CAN timing has not yet been manually specified.\r\n");
858 cmd_des_t const cmd_des_can_init = {
860 "caninit", "Initialize CAN controllers",
861 "### Command syntax ###\n"
865 "### Description ###\n"
867 "This command (re-)initializes all CAN controllers using current\n"
868 "CAN configuration. This configuration can be changed using\n"
869 "canbaudrate command.\n"
871 "In the default configuration the baudrate of all CAN controllers i set\n"
876 CMD_HANDLER(cmd_do_can_init), (void *)&cmd_list_can
879 cmd_des_t const cmd_des_can_baudrate = {
880 0, CDESM_OPCHR|CDESM_RW,
881 "canbaudrate#", "Change baudrate of CAN controller",
882 "### Command syntax ###\n"
884 " canbaudrate<CONTROLLER>?\n"
885 " canbaudrate<CONTROLLER>:<BAUDRATE>\n"
887 "where `<CONTROLLER>` is number in range 1-3 and BAUDRATE is number in\n"
888 "range 1000-10000000 specifying the baudrate in bits per second.\n"
890 "### Description ###\n"
892 "This command is used to set or show the baudrate of a CAN controller.\n"
893 "The baudrate shown is the one which will be used by next invocation of\n"
894 "the caninit command.\n"
895 "The baudrate specified by the command is used to automatic calculation of\n"
896 "the CAN controller timing. If you want to specify the timing manually,\n"
897 "please use the command cantiming.\n"
898 "The automatic calculation might not work properly for some baudrates. In\n"
899 "this case you should calculate the timing manually and specify it by the\n"
904 " --> canbaudrate2?\n"
905 " canbaudrate2=500000\n"
907 " --> canbaudrate2:100000\n",
908 CMD_HANDLER(cmd_do_can_change_baudrate), (void *)&cmd_list_can
911 cmd_des_t const cmd_des_can_timing = {
912 0, CDESM_OPCHR|CDESM_RW,
913 "cantiming#", "Change timing of CAN controller manually",
914 "### Command syntax ###\n"
916 " cantiming<CONTROLLER>?\n"
917 " cantiming<CONTROLLER>:<BRP> <PROP_SEG> <PHASE_SEG1> <PHASE_SEG2> <SJW>\n"
920 " - `<CONTROLLER>` is number in range 1-3\n"
921 " - `<BRP>` (baudrate prescaler) is number in range 1-65\n"
922 " - `<PROP_SEG>` (length of propagation segment in tQ) is a number in range 1-8\n"
923 " - `<PHASE_SEG1>` (phase buffer segment 1 in tQ) is a number in range 1-8\n"
924 " - `<PHASE_SEG2>` (phase buffer segment 2 in tQ) is a number in range 1-8\n"
925 " - `<SJW>` (synchronization jump width in tQ) is a number in range 1-4\n"
927 "### Description ###\n"
929 "This command is used to set or show the timing of a CAN controller.\n"
930 "The timing shown is the one which will be used by next invocation of\n"
931 "the caninit command.\n"
932 "The timing configured by this command defines manually the baudrate of\n"
933 "the CAN controller. If you want to calculate the timing automaticaly from\n"
934 "a baudrate, please use the command canbaudrate.\n"
941 " phase_seg1: 5 tQ\n"
942 " phase_seg2: 5 tQ\n"
944 " sample_pt: 875 ns\n"
948 " --> cantiming2:5 8 7 4 1\n",
949 CMD_HANDLER(cmd_do_can_change_timing), (void *)&cmd_list_can
953 cmd_des_t const cmd_des_can_send = {
955 "cansend", "Test sending message over CAN",
956 "### Command syntax ###\n"
958 " cansend <CONTROLLER> <ID> <DATA>\n"
960 "where `<CONTROLLER>` is number in range 1-3, `<ID>` is a valid CAN ID\n"
961 "and `<DATA>` is 0-8 bytes of data in hexadecimal representation.\n"
962 "There may be any number of spaces between the data bytes.\n"
963 "`<ID>` may be given in octal, decimal or hexadecimal base.\n"
965 "### Description ###\n"
967 "This command sends a CAN frame using specified CAN controller.\n"
969 "The caninit command must be called before using this command.\n"
972 " --> cansend 2 0x123 DEAD BEEF\n"
973 " Sent: can2 123 [4] DE AD BE EF\n",
974 CMD_HANDLER(cmd_do_can_send), (void *)&cmd_list_can
978 cmd_des_t const cmd_des_can_dump = {
980 "candump", "Dump all messages received over CAN",
981 "### Command syntax ###\n"
983 " candump <CONTROLLER>\n"
985 "where `<CONTROLLER>` is a number in range 1-3.\n"
987 "### Description ###\n"
989 "This command prints out all CAN messages received via the specified\n"
992 "IDs are zero-filled to length 3 if a message in the standard frame\n"
993 "format is received and to 8 for extended frame format messages.\n"
995 "`caninit` must be called before using this command.\n"
1000 " can2 0000FADE [2] 12 34\n",
1001 CMD_HANDLER(cmd_do_can_dump), (void *)&cmd_list_can
1004 cmd_des_t const cmd_des_can_test={
1006 "canrpptest", "Test the CAN functions from the RPP library",
1007 "### Command syntax ###\n"
1011 "### Description ###\n"
1013 "This command tests all CAN functions in the RPP library. It requires\n"
1014 "the CAN1 and CAN2 connectors to be connected with HW loopback. The\n"
1015 "following tests are performed:\n"
1017 "1. Test of `rpp_can_init()`, `rpp_can_write()` and `rpp_can_read()` functions.\n"
1019 " At the beginning, the CAN bus is initialized with hardcoded (and\n"
1020 " verified) verified CAN bit timing parameters. Then a message is\n"
1021 " sent to the CAN1 interface and received from CAN2. The received\n"
1022 " message is compared with the sent one. If the transmissions fails,\n"
1023 " reception exceeds a timeout or the sent and received messages\n"
1024 " differ, the command prints an appropriate error code.\n"
1026 "2. Test of CAN bit timing parameters calculation.\n"
1028 " This test subsequently initializes the CAN controller to baudrates\n"
1029 " 125k, 250k and 500k. For each one of them a message is sent to\n"
1030 " CAN1 and received from CAN2. The received message is compared with\n"
1031 " the sent one like in test 1. If the initialization, transmission,\n"
1032 " reception or comparison fails or if the reception timeout is\n"
1033 " reached, an appropriate error code is printed.\n"
1035 "3. Test of the behavior of transmission request overwriting.\n"
1037 " The CAN controller is initialized as in test 1. A transmission\n"
1038 " request for message A is made on CAN1 by calling `rpp_can_write()`.\n"
1039 " Right after that another transmission request for message B is\n"
1040 " made on CAN1 by another call to `rpp_can_write()`. A message B is\n"
1041 " received on CAN2, because the second request came so quickly, that\n"
1042 " it overwrote message A in the TX buffer. The sent and received\n"
1043 " messages are compared to verify that the behavior was correct.\n"
1045 " If the initialization, transmission, reception or comparison fails\n"
1046 " or if the reception timeout is reached, an appropriate error code\n"
1049 "4. Test of the TX request pending flag detection.\n"
1051 " The CAN bus is initialized like in test 1. A message is\n"
1052 " transmitted on CAN1 and the test waits for the TX pending flag to\n"
1053 " be set, which signalizes that there is a message transmission\n"
1054 " request pending. After the flag has been set, the test waits for\n"
1055 " its clearance, which means that the message has been sent. The\n"
1056 " test measures, how many flag test cycles passed, until the flag\n"
1057 " has been cleared. This value is then presented as time. At the\n"
1058 " end, the message is received from CAN2 and it is compared with the\n"
1059 " sent message for verification.\n"
1061 " If the initialization, transmission, reception or comparison fails or if\n"
1062 " timeout is reached while waiting for the flag set/clear or receive timeout\n"
1063 " is reached, an appropriate error code is printed.\n"
1065 "5. Test of the message received (RX) indication.\n"
1067 " The CAN bus is initialized like in test 1. A message is\n"
1068 " transmitted on CAN1. The test then waits for the RX indication to\n"
1069 " be set, which indicates that a message has been received. The\n"
1070 " message is picked up by calling `rpp_can_read()`. This should\n"
1071 " clear the indicator, which is tested. Finally the received\n"
1072 " messages is compared with the sent one.\n"
1074 " If the initialization, transmission, reception, message comparison or indicator\n"
1075 " test fails or if timeout is reached while waiting for the flag set, the\n"
1076 " appropriate error code is printed.\n"
1078 "At the end the CAN bus is reset and left with the configuration from\n"
1081 "The command can be called even after the CAN bus has been already\n"
1082 "configured by previous invocation of the `caninit` command. The\n"
1083 "previous timing configuration set by `cantiming#` command not\n"
1084 "modified. Therefore, calling `caninit` after this command finishes\n"
1085 "restores the previous timing settings.\n"
1087 "For error codes description please refer to the API documentation for\n"
1088 "the rpp-test-sw.\n"
1093 " This is a test for RPP CAN library functions:\n"
1094 " Test of simple message transmission and reception.\n"
1095 " CAN bus Initialization...OK\n"
1096 " Transmission and reception...OK\n"
1098 " Test of automatic CAN bit timing calculation.\n"
1099 " Baudrate: 125000: OK\n"
1100 " Baudrate: 250000: OK\n"
1101 " Baudrate: 500000: OK\n"
1103 " Test of transmission request rewritting.\n"
1104 " CAN bus Initialization...OK\n"
1105 " TX request rewritting...OK\n"
1107 " Test of TX request pending flag detection.\n"
1108 " CAN bus Initialization...OK\n"
1109 " TX request pending flag behavioral: OK, time: 256 cycles.\n"
1111 " Test of RX indicator.\n"
1112 " CAN bus Initialization...OK\n"
1113 " RX indicator behavioral:\n"
1114 " OK, time: 0 cycles.\n"
1116 " Reset the CAN bus.\n"
1117 " CAN bus Initialization...OK\n",
1118 CMD_HANDLER(cmd_do_can_test_functions), (void *)&cmd_list_can
1124 cmd_des_t const *cmd_list_can[] = {
1126 &cmd_des_can_baudrate,
1127 &cmd_des_can_timing,