]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blob - rpp/lib/cmdproc/src/commands/cmd_lin.c
Exclude docgen.c from CCS build
[pes-rpp/rpp-test-sw.git] / rpp / lib / cmdproc / src / 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 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.
13  *
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.
18  *
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/>.
21  *
22  * File : cmd_lin.c
23  *
24  * Abstract:
25  *      This file contains commands for LIN control.
26  *
27  */
28
29
30 #include "commands/cmd_lin.h"
31
32 #ifndef DOCGEN
33
34 #include "rpp/rpp.h"
35 #include "sys/sys.h"
36 #include "hal/hal.h"
37
38 /** Semaphore used to stop command, until message is received */
39 xSemaphoreHandle linMsgReceived;
40 /** Semaphore used to stop command, until ID is received */
41 xSemaphoreHandle linIDReceived;
42
43 /**
44  *      @brief  Function called by LIN ISR
45  *      Gives semaphores according the type of interrupt
46  *
47  *      @param[in] lin  Pointer to LIN registers
48  *      @param[in] flags        Type of interrupt
49  */
50 void linNotification(linBASE_t *lin, uint32_t flags)
51 {
52                 if (flags & LIN_ID_INT) {
53                         xSemaphoreGiveFromISR(linIDReceived, NULL);
54                 }
55                 if (flags & LIN_RX_INT) {
56                         lin->FLR |= (1 << 9);
57                         xSemaphoreGiveFromISR(linMsgReceived, NULL);
58                 }
59 }
60
61 /**     @brief Command for testing LIN loopback
62  *
63  *      Command sends short data chunk and counts errors when receiving through loopback.
64  *
65  * @param[in]   cmd_io  Pointer to IO functions
66  * @param[in]   cmd_des Pointer to command descriptor
67  * @param[in]   param   Pointer to an array of parameters
68  *
69  * @return
70  */
71 int cmd_do_lin_loop_back(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
72         uint8_t txData[8] = {'L', 'I', 'N', ' ', 'T', 'E', 'S', 'T'};
73         uint8_t rxData[8];
74         uint8_t txID = 0xAC;
75         uint8_t rxID = 0;
76
77         linEnableLoopback(linREG, Digital);
78         hal_gpio_pin_set_value(PIN_DSC_LIN1NSLP, 1);
79         linIDReceived = xSemaphoreCreateCounting(1, 0);
80         linMsgReceived = xSemaphoreCreateCounting(1, 0);
81
82         linSetLength(linREG, 8);
83         linSendHeader(linREG, txID);
84         while(!linIsTxReady(linREG)) ;
85         xSemaphoreTake(linIDReceived, portMAX_DELAY);
86         rxID = linGetIdentifier(linREG);
87         if (rxID == txID) {
88                 linSend(linREG, txData);
89                 while(!linIsTxReady(linREG)) ;
90                 xSemaphoreTake(linMsgReceived, portMAX_DELAY);
91                 linGetData(linREG, rxData);
92                 uint8_t errCnt = 0;
93                 uint8_t i;
94                 for (i = 0; i < 8; i++) {
95                         if (txData[i] != rxData[i]) errCnt++;
96                 }
97
98                 if (!errCnt) {
99                         rpp_sci_printf("OK");
100                 }
101                 else {
102                         rpp_sci_printf("Transmission errors: %d\r\n", errCnt);
103                 }
104         }
105         else {
106                 rpp_sci_printf("FAILED: Sent and Received ID does not match.");
107         }
108         vSemaphoreDelete(linIDReceived);
109         vSemaphoreDelete(linMsgReceived);
110         hal_gpio_pin_set_value(PIN_DSC_LIN1NSLP, 0);
111         return 0;
112 }
113
114 #endif  /* DOCGEN */
115
116 /** Descriptor of command for lin loopback test */
117 cmd_des_t const cmd_des_lin_loop_back={
118     0, 0,
119     "testlin","Test digital loopback on LIN",
120     "=== Description ===\n"
121     "\n"
122     "This command can be used for testing LIN. Command starts sending short\n"
123     "message on LIN port and is testing if it is correctly received through\n"
124     "internal loopback.\n"
125     "\n"
126     "=== Command syntax ===\n"
127     "\n"
128     "   --> testlin\n",
129     CMD_HANDLER(cmd_do_lin_loop_back), (void *)&cmd_list_lin
130 };
131
132 /** List of commands for lin, defined as external */
133 cmd_des_t const *cmd_list_lin[]={
134   &cmd_des_lin_loop_back,
135   NULL
136 };