--- /dev/null
+/*
+ * Copyright (C) 2012-2013 Czech Technical University in Prague
+ *
+ * Created on: 28.2.2013
+ *
+ * Authors:
+ * - Michal Horn
+ *
+ * This document contains proprietary information belonging to Czech
+ * Technical University in Prague. Passing on and copying of this
+ * document, and communication of its contents is not permitted
+ * without prior written authorization.
+ *
+ * File : cmd_lin.c
+ *
+ * Abstract:
+ * This file contains commands for LIN control.
+ *
+ */
+
+
+#include "cmd_lin.h"
+
+#ifndef DOCGEN
+
+#include "rpp/rpp.h"
+#include "sys/sys.h"
+#include "hal/hal.h"
+
+/** Semaphore used to stop command, until message is received */
+extern xSemaphoreHandle linMsgReceived;
+/** Semaphore used to stop command, until ID is received */
+extern xSemaphoreHandle linIDReceived;
+
+/** @brief Command for testing LIN loopback
+ *
+ * @param[in] cmd_io Pointer to IO functions
+ * @param[in] cmd_des Pointer to command descriptor
+ * @param[in] param Pointer to an array of parameters
+ *
+ * @return
+ */
+int cmd_do_lin_loop_back(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+ uint8_t txData[8] = {'L', 'I', 'N', ' ', 'T', 'E', 'S', 'T'};
+ uint8_t rxData[8];
+ uint8_t txID = 0xAC;
+ uint8_t rxID = 0;
+
+ linEnableLoopback(linREG, Digital);
+ hal_gpio_pin_set_value(PIN_DSC_LIN1NSLP, 1);
+ linIDReceived = xSemaphoreCreateCounting(1, 0);
+ linMsgReceived = xSemaphoreCreateCounting(1, 0);
+
+ linSetLength(linREG, 8);
+ linSendHeader(linREG, txID);
+ while (!linIsTxReady(linREG)) ;
+ xSemaphoreTake(linIDReceived, portMAX_DELAY);
+ rxID = linGetIdentifier(linREG);
+ if (rxID == txID) {
+ linSend(linREG, txData);
+ while (!linIsTxReady(linREG)) ;
+ xSemaphoreTake(linMsgReceived, portMAX_DELAY);
+ linGetData(linREG, rxData);
+ uint8_t errCnt = 0;
+ uint8_t i;
+ for (i = 0; i < 8; i++) {
+ if (txData[i] != rxData[i]) errCnt++;
+ }
+
+ if (!errCnt)
+ rpp_sci_printf("OK");
+ else
+ rpp_sci_printf("Transmission errors: %d\r\n", errCnt);
+ }
+ else
+ rpp_sci_printf("FAILED: Sent and Received ID does not match.");
+ vSemaphoreDelete(linIDReceived);
+ vSemaphoreDelete(linMsgReceived);
+ hal_gpio_pin_set_value(PIN_DSC_LIN1NSLP, 0);
+ return 0;
+}
+
+#endif /* DOCGEN */
+
+/** Descriptor of command for lin loopback test */
+cmd_des_t const cmd_des_lin_loop_back = {
+ 0, 0,
+ "lintest","Test the digital loopback on LIN",
+ "### Command syntax ###\n"
+ "\n"
+ " lintest\n"
+ "\n"
+ "### Description ###\n"
+ "\n"
+ "This command can be used for testing the LIN. The command starts to\n"
+ "send a short message on the LIN port and is testing if it is correctly\n"
+ "received via an internal loopback.\n",
+ CMD_HANDLER(cmd_do_lin_loop_back), (void *)&cmd_list_lin
+};
+
+/** List of commands for lin, defined as external */
+cmd_des_t const *cmd_list_lin[] = {
+ &cmd_des_lin_loop_back,
+ NULL
+};