2 * Copyright (C) 2012-2013, 2015 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 LIN control.
29 /** Semaphore used to stop command, until message is received */
30 extern xSemaphoreHandle linMsgReceived;
31 /** Semaphore used to stop command, until ID is received */
32 extern xSemaphoreHandle linIDReceived;
34 /** @brief Command for testing LIN loopback
36 * @param[in] cmd_io Pointer to IO functions
37 * @param[in] cmd_des Pointer to command descriptor
38 * @param[in] param Pointer to an array of parameters
42 int cmd_do_lin_loop_back(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
44 uint8_t txData[8] = {'L', 'I', 'N', ' ', 'T', 'E', 'S', 'T'};
49 linEnableLoopback(linREG, Digital);
50 rpp_gio_set(PIN_LIN1NSLP, 1);
51 linIDReceived = xSemaphoreCreateCounting(1, 0);
52 linMsgReceived = xSemaphoreCreateCounting(1, 0);
54 linSetLength(linREG, 8);
55 linSendHeader(linREG, txID);
56 while (!linIsTxReady(linREG)) ;
57 xSemaphoreTake(linIDReceived, portMAX_DELAY);
58 rxID = linGetIdentifier(linREG);
60 linSend(linREG, txData);
61 while (!linIsTxReady(linREG)) ;
62 xSemaphoreTake(linMsgReceived, portMAX_DELAY);
63 linGetData(linREG, rxData);
66 for (i = 0; i < 8; i++) {
67 if (txData[i] != rxData[i]) errCnt++;
73 rpp_sci_printf("Transmission errors: %d\r\n", errCnt);
76 rpp_sci_printf("FAILED: Sent and Received ID does not match.");
77 vSemaphoreDelete(linIDReceived);
78 vSemaphoreDelete(linMsgReceived);
79 rpp_gio_set(PIN_LIN1NSLP, 0);
85 /** Descriptor of command for lin loopback test */
86 cmd_des_t const cmd_des_lin_loop_back = {
88 "lintest","Test the digital loopback on LIN",
89 "### Command syntax ###\n"
93 "### Description ###\n"
95 "This command can be used for testing the LIN. The command starts to\n"
96 "send a short message on the LIN port and is testing if it is correctly\n"
97 "received via an internal loopback.\n",
98 CMD_HANDLER(cmd_do_lin_loop_back), (void *)&cmd_list_lin
101 /** List of commands for lin, defined as external */
102 cmd_des_t const *cmd_list_lin[] = {
103 &cmd_des_lin_loop_back,