]> rtime.felk.cvut.cz Git - rpp-test-sw.git/blob - rpp-test-sw/commands/cmd_lin.c
661b62e29239db862c98362d242566f68a1417bf
[rpp-test-sw.git] / rpp-test-sw / commands / cmd_lin.c
1 /*
2  * Copyright (C) 2012-2013, 2015 Czech Technical University in Prague
3  *
4  * Created on: 28.2.2013
5  *
6  * Authors:
7  *     - Michal Horn
8  *
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.
13  *
14  * File : cmd_lin.c
15  *
16  * Abstract:
17  *      This file contains commands for LIN control.
18  *
19  */
20
21
22 #include "cmd_lin.h"
23
24 #ifndef DOCGEN
25
26 #include "rpp/rpp.h"
27 #include "sys/sys.h"
28
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;
33
34 /**     @brief Command for testing LIN loopback
35  *
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
39  *
40  * @return
41  */
42 int cmd_do_lin_loop_back(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
43 {
44         uint8_t txData[8] = {'L', 'I', 'N', ' ', 'T', 'E', 'S', 'T'};
45         uint8_t rxData[8];
46         uint8_t txID = 0xAC;
47         uint8_t rxID = 0;
48
49         linEnableLoopback(linREG, Digital);
50         rpp_gio_set(PIN_LIN1NSLP, 1);
51         linIDReceived = xSemaphoreCreateCounting(1, 0);
52         linMsgReceived = xSemaphoreCreateCounting(1, 0);
53
54         linSetLength(linREG, 8);
55         linSendHeader(linREG, txID);
56         while (!linIsTxReady(linREG)) ;
57         xSemaphoreTake(linIDReceived, portMAX_DELAY);
58         rxID = linGetIdentifier(linREG);
59         if (rxID == txID) {
60                 linSend(linREG, txData);
61                 while (!linIsTxReady(linREG)) ;
62                 xSemaphoreTake(linMsgReceived, portMAX_DELAY);
63                 linGetData(linREG, rxData);
64                 uint8_t errCnt = 0;
65                 uint8_t i;
66                 for (i = 0; i < 8; i++) {
67                         if (txData[i] != rxData[i]) errCnt++;
68                 }
69
70                 if (!errCnt)
71                         rpp_sci_printf("OK");
72                 else
73                         rpp_sci_printf("Transmission errors: %d\r\n", errCnt);
74         }
75         else
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);
80         return 0;
81 }
82
83 #endif  /* DOCGEN */
84
85 /** Descriptor of command for lin loopback test */
86 cmd_des_t const cmd_des_lin_loop_back = {
87         0, 0,
88         "lintest","Test the digital loopback on LIN",
89         "### Command syntax ###\n"
90         "\n"
91         "    lintest\n"
92         "\n"
93         "### Description ###\n"
94         "\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
99 };
100
101 /** List of commands for lin, defined as external */
102 cmd_des_t const *cmd_list_lin[] = {
103         &cmd_des_lin_loop_back,
104         NULL
105 };