2 * Copyright (C) 2012-2013 Czech Technical University in Prague
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.
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.
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/>.
22 * File : cmd_fr_basic_test.c
25 * The file contains a set of commands to control the FlexRay driver.
26 * Those commands can be used to configure RPP board as a FlexRay node,
27 * configure a set of TX and RX buffers, get status of the buffers and
28 * the FlexRay controller, manipulate with timers and control the transmission
33 #include "cmd_fr_basic_test.h"
38 #include "cmdproc_utils.h"
44 #define printf rpp_sci_printf
46 static inline int badpar(const char *msg)
49 return -CMDERR_BADPAR;
54 * This structure contains global FlexRay configuration.
55 * All nodes in the network have to use the same values for
56 * all parameters of this structure.
58 static Fr_TMS570LS_ClusterConfigType Fr_cluster_config = {
59 .gColdStartAttempts = 0x2,
61 .gMacroPerCycle = 0x15E0, // (cycle period, 5.6us)
62 .gMaxWithoutClockCorrectionFatal = 0xF,
63 .gMaxWithoutClockCorrectionPassive = 0xF,
64 .gNetworkManagementVectorLength = 12,
65 .gNumberOfMinislots = 0x15A,
66 .gNumberOfStaticSlots = 0x8,
67 .gOffsetCorrectionStart = 0xAE4,
68 .gPayloadLengthStatic = 0x9,
70 .gdActionPointOffset = 0x4,
71 .gdCASRxLowMax = 0x43,
72 .gdDynamicSlotIdlePhase = 0x1,
74 .gdMinislotActionPointOffset = 0x2,
76 .gdSampleClockPeriod = 0, // 10mbit/sec
78 .gdTSSTransmitter = 0xA,
79 .gdWakeupSymbolRxIdle = 18,
80 .gdWakeupSymbolRxLow = 18,
81 .gdWakeupSymbolRxWindow = 76,
82 .gdWakeupSymbolTxIdle = 180,
83 .gdWakeupSymbolTxLow = 60
87 * This structure contains local configuration of the FlexRay node A.
88 * All nodes in the network shall have their own local configuraion,
89 * but it does not matters if they share some together, until their
90 * buffer configuration differs.
92 static Fr_TMS570LS_NodeConfigType Fr_node_A_config = {
93 .pAllowHaltDueToClock = 0,
94 .pAllowPassiveToActive = FALSE,
95 .pChannels = FR_CHANNEL_AB,
96 .pClusterDriftDamping = 0x1,
97 .pDelayCompensationA = 0x3,
98 .pDelayCompensationB = 0x3,
99 .pExternOffsetCorrection = 0,
100 .pExternRateCorrection = 0,
101 .pKeySlotUsedForStartup = TRUE,
102 .pKeySlotUsedForSync = TRUE,
104 .pMacroInitialOffsetA = 0x6,
105 .pMacroInitialOffsetB = 0x6,
106 .pMicroInitialOffsetA = 0x18,
107 .pMicroInitialOffsetB = 0x18,
108 .pMicroPerCycle = 0x36B00,
109 .pRateCorrectionOut = 0xCD,
110 .pOffsetCorrectionOut = 0x151,
111 .pSamplesPerMicrotick = 0, // 10 mbit/sec
112 .pSingleSlotEnabled = TRUE,
113 .pWakeupChannel = FR_CHANNEL_A,
115 .pdAcceptedStartupRange = 0x81,
116 .pdListenTimeout = 0x36DA2,
118 .pDecodingCorrection = 0x33
122 * This structure contains local configuration of the FlexRay node B.
123 * All nodes in the network shall have their own local configuraion,
124 * but it does not matters if they share some together, until their
125 * buffer configuration differs.
127 static Fr_TMS570LS_NodeConfigType Fr_node_B_config = {
128 .pAllowHaltDueToClock = 0,
129 .pAllowPassiveToActive = FALSE,
130 .pChannels = FR_CHANNEL_AB,
131 .pClusterDriftDamping = 0x1,
132 .pDelayCompensationA = 0x3,
133 .pDelayCompensationB = 0x3,
134 .pExternOffsetCorrection = 0,
135 .pExternRateCorrection = 0,
136 .pKeySlotUsedForStartup = TRUE,
137 .pKeySlotUsedForSync = TRUE,
139 .pMacroInitialOffsetA = 0x6,
140 .pMacroInitialOffsetB = 0x6,
141 .pMicroInitialOffsetA = 0x18,
142 .pMicroInitialOffsetB = 0x18,
143 .pMicroPerCycle = 0x36B00,
144 .pRateCorrectionOut = 0xCD,
145 .pOffsetCorrectionOut = 0x151,
146 .pSamplesPerMicrotick = 0, // 10 mbit/sec
147 .pSingleSlotEnabled = TRUE,
148 .pWakeupChannel = FR_CHANNEL_A,
150 .pdAcceptedStartupRange = 0x81,
151 .pdListenTimeout = 0x36DA2,
153 .pDecodingCorrection = 0x33
156 static Fr_TMS570LS_MsgRAMConfig Fr_node_A_msgRAM_config = {
157 .dynSegmentBufferCount = 3,
158 .fifoBufferCount = 5,
159 .secureBuffers = FR_SB_RECONFIG_ENABLED,
160 .statSegmentBufferCount = 5,
161 .syncFramePayloadMultiplexEnabled = 0
164 static Fr_TMS570LS_MsgRAMConfig Fr_node_B_msgRAM_config = {
165 .dynSegmentBufferCount = 3,
166 .fifoBufferCount = 5,
167 .secureBuffers = FR_SB_RECONFIG_ENABLED,
168 .statSegmentBufferCount = 5,
169 .syncFramePayloadMultiplexEnabled = 0
172 static Fr_TMS570LS_BufferConfigType Fr_node_A_static_buffers_config[] = {
174 .channel = FR_CHANNEL_AB,
175 .cycleCounterFiltering = 0,
178 .msgBufferInterrupt = TRUE,
179 .payloadPreambleIndicatorTr = FALSE,
180 .rejectNullFrames = FALSE,
181 .rejectStaticSegment = FALSE,
182 .singleTransmit = FALSE,
186 .channel = FR_CHANNEL_AB,
187 .cycleCounterFiltering = 0,
190 .msgBufferInterrupt = TRUE,
191 .payloadPreambleIndicatorTr = FALSE,
192 .rejectNullFrames = FALSE,
193 .rejectStaticSegment = FALSE,
194 .singleTransmit = FALSE,
198 .channel = FR_CHANNEL_AB,
199 .cycleCounterFiltering = 0,
202 .msgBufferInterrupt = TRUE,
203 .payloadPreambleIndicatorTr = FALSE,
204 .rejectNullFrames = FALSE,
205 .rejectStaticSegment = FALSE,
206 .singleTransmit = TRUE,
210 .channel = FR_CHANNEL_AB,
211 .cycleCounterFiltering = 0,
214 .msgBufferInterrupt = TRUE,
215 .payloadPreambleIndicatorTr = FALSE,
216 .rejectNullFrames = FALSE,
217 .rejectStaticSegment = FALSE,
218 .singleTransmit = TRUE,
222 .channel = FR_CHANNEL_AB,
223 .cycleCounterFiltering = 0,
226 .msgBufferInterrupt = TRUE,
227 .payloadPreambleIndicatorTr = TRUE,
228 .rejectNullFrames = FALSE,
229 .rejectStaticSegment = FALSE,
230 .singleTransmit = FALSE,
236 static Fr_TMS570LS_BufferConfigType Fr_node_B_static_buffers_config[] = {
238 .channel = FR_CHANNEL_AB,
239 .cycleCounterFiltering = 0,
242 .msgBufferInterrupt = TRUE,
243 .payloadPreambleIndicatorTr = FALSE,
244 .rejectNullFrames = FALSE,
245 .rejectStaticSegment = FALSE,
246 .singleTransmit = FALSE,
250 .channel = FR_CHANNEL_AB,
251 .cycleCounterFiltering = 0,
254 .msgBufferInterrupt = TRUE,
255 .payloadPreambleIndicatorTr = FALSE,
256 .rejectNullFrames = FALSE,
257 .rejectStaticSegment = FALSE,
258 .singleTransmit = FALSE,
262 .channel = FR_CHANNEL_AB,
263 .cycleCounterFiltering = 0,
266 .msgBufferInterrupt = TRUE,
267 .payloadPreambleIndicatorTr = FALSE,
268 .rejectNullFrames = FALSE,
269 .rejectStaticSegment = FALSE,
270 .singleTransmit = TRUE,
274 .channel = FR_CHANNEL_AB,
275 .cycleCounterFiltering = 0,
278 .msgBufferInterrupt = TRUE,
279 .payloadPreambleIndicatorTr = FALSE,
280 .rejectNullFrames = FALSE,
281 .rejectStaticSegment = FALSE,
282 .singleTransmit = TRUE,
286 .channel = FR_CHANNEL_AB,
287 .cycleCounterFiltering = 0,
290 .msgBufferInterrupt = TRUE,
291 .payloadPreambleIndicatorTr = TRUE,
292 .rejectNullFrames = FALSE,
293 .rejectStaticSegment = FALSE,
294 .singleTransmit = FALSE,
299 static Fr_TMS570LS_BufferConfigType Fr_node_A_dynamic_buffers_config[] = {
301 .channel = FR_CHANNEL_A,
302 .cycleCounterFiltering = 0,
305 .msgBufferInterrupt = TRUE,
306 .payloadPreambleIndicatorTr = FALSE,
307 .rejectNullFrames = FALSE,
308 .rejectStaticSegment = FALSE,
309 .singleTransmit = FALSE,
313 .channel = FR_CHANNEL_B,
314 .cycleCounterFiltering = 0,
317 .msgBufferInterrupt = TRUE,
318 .payloadPreambleIndicatorTr = FALSE,
319 .rejectNullFrames = FALSE,
320 .rejectStaticSegment = FALSE,
321 .singleTransmit = FALSE,
325 .channel = FR_CHANNEL_A,
326 .cycleCounterFiltering = 0,
329 .msgBufferInterrupt = TRUE,
330 .payloadPreambleIndicatorTr = FALSE,
331 .rejectNullFrames = FALSE,
332 .rejectStaticSegment = FALSE,
333 .singleTransmit = TRUE,
339 static Fr_TMS570LS_BufferConfigType Fr_node_B_dynamic_buffers_config[] = {
341 .channel = FR_CHANNEL_B,
342 .cycleCounterFiltering = 0,
345 .msgBufferInterrupt = TRUE,
346 .payloadPreambleIndicatorTr = FALSE,
347 .rejectNullFrames = FALSE,
348 .rejectStaticSegment = FALSE,
349 .singleTransmit = TRUE,
353 .channel = FR_CHANNEL_A,
354 .cycleCounterFiltering = 0,
357 .msgBufferInterrupt = TRUE,
358 .payloadPreambleIndicatorTr = FALSE,
359 .rejectNullFrames = FALSE,
360 .rejectStaticSegment = FALSE,
361 .singleTransmit = TRUE,
365 .channel = FR_CHANNEL_A,
366 .cycleCounterFiltering = 0,
369 .msgBufferInterrupt = TRUE,
370 .payloadPreambleIndicatorTr = FALSE,
371 .rejectNullFrames = FALSE,
372 .rejectStaticSegment = FALSE,
373 .singleTransmit = TRUE,
378 static Fr_TMS570LS_BufferConfigType Fr_node_A_fifo_buffers_config[] = {
380 .channel = FR_CHANNEL_AB,
381 .cycleCounterFiltering = 0,
384 .msgBufferInterrupt = FALSE, // Recomended for FIFO buffers
385 .payloadPreambleIndicatorTr = FALSE,
386 .rejectNullFrames = TRUE,
387 .rejectStaticSegment = FALSE,
388 .singleTransmit = FALSE,
392 .channel = FR_CHANNEL_AB,
393 .cycleCounterFiltering = 0,
396 .msgBufferInterrupt = FALSE, // Recomended for FIFO buffers
397 .payloadPreambleIndicatorTr = FALSE,
398 .rejectNullFrames = TRUE,
399 .rejectStaticSegment = FALSE,
400 .singleTransmit = FALSE,
404 .channel = FR_CHANNEL_AB,
405 .cycleCounterFiltering = 0,
408 .msgBufferInterrupt = FALSE, // Recomended for FIFO buffers
409 .payloadPreambleIndicatorTr = FALSE,
410 .rejectNullFrames = TRUE,
411 .rejectStaticSegment = FALSE,
412 .singleTransmit = FALSE,
416 .channel = FR_CHANNEL_AB,
417 .cycleCounterFiltering = 0,
420 .msgBufferInterrupt = FALSE, // Recomended for FIFO buffers
421 .payloadPreambleIndicatorTr = FALSE,
422 .rejectNullFrames = TRUE,
423 .rejectStaticSegment = FALSE,
424 .singleTransmit = FALSE,
428 .channel = FR_CHANNEL_AB,
429 .cycleCounterFiltering = 0,
432 .msgBufferInterrupt = FALSE, // Recomended for FIFO buffers
433 .payloadPreambleIndicatorTr = FALSE,
434 .rejectNullFrames = TRUE,
435 .rejectStaticSegment = FALSE,
436 .singleTransmit = FALSE,
441 static Fr_TMS570LS_BufferConfigType Fr_node_B_fifo_buffers_config[] = {
443 .channel = FR_CHANNEL_AB,
444 .cycleCounterFiltering = 0,
447 .msgBufferInterrupt = FALSE, // Recommended for FIFO buffers
448 .payloadPreambleIndicatorTr = FALSE,
449 .rejectNullFrames = TRUE,
450 .rejectStaticSegment = FALSE,
451 .singleTransmit = FALSE,
452 .slotId = 0 // No Frame is rejected
455 .channel = FR_CHANNEL_AB,
456 .cycleCounterFiltering = 0,
459 .msgBufferInterrupt = FALSE, // Recommended for FIFO buffers
460 .payloadPreambleIndicatorTr = FALSE,
461 .rejectNullFrames = TRUE,
462 .rejectStaticSegment = FALSE,
463 .singleTransmit = FALSE,
464 .slotId = 0 // No Frame is rejected
467 .channel = FR_CHANNEL_AB,
468 .cycleCounterFiltering = 0,
471 .msgBufferInterrupt = FALSE, // Recommended for FIFO buffers
472 .payloadPreambleIndicatorTr = FALSE,
473 .rejectNullFrames = TRUE,
474 .rejectStaticSegment = FALSE,
475 .singleTransmit = FALSE,
476 .slotId = 0 // No Frame is rejected
479 .channel = FR_CHANNEL_AB,
480 .cycleCounterFiltering = 0,
483 .msgBufferInterrupt = FALSE, // Recommended for FIFO buffers
484 .payloadPreambleIndicatorTr = FALSE,
485 .rejectNullFrames = TRUE,
486 .rejectStaticSegment = FALSE,
487 .singleTransmit = FALSE,
488 .slotId = 0 // No Frame is rejected
491 .channel = FR_CHANNEL_AB,
492 .cycleCounterFiltering = 0,
495 .msgBufferInterrupt = FALSE, // Recommended for FIFO buffers
496 .payloadPreambleIndicatorTr = FALSE,
497 .rejectNullFrames = TRUE,
498 .rejectStaticSegment = FALSE,
499 .singleTransmit = FALSE,
500 .slotId = 0 // No Frame is rejected
505 * This is an unifying configuration structure for the node A.
506 * It joins all the configuration structure together.
508 static Fr_ConfigType Fr_config_node_A= {
509 .clusterConfiguration = &Fr_cluster_config,
510 .dynamicBufferConfigs = Fr_node_A_dynamic_buffers_config,
511 .fifoBufferConfigs = Fr_node_A_fifo_buffers_config,
512 .msgRAMConfig = &Fr_node_A_msgRAM_config,
513 .nodeConfiguration = &Fr_node_A_config,
514 .staticBufferConfigs = Fr_node_A_static_buffers_config
518 * This is an unifying configuration structure for the node A.
519 * It joins all the configuration structure together.
521 static Fr_ConfigType Fr_config_node_B= {
522 .clusterConfiguration = &Fr_cluster_config,
523 .dynamicBufferConfigs = Fr_node_B_dynamic_buffers_config,
524 .fifoBufferConfigs = Fr_node_B_fifo_buffers_config,
525 .msgRAMConfig = &Fr_node_B_msgRAM_config,
526 .nodeConfiguration = &Fr_node_B_config,
527 .staticBufferConfigs = Fr_node_B_static_buffers_config
530 /* User configuration */
532 static Fr_TMS570LS_ClusterConfigType user_cluster_config;
533 static Fr_TMS570LS_NodeConfigType user_node_config;
534 static Fr_TMS570LS_MsgRAMConfig user_msg_ram_config;
535 static Fr_TMS570LS_BufferConfigType user_static_buffer_config[RPP_FR_MAX_STATIC_BUF_CNT];
536 static Fr_TMS570LS_BufferConfigType user_dynamic_buffer_config[RPP_FR_MAX_DYNAMIC_BUF_CNT];
537 static Fr_TMS570LS_BufferConfigType user_fifo_buffer_config[RPP_FR_MAX_FIFO_BUF_DEPTH];
538 static Fr_ConfigType user_configuration = {
539 .clusterConfiguration = &user_cluster_config,
540 .nodeConfiguration = &user_node_config,
541 .msgRAMConfig = &user_msg_ram_config,
542 .staticBufferConfigs = user_static_buffer_config,
543 .dynamicBufferConfigs = user_dynamic_buffer_config,
544 .fifoBufferConfigs = user_fifo_buffer_config,
547 #define USER_CONFIG_NOT_DONE 0x0
548 #define USER_CONFIG_CLUSTER 0x1
549 #define USER_CONFIG_NODE 0x2
551 static uint8_t user_configuration_state = USER_CONFIG_NOT_DONE;
552 static uint8_t user_static_buffer_configured = 0;
553 static uint8_t user_dynamic_buffer_configured = 0;
554 static uint8_t user_fifo_buffer_depth = 0;
557 * Split string into numbers
559 * The function takes a string with hexadecimal numbers,
560 * separated by spaces, and converts it into an array of numbers.
562 * For example "0x2 0xA 0XDD 0xABCD" -> {0x2, 0xA, 0XDD, 0xABCD}
564 * @param [in] params Address of the string which will be converted
565 * @param [in] params_cnt A number of parameters, which should be found and converted from the string params
566 * @param [out] tmp_params Address, where converted array of numbers will be stored
568 * @return SUCCESS when all parameters were converted to the array of numbers,
569 * FAILURE when the string was too short, too long or some other error occurred.
571 static int8_t rpp_fr_parse_params(const char* params, uint32_t params_cnt, uint32_t* tmp_params) {
572 char cpy_params[256];
576 if (params == NULL || tmp_params == NULL) {
579 strncpy(cpy_params, params, 256);
580 token = strtok(cpy_params, " ");
584 for (i = 0; i < params_cnt; i++) {
585 if (sscanf(token, "%i", &tmp_params[i]) == EOF) { // No number found
588 if ((token = strtok(NULL, " ")) == NULL && i < params_cnt-1) { // Not enough parameters in the string
595 int8_t rpp_fr_config_cluster_params(const char* params) {
596 uint32_t tmp_params[FR_CLUSTER_PARAMS_CNT];
598 if (rpp_fr_parse_params(params, FR_CLUSTER_PARAMS_CNT, tmp_params) == FAILURE) {
602 user_cluster_config.gColdStartAttempts = tmp_params[0];
603 user_cluster_config.gListenNoise = tmp_params[1];
604 user_cluster_config.gMacroPerCycle = tmp_params[2];
605 user_cluster_config.gMaxWithoutClockCorrectionFatal = tmp_params[3];
606 user_cluster_config.gMaxWithoutClockCorrectionPassive = tmp_params[4];
607 user_cluster_config.gNetworkManagementVectorLength = tmp_params[5];
608 user_cluster_config.gNumberOfMinislots = tmp_params[6];
609 user_cluster_config.gNumberOfStaticSlots = tmp_params[7];
610 user_cluster_config.gOffsetCorrectionStart = tmp_params[8];
611 user_cluster_config.gPayloadLengthStatic = tmp_params[9];
612 user_cluster_config.gSyncNodeMax = tmp_params[10];
613 user_cluster_config.gdActionPointOffset = tmp_params[11];
614 user_cluster_config.gdCASRxLowMax = tmp_params[12];
615 user_cluster_config.gdDynamicSlotIdlePhase = tmp_params[13];
616 user_cluster_config.gdMinislot = tmp_params[14];
617 user_cluster_config.gdMinislotActionPointOffset = tmp_params[15];
618 user_cluster_config.gdNIT = tmp_params[16];
619 user_cluster_config.gdSampleClockPeriod = tmp_params[17];
620 user_cluster_config.gdStaticSlot = tmp_params[18];
621 user_cluster_config.gdTSSTransmitter = tmp_params[19];
622 user_cluster_config.gdWakeupSymbolRxIdle = tmp_params[20];
623 user_cluster_config.gdWakeupSymbolRxLow = tmp_params[21];
624 user_cluster_config.gdWakeupSymbolRxWindow = tmp_params[22];
625 user_cluster_config.gdWakeupSymbolTxIdle = tmp_params[23];
626 user_cluster_config.gdWakeupSymbolTxLow = tmp_params[24];
628 user_configuration_state |= USER_CONFIG_CLUSTER;
632 int8_t rpp_fr_config_node_params(const char* params) {
633 uint32_t tmp_params[FR_NODE_PARAMS_CNT+2]; // +2 because two more parameters from message RAM structure are expected in the string.
634 Fr_ChannelType channels[3] = {FR_CHANNEL_A, FR_CHANNEL_B, FR_CHANNEL_AB};
635 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};
637 if (rpp_fr_parse_params(params, FR_NODE_PARAMS_CNT+2, tmp_params) == FAILURE) {
641 user_node_config.pAllowHaltDueToClock = tmp_params[0];
642 user_node_config.pAllowPassiveToActive = tmp_params[1];
643 if (tmp_params[2] > 2) return FAILURE;
644 user_node_config.pChannels = channels[ tmp_params[2] ];
645 user_node_config.pClusterDriftDamping = tmp_params[3];
646 user_node_config.pDelayCompensationA = tmp_params[4];
647 user_node_config.pDelayCompensationB = tmp_params[5];
648 user_node_config.pExternOffsetCorrection = tmp_params[6];
649 user_node_config.pExternRateCorrection = tmp_params[7];
650 user_node_config.pKeySlotUsedForStartup = tmp_params[8];
651 user_node_config.pKeySlotUsedForSync = tmp_params[9];
652 user_node_config.pLatestTx = tmp_params[10];
653 user_node_config.pMacroInitialOffsetA = tmp_params[11];
654 user_node_config.pMacroInitialOffsetB = tmp_params[12];
655 user_node_config.pMicroInitialOffsetA = tmp_params[13];
656 user_node_config.pMicroInitialOffsetB = tmp_params[14];
657 user_node_config.pMicroPerCycle = tmp_params[15];
658 user_node_config.pRateCorrectionOut = tmp_params[16];
659 user_node_config.pOffsetCorrectionOut = tmp_params[17];
660 user_node_config.pSamplesPerMicrotick = tmp_params[18];
661 user_node_config.pSingleSlotEnabled = tmp_params[19];
662 if (tmp_params[20] > 1) return FAILURE;
663 user_node_config.pWakeupChannel = channels[ tmp_params[20] ];
664 user_node_config.pWakeupPattern = tmp_params[21];
665 user_node_config.pdAcceptedStartupRange = tmp_params[22];
666 user_node_config.pdListenTimeout = tmp_params[23];
667 user_node_config.pdMaxDrift = tmp_params[24];
668 user_node_config.pDecodingCorrection = tmp_params[25];
669 user_msg_ram_config.syncFramePayloadMultiplexEnabled = tmp_params[26];
670 if (tmp_params[27] > 3) return FAILURE;
671 user_msg_ram_config.secureBuffers = secure[ tmp_params[27] ];
673 user_configuration_state |= USER_CONFIG_NODE;
677 int cmd_do_fr_config_bufer(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
679 Fr_TMS570LS_BufferConfigType *cfg;
682 char buf_type, channel[3],rxtx[3], single_continuous[11];
683 unsigned buffer, slot, cycleset, maxpayload, intr, preamb;
684 ret = sscanf(param[1], "%c%i slot%i %2s cyc%i %2s max%i %10s ppi%i int%i",
698 printf("Error parsing parameter %d\n", ret+1);
699 return -CMDERR_BADPAR;
704 if (buffer >= RPP_FR_MAX_STATIC_BUF_CNT)
705 return badpar("Buffer index too high\n");
706 cfg = &user_static_buffer_config[buffer];
709 if (buffer >= RPP_FR_MAX_DYNAMIC_BUF_CNT)
710 return badpar("Buffer index too high\n");
711 cfg = &user_dynamic_buffer_config[buffer];
714 return badpar("Invalid buffer type (S, D)\n");
717 if (slot < 1 || slot > 2047)
718 return badpar("Invalid slot number\n");
721 if (strcmp(channel, "A") == 0) cfg->channel = FR_CHANNEL_A;
722 else if (strcmp(channel, "B") == 0) cfg->channel = FR_CHANNEL_B;
723 else if (strcmp(channel, "AB") == 0) cfg->channel = FR_CHANNEL_AB;
724 else return badpar("Channel parsing error\n");
725 if (buf_type == 'D' && cfg->channel == FR_CHANNEL_AB)
726 return badpar("Dynamic segment buffers cannot have AB channels.\n");
728 if (cycleset >= 0x80)
729 return badpar("Cycle set must be less than 0x80.\n");
730 cfg->cycleCounterFiltering = cycleset;
732 if (strcmp(rxtx, "tx") == 0) cfg->isTx = true;
733 else if (strcmp(rxtx, "rx") == 0) cfg->isTx = false;
734 else return badpar("RX/TX parsing error\n");
736 if (maxpayload >= 128)
737 return badpar("Maximum payload in half-words must be less than 128\n");
738 cfg->maxPayload = maxpayload;
740 if (0 == strcmp(single_continuous, "single") ||
741 0 == strcmp(single_continuous, "s"))
742 cfg->singleTransmit = true;
743 else if (0 == strcmp(single_continuous, "continuous") ||
744 0 == strcmp(single_continuous, "c"))
745 cfg->singleTransmit = false;
746 else return badpar("Invalid single/continuous parameter");
749 return badpar("Payload preamble indicator must be 0 or 1");
750 cfg->payloadPreambleIndicatorTr = preamb;
753 return badpar("Interrupt parameter must be 0 or 1");
754 cfg->msgBufferInterrupt = intr;
758 if (buffer >= user_static_buffer_configured)
759 user_static_buffer_configured = buffer + 1;
762 if (buffer >= user_dynamic_buffer_configured)
763 user_dynamic_buffer_configured = buffer + 1;
767 printf("frbtcfgbuf%c%i slot%i %2s cyc%i %2s max%i %10s ppi%i int%i\n",
783 int8_t rpp_fr_config_fifo_buffer(const char* params) {
784 uint32_t tmp_params[FR_FIFO_BUF_PARAMS_CNT+1]; // +1 because the first parameter in the string means the depth of the buffer, and the constant means the number of items in the configuration structure.
785 Fr_ChannelType channels[3] = {FR_CHANNEL_A, FR_CHANNEL_B, FR_CHANNEL_AB};
786 Fr_TMS570LS_BufferConfigType* fifo_buffer_ptr = &user_fifo_buffer_config[0];
788 if (user_fifo_buffer_depth != 0) {
792 if (rpp_fr_parse_params(params, FR_FIFO_BUF_PARAMS_CNT+1, tmp_params) == FAILURE) {
796 if (tmp_params[0] > RPP_FR_MAX_FIFO_BUF_DEPTH) return FAILURE;
797 if (tmp_params[1] > 2) return FAILURE;
799 for (fifo_buffer_ptr = &user_fifo_buffer_config[0]; fifo_buffer_ptr < &user_fifo_buffer_config[tmp_params[0]]; fifo_buffer_ptr++) {
800 fifo_buffer_ptr->channel = channels[ tmp_params[1] ];
801 fifo_buffer_ptr->cycleCounterFiltering = tmp_params[2];
802 fifo_buffer_ptr->maxPayload = tmp_params[3];
803 fifo_buffer_ptr->rejectNullFrames = tmp_params[4];
804 fifo_buffer_ptr->rejectStaticSegment = tmp_params[5];
805 fifo_buffer_ptr->slotId = tmp_params[6];
807 user_fifo_buffer_depth = tmp_params[0];
814 * @brief Do the user configuration of the FlexRay cluster parameters
816 * @param[in] cmd_io Pointer to IO stack
817 * @param[in] des Pointer to command descriptor
818 * @param[in] param Parameters of command
819 * @return 0 when OK or error code
821 int cmd_do_fr_user_config(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
823 token = strtok(param[1], " ");
824 if (strcmp(token, "cluster") == 0) {
825 if (rpp_fr_config_cluster_params(param[2]) == FAILURE) {
826 rpp_sci_printf("FlexRay cluster configuration not accepted.\n");
827 return -CMDERR_BADPAR;
829 rpp_sci_printf("FlexRay cluster configuration accepted.\n");
831 else if (strcmp(token, "node") == 0) {
832 if (rpp_fr_config_node_params(param[2]) == FAILURE) {
833 rpp_sci_printf("FlexRay node configuration not accepted.\n");
834 return -CMDERR_BADPAR;
836 rpp_sci_printf("FlexRay node configuration accepted.\n");
838 else if (strcmp(token, "fifo") == 0) {
839 if (rpp_fr_config_fifo_buffer(param[2]) == FAILURE) {
840 rpp_sci_printf("FIFO buffer configuration not accepted.\n");
841 return -CMDERR_BADPAR;
843 rpp_sci_printf("FIFO buffer configuration accepted.\n");
846 return -CMDERR_BADPAR;
853 * @brief Initialize the device as FlexRay node.
855 * @param[in] cmd_io Pointer to IO stack
856 * @param[in] des Pointer to command descriptor
857 * @param[in] param Parameters of command
858 * @return 0 when OK or error code
860 int cmd_do_fr_init(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
861 const Fr_ConfigType* Fr_ConfigPtr = NULL;
862 int8_t retVal = SUCCESS;
863 uint32_t error = ERR_PARAM_NO_ERROR;
865 if (*param[1] == 'A') {
866 Fr_ConfigPtr = &Fr_config_node_A;
868 else if (*param[1] == 'B') {
869 Fr_ConfigPtr = &Fr_config_node_B;
871 else if (*param[1] == 'U') { // Select the user configuration - call config commands first
872 user_msg_ram_config.statSegmentBufferCount = user_static_buffer_configured;
873 user_msg_ram_config.dynSegmentBufferCount = user_dynamic_buffer_configured;
874 user_msg_ram_config.fifoBufferCount= user_fifo_buffer_depth;
875 Fr_ConfigPtr = &user_configuration;
878 return -CMDERR_BADPAR;
881 retVal = rpp_fr_init_driver(Fr_ConfigPtr, &error);
882 if (retVal == SUCCESS) {
883 rpp_sci_printf("FlexRay driver initialized.\r\n");
886 rpp_sci_printf("FlexRay needs to be configured before initialization.\r\n");
887 return -CMDERR_BADCFG;
890 retVal = rpp_fr_init_controller(0, &error);
891 if (retVal == SUCCESS) {
892 rpp_sci_printf("FlexRay controller initialized.\r\n");
895 if (error & FR_INIT_ERR_CLUSTER_CONFIG) {
896 rpp_sci_printf("Cluster configuration data error: %x\r\n", (retVal & 0x3FFFFFE) >> 1 );
898 else if (error & FR_INIT_ERR_NODE_CONFIG) {
899 rpp_sci_printf("Node configuration data error: %x\r\n", (retVal & 0x3FFFFFE) >> 1 );
901 else if (error & FR_INIT_ERR_MSGRAM_CONFIG) {
902 rpp_sci_printf("Message RAM configuration data error: %x\r\n", (retVal & 0x3FFFFFE) >> 1 );
904 else if (error & FR_INIT_ERR_BUFFPARAM_CONFIG) {
905 rpp_sci_printf("Buffer configuration data error: %x\r\n", (retVal & 0x3FFFFFE) >> 1 );
907 else if (error & (uint32_t)FR_INIT_ERR_BUFF_CONFIG) {
908 rpp_sci_printf("Buffer configuration error: %x\r\n", (retVal & 0x3FFFFFE) >> 1 );
911 rpp_sci_printf("POC state switching error.\r\n");
913 return -CMDERR_BADCFG;
919 * @brief Starts FlexRay communication
921 * @param[in] cmd_io Pointer to IO stack
922 * @param[in] des Pointer to command descriptor
923 * @param[in] param Parameters of command
924 * @return 0 when OK or error code
926 int cmd_do_fr_start(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
927 int8_t retVal = SUCCESS;
928 uint32_t error = ERR_PARAM_NO_ERROR;
930 retVal = rpp_fr_start_communication(0, &error);
931 if (retVal == SUCCESS) {
932 rpp_sci_printf("FlexRay communication is running.\r\n");
935 if (error & FR_STARTUP_ERR_SW_STUP_FOLLOW) {
936 rpp_sci_printf("Can not switch POC to RUN state.\r\n");
938 else if (error & FR_STARTUP_ERR_CSINH_DIS) {
939 rpp_sci_printf("Cold start inhibit disabled error.\r\n");
941 else if (error & FR_STARTUP_ERR_SW_STUP_READY) {
942 rpp_sci_printf("Can not switch back to READY from STARTUP.\r\n");
944 else if (error & FR_STARTUP_ERR_SW_STUP_AS_NCOLD) {
945 rpp_sci_printf("Can not switch to STARTUP as non-coldstarter.\r\n");
948 rpp_sci_printf("General error.\r\n");
950 return -CMDERR_BADCFG;
956 * @brief Invokes POC command ALL_SLOTS
958 * @param[in] cmd_io Pointer to IO stack
959 * @param[in] des Pointer to command descriptor
960 * @param[in] param Parameters of command
961 * @return 0 when OK or error code
963 int cmd_do_fr_allslots(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
964 int8_t retVal = ERR_PARAM_NO_ERROR;
965 retVal = rpp_fr_all_slots(0);
966 if (retVal == SUCCESS) {
967 rpp_sci_printf("FlexRay node started communication in all slots.\r\n");
970 rpp_sci_printf("General error.\r\n");
971 return -CMDERR_BADCFG;
977 * @brief Halt FlexRay communication
979 * @param[in] cmd_io Pointer to IO stack
980 * @param[in] des Pointer to command descriptor
981 * @param[in] param Parameters of command
982 * @return 0 when OK or error code
984 int cmd_do_fr_halt(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
985 int8_t retVal = ERR_PARAM_NO_ERROR;
986 retVal = rpp_fr_halt_communication(0);
987 if (retVal == SUCCESS) {
988 rpp_sci_printf("FlexRay node communication halted.\r\n");
991 rpp_sci_printf("General error.\r\n");
992 return -CMDERR_BADCFG;
998 * @brief Abort FlexRay communication
1000 * @param[in] cmd_io Pointer to IO stack
1001 * @param[in] des Pointer to command descriptor
1002 * @param[in] param Parameters of command
1003 * @return 0 when OK or error code
1005 int cmd_do_fr_abort(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1006 int8_t retVal = ERR_PARAM_NO_ERROR;
1007 retVal = rpp_fr_abort_communication(0);
1008 if (retVal == SUCCESS) {
1009 rpp_sci_printf("FlexRay node communication aborted.\r\n");
1012 rpp_sci_printf("General error.\r\n");
1013 return -CMDERR_BADCFG;
1019 * @brief Send wake up pattern
1021 * @param[in] cmd_io Pointer to IO stack
1022 * @param[in] des Pointer to command descriptor
1023 * @param[in] param Parameters of command
1024 * @return 0 when OK or error code
1026 int cmd_do_fr_sendwup(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1027 int8_t retVal = ERR_PARAM_NO_ERROR;
1028 retVal = rpp_fr_send_wup(0);
1029 if (retVal == SUCCESS) {
1030 rpp_sci_printf("Wake up pattern has been sent.\r\n");
1033 rpp_sci_printf("General error.\r\n");
1034 return -CMDERR_BADCFG;
1040 * @brief Set channel for wake up pattern sending.
1042 * @param[in] cmd_io Pointer to IO stack
1043 * @param[in] des Pointer to command descriptor
1044 * @param[in] param Parameters of command
1045 * @return 0 when OK or error code
1047 int cmd_do_fr_setwuchannel(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1048 int8_t retVal = ERR_PARAM_NO_ERROR;
1049 Fr_ChannelType channel = FR_CHANNEL_A;
1051 if (*param[1] == 'A') {
1052 channel = FR_CHANNEL_A;
1054 else if (*param[1] == 'B') {
1055 channel = FR_CHANNEL_B;
1058 return -CMDERR_BADPAR;
1060 retVal = rpp_fr_set_wu_channel(0, channel);
1061 if (retVal == SUCCESS) {
1062 rpp_sci_printf("Wake up channel has been set.\r\n");
1065 rpp_sci_printf("General error.\r\n");
1066 return -CMDERR_BADCFG;
1072 * @brief Get and print POC status of the FlexRay controller.
1074 * @param[in] cmd_io Pointer to IO stack
1075 * @param[in] des Pointer to command descriptor
1076 * @param[in] param Parameters of command
1077 * @return 0 when OK or error code
1079 int cmd_do_fr_getpocstatus(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1080 int8_t retVal = ERR_PARAM_NO_ERROR;
1081 Fr_POCStatusType status;
1082 char* ErrorModeStrings[] = {"ACTIVE", "HALT", "PASSIVE"};
1083 char* SlotModeStrings[] = {"KEYSLOT", "ALL_PENDING", "ALL"};
1084 char* StartupStateStrings[] = {
1085 "UNDEFINED", "COLDSTART_LISTEN", "COLDSTART_CHECK", "COLDSTART_JOIN",
1086 "COLDSTART_CONSISTENCY_CHECK", "INTEGRATION_LISTEN", "INITIALIZE_SCHEDULE", "INTEGRATION_CONSISTENCY_CHECK",
1087 "COLDSTART_GAP", "EXTERNAL_STARTUP", "ABORT", "COLDSTART_COLLISION_RESOLUTION",
1090 char* StateStrings[] = {
1091 "CONFIG", "DEFAULT_CONFIG", "HALT", "NORMAL_ACTIVE",
1092 "NORMAL_PASSIVE", "READY", "STARTUP", "LOOPBACK",
1095 char* WakeupStatusStrings[] = {
1096 "UNDEFINED", "RECEIVED_HEADER", "RECEIVED_WUP", "COLLISION_HEADER",
1097 "COLLISION_WUP", "COLLISION_UNKNOWN", "TRANSMITTED"
1100 retVal = rpp_fr_get_poc_status(0, &status);
1101 if (retVal == SUCCESS) {
1102 rpp_sci_printf("POC status:\r\n");
1103 rpp_sci_printf("CHIHaltRequest: %s\r\n", (status.CHIHaltRequest == TRUE) ? "TRUE" : "FALSE");
1104 rpp_sci_printf("CHIReadyRequest: %s\r\n", (status.CHIReadyRequest == TRUE) ? "TRUE" : "FALSE");
1105 rpp_sci_printf("ColdstartNoise: %s\r\n", (status.ColdstartNoise == TRUE) ? "TRUE" : "FALSE");
1106 rpp_sci_printf("Freeze: %s\r\n", (status.Freeze == TRUE) ? "TRUE" : "FALSE");
1107 rpp_sci_printf("ErrorMode: %s\r\n", ErrorModeStrings[status.ErrorMode]);
1108 rpp_sci_printf("SlotMode: %s\r\n", SlotModeStrings[status.SlotMode]);
1109 rpp_sci_printf("StartupState: %s\r\n", StartupStateStrings[status.StartupState]);
1110 rpp_sci_printf("State: %s\r\n", StateStrings[status.State]);
1111 rpp_sci_printf("WakeupStatus: %s\r\n", WakeupStatusStrings[status.WakeupStatus]);
1114 rpp_sci_printf("General error.\r\n");
1115 return -CMDERR_BADCFG;
1121 * @brief Send given data through the FlexRay in selected slot.
1123 * @param[in] cmd_io Pointer to IO stack
1124 * @param[in] des Pointer to command descriptor
1125 * @param[in] param Parameters of command
1126 * @return 0 when OK or error code
1128 int cmd_do_fr_transmittxlpdu(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1129 int8_t retVal = ERR_PARAM_NO_ERROR;
1132 int values[MAX_PARAM_VALUES_NUM];
1133 uint8_t data[MAX_PARAM_VALUES_NUM];
1136 if (sscanf(param[1], "%d", &slotID) != 1) {
1137 return -CMDERR_BADPAR;
1139 if (sscanf(param[2], " %2x", &values[0]) != 1) {
1140 return -CMDERR_BADPAR;
1142 data[0] = (uint8_t)values[0];
1143 token = strtok(param[2], " ");
1144 token = strtok(NULL, " ");
1146 while (dataLength < MAX_PARAM_VALUES_NUM && token != NULL) {
1147 if (sscanf(token, "%2x", &values[dataLength]) == EOF) {
1150 data[dataLength] = (uint8_t)values[dataLength];
1151 token = strtok(NULL, " ");
1155 retVal = rpp_fr_transmit_lpdu(0, slotID, data, dataLength);
1156 if (retVal == SUCCESS) {
1157 rpp_sci_printf("Data were set for transmission.\r\n");
1160 rpp_sci_printf("General error.\r\n");
1161 return -CMDERR_BADCFG;
1167 * @brief Cancel the transmission in the selected slot.
1169 * @param[in] cmd_io Pointer to IO stack
1170 * @param[in] des Pointer to command descriptor
1171 * @param[in] param Parameters of command
1172 * @return 0 when OK or error code
1174 int cmd_do_fr_canceltxlpdu(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1175 int8_t retVal = ERR_PARAM_NO_ERROR;
1178 if (sscanf(param[1], "%d", &slotID) != 1) {
1179 return -CMDERR_BADPAR;
1181 if (param[2] != NULL) {
1182 return -CMDERR_BADPAR;
1185 retVal = rpp_fr_cancel_transmit_lpdu(0, slotID);
1186 if (retVal == SUCCESS) {
1187 rpp_sci_printf("Transmission canceled.\r\n");
1190 rpp_sci_printf("General error.\r\n");
1191 return -CMDERR_BADCFG;
1197 * @brief Receive data from selected slot.
1199 * @param[in] cmd_io Pointer to IO stack
1200 * @param[in] des Pointer to command descriptor
1201 * @param[in] param Parameters of command
1202 * @return 0 when OK or error code
1204 int cmd_do_fr_receiverxlpdu(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1205 int8_t retVal = ERR_PARAM_NO_ERROR;
1207 uint8_t data[cPayloadLengthMax];
1208 Fr_RxLPduStatusType status;
1209 uint8_t receivedLength = 0;
1212 if (sscanf(param[1], "%d", &slotID) != 1) {
1213 return -CMDERR_BADPAR;
1215 if (param[2] != NULL) {
1216 return -CMDERR_BADPAR;
1219 retVal = rpp_fr_receive_lpdu(0, slotID, data, &status, &receivedLength);
1220 if (retVal == SUCCESS) {
1222 case FR_RECEIVED_MORE_DATA_AVAILABLE:
1223 rpp_sci_printf("More messages are still in FIFO:\r\n");
1225 rpp_sci_printf("Received message (%d B):\r\n", receivedLength);
1226 for (i = 0; i < receivedLength; i++) {
1227 rpp_sci_printf(" %02x", data[i]);
1229 rpp_sci_printf("\r\n");
1232 rpp_sci_printf("No message received.\r\n");
1237 rpp_sci_printf("General error.\r\n");
1238 return -CMDERR_BADCFG;
1244 * @brief Returns TX LPdu status.
1246 * @param[in] cmd_io Pointer to IO stack
1247 * @param[in] des Pointer to command descriptor
1248 * @param[in] param Parameters of command
1249 * @return 0 when OK or error code
1251 int cmd_do_fr_checktxlpdustatus(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1252 int8_t retVal = ERR_PARAM_NO_ERROR;
1254 Fr_TxLPduStatusType status;
1255 char* statusStrings[] = {"is not", "is"};
1257 if (sscanf(param[1], "%d", &slotID) != 1) {
1258 return -CMDERR_BADPAR;
1260 if (param[2] != NULL) {
1261 return -CMDERR_BADPAR;
1264 retVal = rpp_fr_check_tx_lpdu_status(0, slotID, &status);
1265 if (retVal == SUCCESS) {
1266 rpp_sci_printf("Message transmission %s pending.\r\n", statusStrings[status]);
1269 rpp_sci_printf("General error.\r\n");
1270 return -CMDERR_BADCFG;
1276 * @brief Disable buffer.
1278 * @param[in] cmd_io Pointer to IO stack
1279 * @param[in] des Pointer to command descriptor
1280 * @param[in] param Parameters of command
1281 * @return 0 when OK or error code
1283 int cmd_do_fr_disablelpdu(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1284 int8_t retVal = ERR_PARAM_NO_ERROR;
1287 if (sscanf(param[1], "%d", &slotID) != 1) {
1288 return -CMDERR_BADPAR;
1290 if (param[2] != NULL) {
1291 return -CMDERR_BADPAR;
1294 retVal = rpp_fr_disable_lpdu(0, slotID);
1295 if (retVal == SUCCESS) {
1296 rpp_sci_printf("Buffer disabled.\r\n");
1299 rpp_sci_printf("General error.\r\n");
1300 return -CMDERR_BADCFG;
1306 * @brief Print global time of the FlexRay network.
1308 * @param[in] cmd_io Pointer to IO stack
1309 * @param[in] des Pointer to command descriptor
1310 * @param[in] param Parameters of command
1311 * @return 0 when OK or error code
1313 int cmd_do_fr_getglobaltime(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1314 int8_t retVal = ERR_PARAM_NO_ERROR;
1316 uint16_t macroTick = 0;
1318 retVal = rpp_fr_get_global_time(0, &cycle, ¯oTick);
1319 if (retVal == SUCCESS) {
1320 rpp_sci_printf("Cycle number: %d\r\nMacrotick number: %d\r\n", cycle, macroTick);
1323 rpp_sci_printf("General error.\r\n");
1324 return -CMDERR_BADCFG;
1330 * @brief Print network management vector of the FlexRay node.
1332 * @param[in] cmd_io Pointer to IO stack
1333 * @param[in] des Pointer to command descriptor
1334 * @param[in] param Parameters of command
1335 * @return 0 when OK or error code
1337 int cmd_do_fr_getnmvector(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1338 int8_t retVal = ERR_PARAM_NO_ERROR;
1339 uint8_t nmVector[12];
1342 retVal = rpp_fr_get_network_management_vector(0, nmVector);
1343 if (retVal == SUCCESS) {
1344 rpp_sci_printf("Network management vector:");
1345 for (i = 0; i < Fr_cluster_config.gNetworkManagementVectorLength; i++) {
1346 rpp_sci_printf(" %x", nmVector[i]);
1348 rpp_sci_printf("\r\n");
1351 rpp_sci_printf("General error.\r\n");
1352 return -CMDERR_BADCFG;
1357 int cmd_do_fr_nmwatch(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1358 int8_t retVal = ERR_PARAM_NO_ERROR;
1359 uint8_t nmVector[12];
1362 // Calculate wait time in OS ticks
1363 static const portTickType freq_ticks = 100 /* ms */ / portTICK_RATE_MS;
1364 portTickType last_wake_time = xTaskGetTickCount();
1366 while(cmd_io->getc(cmd_io) < 0) {
1367 retVal = rpp_fr_get_network_management_vector(0, nmVector);
1368 if (retVal == SUCCESS) {
1369 rpp_sci_printf("Network management vector:");
1370 for (i = 0; i < Fr_cluster_config.gNetworkManagementVectorLength; i++) {
1371 rpp_sci_printf(" %02x", nmVector[i]);
1373 rpp_sci_printf("\r");
1376 rpp_sci_printf("General error.\r\n");
1377 return -CMDERR_BADCFG;
1379 vTaskDelayUntil(&last_wake_time, freq_ticks);
1381 rpp_sci_printf("\n");
1386 * @brief Print both channels status of the FlexRay node.
1388 * @param[in] cmd_io Pointer to IO stack
1389 * @param[in] des Pointer to command descriptor
1390 * @param[in] param Parameters of command
1391 * @return 0 when OK or error code
1393 int cmd_do_fr_getchannelstatus(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1394 int8_t retVal = ERR_PARAM_NO_ERROR;
1397 char* decodeStrings[] = {
1398 "aggregated channel status vSS!ValidFrame",
1399 "aggregated channel status vSS!SyntaxError",
1400 "aggregated channel status vSS!ContentError",
1401 "aggregated channel status additional communication",
1402 "aggregated channel status vSS!Bviolation",
1403 "aggregated channel status vSS!TxConflict",
1406 "symbol window status data vSS!ValidMTS",
1407 "symbol window status data vSS!SyntaxError",
1408 "symbol window status data vSS!Bviolation",
1409 "symbol window status data vSS!TxConflict",
1410 "NIT status data vSS!SyntaxError",
1411 "NIT status data vSS!Bviolation",
1415 char* channelNames[] = {"A", "B"};
1416 char* boolStrings[] = {"FALSE", "TRUE"};
1417 uint16_t channelStatuses[2];
1419 retVal = rpp_fr_get_channel_status(0, &channelStatuses[0], &channelStatuses[1]);
1420 if (retVal == SUCCESS) {
1421 for (channel = 0; channel < 2; channel++) {
1422 rpp_sci_printf("Channel %s status:\r\n", channelNames[channel]);
1423 for (index = 0; index < 16; index++) {
1424 rpp_sci_printf("\t%s: %s\r\n", decodeStrings[index], boolStrings[ (channelStatuses[channel] >> index) & 0x1 ] );
1429 rpp_sci_printf("General error.\r\n");
1430 return -CMDERR_BADCFG;
1436 * @brief Print clock correction of the FlexRay node
1438 * @param[in] cmd_io Pointer to IO stack
1439 * @param[in] des Pointer to command descriptor
1440 * @param[in] param Parameters of command
1441 * @return 0 when OK or error code
1443 int cmd_do_fr_getclockcorrection(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1444 int8_t retVal = ERR_PARAM_NO_ERROR;
1445 int16_t rateCorrection;
1446 int32_t offsetCorrection;
1448 retVal = rpp_fr_get_clock_correction(0, &rateCorrection, &offsetCorrection);
1449 if (retVal == SUCCESS) {
1450 rpp_sci_printf("Rate correction: %d\r\nOffset correction: %d\r\n", rateCorrection, offsetCorrection);
1453 rpp_sci_printf("General error.\r\n");
1454 return -CMDERR_BADCFG;
1460 * @brief Print list of syncframec transmitted on both channels via the even and odd cycle.
1462 * @param[in] cmd_io Pointer to IO stack
1463 * @param[in] des Pointer to command descriptor
1464 * @param[in] param Parameters of command
1465 * @return 0 when OK or error code
1467 int cmd_do_fr_getsyncframelist(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1468 int8_t retVal = ERR_PARAM_NO_ERROR;
1469 uint16_t channelAEvenList[FR_MAX_SYNC_FRAME_LIST_SIZE];
1470 uint16_t channelBEvenList[FR_MAX_SYNC_FRAME_LIST_SIZE];
1471 uint16_t channelAOddList[FR_MAX_SYNC_FRAME_LIST_SIZE];
1472 uint16_t channelBOddList[FR_MAX_SYNC_FRAME_LIST_SIZE];
1473 uint32_t listSize = 0;
1476 if (sscanf(param[1], "%d", &listSize) != 1) {
1477 return -CMDERR_BADPAR;
1479 if (param[2] != NULL) {
1480 return -CMDERR_BADPAR;
1482 if (listSize > FR_MAX_SYNC_FRAME_LIST_SIZE) {
1483 return -CMDERR_BADPAR;
1486 retVal = rpp_fr_get_sync_frame_list(0, listSize, channelAEvenList, channelBEvenList, channelAOddList, channelBOddList);
1487 if (retVal == SUCCESS) {
1488 rpp_sci_printf("| Channel A even | channel B even | channel A odd | channel B odd |\r\n");
1489 rpp_sci_printf("|----------------|----------------|----------------|----------------|\r\n");
1490 for (i = 0; i < listSize; i++) {
1491 rpp_sci_printf("| %-14x | %-14x | %-14x | %-14x |\r\n", channelAEvenList[i], channelBEvenList[i], channelAOddList[i], channelBOddList[i]);
1493 rpp_sci_printf("|----------------|----------------|----------------|----------------|\r\n");
1497 rpp_sci_printf("General error.\r\n");
1498 return -CMDERR_BADCFG;
1504 * @brief Print status of wakeup on each channels (wakeup received on channel or not yet received).
1506 * @param[in] cmd_io Pointer to IO stack
1507 * @param[in] des Pointer to command descriptor
1508 * @param[in] param Parameters of command
1509 * @return 0 when OK or error code
1511 int cmd_do_fr_getwakeuprxstatus(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1512 int8_t retVal = ERR_PARAM_NO_ERROR;
1514 char* statusStrings[] = {"was not yet", "was"};
1515 char* channelNames[] = {"A", "B"};
1518 retVal = rpp_fr_get_wakeup_rx_status(0, &status);
1519 if (retVal == SUCCESS) {
1520 for (i = 0; i < 2; i++) {
1521 rpp_sci_printf("Wake up pattern %s received on channel %s.\r\n", statusStrings[(status >> i) & 0x1], channelNames[i]);
1525 rpp_sci_printf("General error.\r\n");
1526 return -CMDERR_BADCFG;
1532 * @brief Set and start absolute timer.
1534 * @param[in] cmd_io Pointer to IO stack
1535 * @param[in] des Pointer to command descriptor
1536 * @param[in] param Parameters of command
1537 * @return 0 when OK or error code
1539 int cmd_do_fr_settimer(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1540 int8_t retVal = ERR_PARAM_NO_ERROR;
1545 if (sscanf(param[1], "%i %i %i", &timer, &cycle, &offset) != 3) {
1546 return -CMDERR_BADPAR;
1549 retVal = rpp_fr_set_timer(0, timer, cycle, offset);
1550 if (retVal == SUCCESS) {
1552 while (i && (cycle & i) == 0)
1557 rpp_sci_printf("Timer was set for every %d-th cycle, offset %d, macrotick %d\n",
1558 i, cycle & ~i, offset);
1561 rpp_sci_printf("General error.\r\n");
1562 return -CMDERR_BADCFG;
1568 * @brief Cancel selected timer
1570 * @param[in] cmd_io Pointer to IO stack
1571 * @param[in] des Pointer to command descriptor
1572 * @param[in] param Parameters of command
1573 * @return 0 when OK or error code
1575 int cmd_do_fr_canceltimer(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1576 int8_t retVal = ERR_PARAM_NO_ERROR;
1579 if (sscanf(param[1], "%d", &timer) != 1) {
1580 return -CMDERR_BADPAR;
1583 if (param[2] != NULL) {
1584 return -CMDERR_BADPAR;
1587 retVal = rpp_fr_cancel_timer(0, timer);
1588 if (retVal == SUCCESS) {
1589 rpp_sci_printf("Timer was canceled.\r\n");
1592 rpp_sci_printf("General error.\r\n");
1593 return -CMDERR_BADCFG;
1599 * @brief Enable/disable, acknowledge, get timer IRQ
1601 * @param[in] cmd_io Pointer to IO stack
1602 * @param[in] des Pointer to command descriptor
1603 * @param[in] param Parameters of command
1604 * @return 0 when OK or error code
1606 int cmd_do_fr_timerirq(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1607 int8_t retVal = ERR_PARAM_NO_ERROR;
1610 boolean_t status = FALSE;
1611 char* boolStrings[] = {"FALSE", "TRUE"};
1614 if (sscanf(param[1], "%d", &timer) != 1) {
1615 return -CMDERR_BADPAR;
1618 if (param[2] == NULL) { // Get timer IRQ
1619 retVal = rpp_fr_get_timer_irq_status(0, timer, &status);
1620 if (retVal == SUCCESS) {
1621 rpp_sci_printf("IRQ = %s\r\n", boolStrings[status]);
1624 rpp_sci_printf("General error.\r\n");
1625 return -CMDERR_BADCFG;
1628 else { // Some set action
1629 if (sscanf(param[2], "%4s", str) != 1) {
1630 return -CMDERR_BADPAR;
1632 if (strcmp(str, "EN") == 0) { // Enable IRQ
1633 retVal = SUCCESS; // No interrupts imlemented
1635 else if (strcmp(str, "DIS") == 0) { // Disable IRQ
1636 retVal = SUCCESS; // No interrupts implemented
1638 else if (strcmp(str, "ACK") == 0) { // Clear IRQ
1639 retVal = rpp_fr_clear_timer_irq(0, timer);
1641 else { // Bad argument
1642 return -CMDERR_BADPAR;
1645 if (retVal == SUCCESS) {
1646 rpp_sci_printf("OK\r\n");
1649 rpp_sci_printf("General error.\r\n");
1650 return -CMDERR_BADCFG;
1657 * @brief Print FlexRay driver version info.
1659 * @param[in] cmd_io Pointer to IO stack
1660 * @param[in] des Pointer to command descriptor
1661 * @param[in] param Parameters of command
1662 * @return 0 when OK or error code
1664 int cmd_do_fr_getversioninfo(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1665 Std_VersionInfoType versionInfo;
1667 rpp_fr_get_driver_version(&versionInfo);
1668 rpp_sci_printf("vendorID: %#x\r\n", versionInfo.vendorID);
1669 rpp_sci_printf("moduleID: %#x\r\n", versionInfo.moduleID);
1670 rpp_sci_printf("sw_major_version: %#x\r\n", versionInfo.sw_major_version);
1671 rpp_sci_printf("sw_minor_version: %#x\r\n", versionInfo.sw_minor_version);
1672 rpp_sci_printf("sw_patch_version: %#x\r\n", versionInfo.sw_patch_version);
1678 * @brief Print value of FlexRay configuratoin parameter.
1680 * @param[in] cmd_io Pointer to IO stack
1681 * @param[in] des Pointer to command descriptor
1682 * @param[in] param Parameters of command
1683 * @return 0 when OK or error code
1685 int cmd_do_fr_readcconfig(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1686 int8_t retVal = ERR_PARAM_NO_ERROR;
1690 if (sscanf(param[1], "%d", &index) != 1) {
1691 return -CMDERR_BADPAR;
1694 if (param[2] != NULL) {
1695 return -CMDERR_BADPAR;
1698 retVal = rpp_fr_read_com_ctrl_config(0, index, &value);
1699 if (retVal == SUCCESS) {
1700 rpp_sci_printf("Value = %#x\r\n", value);
1703 rpp_sci_printf("General error.\r\n");
1704 return -CMDERR_BADCFG;
1711 /** Command descriptor for FlexRay user config cluster command */
1712 cmd_des_t const cmd_des_fr_user_config={
1714 "frbtconfig*","Set the user configuration parameters",
1715 "=== Command syntax ===\n"
1717 " frbtconfig<TYPE> <PARAMS>\n"
1719 "* <TYPE> is a string specifying the type of parameters to be set. It can be: \"cluster\", \"node\", or \"fifo\",\n"
1720 "* <PARAMS> is a sequence of numbers separated by spaces. Each number stands for one parameter.\n"
1722 "=== Description ===\n"
1724 "The command takes the configuration parameters in the form of a string\n"
1725 "and sets the appropriate type of the FlexRay parameters. It is\n"
1726 "necessary to configure parameters of at least cluster, and node and\n"
1727 "one static buffer (see frbtcfgbuf command). The parameters set by this\n"
1728 "command are applied by the frbtinitU command. Once frbtinit is called,\n"
1729 "it is no longer possible to change the parameters.\n"
1731 "The type of the parameters can be selected by the <TYPE> selector.\n"
1733 "Type \"cluster\" sets global FlexRay network parameters. It expects a\n"
1734 "sequence of 25 parameters in this order:\n"
1735 "* 1) gColdStartAttempts\n"
1736 "* 2) gListenNoise\n"
1737 "* 3) gMacroPerCycle\n"
1738 "* 4) gMaxWithoutClockCorrectionFatal\n"
1739 "* 5) gMaxWithoutClockCorrectionPassive\n"
1740 "* 6) gNetworkManagementVectorLength\n"
1741 "* 7) gNumberOfMinislots\n"
1742 "* 8) gNumberOfStaticSlots\n"
1743 "* 9) gOffsetCorrectionStart\n"
1744 "* 10) gPayloadLengthStatic\n"
1745 "* 11) gSyncNodeMax\n"
1746 "* 12) gdActionPointOffset\n"
1747 "* 13) gdCASRxLowMax\n"
1748 "* 14) gdDynamicSlotIdlePhase\n"
1749 "* 15) gdMinislot\n"
1750 "* 16) gdMinislotActionPointOffset\n"
1752 "* 18) gdSampleClockPeriod\n"
1753 "* 19) gdStaticSlot\n"
1754 "* 20) gdTSSTransmitter\n"
1755 "* 21) gdWakeupSymbolRxIdle\n"
1756 "* 22) gdWakeupSymbolRxLow\n"
1757 "* 23) gdWakeupSymbolRxWindow\n"
1758 "* 24) gdWakeupSymbolTxIdle\n"
1759 "* 25) gdWakeupSymbolTxLow\n"
1761 "Type \"node\" sets local FlexRay network parameters. It expects a\n"
1762 "sequence of 28 parameters in this order:\n"
1763 "* 1) pAllowHaltDueToClock\n"
1764 "* 2) pAllowPassiveToActive\n"
1765 "* 3) pChannels (0 - A, 1 - B, 2 - AB)\n"
1766 "* 4) pClusterDriftDamping\n"
1767 "* 5) pDelayCompensationA\n"
1768 "* 6) pDelayCompensationB\n"
1769 "* 7) pExternOffsetCorrection\n"
1770 "* 8) pExternRateCorrection\n"
1771 "* 9) pKeySlotUsedForStartup\n"
1772 "* 10) pKeySlotUsedForSync\n"
1774 "* 12) pMacroInitialOffsetA\n"
1775 "* 13) pMacroInitialOffsetB\n"
1776 "* 14) pMicroInitialOffsetA\n"
1777 "* 15) pMicroInitialOffsetB\n"
1778 "* 16) pMicroPerCycle\n"
1779 "* 17) pRateCorrectionOut\n"
1780 "* 18) pOffsetCorrectionOut\n"
1781 "* 19) pSamplesPerMicrotick\n"
1782 "* 20) pSingleSlotEnabled\n"
1783 "* 21) pWakeupChannel (0 - A, 1 - B)\n"
1784 "* 22) pWakeupPattern\n"
1785 "* 23) pdAcceptedStartupRange\n"
1786 "* 24) pdListenTimeout\n"
1787 "* 25) pdMaxDrift\n"
1788 "* 26) pDecodingCorrection\n"
1789 "* 27) syncFramePayloadMultiplexEnabled\n"
1790 "* 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"
1792 "Type \"fifo\" adds a configuration of a new FIFO buffer. No FIFO\n"
1793 "buffer is obligatory. It expects a sequence of 7 parameters in this\n"
1795 "*1) depth of the FIFO\n"
1796 "*2) channel (0 - A, 1 - B, 2 - AB)\n"
1797 "*3) cycleCounterFiltering\n"
1798 "*4) maxPayload (number of 16b words)\n"
1799 "*5) rejectNullFrames\n"
1800 "*6) rejectStaticSegment\n"
1805 " --> 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"
1806 " FlexRay cluster configuration accepted.\n"
1807 " --> 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"
1808 " FlexRay node configuration accepted.\n",
1809 CMD_HANDLER(cmd_do_fr_user_config), (void *)&cmd_list_fr_basic_test
1812 cmd_des_t const cmd_des_fr_config_buffer={
1814 "frbtcfgbuf?*","Configure a message buffer in the user configuration",
1815 "=== Command syntax ===\n"
1817 " frbtcfgbuf<TYPE><NUM> slot<SLOT> <CHN> cyc<CYC> <RXTX> max<MAX> <REP> ppi<PPI> int<INT>\n"
1819 "* <TYPE> is 'S' for static segment buffers and 'D' for dynamic segment buffers,\n"
1820 "* <NUM> is the number of the buffer. Both static and dynamic buffers are numbered independently starting from zero,\n"
1821 "* <SLOT> is the number of the slot,\n"
1822 "* <CHN> is one of 'A', 'B' or 'AB' and identifies the used channel,\n"
1823 "* <CYC> is the cycle set when to send the buffer,\n"
1824 "* <RXTX> is either string \"rx\" or \"tx\",\n"
1825 "* <MAX> is the number determining the maximum payload (in hald-words),\n"
1826 "* <REP> is a string \"s\" or \"single\" for single transmission or \"c\" or \"continuous\" for continuous transmission,\n"
1827 "* <PPI> is 0 or 1 determining whether the payload preamble indicator is set,\n"
1828 "* <INT> is 0 or 1 add is currently ignored.\n"
1830 "=== Description ===\n"
1832 "The command sets the configuration parameters for static or dynamic\n"
1833 "buffers in user configuration. The parameters set by this command are\n"
1834 "applied by the frbtinitU command. Once frbtinit is called, it is no\n"
1835 "longer possible to change the parameters.\n"
1839 " --> frbtcfgbufS0 slot2 AB cyc0 tx max9 continous ppi0 int1\n"
1840 " frbtcfgbufS0 slot2 AB cyc0 tx max9 continous ppi0 int1\n"
1841 " --> frbtcfgbufS1 slot1 AB cyc0 rx max9 continuous ppi0 int1\n"
1842 " frbtcfgbufS1 slot1 AB cyc0 rx max9 continuous ppi0 int1\n"
1843 " --> frbtcfgbufD0 slot9 A cyc0 rx max0x40 single ppi0 int0\n"
1844 " frbtcfgbufD0 slot9 A cyc0 rx max64 single ppi0 int0\n"
1845 " --> frbtcfgbufD1 slot10 A cyc0 tx max0x40 single ppi0 int0\n"
1846 " frbtcfgbufD1 slot10 A cyc0 tx max64 single ppi0 int0\n",
1847 CMD_HANDLER(cmd_do_fr_config_bufer), (void *)&cmd_list_fr_basic_test
1851 /** Command descriptor for FlexRay init command */
1852 cmd_des_t const cmd_des_fr_init={
1854 "frbtinit?","Initialize a FlexRay node",
1855 "=== Command syntax ===\n"
1859 "where <CFG> identifies the configuration to use. It can be one of A, B\n"
1860 "or U. The A and B are predefined configurations. If U is specified,\n"
1861 "the user configuration previously set by frbtconfig command is used.\n"
1863 "=== Description ===\n"
1865 "The command stands for Fr_Init and Fr_ControllerInit functions from\n"
1866 "the Autosar specification. It initializes the internal data structures\n"
1867 "of the driver and then, based on those data, the controller\n"
1868 "configuration is done. During the controller configuration the\n"
1869 "parameters of the cluster, node, message RAM and buffers are checked.\n"
1870 "If anything goes bad, the command returns an error number, which can\n"
1871 "be decoded by macros defined in driver header file fr_tms570.h with\n"
1872 "prefix ERR_PARAM. If all parameters are OK, all necessary registers of\n"
1873 "the controller are initialized according to the specified\n"
1874 "configuration parameters. At the end of the command, the FlexRay\n"
1875 "controller is switched into READY state and all buffers are configured\n"
1876 "to send NULL frames. This command should be called as the very first\n"
1877 "command, when trying to communicate over the FlexRay bus.\n"
1882 " FlexRay driver initialized.\n"
1883 " FlexRay controller initialized.\n",
1884 CMD_HANDLER(cmd_do_fr_init), (void *)&cmd_list_fr_basic_test
1887 /** Command descriptor for FlexRay controller init command */
1888 cmd_des_t const cmd_des_fr_start={
1890 "frbtstart","Start a new FlexRay network or join to the existing one",
1891 "=== Command syntax ===\n"
1895 "=== Description ===\n"
1897 "The command stands for Fr_StartCommunication function from the Autosar\n"
1898 "specification. If the FlexRay node is configured as a coldstarter node\n"
1899 "(as for example by frbtinitA/B command), then the command first listen\n"
1900 "on the bus. When it does not detect any existing bus communication, it\n"
1901 "tries to initiate a new network. If the initiation fails, the FlexRay\n"
1902 "controller is switched back to the ready state for another attempt\n"
1903 "(calling frbtstart again). If the FlexRay node is configured as\n"
1904 "non-coldstarter, it is listening on the bus until some existing\n"
1905 "communication is detected.\n"
1907 "The command should be called after the frbtinit command.\n"
1912 " FlexRay communication is running.\n",
1913 CMD_HANDLER(cmd_do_fr_start), (void *)&cmd_list_fr_basic_test
1916 /** Command descriptor for FlexRay controller all slots command */
1917 cmd_des_t const cmd_des_fr_allslots={
1919 "frbtallslots","Enables communication for all frames",
1920 "=== Command syntax ===\n"
1924 "=== Description ===\n"
1926 "The command stands for Fr_AllSlots function from the Autosar\n"
1929 "The node can be configured to communicate only on key frames by\n"
1930 "default (as in the case of frbtinitA/B). This command can be used to\n"
1931 "allow the communication on all configured frames. The command invokes\n"
1932 "the FlexRay POC command ALL_SLOTS which enables the communication on\n"
1933 "all frames. The command can be called after the controller\n"
1938 " --> frbtallslots\n"
1939 " FlexRay node started communication on all slots.\n",
1940 CMD_HANDLER(cmd_do_fr_allslots), (void *)&cmd_list_fr_basic_test
1943 /** Command descriptor for FlexRay controller halt command */
1944 cmd_des_t const cmd_des_fr_halt={
1946 "frbthalt","Halt FlexRay communication after the end of the actual communication cycle",
1947 "=== Command syntax ===\n"
1951 "=== Description ===\n"
1953 "The command stands for Fr_HaltCommunication function from the Autosar\n"
1954 "specification. The command invokes the FlexRay POC command HALT, which\n"
1955 "means that communication is stopped after the end of the actual\n"
1956 "communication cycle. On the opposite side, there is a frbtfreeze\n"
1957 "command, which stops the communication immediately. To start the\n"
1958 "communication again, the device has to be reset.\n"
1963 " FlexRay node communication halted.\n",
1964 CMD_HANDLER(cmd_do_fr_halt), (void *)&cmd_list_fr_basic_test
1967 /** Command descriptor for FlexRay controller abort command */
1968 cmd_des_t const cmd_des_fr_abort={
1970 "frbtabort","Abort FlexRay communication immediately",
1971 "=== Command syntax ===\n"
1975 "=== Description ===\n"
1977 "The command stands for Fr_AbortCommunication function from the Autosar\n"
1978 "specification. The command invokes the FlexRay POC command FREEZE,\n"
1979 "which means that the communication is stopped immediately. On the\n"
1980 "opposite side there is a frbthalt command, which stops the\n"
1981 "communication after the end of the actual communication cycle. To\n"
1982 "start the communication again, the device has to be reset.\n"
1987 " FlexRay node communication aborted.\n",
1988 CMD_HANDLER(cmd_do_fr_abort), (void *)&cmd_list_fr_basic_test
1991 /** Command descriptor for FlexRay controller send wake up pattern command */
1992 cmd_des_t const cmd_des_fr_sendwup={
1994 "frbtwup","Initiate the wake up procedure",
1995 "=== Command syntax ===\n"
1999 "=== Description ===\n"
2001 "The command stands for Fr_SendWUP function from the Autosar\n"
2002 "specification. It initiates the wake up procedure by switching FlexRay\n"
2003 "controller state machine to WAKEUP state.\n"
2008 " Wake up pattern has been sent.\n",
2009 CMD_HANDLER(cmd_do_fr_sendwup), (void *)&cmd_list_fr_basic_test
2012 /** Command descriptor for FlexRay controller sent wake up pattern channel command */
2013 cmd_des_t const cmd_des_fr_setwuchannel={
2015 "frbtsetwuch?","Set wake up channel",
2016 "=== Command syntax ===\n"
2018 " frbtsetwuch<CHANNEL>\n"
2020 "where <CHANNEL> is a character A or B, specifying the channel.\n"
2022 "=== Description ===\n"
2024 "The command stands for Fr_SetWakeupChannel function from the Autosar\n"
2025 "specification. Wake up channel is the channel, where Wake Up Pattern\n"
2026 "is sent. The channel can be set after the driver and controller are\n"
2027 "initialized and before the communication is running. The actual\n"
2028 "wake-up pattern is sent by the frbtwup command.\n"
2032 " --> frbtsetwuchA\n"
2033 " Wake up channel has been set.\n",
2034 CMD_HANDLER(cmd_do_fr_setwuchannel), (void *)&cmd_list_fr_basic_test
2037 /** Command descriptor for FlexRay controller get POC status command */
2038 cmd_des_t const cmd_des_fr_getpocstatus={
2040 "frbtgetpocst","Print FlexRay POC status",
2041 "=== Command syntax ===\n"
2045 "=== Description ===\n"
2047 "The command stands for Fr_GetPOCStatus function from the Autosar\n"
2048 "specification. It prints the main FlexRay POC status values in the\n"
2049 "form of a table. The command should be called after the frbtinit\n"
2054 " --> frbtgetpocst\n"
2056 " CHIHaltRequest: FALSE\n"
2057 " CHIReadyRequest: FALSE\n"
2058 " ColdstartNoise: FALSE\n"
2060 " ErrorMode: ACTIVE\n"
2062 " StartupState: UNDEFINED\n"
2064 " WakeupStatus: UNDEFINED\n",
2065 CMD_HANDLER(cmd_do_fr_getpocstatus), (void *)&cmd_list_fr_basic_test
2068 /** Command descriptor for FlexRay transmit tx lpdu command */
2069 cmd_des_t const cmd_des_fr_transmittxlpdu={
2071 "frbttransmit*","Transmit data in selected frame",
2072 "=== Command syntax ===\n"
2074 " frbttransmit<FRID> <DATA>\n"
2076 "* <FRID> is a decimal number specifying the ID of the frame for which a buffer has been configured.\n"
2077 "* <DATA> is a sequence of hexadecimal numbers separated by spaces. Each number represents one byte of the message.\n"
2079 "=== Description ===\n"
2081 "The command stands for Fr_TransmitTxLPdu function from the Autosar\n"
2082 "specification. The command finds the first buffer assigned to the\n"
2083 "specified frame ID and copies the given data into its data section in\n"
2084 "the message RAM. Transmit request is set after the data are copied, so\n"
2085 "transmission starts at the next occurrence of the frame in the\n"
2086 "communication cycle.\n"
2090 " --> frbttransmit1 12 34 56 AA BB CC\n"
2091 " Data were set for transmission.\n",
2092 CMD_HANDLER(cmd_do_fr_transmittxlpdu), (void *)&cmd_list_fr_basic_test
2095 /** Command descriptor for FlexRay cancel tx lpdu command */
2096 cmd_des_t const cmd_des_fr_canceltxlpdu={
2098 "frbtcanceltx*","Stop the transmission of the frame",
2099 "=== Command syntax ===\n"
2101 " frbtcanceltx<FRID>\n"
2103 "where <FRID> is a decimal number specifying the ID of the frame for\n"
2104 "which a buffer has been configured.\n"
2106 "=== Description ===\n"
2108 "The command stands for Fr_CancelTxLPdu function from the Autosar\n"
2109 "specification. The command finds all buffers assigned to the specified\n"
2110 "frame ID and reconfigures them to stop transmitting data. The command\n"
2111 "finishes successfully only if reconfiguration is allowed in message\n"
2112 "RAM configuration (secureBuffers configuration parameter). Only TX\n"
2113 "buffers and buffers not used for startup frames can be canceled.\n"
2117 " --> frbtcanceltx3\n"
2118 " Transmission canceled.\n",
2119 CMD_HANDLER(cmd_do_fr_canceltxlpdu), (void *)&cmd_list_fr_basic_test
2122 /** Command descriptor for FlexRay receive rx lpdu command */
2123 cmd_des_t const cmd_des_fr_receiverxlpdu={
2125 "frbtreceive*","Receive a new message",
2126 "=== Command syntax ===\n"
2128 " frbtreceive<FRID>\n"
2130 "where <FRID> is a decimal number specifying the ID of the frame for\n"
2131 "which a buffer was configured.\n"
2133 "=== Description ===\n"
2135 "The command stands for Fr_ReceiveRxLPdu function from the Autosar\n"
2136 "specification. The command finds the first buffer assigned to the\n"
2137 "specified frame ID, determines if a new message has been received and\n"
2138 "reads it out of the buffer. If no message was received, \"No message\n"
2139 "received\" is printed. If a new message was received, all message data\n"
2140 "are printed as a hexadecimal values. If a new message was retrieved\n"
2141 "from a FIFO buffer and more messages are available in it, \"More\n"
2142 "messages are still in FIFO\" is printed.\n"
2146 " --> frbtreceive0\n"
2147 " More messages are still in FIFO:\n"
2148 " Received message (32 B):\n"
2149 " ee ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\n",
2150 CMD_HANDLER(cmd_do_fr_receiverxlpdu), (void *)&cmd_list_fr_basic_test
2153 /** Command descriptor for FlexRay check TX LPdu status command */
2154 cmd_des_t const cmd_des_fr_checktxlpdustatus={
2156 "frbtchecktx*","Print the status of the transmit buffer",
2157 "=== Command syntax ===\n"
2159 " frbtchecktx<FRID>\n"
2161 "where <FRID> is a decimal number specifying the ID of the frame for\n"
2162 "which a buffer has been configured.\n"
2164 "=== Description ===\n"
2166 "The command stands for Fr_CheckTxLPduStatus function from the Autosar\n"
2167 "specification. The command finds the first buffer assigned to the\n"
2168 "specified frame ID, reads its status and prints it. The buffer can be\n"
2169 "in one of the two states:\n"
2170 "* Message transmission is pending, which means that the buffer has not yet sent its message in single shot mode or that it is in continuous mode.\n"
2171 "* No message transmission is pending, which means that the buffer is in single shot mode and the message has already been sent.\n"
2175 " --> frbtchecktx1\n"
2176 " Message transmission is not pending.\n",
2177 CMD_HANDLER(cmd_do_fr_checktxlpdustatus), (void *)&cmd_list_fr_basic_test
2180 /** Command descriptor for FlexRay disable LPdu command */
2181 cmd_des_t const cmd_des_fr_disablelpdu={
2183 "frbtdisable*","Disable the buffers assigned to the frame",
2184 "=== Command syntax ===\n"
2186 " frbtdisable<FRID>\n"
2188 "where <FRID> is a decimal number specifying the ID of a frame. The\n"
2189 "buffers configure for this frame will be disabled.\n"
2191 "=== Description ===\n"
2193 "The command stands for Fr_DisableLPdu function from the Autosar\n"
2194 "specification. The command finds all buffers assigned to the specified\n"
2195 "frame ID and disables them. This means that those buffers will be\n"
2196 "unavailable for the communication until their reconfiguration (which\n"
2197 "is not yet implemented). Buffers used for startup frames and FIFO RX\n"
2198 "buffers cannot be disabled.\n"
2202 " --> frbtdisable3\n"
2203 " Buffer disabled.\n",
2204 CMD_HANDLER(cmd_do_fr_disablelpdu), (void *)&cmd_list_fr_basic_test
2207 /** Command descriptor for FlexRay get global time command */
2208 cmd_des_t const cmd_des_fr_getglobaltime={
2210 "frbtglobtime","Print actual global time of the network",
2211 "=== Command syntax ===\n"
2215 "=== Description ===\n"
2217 "The command stands for Fr_GetGlobalTime function from the Autosar\n"
2218 "specification. The command prints the time as a number of the current\n"
2219 "cycle and the offset in the cycle in macroticks.\n"
2223 " --> frbtglobtime\n"
2224 " Cycle number: 23\n"
2225 " Macrotick number: 6\n",
2226 CMD_HANDLER(cmd_do_fr_getglobaltime), (void *)&cmd_list_fr_basic_test
2229 /** Command descriptor for FlexRay get network management vector command */
2230 cmd_des_t const cmd_des_fr_getnmvector={
2232 "frbtnmvector","Print network management vector of the node",
2233 "=== Command syntax ===\n"
2237 "=== Description ===\n"
2239 "The command stands for Fr_GetNmVector function from the Autosar\n"
2240 "specification. It prints the values of the network management vector\n"
2241 "as hexadecimal numbers.\n"
2245 " --> frbtnmvector\n"
2246 " Network management vector: 0 0 0 0 0 0 0 0 0 0 0 0\n",
2247 CMD_HANDLER(cmd_do_fr_getnmvector), (void *)&cmd_list_fr_basic_test
2250 /** Command descriptor for FlexRay get network management vector command */
2251 cmd_des_t const cmd_des_fr_nmwatch={
2253 "frbtnmwatch","Watch the changes of the network managment vector in real-time",
2254 "=== Command syntax ===\n"
2258 "=== Description ===\n"
2260 "Reads the network management vector every 100 ms and prints it out.\n"
2264 " --> frbtnmwatch\n"
2265 " Network management vector: 0 0 0 0 0 0 0 0 0 0 0 0\n",
2266 CMD_HANDLER(cmd_do_fr_nmwatch), (void *)&cmd_list_fr_basic_test
2269 /** Command descriptor for FlexRay get channel status command */
2270 cmd_des_t const cmd_des_fr_getchannelstatus={
2272 "frbtchstat","Print channel A and B status",
2273 "=== Command syntax ===\n"
2277 "=== Description ===\n"
2279 "The command stands for Fr_GetChannelStatus function from the Autosar\n"
2285 " Channel A status:\n"
2286 " aggregated channel status vSS!ValidFrame: TRUE\n"
2287 " aggregated channel status vSS!SyntaxError: FALSE\n"
2288 " aggregated channel status vSS!ContentError: FALSE\n"
2289 " aggregated channel status additional communication: FALSE\n"
2290 " aggregated channel status vSS!Bviolation: FALSE\n"
2291 " aggregated channel status vSS!TxConflict: FALSE\n"
2292 " Not used (0): FALSE\n"
2293 " Not used (0): FALSE\n"
2294 " symbol window status data vSS!ValidMTS: FALSE\n"
2295 " symbol window status data vSS!SyntaxError: FALSE\n"
2296 " symbol window status data vSS!Bviolation: FALSE\n"
2297 " symbol window status data vSS!TxConflict: FALSE\n"
2298 " NIT status data vSS!SyntaxError: FALSE\n"
2299 " NIT status data vSS!Bviolation: FALSE\n"
2300 " Not used (0): FALSE\n"
2301 " Not used (0): FALSE\n"
2302 " Channel B status:\n"
2303 " aggregated channel status vSS!ValidFrame: TRUE\n"
2304 " aggregated channel status vSS!SyntaxError: FALSE\n"
2305 " aggregated channel status vSS!ContentError: FALSE\n"
2306 " aggregated channel status additional communication: FALSE\n"
2307 " aggregated channel status vSS!Bviolation: FALSE\n"
2308 " aggregated channel status vSS!TxConflict: FALSE\n"
2309 " Not used (0): FALSE\n"
2310 " Not used (0): FALSE\n"
2311 " symbol window status data vSS!ValidMTS: FALSE\n"
2312 " symbol window status data vSS!SyntaxError: FALSE\n"
2313 " symbol window status data vSS!Bviolation: FALSE\n"
2314 " symbol window status data vSS!TxConflict: FALSE\n"
2315 " NIT status data vSS!SyntaxError: FALSE\n"
2316 " NIT status data vSS!Bviolation: FALSE\n"
2317 " Not used (0): FALSE\n"
2318 " Not used (0): FALSE\n",
2319 CMD_HANDLER(cmd_do_fr_getchannelstatus), (void *)&cmd_list_fr_basic_test
2322 /** Command descriptor for FlexRay get clock correction command */
2323 cmd_des_t const cmd_des_fr_getclockcorrection={
2325 "frbtclkcor","Print clock correction (rate and offset)",
2326 "=== Command syntax ===\n"
2330 "=== Description ===\n"
2332 "The command stands for Fr_GetClockCorrection function from the Autosar\n"
2338 " Rate correction: 0\n"
2339 " Offset correction: 0\n",
2340 CMD_HANDLER(cmd_do_fr_getclockcorrection), (void *)&cmd_list_fr_basic_test
2343 /** Command descriptor for FlexRay get sync frame list command */
2344 cmd_des_t const cmd_des_fr_getsyncframelist={
2346 "frbtgetsyncfrlist*","Print the list of sync frames transmitted on both channels via the odd and even communication cycle",
2347 "=== Command syntax ===\n"
2349 " frbtgetsyncfrlist<LENGTH>\n"
2351 "where <LENGTH> is a decimal number in range 0 - 15, specifying the\n"
2352 "length of the list to be printed.\n"
2354 "=== Description ===\n"
2356 "The command stands for Fr_GetSyncFrameList function from the Autosar\n"
2361 " --> frbtgetsyncfrlist2\n"
2362 " | Channel A even | channel B even | channel A odd | channel B odd |\n"
2363 " |----------------|----------------|----------------|----------------|\n"
2364 " | 1 | 1 | 1 | 1 |\n"
2365 " | 2 | 2 | 2 | 2 |\n"
2366 " |----------------|----------------|----------------|----------------|\n",
2367 CMD_HANDLER(cmd_do_fr_getsyncframelist), (void *)&cmd_list_fr_basic_test
2370 /** Command descriptor for FlexRay get sync frame list command */
2371 cmd_des_t const cmd_des_fr_getwakeuprxstatus={
2373 "frbtgetwurxstat","Prints whether the wake up pattern has been or has not been received",
2374 "=== Command syntax ===\n"
2376 " frbtgetwurxstat\n"
2378 "=== Description ===\n"
2380 "The command stands for Fr_GetWakeupRxStatus function from the Autosar\n"
2381 "specification. The status of the wake up receiving is bitcoded in the\n"
2382 "controller. This command decodes and prints it in a readable format.\n"
2386 " --> frbtgetwurxstat\n"
2387 " Wake up pattern was not yet received on channel A.\n"
2388 " Wake up pattern was not yet received on channel B.\n",
2389 CMD_HANDLER(cmd_do_fr_getwakeuprxstatus), (void *)&cmd_list_fr_basic_test
2392 /** Command descriptor for FlexRay set absolute timer command */
2393 cmd_des_t const cmd_des_fr_settimer={
2395 "frbtsettimer*","Set and start timer",
2396 "=== Command syntax ===\n"
2398 " frbtsettimer<TMID> <CYCLE> <OFFSET>\n"
2400 "* <TMID> is a number (0, 1) specifying the timer.\n"
2401 "* <CYCLE> is a 7-bit number (0 - 127) specifying the set of cycles, in which timer interrupt should be requested. The first set bit determines the period (1, 2, ..., 64) and the lower bits determine the offset in cycles within the period.\n"
2402 "* <OFFSET> is a decimal number (0 - 16383) specifying the offset in macroticks, where precisely in the cycle should be the timer interrupt requested.\n"
2404 "=== Description ===\n"
2406 "The command is similar to Fr_SetAbsoluteTimer function from the\n"
2407 "Autosar specification. The difference is that the command allows to\n"
2408 "specify a set of cycles, not only one of 64 cycles. It sets the timer\n"
2409 "selected by the parameter and enables it.\n"
2411 "Before using this command, FlexRay communication has to be started\n"
2412 "(see frbtstart).\n"
2416 " --> frbtsettimer0 32 50\n"
2417 " Timer was set for every 32-th cycle, offset 0, macrotick 50\n"
2418 " --> frbtsettimer0 31 50\n"
2419 " Timer was set for every 16-th cycle, offset 15, macrotick 50\n"
2420 " --> frbtsettimer0 0x42 0\n"
2421 " Timer was set for every 64-th cycle, offset 2, macrotick 0\n",
2422 CMD_HANDLER(cmd_do_fr_settimer), (void *)&cmd_list_fr_basic_test
2425 /** Command descriptor for FlexRay cancel absolute timer command */
2426 cmd_des_t const cmd_des_fr_canceltimer={
2428 "frbtcanceltimer*","Stop the timer",
2429 "=== Command syntax ===\n"
2431 " frbtcanceltimer<TMID>\n"
2432 "where <TMID> is a number (0 or 1) specifying the timer.\n"
2434 "=== Description ===\n"
2436 "The command stands for Fr_CancelAbsoluteTimer function from the\n"
2437 "Autosar specification. It stops the timer selected by the parameter.\n"
2441 " --> frbtcanceltimer0\n"
2442 " Timer was canceled.\n",
2443 CMD_HANDLER(cmd_do_fr_canceltimer), (void *)&cmd_list_fr_basic_test
2446 /** Command descriptor for FlexRay absolute timer irq manipulation command */
2447 cmd_des_t const cmd_des_fr_timerirq={
2449 "frbttimerirq*","Perform selected action on the timer IRQ",
2450 "=== Command syntax ===\n"
2452 " frbttimerirq<TMID> <ACTION> - Run the <ACTION> on specified timer\n"
2453 " frbttimerirq<TMID> - Get timer IRQ status\n"
2456 "* <TMID> is a number (0, 1) specifying the timer.\n"
2457 "* where <ACTION> is a string specifying the action to be performed on the selected timer IRQ.\n"
2459 "<ACTIONS> can be one of:\n"
2460 "* EN - Enable the IRQ on the selected timer\n"
2461 "* DIS - Disable the IRQ on the selected timer\n"
2462 "* ACK - Acknowledge the IRQ on the selected timer (reset flag in the register).\n"
2464 "=== Description ===\n"
2466 "The command stands for Fr_EnableAbsoluteTimerIRQ,\n"
2467 "Fr_AckAbsoluteTimerIRQ, Fr_DisableAbsoluteTimerIRQ and\n"
2468 "Fr_GetAbsoluteTimerIRQStatus functions from the Autosar specification.\n"
2469 "It masks or demasks the IRQ for the timer, or acknowledges the\n"
2470 "interrupt request. If no action is specified it prints whether the IRQ\n"
2471 "is pending for the timer.\n"
2475 " --> frbttimerirq0\n"
2478 " --> frbttimerirq0 EN\n"
2480 CMD_HANDLER(cmd_do_fr_timerirq), (void *)&cmd_list_fr_basic_test
2483 /** Command descriptor for FlexRay get version info command */
2484 cmd_des_t const cmd_des_fr_getversioninfo={
2486 "frbtversion","Print FlexRay driver version information",
2487 "=== Command syntax ===\n"
2491 "=== Description ===\n"
2493 "The command stands for Fr_GetVersionInfo function from the Autosar\n"
2495 "It reads and prints the information about vendor, module and version of\n"
2496 "the FlexRay driver\n"
2500 " --> frbtversion\n"
2501 " vendorID: 0xAAAA\n"
2502 " moduleID: 0xBBBB\n"
2503 " sw_major_version: 0x1\n"
2504 " sw_minor_version: 0x2\n"
2505 " sw_patch_version: 0x4\n",
2506 CMD_HANDLER(cmd_do_fr_getversioninfo), (void *)&cmd_list_fr_basic_test
2509 /** Command descriptor for FlexRay get controller configuration command */
2510 cmd_des_t const cmd_des_fr_readcconfig={
2512 "frbtccconfig*","Print value of a FlexRay cluster and node configuration parameter",
2513 "=== Command syntax ===\n"
2515 " frbtccconfig<INDEX>\n"
2517 "where <INDEX> is an identifier of the parameter.\n"
2519 "=== Description ===\n"
2521 "The command stands for Fr_ReadCCConfig function from the Autosar\n"
2522 "specification. The driver stores the configuration parameters as an\n"
2523 "array. Each parameter can be indexed and returned by this command. See\n"
2524 "Autosar specification of the FlexRay driver\n"
2525 "(http://www.autosar.org/download/R4.1/AUTOSAR_SWS_FlexRayDriver.pdf),\n"
2526 "section 8.2.1 for parameter indexes.\n"
2530 " --> frbtccconfig1\n"
2532 CMD_HANDLER(cmd_do_fr_readcconfig), (void *)&cmd_list_fr_basic_test
2535 /** List of commands for flexRay, defined as external */
2536 cmd_des_t const *cmd_list_fr_basic_test[]={
2537 &cmd_des_fr_user_config,
2538 &cmd_des_fr_config_buffer,
2541 &cmd_des_fr_allslots,
2544 &cmd_des_fr_sendwup,
2545 &cmd_des_fr_setwuchannel,
2546 &cmd_des_fr_getpocstatus,
2547 &cmd_des_fr_transmittxlpdu,
2548 &cmd_des_fr_canceltxlpdu,
2549 &cmd_des_fr_receiverxlpdu,
2550 &cmd_des_fr_checktxlpdustatus,
2551 &cmd_des_fr_disablelpdu,
2552 &cmd_des_fr_getglobaltime,
2553 &cmd_des_fr_getnmvector,
2554 &cmd_des_fr_nmwatch,
2555 &cmd_des_fr_getchannelstatus,
2556 &cmd_des_fr_getclockcorrection,
2557 &cmd_des_fr_getsyncframelist,
2558 &cmd_des_fr_getwakeuprxstatus,
2559 &cmd_des_fr_settimer,
2560 &cmd_des_fr_canceltimer,
2561 &cmd_des_fr_timerirq,
2562 &cmd_des_fr_getversioninfo,
2563 &cmd_des_fr_readcconfig,