]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blob - rpp-test-sw/commands/cmd_lin.c
602ad7569ee60eb906bfd232fe0c50483f0d01ad
[pes-rpp/rpp-test-sw.git] / rpp-test-sw / commands / cmd_lin.c
1 /*
2  * Copyright (C) 2012-2013 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 #include "hal/hal.h"
29
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;
34
35 /**     @brief Command for testing LIN loopback
36  *
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
40  *
41  * @return
42  */
43 int cmd_do_lin_loop_back(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
44 {
45         uint8_t txData[8] = {'L', 'I', 'N', ' ', 'T', 'E', 'S', 'T'};
46         uint8_t rxData[8];
47         uint8_t txID = 0xAC;
48         uint8_t rxID = 0;
49
50         linEnableLoopback(linREG, Digital);
51         hal_gpio_pin_set_value(PIN_DSC_LIN1NSLP, 1);
52         linIDReceived = xSemaphoreCreateCounting(1, 0);
53         linMsgReceived = xSemaphoreCreateCounting(1, 0);
54
55         linSetLength(linREG, 8);
56         linSendHeader(linREG, txID);
57         while (!linIsTxReady(linREG)) ;
58         xSemaphoreTake(linIDReceived, portMAX_DELAY);
59         rxID = linGetIdentifier(linREG);
60         if (rxID == txID) {
61                 linSend(linREG, txData);
62                 while (!linIsTxReady(linREG)) ;
63                 xSemaphoreTake(linMsgReceived, portMAX_DELAY);
64                 linGetData(linREG, rxData);
65                 uint8_t errCnt = 0;
66                 uint8_t i;
67                 for (i = 0; i < 8; i++) {
68                         if (txData[i] != rxData[i]) errCnt++;
69                 }
70
71                 if (!errCnt)
72                         rpp_sci_printf("OK");
73                 else
74                         rpp_sci_printf("Transmission errors: %d\r\n", errCnt);
75         }
76         else
77                 rpp_sci_printf("FAILED: Sent and Received ID does not match.");
78         vSemaphoreDelete(linIDReceived);
79         vSemaphoreDelete(linMsgReceived);
80         hal_gpio_pin_set_value(PIN_DSC_LIN1NSLP, 0);
81         return 0;
82 }
83
84 #endif  /* DOCGEN */
85
86 /** Descriptor of command for lin loopback test */
87 cmd_des_t const cmd_des_lin_loop_back = {
88         0, 0,
89         "lintest","Test the digital loopback on LIN",
90         "### Command syntax ###\n"
91         "\n"
92         "    lintest\n"
93         "\n"
94         "### Description ###\n"
95         "\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
100 };
101
102 /** List of commands for lin, defined as external */
103 cmd_des_t const *cmd_list_lin[] = {
104         &cmd_des_lin_loop_back,
105         NULL
106 };