/*
- * Copyright (C) 2012-2013 Czech Technical University in Prague
+ * Copyright (C) 2012-2014 Czech Technical University in Prague
*
* Created on: 28.2.2013
*
* Authors:
* - Michal Horn
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * This document contains proprietary information belonging to Czech
+ * Technical University in Prague. Passing on and copying of this
+ * document, and communication of its contents is not permitted
+ * without prior written authorization.
*
* File : cmd_can.c
*
return 1;
}
+ if (controller_id < 1 || controller_id > 3) {
+ rpp_sci_printf("Invalid controller ID\n");
+ return -CMDERR_NODEV;
+ }
+
rpp_can_init(&can_config);
while (cmd_io->getc(cmd_io) < 0) {
"\n"
"### Example ###\n"
" --> caninit\n",
- CMD_HANDLER(cmd_do_can_init), (void*)&cmd_list_can
+ CMD_HANDLER(cmd_do_can_init), (void *)&cmd_list_can
};
cmd_des_t const cmd_des_can_baudrate = {
" canbaudrate2=500000\n"
"\n"
" --> canbaudrate2:100000\n",
- CMD_HANDLER(cmd_do_can_change_baudrate), (void*)&cmd_list_can
+ CMD_HANDLER(cmd_do_can_change_baudrate), (void *)&cmd_list_can
};
cmd_des_t const cmd_des_can_timing = {
" tQ: 125 ns\n"
"\n"
" --> cantiming2:5 8 7 4 1\n",
- CMD_HANDLER(cmd_do_can_change_timing), (void*)&cmd_list_can
+ CMD_HANDLER(cmd_do_can_change_timing), (void *)&cmd_list_can
};
"### Example ###\n"
" --> cansend 2 0x123 DEAD BEEF\n"
" Sent: can2 123 [4] DE AD BE EF\n",
- CMD_HANDLER(cmd_do_can_send), (void*)&cmd_list_can
+ CMD_HANDLER(cmd_do_can_send), (void *)&cmd_list_can
};
"IDs are zero-filled to length 3 if a message in the standard frame\n"
"format is received and to 8 for extended frame format messages.\n"
"\n"
- "caninit must be called before using this command.\n"
+ "`caninit` must be called before using this command.\n"
"\n"
"### Example ###\n"
"\n"
" --> candump 2\n"
- "can2 0000FADE [2] 12 34\n",
- CMD_HANDLER(cmd_do_can_dump), (void*)&cmd_list_can
+ " can2 0000FADE [2] 12 34\n",
+ CMD_HANDLER(cmd_do_can_dump), (void *)&cmd_list_can
};
-cmd_des_t const cmd_des_can_test = {
- 0, 0,
- "canrpptest", "Test the CAN functions from the RPP library",
- "### Command syntax ###\n"
- "\n"
- " canrpptest\n"
- "\n"
- "### Description ###\n"
- "\n"
- "This command tests all CAN functions in the RPP library. It does those\n"
- "particular tests:\n"
- "\n"
- "1) Test of the rpp_can_init(), rpp_can_write() and rpp_can_read() functions.\n"
- " At the beginning, the CAN bus is initialized with manually specified and\n"
- " verified CAN bit timing parameters. Then a message is sent on the CAN1 and is\n"
- " received on the CAN2. Finally the received message is compared with the sent one.\n"
- " If the transmissions fails, reception exceeds a timeout or the sent and\n"
- " received messages do not match, the command prints the appropriate error\n"
- " code."
- "2) Test of the CAN bit timing parameters calculation.\n"
- " This test subsequently initializes the CAN bus to a baudrates 125k, 250k\n"
- " and 500k. For each one of them a message is sent on CAN1 and received on CAN2.\n"
- " Finally the received message is compared with the sent one like in a test (1).\n"
- " If the initialization, transmission, reception or comparison fails or\n"
- " if the reception timeout is reached, an appropriate error code is printed.\n"
- "3) Test of the behavior of transmission request overwriting.\n"
- " The CAN bus is initialized like in the test (1). A message A transmission\n"
- " request is posted on CAN1 by calling rpp_can_write() and right after that\n"
- " another message B transmission request is posted on CAN1 by another call of\n"
- " the rpp_can_write(). A message B is received on CAN2, because the second request\n"
- " came so quickly, that it overwrote the first one. The sent and received messages\n"
- " are compared to verify that the transmission was correct.\n"
- " If the initialization, transmission, reception or comparison fails or\n"
- " if the reception timeout is reached, an appropriate error code is printed.\n"
- "4) Test of the TX request pending flag detection.\n"
- " The CAN bus is initialized like in the test (1). A message is transmitted\n"
- " on the CAN1 and the test waits for the TX pending flag to be set, which\n"
- " signalizes that there is a message transmission request pending. After the\n"
- " flag has been set, the test waits for its clearance, which means that the\n"
- " message has been sent. The test measures, how many flag test cycles passed,\n"
- " until the flag has been cleared. This value is then presented as a time.\n"
- " At the end, the message is received on the CAN2 and is compared with the\n"
- " sent message for verification.\n"
- " If the initialization, transmission, reception or comparison fails or if\n"
- " timeout is reached while waiting for the flag set/clear or receive timeout\n"
- " is reached, an appropriate error code is printed.\n"
- "5) Test of the message received (RX) indicator.\n"
- " The CAN bus is initialized like in the test (1). A message is transmitted\n"
- " on the CAN1. The test then waits for the RX indicator to be set, which\n"
- " indicates that a message has been received. The message is picked up by\n"
- " the rpp_can_read(). This should clear the indicator, which is tested. Finally\n"
- " the received messages is compared with the sent one.\n"
- " If the initialization, transmission, reception, message comparison or indicator\n"
- " test fails or if timeout is reached while waiting for the flag set, the\n"
- " appropriate error code is printed.\n"
- "\n"
- "At the end the CAN bus is reset and left with the configuration from test (1).\n"
- "Those tests assumes the CAN1 and CAN2 to be connected in HW loopback.\n"
- "Any previous configuration is canceled, but is not deleted, so any following\n"
- "call of caninit command will restore the CAN bus to previous configuration.\n"
- "\n"
- "For error codes description refer please the API documentation for the rpp-test-sw.\n"
- "\n"
- "### Example ###\n"
- "\n"
- " --> canrpptest\n"
- "This is a test for RPP CAN library functions:"
- "Test of simple message transmission and reception."
- " CAN bus Initialization...OK"
- " Transmission and reception...OK"
- "---"
- "Test od automatic CAN bit timing calculation."
- " Baudrate: 125000: OK"
- " Baudrate: 250000: OK"
- " Baudrate: 500000: OK"
- "---"
- "Test of transmission request rewritting."
- " CAN bus Initialization...OK"
- " TX request rewritting...OK"
- "---"
- "Test of TX request pending flag detection."
- " CAN bus Initialization...OK"
- " TX request pending flag behavioral: OK, time: 256 cycles."
- "---"
- "Test of RX indicator."
- " CAN bus Initialization...OK"
- " RX indicator behavioral:"
- "OK, time: 0 cycles."
- "---"
- "Reset the CAN bus."
- " CAN bus Initialization...OK",
- CMD_HANDLER(cmd_do_can_test_functions), (void*)&cmd_list_can
+cmd_des_t const cmd_des_can_test={
+ 0, 0,
+ "canrpptest", "Test the CAN functions from the RPP library",
+ "### Command syntax ###\n"
+ "\n"
+ " canrpptest\n"
+ "\n"
+ "### Description ###\n"
+ "\n"
+ "This command tests all CAN functions in the RPP library. It requires\n"
+ "the CAN1 and CAN2 connectors to be connected with HW loopback. The\n"
+ "following tests are performed:\n"
+ "\n"
+ "1. Test of `rpp_can_init()`, `rpp_can_write()` and `rpp_can_read()` functions.\n"
+ "\n"
+ " At the beginning, the CAN bus is initialized with hardcoded (and\n"
+ " verified) verified CAN bit timing parameters. Then a message is\n"
+ " sent to the CAN1 interface and received from CAN2. The received\n"
+ " message is compared with the sent one. If the transmissions fails,\n"
+ " reception exceeds a timeout or the sent and received messages\n"
+ " differ, the command prints an appropriate error code.\n"
+ "\n"
+ "2. Test of CAN bit timing parameters calculation.\n"
+ "\n"
+ " This test subsequently initializes the CAN controller to baudrates\n"
+ " 125k, 250k and 500k. For each one of them a message is sent to\n"
+ " CAN1 and received from CAN2. The received message is compared with\n"
+ " the sent one like in test 1. If the initialization, transmission,\n"
+ " reception or comparison fails or if the reception timeout is\n"
+ " reached, an appropriate error code is printed.\n"
+ "\n"
+ "3. Test of the behavior of transmission request overwriting.\n"
+ "\n"
+ " The CAN controller is initialized as in test 1. A transmission\n"
+ " request for message A is made on CAN1 by calling `rpp_can_write()`.\n"
+ " Right after that another transmission request for message B is\n"
+ " made on CAN1 by another call to `rpp_can_write()`. A message B is\n"
+ " received on CAN2, because the second request came so quickly, that\n"
+ " it overwrote message A in the TX buffer. The sent and received\n"
+ " messages are compared to verify that the behavior was correct.\n"
+ "\n"
+ " If the initialization, transmission, reception or comparison fails\n"
+ " or if the reception timeout is reached, an appropriate error code\n"
+ " is printed.\n"
+ "\n"
+ "4. Test of the TX request pending flag detection.\n"
+ "\n"
+ " The CAN bus is initialized like in test 1. A message is\n"
+ " transmitted on CAN1 and the test waits for the TX pending flag to\n"
+ " be set, which signalizes that there is a message transmission\n"
+ " request pending. After the flag has been set, the test waits for\n"
+ " its clearance, which means that the message has been sent. The\n"
+ " test measures, how many flag test cycles passed, until the flag\n"
+ " has been cleared. This value is then presented as time. At the\n"
+ " end, the message is received from CAN2 and it is compared with the\n"
+ " sent message for verification.\n"
+ "\n"
+ " If the initialization, transmission, reception or comparison fails or if\n"
+ " timeout is reached while waiting for the flag set/clear or receive timeout\n"
+ " is reached, an appropriate error code is printed.\n"
+ "\n"
+ "5. Test of the message received (RX) indication.\n"
+ "\n"
+ " The CAN bus is initialized like in test 1. A message is\n"
+ " transmitted on CAN1. The test then waits for the RX indication to\n"
+ " be set, which indicates that a message has been received. The\n"
+ " message is picked up by calling `rpp_can_read()`. This should\n"
+ " clear the indicator, which is tested. Finally the received\n"
+ " messages is compared with the sent one.\n"
+ "\n"
+ " If the initialization, transmission, reception, message comparison or indicator\n"
+ " test fails or if timeout is reached while waiting for the flag set, the\n"
+ " appropriate error code is printed.\n"
+ "\n"
+ "At the end the CAN bus is reset and left with the configuration from\n"
+ "test 1.\n"
+ "\n"
+ "The command can be called even after the CAN bus has been already\n"
+ "configured by previous invocation of the `caninit` command. The\n"
+ "previous timing configuration set by `cantiming#` command not\n"
+ "modified. Therefore, calling `caninit` after this command finishes\n"
+ "restores the previous timing settings.\n"
+ "\n"
+ "For error codes description please refer to the API documentation for\n"
+ "the rpp-test-sw.\n"
+ "\n"
+ "### Example ###\n"
+ "\n"
+ " --> canrpptest\n"
+ " This is a test for RPP CAN library functions:\n"
+ " Test of simple message transmission and reception.\n"
+ " CAN bus Initialization...OK\n"
+ " Transmission and reception...OK\n"
+ " ---\n"
+ " Test of automatic CAN bit timing calculation.\n"
+ " Baudrate: 125000: OK\n"
+ " Baudrate: 250000: OK\n"
+ " Baudrate: 500000: OK\n"
+ " ---\n"
+ " Test of transmission request rewritting.\n"
+ " CAN bus Initialization...OK\n"
+ " TX request rewritting...OK\n"
+ " ---\n"
+ " Test of TX request pending flag detection.\n"
+ " CAN bus Initialization...OK\n"
+ " TX request pending flag behavioral: OK, time: 256 cycles.\n"
+ " ---\n"
+ " Test of RX indicator.\n"
+ " CAN bus Initialization...OK\n"
+ " RX indicator behavioral:\n"
+ " OK, time: 0 cycles.\n"
+ " ---\n"
+ " Reset the CAN bus.\n"
+ " CAN bus Initialization...OK\n",
+ CMD_HANDLER(cmd_do_can_test_functions), (void *)&cmd_list_can
};