X-Git-Url: http://rtime.felk.cvut.cz/gitweb/pes-rpp/rpp-test-sw.git/blobdiff_plain/9a505b7a1923b903d8b49fc96a2d8c57785dc742..5e93bbbb1d36af8d76fe433de6219038ffc65774:/rpp-test-sw/commands/cmd_fray.c diff --git a/rpp-test-sw/commands/cmd_fray.c b/rpp-test-sw/commands/cmd_fray.c index 0c0e1fd..1bbf556 100644 --- a/rpp-test-sw/commands/cmd_fray.c +++ b/rpp-test-sw/commands/cmd_fray.c @@ -1,23 +1,15 @@ /* - * 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 . + * 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 * @@ -40,11 +32,10 @@ #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 "sys/ti_drv_fray.h" +#include "spi_resp_transl.h" /** * This structure contains global FlexRay configuration. @@ -54,7 +45,7 @@ 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, @@ -69,7 +60,7 @@ static Fr_TMS570LS_ClusterConfigType Fr_cluster_config = { .gdMinislot = 0x4, .gdMinislotActionPointOffset = 0x2, .gdNIT = 0xAE3, - .gdSampleClockPeriod = 0, // 10mbit/sec + .gdSampleClockPeriod = 0, // 10mbit/sec .gdStaticSlot = 0x56, .gdTSSTransmitter = 0xA, .gdWakeupSymbolRxIdle = 18, @@ -100,10 +91,10 @@ static Fr_TMS570LS_NodeConfigType Fr_node_A_config = { .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, @@ -118,32 +109,32 @@ static Fr_TMS570LS_NodeConfigType Fr_node_A_config = { * That is the node that receives messages from the node A. */ static Fr_TMS570LS_NodeConfigType Fr_node_B_config = { - .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 + .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 }; /** @@ -179,32 +170,32 @@ static Fr_TMS570LS_MsgRAMConfig Fr_node_B_msgRAM_config = { * 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, - .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, + .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 + } }; /** @@ -268,10 +259,11 @@ static Fr_ConfigType Fr_config_node_B = { }; /** - * 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; @@ -287,50 +279,50 @@ int8_t transmit_node_a() { * @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); @@ -343,14 +335,15 @@ int cmd_do_fray_status(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[ } /** - * @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; @@ -361,10 +354,10 @@ int cmd_do_test_frayA(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[] 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; @@ -383,19 +376,18 @@ int cmd_do_test_frayA(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[] 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 { @@ -410,17 +402,15 @@ int cmd_do_test_frayA(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[] } 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 @@ -437,10 +427,10 @@ int cmd_do_test_frayB(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[] 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; @@ -474,9 +464,8 @@ int cmd_do_test_frayB(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[] 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++; @@ -488,19 +477,17 @@ int cmd_do_test_frayB(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[] } } 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" @@ -522,63 +509,63 @@ cmd_des_t const cmd_des_fray_stat={ }; /** 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 []\n" - "\n" - "where `` 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 []\n" + "\n" + "where `` 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 []\n" - "\n" - "where `` 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 []\n" + "\n" + "where `` 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 };