2 * Copyright (C) 2012-2013 Czech Technical University in Prague
4 * Created on: 28.2.2013
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * This file contains commands for LIN control.
38 /** Semaphore used to stop command, until message is received */
39 extern xSemaphoreHandle linMsgReceived;
40 /** Semaphore used to stop command, until ID is received */
41 extern xSemaphoreHandle linIDReceived;
43 /** @brief Command for testing LIN loopback
45 * @param[in] cmd_io Pointer to IO functions
46 * @param[in] cmd_des Pointer to command descriptor
47 * @param[in] param Pointer to an array of parameters
51 int cmd_do_lin_loop_back(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
52 uint8_t txData[8] = {'L', 'I', 'N', ' ', 'T', 'E', 'S', 'T'};
57 linEnableLoopback(linREG, Digital);
58 hal_gpio_pin_set_value(PIN_DSC_LIN1NSLP, 1);
59 linIDReceived = xSemaphoreCreateCounting(1, 0);
60 linMsgReceived = xSemaphoreCreateCounting(1, 0);
62 linSetLength(linREG, 8);
63 linSendHeader(linREG, txID);
64 while(!linIsTxReady(linREG)) ;
65 xSemaphoreTake(linIDReceived, portMAX_DELAY);
66 rxID = linGetIdentifier(linREG);
68 linSend(linREG, txData);
69 while(!linIsTxReady(linREG)) ;
70 xSemaphoreTake(linMsgReceived, portMAX_DELAY);
71 linGetData(linREG, rxData);
74 for (i = 0; i < 8; i++) {
75 if (txData[i] != rxData[i]) errCnt++;
82 rpp_sci_printf("Transmission errors: %d\r\n", errCnt);
86 rpp_sci_printf("FAILED: Sent and Received ID does not match.");
88 vSemaphoreDelete(linIDReceived);
89 vSemaphoreDelete(linMsgReceived);
90 hal_gpio_pin_set_value(PIN_DSC_LIN1NSLP, 0);
96 /** Descriptor of command for lin loopback test */
97 cmd_des_t const cmd_des_lin_loop_back={
99 "lintest","Test the digital loopback on LIN",
100 "=== Command syntax ===\n"
104 "=== Description ===\n"
106 "This command can be used for testing the LIN. The command starts to\n"
107 "send a short message on the LIN port and is testing if it is correctly\n"
108 "received via an internal loopback.\n",
109 CMD_HANDLER(cmd_do_lin_loop_back), (void *)&cmd_list_lin
112 /** List of commands for lin, defined as external */
113 cmd_des_t const *cmd_list_lin[]={
114 &cmd_des_lin_loop_back,