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