]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blobdiff - commands/cmd_fr_basic_test.c
FlexRay commands description for halt, abort and restart communication modified,...
[pes-rpp/rpp-test-sw.git] / commands / cmd_fr_basic_test.c
index f0d197fb6e09f4390167f6f6cb35b593e15eba3b..3daea06a51572d61983678127fb750626949a828 100644 (file)
 
 #ifndef DOCGEN
 
+#include <string.h>
 #include "cmdproc_utils.h"
 #include "drv/drv.h"
 #include "rpp/rpp.h"
 #include "hal/hal.h"
 #include "stdio.h"
 
+#define printf rpp_sci_printf
+
+static inline int badpar(const char *msg)
+{
+       printf("%s", msg);
+       return -CMDERR_BADPAR;
+}
+
+
 /**
  * This structure contains global FlexRay configuration.
  * All nodes in the network have to use the same values for
@@ -81,7 +91,7 @@ static Fr_TMS570LS_ClusterConfigType Fr_cluster_config = {
  */
 static Fr_TMS570LS_NodeConfigType Fr_node_A_config = {
        .pAllowHaltDueToClock = 0,
-       .pAllowPassiveToActive = FALSE,
+       .pAllowPassiveToActive = 0xF,
        .pChannels = FR_CHANNEL_AB,
        .pClusterDriftDamping = 0x1,
        .pDelayCompensationA = 0x3,
@@ -116,7 +126,7 @@ static Fr_TMS570LS_NodeConfigType Fr_node_A_config = {
  */
 static Fr_TMS570LS_NodeConfigType Fr_node_B_config = {
                .pAllowHaltDueToClock = 0,
-               .pAllowPassiveToActive = FALSE,
+               .pAllowPassiveToActive = 0xF,
                .pChannels = FR_CHANNEL_AB,
                .pClusterDriftDamping = 0x1,
                .pDelayCompensationA = 0x3,
@@ -517,6 +527,339 @@ static Fr_ConfigType Fr_config_node_B= {
        .staticBufferConfigs = Fr_node_B_static_buffers_config
 };
 
+/* User configuration */
+
+static Fr_TMS570LS_ClusterConfigType user_cluster_config;
+static Fr_TMS570LS_NodeConfigType user_node_config;
+static Fr_TMS570LS_MsgRAMConfig user_msg_ram_config;
+static Fr_TMS570LS_BufferConfigType user_static_buffer_config[RPP_FR_MAX_STATIC_BUF_CNT];
+static Fr_TMS570LS_BufferConfigType user_dynamic_buffer_config[RPP_FR_MAX_DYNAMIC_BUF_CNT];
+static Fr_TMS570LS_BufferConfigType user_fifo_buffer_config[RPP_FR_MAX_FIFO_BUF_DEPTH];
+static Fr_ConfigType user_configuration = {
+       .clusterConfiguration = &user_cluster_config,
+       .nodeConfiguration = &user_node_config,
+       .msgRAMConfig = &user_msg_ram_config,
+       .staticBufferConfigs = user_static_buffer_config,
+       .dynamicBufferConfigs = user_dynamic_buffer_config,
+       .fifoBufferConfigs = user_fifo_buffer_config,
+};;
+
+#define USER_CONFIG_NOT_DONE           0x0
+#define USER_CONFIG_CLUSTER            0x1
+#define USER_CONFIG_NODE                       0x2
+
+static uint8_t user_configuration_state = USER_CONFIG_NOT_DONE;
+static uint8_t user_static_buffer_configured = 0;
+static uint8_t user_dynamic_buffer_configured = 0;
+static uint8_t user_fifo_buffer_depth = 0;
+
+/**
+ * Split string into numbers
+ *
+ * The function takes a string with hexadecimal numbers,
+ * separated by spaces, and converts it into an array of numbers.
+ *
+ * For example "0x2 0xA 0XDD 0xABCD" -> {0x2, 0xA, 0XDD, 0xABCD}
+ *
+ * @param [in] params Address of the string which will be converted
+ * @param [in] params_cnt A number of parameters, which should be found and converted from the string params
+ * @param [out] tmp_params Address, where converted array of numbers will be stored
+ *
+ * @return SUCCESS when all parameters were converted to the array of numbers,
+ *         FAILURE when the string was too short, too long or some other error occurred.
+ */
+static int8_t cmd_fr_parse_params(const char* params, uint32_t params_cnt, uint32_t* tmp_params) {
+       char cpy_params[256];
+       char* token;
+       int i;
+
+       if (params == NULL || tmp_params == NULL) {
+               return FAILURE;
+       }
+       strncpy(cpy_params, params, 256);
+       token = strtok(cpy_params, " ");
+       if (token == NULL) {
+               return FAILURE;
+       }
+       for (i = 0; i < params_cnt; i++) {
+               if (sscanf(token, "%i", &tmp_params[i]) == EOF) {       // No number found
+                       return FAILURE;
+               }
+               if ((token = strtok(NULL, " ")) == NULL && i < params_cnt-1) {  // Not enough parameters in the string
+                       return FAILURE;
+               }
+       }
+       return SUCCESS;
+}
+
+int8_t cmd_fr_config_cluster_params(const char* params) {
+       uint32_t tmp_params[FR_CLUSTER_PARAMS_CNT];
+
+       if (cmd_fr_parse_params(params, FR_CLUSTER_PARAMS_CNT, tmp_params) == FAILURE) {
+               return FAILURE;
+       }
+
+       user_cluster_config.gColdStartAttempts = tmp_params[0];
+       user_cluster_config.gListenNoise = tmp_params[1];
+       user_cluster_config.gMacroPerCycle = tmp_params[2];
+       user_cluster_config.gMaxWithoutClockCorrectionFatal = tmp_params[3];
+       user_cluster_config.gMaxWithoutClockCorrectionPassive = tmp_params[4];
+       user_cluster_config.gNetworkManagementVectorLength = tmp_params[5];
+       user_cluster_config.gNumberOfMinislots = tmp_params[6];
+       user_cluster_config.gNumberOfStaticSlots = tmp_params[7];
+       user_cluster_config.gOffsetCorrectionStart = tmp_params[8];
+       user_cluster_config.gPayloadLengthStatic = tmp_params[9];
+       user_cluster_config.gSyncNodeMax = tmp_params[10];
+       user_cluster_config.gdActionPointOffset = tmp_params[11];
+       user_cluster_config.gdCASRxLowMax = tmp_params[12];
+       user_cluster_config.gdDynamicSlotIdlePhase = tmp_params[13];
+       user_cluster_config.gdMinislot = tmp_params[14];
+       user_cluster_config.gdMinislotActionPointOffset = tmp_params[15];
+       user_cluster_config.gdNIT = tmp_params[16];
+       user_cluster_config.gdSampleClockPeriod = tmp_params[17];
+       user_cluster_config.gdStaticSlot = tmp_params[18];
+       user_cluster_config.gdTSSTransmitter = tmp_params[19];
+       user_cluster_config.gdWakeupSymbolRxIdle = tmp_params[20];
+       user_cluster_config.gdWakeupSymbolRxLow = tmp_params[21];
+       user_cluster_config.gdWakeupSymbolRxWindow = tmp_params[22];
+       user_cluster_config.gdWakeupSymbolTxIdle = tmp_params[23];
+       user_cluster_config.gdWakeupSymbolTxLow = tmp_params[24];
+
+       user_configuration_state |= USER_CONFIG_CLUSTER;
+       return SUCCESS;
+}
+
+int8_t cmd_fr_config_node_params(const char* params) {
+       uint32_t tmp_params[FR_NODE_PARAMS_CNT+2];      // +2 because two more parameters from message RAM structure are expected in the string.
+       Fr_ChannelType channels[3] = {FR_CHANNEL_A, FR_CHANNEL_B, FR_CHANNEL_AB};
+       Fr_TMS570LS_SecureBuffersType secure[4] = {FR_SB_RECONFIG_ENABLED, FR_SB_STAT_REC_DISABLED_STAT_TR_DISABLED, FR_SB_ALL_REC_DISABLED, FR_SB_ALL_REC_DISABLED_STAT_TR_DISABLED};
+
+       if (cmd_fr_parse_params(params, FR_NODE_PARAMS_CNT+2, tmp_params) == FAILURE) {
+               return FAILURE;
+       }
+
+       user_node_config.pAllowHaltDueToClock = tmp_params[0];
+       user_node_config.pAllowPassiveToActive = tmp_params[1];
+       if (tmp_params[2] > 2) return FAILURE;
+       user_node_config.pChannels = channels[ tmp_params[2] ];
+       user_node_config.pClusterDriftDamping = tmp_params[3];
+       user_node_config.pDelayCompensationA = tmp_params[4];
+       user_node_config.pDelayCompensationB = tmp_params[5];
+       user_node_config.pExternOffsetCorrection = tmp_params[6];
+       user_node_config.pExternRateCorrection = tmp_params[7];
+       user_node_config.pKeySlotUsedForStartup = tmp_params[8];
+       user_node_config.pKeySlotUsedForSync = tmp_params[9];
+       user_node_config.pLatestTx = tmp_params[10];
+       user_node_config.pMacroInitialOffsetA = tmp_params[11];
+       user_node_config.pMacroInitialOffsetB = tmp_params[12];
+       user_node_config.pMicroInitialOffsetA = tmp_params[13];
+       user_node_config.pMicroInitialOffsetB = tmp_params[14];
+       user_node_config.pMicroPerCycle = tmp_params[15];
+       user_node_config.pRateCorrectionOut = tmp_params[16];
+       user_node_config.pOffsetCorrectionOut = tmp_params[17];
+       user_node_config.pSamplesPerMicrotick = tmp_params[18];
+       user_node_config.pSingleSlotEnabled = tmp_params[19];
+       if (tmp_params[20] > 1) return FAILURE;
+       user_node_config.pWakeupChannel = channels[ tmp_params[20] ];
+       user_node_config.pWakeupPattern = tmp_params[21];
+       user_node_config.pdAcceptedStartupRange = tmp_params[22];
+       user_node_config.pdListenTimeout = tmp_params[23];
+       user_node_config.pdMaxDrift = tmp_params[24];
+       user_node_config.pDecodingCorrection = tmp_params[25];
+       user_msg_ram_config.syncFramePayloadMultiplexEnabled = tmp_params[26];
+       if (tmp_params[27] > 3) return FAILURE;
+       user_msg_ram_config.secureBuffers = secure[ tmp_params[27] ];
+
+       user_configuration_state |= USER_CONFIG_NODE;
+       return SUCCESS;
+}
+
+int cmd_do_fr_config_fifo(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+       Fr_TMS570LS_BufferConfigType* fifo_buffer_ptr = &user_fifo_buffer_config[0];
+       int ret, i;
+       char channel[3], rej_static_frames[8], rej_null_frames[8];
+       unsigned depth, slot, cycleset, maxpayload;
+       Fr_TMS570LS_BufferConfigType tmp_buffer;
+
+       ret = sscanf(param[2], "slot%i depth%i %2s cyc%i max%i %10s %10s",
+                    &slot,
+                    &depth,
+                    channel,
+                    &cycleset,
+                    &maxpayload,
+                    rej_null_frames,
+                    rej_static_frames
+                    );
+       if (ret != 7) {
+               printf("Error parsing parameter %d\n", ret+1);
+               return -CMDERR_BADPAR;
+       }
+
+       if (depth < 1 || depth >= RPP_FR_MAX_FIFO_BUF_DEPTH)
+               return badpar("Depth too high\n");
+       user_fifo_buffer_depth = depth;
+
+       if (slot > 2047)
+               return badpar("Invalid slot number\n");
+       tmp_buffer.slotId = slot;
+       if (strcmp(channel, "A") == 0) tmp_buffer.channel = FR_CHANNEL_A;
+       else if (strcmp(channel, "B") == 0) tmp_buffer.channel = FR_CHANNEL_B;
+       else if (strcmp(channel, "AB") == 0) tmp_buffer.channel = FR_CHANNEL_AB;
+       else return badpar("Channel parsing error\n");
+       
+       if (cycleset >= 0x80)
+               return badpar("Cycle set must be less than 0x80.\n");
+       tmp_buffer.cycleCounterFiltering = cycleset;
+
+       if (maxpayload >= 128)
+               return badpar("Maximum payload in half-words must be less than 128\n");
+       tmp_buffer.maxPayload = maxpayload;
+       
+       if (strcmp(rej_null_frames, "rejnull") == 0) tmp_buffer.rejectNullFrames = true;
+       else if (strcmp(rej_null_frames, "accnull") == 0) tmp_buffer.rejectNullFrames = false;
+       else return badpar("Reject/accept NULL frames parsing error\n");
+
+       if (strcmp(rej_static_frames, "rejstat") == 0)
+               tmp_buffer.rejectStaticSegment = true;
+       else if (strcmp(rej_static_frames, "accstat") == 0)
+               tmp_buffer.rejectStaticSegment = false;
+       else return badpar("Invalid reject/accept static frame parameter");
+
+       for (i = 0; i < user_fifo_buffer_depth; i++) {
+               fifo_buffer_ptr[i].slotId = tmp_buffer.slotId;  
+               fifo_buffer_ptr[i].maxPayload = tmp_buffer.maxPayload;
+               fifo_buffer_ptr[i].channel= tmp_buffer.channel;
+               fifo_buffer_ptr[i].cycleCounterFiltering = tmp_buffer.cycleCounterFiltering;
+               fifo_buffer_ptr[i].isTx = FALSE;
+               fifo_buffer_ptr[i].singleTransmit = FALSE;
+               fifo_buffer_ptr[i].payloadPreambleIndicatorTr = FALSE;
+               fifo_buffer_ptr[i].rejectNullFrames = tmp_buffer.rejectNullFrames;
+               fifo_buffer_ptr[i].rejectStaticSegment = tmp_buffer.rejectStaticSegment;
+               fifo_buffer_ptr[i].msgBufferInterrupt = 0;
+       }
+
+       printf("frbtcfgfifo slot%i depth%i %2s cyc%i max%i %10s %10s\n",
+                    slot,
+                    depth,
+                    channel,
+                    cycleset,
+                    maxpayload,
+                    rej_null_frames,
+                    rej_static_frames
+               );
+       
+       return SUCCESS;
+}
+
+int cmd_do_fr_config_bufer(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+       Fr_TMS570LS_BufferConfigType *cfg;
+
+       int ret;
+       char buf_type, channel[3],rxtx[3], single_continuous[11];
+       unsigned buffer, slot, cycleset, maxpayload, intr, preamb;
+       
+       ret = sscanf(param[1], "%c%i slot%i %2s cyc%i %2s max%i %10s ppi%i int%i",
+                    &buf_type,
+                    &buffer,
+                    &slot,
+                    channel,
+                    &cycleset,
+                    rxtx,
+                    &maxpayload,
+                    single_continuous,
+                    &preamb,
+                    &intr
+                    );
+       if (ret != 10) {
+               printf("Error parsing parameter %d\n", ret+1);
+               return -CMDERR_BADPAR;
+       
+       }
+       
+       switch (buf_type) {
+       case 'S':
+               if (buffer >= RPP_FR_MAX_STATIC_BUF_CNT)
+                       return badpar("Buffer index too high\n");
+               cfg = &user_static_buffer_config[buffer];
+               break;
+       case 'D':
+               if (buffer >= RPP_FR_MAX_DYNAMIC_BUF_CNT)
+                       return badpar("Buffer index too high\n");
+               cfg = &user_dynamic_buffer_config[buffer];
+               break;
+       default:
+               return badpar("Invalid buffer type (S, D)\n");
+       }
+
+       if (slot < 1 || slot > 2047)
+               return badpar("Invalid slot number\n");
+       cfg->slotId = slot;
+
+       if (strcmp(channel, "A") == 0) cfg->channel = FR_CHANNEL_A;
+       else if (strcmp(channel, "B") == 0) cfg->channel = FR_CHANNEL_B;
+       else if (strcmp(channel, "AB") == 0) cfg->channel = FR_CHANNEL_AB;
+       else return badpar("Channel parsing error\n");
+       if (buf_type == 'D' && cfg->channel == FR_CHANNEL_AB)
+               return badpar("Dynamic segment buffers cannot have AB channels.\n");
+
+       if (cycleset >= 0x80)
+               return badpar("Cycle set must be less than 0x80.\n");
+       cfg->cycleCounterFiltering = cycleset;
+
+       if (strcmp(rxtx, "tx") == 0) cfg->isTx = true;
+       else if (strcmp(rxtx, "rx") == 0) cfg->isTx = false;
+       else return badpar("RX/TX parsing error\n");
+
+       if (maxpayload >= 128)
+               return badpar("Maximum payload in half-words must be less than 128\n");
+       cfg->maxPayload = maxpayload;
+
+       if (0 == strcmp(single_continuous, "single") ||
+           0 == strcmp(single_continuous, "s"))
+               cfg->singleTransmit = true;
+       else if (0 == strcmp(single_continuous, "continuous") ||
+           0 == strcmp(single_continuous, "c"))
+               cfg->singleTransmit = false;
+       else return badpar("Invalid single/continuous parameter");
+
+       if (preamb > 1)
+               return badpar("Payload preamble indicator must be 0 or 1");
+       cfg->payloadPreambleIndicatorTr = preamb;
+
+       if (intr > 1)
+               return badpar("Interrupt parameter must be 0 or 1");
+       cfg->msgBufferInterrupt = intr;
+
+       switch (buf_type) {
+       case 'S':
+               if (buffer >= user_static_buffer_configured)
+                       user_static_buffer_configured = buffer + 1;
+               break;
+       case 'D':
+               if (buffer >= user_dynamic_buffer_configured)
+                       user_dynamic_buffer_configured = buffer + 1;
+               break;
+       }
+
+       printf("frbtcfgbuf%c%i slot%i %2s cyc%i %2s max%i %10s ppi%i int%i\n",
+                    buf_type,
+                    buffer,
+                    slot,
+                    channel,
+                    cycleset,
+                    rxtx,
+                    maxpayload,
+                    single_continuous,
+                    preamb,
+                    intr
+               );
+
+       return 0;
+}
+
+
+
 /**
  *     @brief  Do the user configuration of the FlexRay cluster parameters
  *
@@ -529,41 +872,19 @@ int cmd_do_fr_user_config(cmd_io_t *cmd_io, const struct cmd_des *des, char *par
        char* token;
        token = strtok(param[1], " ");
        if (strcmp(token, "cluster") == 0) {
-               if (rpp_fr_config_cluster_params(param[2]) == FAILURE) {
+               if (cmd_fr_config_cluster_params(param[2]) == FAILURE) {
                        rpp_sci_printf("FlexRay cluster configuration not accepted.\n");
                        return -CMDERR_BADPAR;
                }
                rpp_sci_printf("FlexRay cluster configuration accepted.\n");
        }
        else if (strcmp(token, "node") == 0) {
-               if (rpp_fr_config_node_params(param[2]) == FAILURE) {
+               if (cmd_fr_config_node_params(param[2]) == FAILURE) {
                        rpp_sci_printf("FlexRay node configuration not accepted.\n");
                        return -CMDERR_BADPAR;
                }
                rpp_sci_printf("FlexRay node configuration accepted.\n");
        }
-       else if (strcmp(token, "stat") == 0) {
-               if (rpp_fr_config_static_buffer(param[2]) == FAILURE) {
-                       rpp_sci_printf("Static buffer configuration not accepted.\n");
-                       return -CMDERR_BADPAR;
-               }
-               rpp_sci_printf("Static buffer configuration accepted.\n");
-       }
-       else if (strcmp(token, "dyn") == 0) {
-               if (rpp_fr_config_dynamic_buffer(param[2]) == FAILURE) {
-                       rpp_sci_printf("Dynamic buffer configuration not accepted.\n");
-                       return -CMDERR_BADPAR;
-               }
-               rpp_sci_printf("Dynamic buffer configuration accepted.\n");
-
-       }
-       else if (strcmp(token, "fifo") == 0) {
-               if (rpp_fr_config_fifo_buffer(param[2]) == FAILURE) {
-                       rpp_sci_printf("FIFO buffer configuration not accepted.\n");
-                       return -CMDERR_BADPAR;
-               }
-               rpp_sci_printf("FIFO buffer configuration accepted.\n");
-       }
        else {
                return -CMDERR_BADPAR;
        }
@@ -591,7 +912,10 @@ int cmd_do_fr_init(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
                Fr_ConfigPtr = &Fr_config_node_B;
        }
        else if (*param[1] == 'U') {    // Select the user configuration  -  call config commands first
-               Fr_ConfigPtr = NULL;
+               user_msg_ram_config.statSegmentBufferCount = user_static_buffer_configured;
+               user_msg_ram_config.dynSegmentBufferCount = user_dynamic_buffer_configured;
+               user_msg_ram_config.fifoBufferCount= user_fifo_buffer_depth;
+               Fr_ConfigPtr = &user_configuration;
        }
        else {
                return -CMDERR_BADPAR;
@@ -602,8 +926,15 @@ int cmd_do_fr_init(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
                rpp_sci_printf("FlexRay driver initialized.\r\n");
        }
        else {
-               rpp_sci_printf("FlexRay needs to be configured before initialization.\r\n");
-               return -CMDERR_BADCFG;
+               retVal = rpp_fr_init_controller(0, &error);
+               if (retVal == SUCCESS) {
+                       rpp_sci_printf("FlexRay controller reinitialized.\r\n");
+                       return 0;
+               }
+               else {
+                       rpp_sci_printf("FlexRay needs to be configured before initialization.\r\n");
+                       return -CMDERR_BADCFG;
+               }
        }
 
        retVal = rpp_fr_init_controller(0, &error);
@@ -935,6 +1266,8 @@ int cmd_do_fr_receiverxlpdu(cmd_io_t *cmd_io, const struct cmd_des *des, char *p
                return -CMDERR_BADPAR;
        }
 
+       memset(data, 0, sizeof(data));
+
        retVal = rpp_fr_receive_lpdu(0, slotID, data, &status, &receivedLength);
        if (retVal == SUCCESS) {
                switch (status) {
@@ -1073,6 +1406,34 @@ int cmd_do_fr_getnmvector(cmd_io_t *cmd_io, const struct cmd_des *des, char *par
        return 0;
 }
 
+int cmd_do_fr_nmwatch(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+       int8_t retVal = ERR_PARAM_NO_ERROR;
+       uint8_t nmVector[12];
+       uint8_t i;
+
+       // Calculate wait time in OS ticks
+       static const portTickType freq_ticks = 100 /* ms */ / portTICK_RATE_MS;
+       portTickType last_wake_time = xTaskGetTickCount();
+
+       while(cmd_io->getc(cmd_io) < 0) {
+               retVal = rpp_fr_get_network_management_vector(0, nmVector);
+               if (retVal == SUCCESS) {
+                       rpp_sci_printf("Network management vector:");
+                       for (i = 0; i < Fr_cluster_config.gNetworkManagementVectorLength; i++) {
+                               rpp_sci_printf(" %02x", nmVector[i]);
+                       }
+                       rpp_sci_printf("\r");
+               }
+               else {
+                       rpp_sci_printf("General error.\r\n");
+                       return -CMDERR_BADCFG;
+               }
+               vTaskDelayUntil(&last_wake_time, freq_ticks);
+       }
+       rpp_sci_printf("\n");
+       return 0;
+}
+
 /**
  *     @brief  Print both channels status of the FlexRay node.
  *
@@ -1232,7 +1593,6 @@ int cmd_do_fr_settimer(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[
        int timer = 0;
        int cycle = 0;
        int offset = 0;
-       char* token = NULL;
 
        if (sscanf(param[1], "%i %i %i", &timer, &cycle, &offset) != 3) {
                return -CMDERR_BADPAR;
@@ -1241,12 +1601,13 @@ int cmd_do_fr_settimer(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[
        retVal = rpp_fr_set_timer(0, timer, cycle, offset);
        if (retVal == SUCCESS) {
                uint8_t i = 0x40;
-               while (i && cycle & i == 0)
+               while (i && (cycle & i) == 0)
                        i >>= 1;
                if (!i)
                        i = 1;
 
-               rpp_sci_printf("Timer was set for every %d-th cycle, offset %d\n", i, cycle & ~i);
+               rpp_sci_printf("Timer was set for every %d-th cycle, offset %d, macrotick %d\n",
+                              i, cycle & ~i, offset);
        }
        else {
                rpp_sci_printf("General error.\r\n");
@@ -1397,27 +1758,85 @@ int cmd_do_fr_readcconfig(cmd_io_t *cmd_io, const struct cmd_des *des, char *par
        return 0;
 }
 
+/**
+ *     @brief  Reconfigure buffer
+ *
+ * @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_fr_reconfigure_buffer(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+       int ret;
+       char channel[3];
+       unsigned id, slot, maxpayload, cycleset;
+       Fr_TMS570LS_BufferConfigType tmp_buffer;
+
+       ret = sscanf(param[2], "id%i slot%i %2s cyc%i max%i",
+                    &id,
+                    &slot,
+                    channel,
+                    &cycleset,
+                    &maxpayload
+                    );
+       if (ret != 5) {
+               printf("Error parsing parameter %d\n", ret+1);
+               return -CMDERR_BADPAR;
+       }
+
+       if (slot > 2047 || id > 2047)
+               return badpar("Invalid slot number\n");
+       tmp_buffer.slotId = slot;
+       if (strcmp(channel, "A") == 0) tmp_buffer.channel = FR_CHANNEL_A;
+       else if (strcmp(channel, "B") == 0) tmp_buffer.channel = FR_CHANNEL_B;
+       else if (strcmp(channel, "AB") == 0) tmp_buffer.channel = FR_CHANNEL_AB;
+       else return badpar("Channel parsing error\n");
+
+       if (cycleset >= 0x80)
+               return badpar("Cycle set must be less than 0x80.\n");
+       tmp_buffer.cycleCounterFiltering = cycleset;
+
+       if (maxpayload >= 128)
+               return badpar("Maximum payload in half-words must be less than 128\n");
+       tmp_buffer.maxPayload = maxpayload;
+
+       if (rpp_fr_reconfigure_lpdu(0, id, tmp_buffer.slotId, tmp_buffer.channel, tmp_buffer.cycleCounterFiltering, tmp_buffer.maxPayload) == SUCCESS) {
+               printf("frbtreconfigbuf id%i slot%i %2s cyc%i max%i",
+                            id,
+                            slot,
+                            channel,
+                            cycleset,
+                            maxpayload
+                            );
+               return 0;
+       }
+       else {
+               printf("Reconfiguration failed.\n");
+       }
+       return -CMDERR_BADPAR;
+}
+
 #endif /* DOCGEN */
 
 /** Command descriptor for FlexRay user config cluster command */
 cmd_des_t const cmd_des_fr_user_config={
        0, 0,
        "frbtconfig*","Set the user configuration parameters",
-       "=== Command syntax ===\n"
+               "=== Command syntax ===\n"
        "\n"
        "   frbtconfig<TYPE> <PARAMS>\n"
        "where\n"
-       "* <TYPE> is a string specifying the type of parameters to be set. It can be: \"cluster\", \"node\", \"stat\", \"fifo\" or \"dyn\"\n"
-       "* <PARAMS> is a sequence of hexadecimal numbers separated by spaces. Each number stands for one parameter.\n"
+       "* <TYPE> is a string specifying the type of parameters to be set. It can be: \"cluster\" or  \"node\"\n"
+       "* <PARAMS> is a sequence of numbers separated by spaces. Each number stands for one parameter.\n"
        "\n"
        "=== Description ===\n"
        "\n"
        "The command takes the configuration parameters in the form of a string\n"
        "and sets the appropriate type of the FlexRay parameters. It is\n"
-       "necessary to configure parameters of at least cluster, node and one\n"
-       "static buffer. The parameters set by this command are applied by\n"
-       "the frbtinit command. Once frbtinit is called, it is no longer\n"
-       "possible to change the parameters.\n"
+       "necessary to configure parameters of at least cluster, and node and\n"
+       "one static buffer (see frbtcfgbuf command). The parameters set by this\n"
+       "command are applied by the frbtinitU command. Once frbtinit is called,\n"
+       "it is no longer possible to change the parameters.\n"
        "\n"
        "The type of the parameters can be selected by the <TYPE> selector.\n"
        "\n"
@@ -1480,52 +1899,82 @@ cmd_des_t const cmd_des_fr_user_config={
        "* 27) syncFramePayloadMultiplexEnabled\n"
        "* 28) secureBuffers (0 - FR_SB_RECONFIG_ENABLED, 1 - FR_SB_STAT_REC_DISABLED_STAT_TR_DISABLED, 2 - FR_SB_ALL_REC_DISABLED, 3 - FR_SB_ALL_REC_DISABLED_STAT_TR_DISABLED)\n"
        "\n"
-       "Type \"stat\" adds a configuration for a new static segment buffer. At\n"
-       "least one buffer must be configured. A sequence of 8 parameters is\n"
-       "expected in this order:\n"
-       "* 1) channel (0 - A, 1 - B, 2 - AB)\n"
-       "* 2) cycleCounterFiltering\n"
-       "* 3) isTx\n"
-       "* 4) maxPayload (number of 16b words)\n"
-       "* 5) msgBufferInterrupt\n"
-       "* 6) payloadPreambleIndicatorTr\n"
-       "* 7) singleTransmit\n"
-       "* 8) slotId\n"
-       "\n"
-       "Type \"dyn\" adds a configuration for a new dynamic segment buffer. No\n"
-       "dynamic segment buffer is obligatory. It expects a sequence of 8\n"
-       "parameters in this order:\n"
-       "* 1) channel (0 - A, 1 - B)\n"
-       "* 2) cycleCounterFiltering\n"
-       "* 3) isTx\n"
-       "* 4) maxPayload (number of 16b words)\n"
-       "* 5) msgBufferInterrupt\n"
-       "* 6) payloadPreambleIndicatorTr\n"
-       "* 7) singleTransmit\n"
-       "* 8) slotId\n"
-       "\n"
-       "Type \"fifo\" adds a configuration of a new FIFO buffer. No FIFO\n"
-       "buffer is obligatory. It expects a sequence of 7 parameters in this\n"
-       "order:\n"
-       "*1) depth of the FIFO\n"
-       "*2) channel (0 - A, 1 - B, 2 - AB)\n"
-       "*3) cycleCounterFiltering\n"
-       "*4) maxPayload (number of 16b words)\n"
-       "*5) rejectNullFrames\n"
-       "*6) rejectStaticSegment\n"
-       "*7) slotId\n"
-       "\n"
        "=== Example ===\n"
        "\n"
        "   --> frbtconfigcluster 0x2 0xF 0x15E0 0xF 0xF 0xC 0x15A 0x8 0xAE4 0x9 0xF 0x4 0x43 0x1 0x4 0x2 0xAE3 0x0 0x56 0xA 0x12 0x12 0x4C 0xB4 0x3C\n"
        "   FlexRay cluster configuration accepted.\n"
        "   --> frbtconfignode 0x0 0x0 0x2 0x1 0x3 0x3 0x0 0x0 0x1 0x1 0x10D 0x6 0x6 0x18 0x18 0x36B00 0xCD 0x151 0x0 0x1 0x0 0x2 0x81 0x36DA2 0x151 0x33 0x0 0x0\n"
-       "   FlexRay node configuration accepted.\n"
-       "   --> frbtconfigstat 0x2 0x0 0x1 0x9 0x1 0x0 0x0 0x1\n"
-       "   Static buffer configuration accepted.\n",
+       "   FlexRay node configuration accepted.\n",
        CMD_HANDLER(cmd_do_fr_user_config), (void *)&cmd_list_fr_basic_test
 };
 
+cmd_des_t const cmd_des_fr_config_buffer={
+       0, 0,
+       "frbtcfgbuf?*","Configure a message buffer in the user configuration",
+       "=== Command syntax ===\n"
+       "\n"
+       "   frbtcfgbuf<TYPE><NUM> slot<SLOT> <CHN> cyc<CYC> <RXTX> max<MAX> <REP> ppi<PPI> int<INT>\n"
+       "where\n"
+       "* <TYPE> is 'S' for static segment buffers and 'D' for dynamic segment buffers,\n"
+       "* <NUM> is the number of the buffer. Both static and dynamic buffers are numbered independently starting from zero,\n"
+       "* <SLOT> is the number of the slot,\n"
+       "* <CHN> is one of 'A', 'B' or 'AB' and identifies the used channel,\n"
+       "* <CYC> is the cycle set when to send the buffer,\n"
+       "* <RXTX> is either string \"rx\" or \"tx\",\n"
+       "* <MAX> is the number determining the maximum payload (in hald-words),\n"
+       "* <REP> is a string \"s\" or \"single\" for single transmission or \"c\" or \"continuous\" for continuous transmission,\n"
+       "* <PPI> is 0 or 1 determining whether the payload preamble indicator is set,\n"
+       "* <INT> is 0 or 1 and is currently ignored.\n"
+       "\n"
+       "=== Description ===\n"
+       "\n"
+       "The command sets the configuration parameters for static or dynamic\n"
+       "buffers in user configuration. The parameters set by this command are\n"
+       "applied by the frbtinitU command. Once frbtinit is called, it is no\n"
+       "longer possible to change the parameters.\n"
+       "\n"
+       "=== Example ===\n"
+       "\n"
+       "   --> frbtcfgbufS0 slot2 AB cyc0 tx max9 continous ppi0 int1\n"
+       "   frbtcfgbufS0 slot2 AB cyc0 tx max9  continous ppi0 int1\n"
+       "   --> frbtcfgbufS1 slot1 AB cyc0 rx max9 continuous ppi0 int1\n"
+       "   frbtcfgbufS1 slot1 AB cyc0 rx max9 continuous ppi0 int1\n"
+       "   --> frbtcfgbufD0  slot9  A cyc0 rx max0x40 single ppi0 int0\n"
+       "   frbtcfgbufD0 slot9  A cyc0 rx max64 single ppi0 int0\n"
+       "   --> frbtcfgbufD1  slot10 A cyc0 tx max0x40 single ppi0 int0\n"
+       "   frbtcfgbufD1 slot10  A cyc0 tx max64 single ppi0 int0\n",
+       CMD_HANDLER(cmd_do_fr_config_bufer), (void *)&cmd_list_fr_basic_test
+};
+
+cmd_des_t const cmd_des_fr_config_fifo={
+       0, 0,
+       "frbtcfgfifo*","Configure a RX FIFO message buffer in the user configuration",
+       "=== Command syntax ===\n"
+       "\n"
+       "   frbtcfgfifo slot<SLOT> depth<DEPTH> <CHN> cyc<CYC> max<MAX> <REJNULL> <REJSTAT> int<INT>\n"
+       "where\n"
+       "* <SLOT> is the number of the slot,\n"
+       "* <DEPTH> is a number specifying the depth of the FIFO,\n"
+       "* <CHN> is one of 'A', 'B' or 'AB' and identifies the used channel,\n"
+       "* <CYC> is the cycle set when to send the buffer,\n"
+       "* <MAX> is the number determining the maximum payload (in hald-words),\n"
+       "* <REJNULL> is a string \"rejnull\" for rejecting NULL frames or \"accnull\" for accepting NULL frames,\n"
+       "* <REJSTAT> is a string \"rejstat\" for rejecting frames in static segment or \"accstat\" for accepting frames from static segment,\n"
+       "* <INT> is 0 or 1 and is currently ignored.\n"
+       "\n"
+       "=== Description ===\n"
+       "\n"
+       "The command sets the configuration parameters for RX FIFO buffer\n"
+       "in user configuration. The parameters set by this command are\n"
+       "applied by the frbtinitU command. Once frbtinit is called, it is no\n"
+       "longer possible to change the parameters.\n"
+       "\n"
+       "=== Example ===\n"
+       "\n"
+       "   --> frbtcfgfifo slot0 depth5 AB cyc0 max20 rejnull accstat int1\n"
+       "   frbtcfgfifo slot0 depth5 AB cyc0 max20  rejnull accstat int1\n",
+       CMD_HANDLER(cmd_do_fr_config_fifo), (void *)&cmd_list_fr_basic_test
+};
 
 /** Command descriptor for FlexRay init command */
 cmd_des_t const cmd_des_fr_init={
@@ -1574,7 +2023,8 @@ cmd_des_t const cmd_des_fr_start={
        "=== Description ===\n"
        "\n"
        "The command stands for Fr_StartCommunication function from the Autosar\n"
-       "specification. If the FlexRay node is configured as a coldstarter node\n"
+       "specification.\n"
+       "If the FlexRay node is configured as a coldstarter node\n"
        "(as for example by frbtinitA/B command), then the command first listen\n"
        "on the bus. When it does not detect any existing bus communication, it\n"
        "tries to initiate a new network. If the initiation fails, the FlexRay\n"
@@ -1633,8 +2083,8 @@ cmd_des_t const cmd_des_fr_halt={
        "specification. The command invokes the FlexRay POC command HALT, which\n"
        "means that communication is stopped after the end of the actual\n"
        "communication cycle. On the opposite side, there is a frbtfreeze\n"
-       "command, which stops the communication immediately. To start the\n"
-       "communication again, the device has to be reset.\n"
+       "command, which stops the communication immediately. To restart the\n"
+       "communication, the frbtinit and frbtstart commands have to be called.\n"
        "\n"
        "=== Example ===\n"
        "\n"
@@ -1658,7 +2108,8 @@ cmd_des_t const cmd_des_fr_abort={
        "which means that the communication is stopped immediately. On the\n"
        "opposite side there is a frbthalt command, which stops the\n"
        "communication after the end of the actual communication cycle. To\n"
-       "start the communication again, the device has to be reset.\n"
+       "restart the communication, the frbtinit and frbtstart commands have\n"
+       "to be called.\n"
        "\n"
        "=== Example ===\n"
        "\n"
@@ -1926,6 +2377,25 @@ cmd_des_t const cmd_des_fr_getnmvector={
        CMD_HANDLER(cmd_do_fr_getnmvector), (void *)&cmd_list_fr_basic_test
 };
 
+/** Command descriptor for FlexRay get network management vector command */
+cmd_des_t const cmd_des_fr_nmwatch={
+       0, 0,
+       "frbtnmwatch","Watch the changes of the network managment vector in real-time",
+       "=== Command syntax ===\n"
+       "\n"
+       "   frbtnmwatch\n"
+       "\n"
+       "=== Description ===\n"
+       "\n"
+       "Reads the network management vector every 100 ms and prints it out.\n"
+       "\n"
+       "=== Example ===\n"
+       "\n"
+       "   --> frbtnmwatch\n"
+       "   Network management vector: 0 0 0 0 0 0 0 0 0 0 0 0\n",
+       CMD_HANDLER(cmd_do_fr_nmwatch), (void *)&cmd_list_fr_basic_test
+};
+
 /** Command descriptor for FlexRay get channel status command */
 cmd_des_t const cmd_des_fr_getchannelstatus={
        0, 0,
@@ -2068,10 +2538,17 @@ cmd_des_t const cmd_des_fr_settimer={
        "specify a set of cycles, not only one of 64 cycles. It sets the timer\n"
        "selected by the parameter and enables it.\n"
        "\n"
+       "Before using this command, FlexRay communication has to be started\n"
+       "(see frbtstart).\n"
+       "\n"
        "=== Example ===\n"
        "\n"
        "   --> frbtsettimer0 32 50\n"
-       "   Timer was set.\n",
+       "   Timer was set for every 32-th cycle, offset 0, macrotick 50\n"
+       "   --> frbtsettimer0 31 50\n"
+       "   Timer was set for every 16-th cycle, offset 15, macrotick 50\n"
+       "   --> frbtsettimer0 0x42 0\n"
+       "   Timer was set for every 64-th cycle, offset 2, macrotick 0\n",
        CMD_HANDLER(cmd_do_fr_settimer), (void *)&cmd_list_fr_basic_test
 };
 
@@ -2185,9 +2662,42 @@ cmd_des_t const cmd_des_fr_readcconfig={
        CMD_HANDLER(cmd_do_fr_readcconfig), (void *)&cmd_list_fr_basic_test
 };
 
+/** Command descriptor for FlexRay reconfigure buffer command */
+cmd_des_t const cmd_des_fr_reconfigure_buffer={
+       0, 0,
+       "frbtreconfigurebuf*","Reconfigure a buffer to communicate in another slot",
+       "=== Command syntax ===\n"
+       "\n"
+       "   frbtreconfigurebuf id<ID> slot<SLOT> <CHN> cyc<CYC> max<MAX>\n"
+       "where\n"
+       "* <ID> is a number specifying a slot, where the buffer is currently communicating,\n"
+       "* <SLOT> is a number, where buffer will be communicating after the reconfiguration,\n"
+       "* <CHN> is one of 'A', 'B' or 'AB' and identifies the used channel,\n"
+       "* <CYC> is the cycle set when to send the buffer,\n"
+       "* <MAX> is the number determining the maximum payload (in hald-words).\n"
+       "\n"
+       "=== Description ===\n"
+       "\n"
+       "The command stands for Fr_ReconfigLPDu function from the Autosar\n"
+       "specification. It reconfigures specified buffer to communicate in\n"
+       "different slot.\n"
+       "The reconfiguration must be allowed in node configuration parameter\n"
+       "secureBuffers. Buffers used for synchronization or assigned to the FIFO\n"
+       "are not reconfigurable.\n"
+       "\n"
+       "=== Example ===\n"
+       "\n"
+       "   --> frbtreconfigurebuf id2 slot3 AB 0 9\n"
+       "   frbtreconfigurebuf id2 slot3 AB 0 9\n",
+       CMD_HANDLER(cmd_do_fr_reconfigure_buffer), (void *)&cmd_list_fr_basic_test
+};
+
+
 /** List of commands for flexRay, defined as external */
 cmd_des_t const *cmd_list_fr_basic_test[]={
   &cmd_des_fr_user_config,
+  &cmd_des_fr_config_buffer,
+  &cmd_des_fr_config_fifo,
   &cmd_des_fr_init,
   &cmd_des_fr_start,
   &cmd_des_fr_allslots,
@@ -2203,6 +2713,7 @@ cmd_des_t const *cmd_list_fr_basic_test[]={
   &cmd_des_fr_disablelpdu,
   &cmd_des_fr_getglobaltime,
   &cmd_des_fr_getnmvector,
+  &cmd_des_fr_nmwatch,
   &cmd_des_fr_getchannelstatus,
   &cmd_des_fr_getclockcorrection,
   &cmd_des_fr_getsyncframelist,
@@ -2212,5 +2723,6 @@ cmd_des_t const *cmd_list_fr_basic_test[]={
   &cmd_des_fr_timerirq,
   &cmd_des_fr_getversioninfo,
   &cmd_des_fr_readcconfig,
+  &cmd_des_fr_reconfigure_buffer,
   NULL
 };