/*
- * Copyright (C) 2012-2013 Czech Technical University in Prague
+ * Copyright (C) 2012-2013, 2015 Czech Technical University in Prague
*
* Created on: 28.2.2013
*
* Authors:
* - Michal Horn
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * 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_fray.c
*
#ifndef DOCGEN
#include "rpp/rpp.h"
-#include "drv/fray.h"
#include "cmdproc_utils.h"
-#include "hal/hal.h"
+#include "drv/digital_io_def.h"
#include "cmdproc.h"
+#include "spi_resp_transl.h"
/**
* This structure contains global FlexRay configuration.
static Fr_TMS570LS_ClusterConfigType Fr_cluster_config = {
.gColdStartAttempts = 0x2,
.gListenNoise = 0xF,
- .gMacroPerCycle = 0x15E0, // Macrotick = 1us
+ .gMacroPerCycle = 0x15E0, // Macrotick = 1us
.gMaxWithoutClockCorrectionFatal = 0xF,
.gMaxWithoutClockCorrectionPassive = 0xF,
.gNetworkManagementVectorLength = 12,
.gdMinislot = 0x4,
.gdMinislotActionPointOffset = 0x2,
.gdNIT = 0xAE3,
- .gdSampleClockPeriod = 0, // 10mbit/sec
+ .gdSampleClockPeriod = 0, // 10mbit/sec
.gdStaticSlot = 0x56,
.gdTSSTransmitter = 0xA,
.gdWakeupSymbolRxIdle = 18,
.gdWakeupSymbolTxLow = 60
};
+
/**
* This structure contains local configuration of the FlexRay node A.
* That is the node that transmits messages to the node B.
*/
static Fr_TMS570LS_NodeConfigType Fr_node_A_config = {
.pAllowHaltDueToClock = 0,
- .pAllowPassiveToActive = FALSE,
+ .pAllowPassiveToActive = 0xF,
.pChannels = FR_CHANNEL_AB,
.pClusterDriftDamping = 0x1,
.pDelayCompensationA = 0x3,
.pMacroInitialOffsetB = 0x6,
.pMicroInitialOffsetA = 0x18,
.pMicroInitialOffsetB = 0x18,
- .pMicroPerCycle = 0x36B00, // (cycle period, 5.6ms), uT = 25ns@10Mbit/sec, 25ns@5Mbit/sec, 50ns@2.5Mbit/sec
+ .pMicroPerCycle = 0x36B00, // (cycle period, 5.6ms), uT = 25ns@10Mbit/sec, 25ns@5Mbit/sec, 50ns@2.5Mbit/sec
.pRateCorrectionOut = 0xCD,
.pOffsetCorrectionOut = 0x151,
- .pSamplesPerMicrotick = 0, // 10 mbit/sec
+ .pSamplesPerMicrotick = 0, // 10 mbit/sec
.pSingleSlotEnabled = TRUE,
.pWakeupChannel = FR_CHANNEL_A,
.pWakeupPattern = 2,
* That is the node that receives messages from the node A.
*/
static Fr_TMS570LS_NodeConfigType Fr_node_B_config = {
- .pAllowHaltDueToClock = 0,
- .pAllowPassiveToActive = FALSE,
- .pChannels = FR_CHANNEL_AB,
- .pClusterDriftDamping = 0x1,
- .pDelayCompensationA = 0x3,
- .pDelayCompensationB = 0x3,
- .pExternOffsetCorrection = 0,
- .pExternRateCorrection = 0,
- .pKeySlotUsedForStartup = TRUE,
- .pKeySlotUsedForSync = TRUE,
- .pLatestTx = 0x10D,
- .pMacroInitialOffsetA = 0x6,
- .pMacroInitialOffsetB = 0x6,
- .pMicroInitialOffsetA = 0x18,
- .pMicroInitialOffsetB = 0x18,
- .pMicroPerCycle = 0x36B00,
- .pRateCorrectionOut = 0xCD,
- .pOffsetCorrectionOut = 0x151,
- .pSamplesPerMicrotick = 0, // 10 mbit/sec
- .pSingleSlotEnabled = TRUE,
- .pWakeupChannel = FR_CHANNEL_A,
- .pWakeupPattern = 2,
- .pdAcceptedStartupRange = 0x81,
- .pdListenTimeout = 0x36DA2,
- .pdMaxDrift = 0x151,
- .pDecodingCorrection = 0x33
+ .pAllowHaltDueToClock = 0,
+ .pAllowPassiveToActive = 0xF,
+ .pChannels = FR_CHANNEL_AB,
+ .pClusterDriftDamping = 0x1,
+ .pDelayCompensationA = 0x3,
+ .pDelayCompensationB = 0x3,
+ .pExternOffsetCorrection = 0,
+ .pExternRateCorrection = 0,
+ .pKeySlotUsedForStartup = TRUE,
+ .pKeySlotUsedForSync = TRUE,
+ .pLatestTx = 0x10D,
+ .pMacroInitialOffsetA = 0x6,
+ .pMacroInitialOffsetB = 0x6,
+ .pMicroInitialOffsetA = 0x18,
+ .pMicroInitialOffsetB = 0x18,
+ .pMicroPerCycle = 0x36B00,
+ .pRateCorrectionOut = 0xCD,
+ .pOffsetCorrectionOut = 0x151,
+ .pSamplesPerMicrotick = 0, // 10 mbit/sec
+ .pSingleSlotEnabled = TRUE,
+ .pWakeupChannel = FR_CHANNEL_A,
+ .pWakeupPattern = 2,
+ .pdAcceptedStartupRange = 0x81,
+ .pdListenTimeout = 0x36DA2,
+ .pdMaxDrift = 0x151,
+ .pDecodingCorrection = 0x33
};
/**
* single-shot to send only one message after some period.
*/
static Fr_TMS570LS_BufferConfigType Fr_node_A_static_buffers_config[] = {
- {
- .channel = FR_CHANNEL_AB,
- .cycleCounterFiltering = 0,
- .isTx = TRUE,
- .maxPayload = 9,
- .msgBufferInterrupt = TRUE,
- .payloadPreambleIndicatorTr = FALSE,
- .rejectNullFrames = FALSE,
- .rejectStaticSegment = FALSE,
- .singleTransmit = FALSE,
- .slotId = 1
- },
- {
- .channel = FR_CHANNEL_AB,
- .cycleCounterFiltering = 0,
- .isTx = TRUE,
- .maxPayload = 9,
- .msgBufferInterrupt = TRUE,
- .payloadPreambleIndicatorTr = FALSE,
- .rejectNullFrames = FALSE,
- .rejectStaticSegment = FALSE,
- .singleTransmit = TRUE,
- .slotId = 3
- }
+ {
+ .channel = FR_CHANNEL_AB,
+ .cycleCounterFiltering = 0,
+ .isTx = TRUE,
+ .fidMask = 0,
+ .maxPayload = 9,
+ .msgBufferInterrupt = TRUE,
+ .payloadPreambleIndicatorTr = FALSE,
+ .rejectNullFrames = FALSE,
+ .rejectStaticSegment = FALSE,
+ .singleTransmit = FALSE,
+ .slotId = 1
+ },
+ {
+ .channel = FR_CHANNEL_AB,
+ .cycleCounterFiltering = 0,
+ .isTx = TRUE,
+ .fidMask = 0,
+ .maxPayload = 9,
+ .msgBufferInterrupt = TRUE,
+ .payloadPreambleIndicatorTr = FALSE,
+ .rejectNullFrames = FALSE,
+ .rejectStaticSegment = FALSE,
+ .singleTransmit = TRUE,
+ .slotId = 3
+ }
};
/**
.channel = FR_CHANNEL_AB,
.cycleCounterFiltering = 0,
.isTx = TRUE,
+ .fidMask = 0,
.maxPayload = 9,
.msgBufferInterrupt = TRUE,
.payloadPreambleIndicatorTr = FALSE,
.channel = FR_CHANNEL_AB,
.cycleCounterFiltering = 0,
.isTx = FALSE,
+ .fidMask = 0,
.maxPayload = 9,
.msgBufferInterrupt = TRUE,
.payloadPreambleIndicatorTr = FALSE,
};
/**
- * Loads data into TX buffer for FlexRay node A.
- * Set TX Request for the buffer to start the transmission.
+ * Loads data into TX buffer for FlexRay node A.
+ * Set TX Request for the buffer to start the transmission.
*/
-int8_t transmit_node_a() {
+int8_t transmit_node_a()
+{
uint8_t data[18];
int i;
* @return 0 if message was received and is correct
* 1 if message was received and is incorrect
*/
-int check_message(const uint8_t *data) {
+int check_message(const uint8_t *data)
+{
int i;
for (i = 0; i < 18; i++) {
- if (data[i] != i) {
+ if (data[i] != i)
return 1;
- }
}
return 0;
}
/**
- * @brief Get FlexRay status in human readable form
+ * @brief Get FlexRay status in human readable form
*
- * Command sends some data on SPI (data do not matters, chips are read only) and retreives a response.
- * The response is translated and displayed as readable text.
+ * Command sends some data on SPI (data do not matters, chips are read only) and retreives a response.
+ * The response is translated and displayed as readable text.
*
* @param[in] cmd_io Pointer to IO stack
* @param[in] des Pointer to command descriptor
* @param[in] param Parameters of command
* @return 0 when OK or error code
*/
-int cmd_do_fray_status(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+int cmd_do_fray_status(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
char *p;
int pin;
uint32_t numCmdDesc;
int i;
uint32_t numFieldDesc;
- p=param[1];
- if (sscanf(p, "%d", &pin) != 1) {
+ p = param[1];
+ if (sscanf(p, "%d", &pin) != 1)
return -CMDERR_BADPAR;
- }
pin--; // Highlevel command has pin number mapped according the board scheme, this switches to internal representation
if (pin > FRAY_NUM_PORTS || pin < 0) return -CMDERR_BADPAR;
if (Fr_spi_transfer(pin) != 0) return -CMDERR_BADDIO;
spitr_reg_translate_table_t translatedData;
- const spitr_cmd_map_t* cmdDesc = get_spi_cmd_map(PORT_NAME_FRAY1, -1, &numCmdDesc);
- if(cmdDesc == NULL) return -CMDERR_BADREG;
+ const spitr_cmd_map_t *cmdDesc = get_spi_cmd_map(DIO_PORT_NAME_FRAY1, -1, &numCmdDesc);
+ if (cmdDesc == NULL) return -CMDERR_BADREG;
- const spitr_field_desc_t* fieldDescs = get_spi_field_desc(cmdDesc, numCmdDesc, Fr_spi_get_cmd(pin), &numFieldDesc);
+ const spitr_field_desc_t *fieldDescs = get_spi_field_desc(cmdDesc, numCmdDesc, Fr_spi_get_cmd(pin), &numFieldDesc);
if (fieldDescs == NULL)
return -CMDERR_BADPAR;
uint32_t fr_spi_response = Fr_spi_response(pin);
}
/**
- * @brief Start sending data on the FlexRay as node A
+ * @brief Start sending data on the FlexRay as node A
*
* @param[in] cmd_io Pointer to IO stack
* @param[in] des Pointer to command descriptor
* @param[in] param Parameters of command
* @return 0 when OK or error code
*/
-int cmd_do_test_frayA(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+int cmd_do_test_frayA(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
uint32_t i;
uint32_t error = 0;
uint32_t msg_cnt = 0;
if (param[1] && sscanf(param[1], "%d", &count) != 1)
return -CMDERR_BADPAR;
- if (rpp_fr_init_driver(&Fr_config_node_A, &error) == FAILURE) {
+ if (rpp_fr_init_driver(&Fr_config_node_A, &error) == FAILURE) {
rpp_sci_printf("Fray driver initialization failed: %#x.\n", error);
return -CMDERR_BADCFG;
- }
+ }
if (rpp_fr_init_controller(0, &error) == FAILURE) {
rpp_sci_printf("Fray control node initialization failed: %#x.\n", error);
return -CMDERR_BADCFG;
rpp_sci_printf("Connected. Frames transmission is starting. O means OK, X means Error\r\n");
if (rpp_fr_clear_timer_irq(0,0) == FAILURE ||
- rpp_fr_set_timer(0,0,10,1) == FAILURE
+ rpp_fr_set_timer(0,0,10,1) == FAILURE
) {
rpp_sci_printf("Absolute timer setting failed.\n");
return -CMDERR_BADCFG;
}
- for (i = 0; i < count; i++){
+ for (i = 0; i < count; i++) {
if (transmit_node_a() == FAILURE) {
rpp_sci_printf("X");
error++;
}
- else {
+ else
rpp_sci_printf("O");
- }
msg_cnt++;
do {
}
rpp_sci_printf("\r\nTransmitted %d messages with %d errors.\r\n", msg_cnt, error);
- if (rpp_fr_halt_communication(0) != SUCCESS) {
+ if (rpp_fr_halt_communication(0) != SUCCESS)
rpp_sci_printf("FlexRay HALT command failed, please reset the board to stop transmission.\r\n");
- }
- else {
+ else
rpp_sci_printf("FlexRay halted, reset the board to make FlexRay usable again.\r\n");
- }
return 0;
}
/**
- * @brief Start receiving data on the FlexRay as node B
+ * @brief Start receiving data on the FlexRay as node B
*
* @param[in] cmd_io Pointer to IO stack
* @param[in] des Pointer to command descriptor
if (param[1] && sscanf(param[1], "%d", &count) != 1)
return -CMDERR_BADPAR;
- if (rpp_fr_init_driver(&Fr_config_node_B, &error) == FAILURE) {
+ if (rpp_fr_init_driver(&Fr_config_node_B, &error) == FAILURE) {
rpp_sci_printf("Fray driver initialization failed: %#x.\n", error);
return -CMDERR_BADCFG;
- }
+ }
if (rpp_fr_init_controller(0, &error) == FAILURE) {
rpp_sci_printf("Fray control node initialization failed: %#x.\n", error);
return -CMDERR_BADCFG;
rpp_fr_get_global_time(0, &cycle2, &mtick);
} while (status == FR_NOT_RECEIVED && (cycle2 != ((cycle1-1) & 0x3F)));
- if (status == FR_NOT_RECEIVED) {
+ if (status == FR_NOT_RECEIVED)
rpp_sci_printf("T");
- }
else if (check_message(data) == 0) {
rpp_sci_printf("O");
msg_cnt++;
}
}
rpp_sci_printf("\r\nReceived %d messages with %d errors.\r\n", msg_cnt, error);
- if (rpp_fr_halt_communication(0) != SUCCESS) {
+ if (rpp_fr_halt_communication(0) != SUCCESS)
rpp_sci_printf("FlexRay HALT command failed, please reset the board to stop transmission.\r\n");
- }
- else {
+ else
rpp_sci_printf("FlexRay halted\r\n");
- }
return 0;
}
-#endif /* DOCGEN */
+#endif /* DOCGEN */
/** Command descriptor for FlexRay status command */
-cmd_des_t const cmd_des_fray_stat={
+cmd_des_t const cmd_des_fray_stat = {
0, 0,
"frayxcvrstat#","Get the status of a FlexRay transceiver in a human readable form",
- "=== Command syntax ===\n"
+ "### Command syntax ###\n"
"\n"
- " frayxcvrstat<CHN>\n"
+ " frayxcvrstat<CHN>\n"
"where CHN is a number in range 1-2\n"
"\n"
- "=== Description ===\n"
+ "### Description ###\n"
"\n"
"The command receives response from a FlexRay transceiver via SPI, and\n"
"prints in the form of attribute-value table.\n"
"\n"
- "=== Example ===\n"
+ "### Example ###\n"
"\n"
- " --> frayxcvrstat1\n"
+ " --> frayxcvrstat1\n"
"\n"
"Prints the status of FRAY1 transceiver.\n",
CMD_HANDLER(cmd_do_fray_status), (void *)&cmd_list_fray
};
/** Command descriptor for FlexRay 1 test node A */
-cmd_des_t const cmd_des_test_fray_a={
- 0, 0,
- "fraytestA","Run the FlexRay test as A node",
- "=== Command syntax ===\n"
- "\n"
- " fraytestA [<COUNT>]\n"
- "\n"
- "where <COUNT> is an optional number of messages to send. The default\n"
- "is 100.\n"
- "\n"
- "=== Description ===\n"
- "\n"
- "The commands creates FlexRay node A and starts sending a message\n"
- "approximately every communication cycle. COUNT messages are sent for the\n"
- "test of the connection. The command should be run with two devices\n"
- "connected by a FlexRay bus and the second device should be running the\n"
- "fraytestB command (it is necessary to run both commands shortly after\n"
- "each other).\n"
- "\n"
- "When the command transmits a message a character is printed. O means\n"
- "that the message was transmitted correctly, X signals a transmission\n"
- "error. The number of TX errors and successfully transmitted messages\n"
- "is maintained during the test and printed at the end.\n",
- CMD_HANDLER(cmd_do_test_frayA), (void *)&cmd_list_fray
+cmd_des_t const cmd_des_test_fray_a = {
+ 0, 0,
+ "fraytestA","Run the FlexRay test as A node",
+ "### Command syntax ###\n"
+ "\n"
+ " fraytestA [<COUNT>]\n"
+ "\n"
+ "where `<COUNT>` is an optional number of messages to send. The default\n"
+ "is 100.\n"
+ "\n"
+ "### Description ###\n"
+ "\n"
+ "The commands creates FlexRay node A and starts sending a message\n"
+ "approximately every communication cycle. COUNT messages are sent for the\n"
+ "test of the connection. The command should be run with two devices\n"
+ "connected by a FlexRay bus and the second device should be running the\n"
+ "fraytestB command (it is necessary to run both commands shortly after\n"
+ "each other).\n"
+ "\n"
+ "When the command transmits a message a character is printed. O means\n"
+ "that the message was transmitted correctly, X signals a transmission\n"
+ "error. The number of TX errors and successfully transmitted messages\n"
+ "is maintained during the test and printed at the end.\n",
+ CMD_HANDLER(cmd_do_test_frayA), (void *)&cmd_list_fray
};
/** Command descriptor for FlexRay 1 test node B */
-cmd_des_t const cmd_des_test_fray_b={
- 0, 0,
- "fraytestB","Run the FlexRay test as B node",
- "=== Command syntax ===\n"
- "\n"
- " fraytestB [<COUNT>]\n"
- "\n"
- "where <COUNT> is an optional number of messages to receive. The default\n"
- "is 100.\n"
- "\n"
- "=== Description ===\n"
- "\n"
- "The commands creates FlexRay node B and starts receiving a messages.\n"
- "100 messages should be received. The command should be run with two\n"
- "devices connected by a FlexRay bus and the second device should be\n"
- "running the fraytestA command (it is necessary to run both commands\n"
- "shortly after each other).\n"
- "\n"
- "When the command receives a message a character is printed. O means\n"
- "that the message was received correctly, X signals an error in data, T\n"
- "means timeout (i.e. no message was received within 63 cycles). The\n"
- "number of RX errors and successfully received messages is maintained\n"
- "during the test and printed at the end.\n",
- CMD_HANDLER(cmd_do_test_frayB), (void *)&cmd_list_fray
+cmd_des_t const cmd_des_test_fray_b = {
+ 0, 0,
+ "fraytestB","Run the FlexRay test as B node",
+ "### Command syntax ###\n"
+ "\n"
+ " fraytestB [<COUNT>]\n"
+ "\n"
+ "where `<COUNT>` is an optional number of messages to receive. The default\n"
+ "is 100.\n"
+ "\n"
+ "### Description ###\n"
+ "\n"
+ "The commands creates FlexRay node B and starts receiving a messages.\n"
+ "100 messages should be received. The command should be run with two\n"
+ "devices connected by a FlexRay bus and the second device should be\n"
+ "running the fraytestA command (it is necessary to run both commands\n"
+ "shortly after each other).\n"
+ "\n"
+ "When the command receives a message a character is printed. O means\n"
+ "that the message was received correctly, X signals an error in data, T\n"
+ "means timeout (i.e. no message was received within 63 cycles). The\n"
+ "number of RX errors and successfully received messages is maintained\n"
+ "during the test and printed at the end.\n",
+ CMD_HANDLER(cmd_do_test_frayB), (void *)&cmd_list_fray
};
/** List of commands for din, defined as external */
-cmd_des_t const *cmd_list_fray[]={
- &cmd_des_fray_stat,
- &cmd_des_test_fray_a,
- &cmd_des_test_fray_b,
- NULL
+cmd_des_t const *cmd_list_fray[] = {
+ &cmd_des_fray_stat,
+ &cmd_des_test_fray_a,
+ &cmd_des_test_fray_b,
+ NULL
};