]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blob - commands/cmd_fr_basic_test.c
137afc640f8ff4d7db3022e6f768542e9c993b9f
[pes-rpp/rpp-test-sw.git] / commands / cmd_fr_basic_test.c
1 /*
2  * Copyright (C) 2012-2013 Czech Technical University in Prague
3  *
4  * Created on: 6.8.2013
5  *
6  * Authors:
7  *     - Michal Horn
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * File : cmd_fr_basic_test.c
23  *
24  * Abstract:
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
29  *              of messages.
30  */
31
32
33 #include "cmd_fr_basic_test.h"
34
35 #ifndef DOCGEN
36
37 #include <string.h>
38 #include "cmdproc_utils.h"
39 #include "drv/drv.h"
40 #include "rpp/rpp.h"
41 #include "hal/hal.h"
42 #include "stdio.h"
43
44 #define printf rpp_sci_printf
45
46 static inline int badpar(const char *msg)
47 {
48         printf("%s", msg);
49         return -CMDERR_BADPAR;
50 }
51
52
53 /**
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.
57  */
58 static Fr_TMS570LS_ClusterConfigType Fr_cluster_config = {
59         .gColdStartAttempts = 0x2,
60         .gListenNoise = 0xF,
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,
69         .gSyncNodeMax = 0xF,
70         .gdActionPointOffset = 0x4,
71         .gdCASRxLowMax = 0x43,
72         .gdDynamicSlotIdlePhase = 0x1,
73         .gdMinislot = 0x4,
74         .gdMinislotActionPointOffset = 0x2,
75         .gdNIT = 0xAE3,
76         .gdSampleClockPeriod = 0,               // 10mbit/sec
77         .gdStaticSlot = 0x56,
78         .gdTSSTransmitter = 0xA,
79         .gdWakeupSymbolRxIdle = 18,
80         .gdWakeupSymbolRxLow = 18,
81         .gdWakeupSymbolRxWindow = 76,
82         .gdWakeupSymbolTxIdle = 180,
83         .gdWakeupSymbolTxLow = 60
84 };
85
86 /**
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.
91  */
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,
103         .pLatestTx = 0x10D,
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,
114         .pWakeupPattern = 2,
115         .pdAcceptedStartupRange = 0x81,
116         .pdListenTimeout = 0x36DA2,
117         .pdMaxDrift = 0x151,
118         .pDecodingCorrection = 0x33
119 };
120
121 /**
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.
126  */
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,
138                 .pLatestTx = 0x10D,
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,
149                 .pWakeupPattern = 2,
150                 .pdAcceptedStartupRange = 0x81,
151                 .pdListenTimeout = 0x36DA2,
152                 .pdMaxDrift = 0x151,
153                 .pDecodingCorrection = 0x33
154 };
155
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
162 };
163
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
170 };
171
172 static Fr_TMS570LS_BufferConfigType Fr_node_A_static_buffers_config[] = {
173         {
174                 .channel = FR_CHANNEL_AB,
175                 .cycleCounterFiltering = 0,
176                 .isTx = TRUE,
177                 .maxPayload = 9,
178                 .msgBufferInterrupt = TRUE,
179                 .payloadPreambleIndicatorTr = FALSE,
180                 .rejectNullFrames = FALSE,
181                 .rejectStaticSegment = FALSE,
182                 .singleTransmit = FALSE,
183                 .slotId = 1
184         },
185         {
186                 .channel = FR_CHANNEL_AB,
187                 .cycleCounterFiltering = 0,
188                 .isTx = FALSE,
189                 .maxPayload = 9,
190                 .msgBufferInterrupt = TRUE,
191                 .payloadPreambleIndicatorTr = FALSE,
192                 .rejectNullFrames = FALSE,
193                 .rejectStaticSegment = FALSE,
194                 .singleTransmit = FALSE,
195                 .slotId = 2
196         },
197         {
198                 .channel = FR_CHANNEL_AB,
199                 .cycleCounterFiltering = 0,
200                 .isTx = TRUE,
201                 .maxPayload = 9,
202                 .msgBufferInterrupt = TRUE,
203                 .payloadPreambleIndicatorTr = FALSE,
204                 .rejectNullFrames = FALSE,
205                 .rejectStaticSegment = FALSE,
206                 .singleTransmit = TRUE,
207                 .slotId = 3
208         },
209         {
210                 .channel = FR_CHANNEL_AB,
211                 .cycleCounterFiltering = 0,
212                 .isTx = FALSE,
213                 .maxPayload = 9,
214                 .msgBufferInterrupt = TRUE,
215                 .payloadPreambleIndicatorTr = FALSE,
216                 .rejectNullFrames = FALSE,
217                 .rejectStaticSegment = FALSE,
218                 .singleTransmit = TRUE,
219                 .slotId = 4
220         },
221         {
222                 .channel = FR_CHANNEL_AB,
223                 .cycleCounterFiltering = 0,
224                 .isTx = TRUE,
225                 .maxPayload = 9,
226                 .msgBufferInterrupt = TRUE,
227                 .payloadPreambleIndicatorTr = TRUE,
228                 .rejectNullFrames = FALSE,
229                 .rejectStaticSegment = FALSE,
230                 .singleTransmit = FALSE,
231                 .slotId = 5
232         }
233
234 };
235
236 static Fr_TMS570LS_BufferConfigType Fr_node_B_static_buffers_config[] = {
237         {
238                 .channel = FR_CHANNEL_AB,
239                 .cycleCounterFiltering = 0,
240                 .isTx = TRUE,
241                 .maxPayload = 9,
242                 .msgBufferInterrupt = TRUE,
243                 .payloadPreambleIndicatorTr = FALSE,
244                 .rejectNullFrames = FALSE,
245                 .rejectStaticSegment = FALSE,
246                 .singleTransmit = FALSE,
247                 .slotId = 2
248         },
249         {
250                 .channel = FR_CHANNEL_AB,
251                 .cycleCounterFiltering = 0,
252                 .isTx = FALSE,
253                 .maxPayload = 9,
254                 .msgBufferInterrupt = TRUE,
255                 .payloadPreambleIndicatorTr = FALSE,
256                 .rejectNullFrames = FALSE,
257                 .rejectStaticSegment = FALSE,
258                 .singleTransmit = FALSE,
259                 .slotId = 1
260         },
261         {
262                 .channel = FR_CHANNEL_AB,
263                 .cycleCounterFiltering = 0,
264                 .isTx = TRUE,
265                 .maxPayload = 9,
266                 .msgBufferInterrupt = TRUE,
267                 .payloadPreambleIndicatorTr = FALSE,
268                 .rejectNullFrames = FALSE,
269                 .rejectStaticSegment = FALSE,
270                 .singleTransmit = TRUE,
271                 .slotId = 4
272         },
273         {
274                 .channel = FR_CHANNEL_AB,
275                 .cycleCounterFiltering = 0,
276                 .isTx = FALSE,
277                 .maxPayload = 9,
278                 .msgBufferInterrupt = TRUE,
279                 .payloadPreambleIndicatorTr = FALSE,
280                 .rejectNullFrames = FALSE,
281                 .rejectStaticSegment = FALSE,
282                 .singleTransmit = TRUE,
283                 .slotId = 3
284         },
285         {
286                 .channel = FR_CHANNEL_AB,
287                 .cycleCounterFiltering = 0,
288                 .isTx = FALSE,
289                 .maxPayload = 9,
290                 .msgBufferInterrupt = TRUE,
291                 .payloadPreambleIndicatorTr = TRUE,
292                 .rejectNullFrames = FALSE,
293                 .rejectStaticSegment = FALSE,
294                 .singleTransmit = FALSE,
295                 .slotId = 5
296         }
297 };
298
299 static Fr_TMS570LS_BufferConfigType Fr_node_A_dynamic_buffers_config[] = {
300         {
301                 .channel = FR_CHANNEL_A,
302                 .cycleCounterFiltering = 0,
303                 .isTx = TRUE,
304                 .maxPayload = 64,
305                 .msgBufferInterrupt = TRUE,
306                 .payloadPreambleIndicatorTr = FALSE,
307                 .rejectNullFrames = FALSE,
308                 .rejectStaticSegment = FALSE,
309                 .singleTransmit = FALSE,
310                 .slotId = 9
311         },
312         {
313                 .channel = FR_CHANNEL_B,
314                 .cycleCounterFiltering = 0,
315                 .isTx = FALSE,
316                 .maxPayload = 32,
317                 .msgBufferInterrupt = TRUE,
318                 .payloadPreambleIndicatorTr = FALSE,
319                 .rejectNullFrames = FALSE,
320                 .rejectStaticSegment = FALSE,
321                 .singleTransmit = FALSE,
322                 .slotId = 10
323         },
324         {
325                 .channel = FR_CHANNEL_A,
326                 .cycleCounterFiltering = 0,
327                 .isTx = TRUE,
328                 .maxPayload = 16,
329                 .msgBufferInterrupt = TRUE,
330                 .payloadPreambleIndicatorTr = FALSE,
331                 .rejectNullFrames = FALSE,
332                 .rejectStaticSegment = FALSE,
333                 .singleTransmit = TRUE,
334                 .slotId = 11
335         }
336 };
337
338
339 static Fr_TMS570LS_BufferConfigType Fr_node_B_dynamic_buffers_config[] = {
340         {
341                 .channel = FR_CHANNEL_B,
342                 .cycleCounterFiltering = 0,
343                 .isTx = TRUE,
344                 .maxPayload = 32,
345                 .msgBufferInterrupt = TRUE,
346                 .payloadPreambleIndicatorTr = FALSE,
347                 .rejectNullFrames = FALSE,
348                 .rejectStaticSegment = FALSE,
349                 .singleTransmit = TRUE,
350                 .slotId = 10
351         },
352         {
353                 .channel = FR_CHANNEL_A,
354                 .cycleCounterFiltering = 0,
355                 .isTx = FALSE,
356                 .maxPayload = 64,
357                 .msgBufferInterrupt = TRUE,
358                 .payloadPreambleIndicatorTr = FALSE,
359                 .rejectNullFrames = FALSE,
360                 .rejectStaticSegment = FALSE,
361                 .singleTransmit = TRUE,
362                 .slotId = 9
363         },
364         {
365                 .channel = FR_CHANNEL_A,
366                 .cycleCounterFiltering = 0,
367                 .isTx = TRUE,
368                 .maxPayload = 9,
369                 .msgBufferInterrupt = TRUE,
370                 .payloadPreambleIndicatorTr = FALSE,
371                 .rejectNullFrames = FALSE,
372                 .rejectStaticSegment = FALSE,
373                 .singleTransmit = TRUE,
374                 .slotId = 12
375         }
376 };
377
378 static Fr_TMS570LS_BufferConfigType Fr_node_A_fifo_buffers_config[] = {
379         {
380                 .channel = FR_CHANNEL_AB,
381                 .cycleCounterFiltering = 0,
382                 .isTx = FALSE,
383                 .maxPayload = 127,
384                 .msgBufferInterrupt = FALSE, // Recomended for FIFO buffers
385                 .payloadPreambleIndicatorTr = FALSE,
386                 .rejectNullFrames = TRUE,
387                 .rejectStaticSegment = FALSE,
388                 .singleTransmit = FALSE,
389                 .slotId = 12
390         },
391         {
392                 .channel = FR_CHANNEL_AB,
393                 .cycleCounterFiltering = 0,
394                 .isTx = FALSE,
395                 .maxPayload = 127,
396                 .msgBufferInterrupt = FALSE, // Recomended for FIFO buffers
397                 .payloadPreambleIndicatorTr = FALSE,
398                 .rejectNullFrames = TRUE,
399                 .rejectStaticSegment = FALSE,
400                 .singleTransmit = FALSE,
401                 .slotId = 12
402         },
403         {
404                 .channel = FR_CHANNEL_AB,
405                 .cycleCounterFiltering = 0,
406                 .isTx = FALSE,
407                 .maxPayload = 127,
408                 .msgBufferInterrupt = FALSE, // Recomended for FIFO buffers
409                 .payloadPreambleIndicatorTr = FALSE,
410                 .rejectNullFrames = TRUE,
411                 .rejectStaticSegment = FALSE,
412                 .singleTransmit = FALSE,
413                 .slotId = 12
414         },
415         {
416                 .channel = FR_CHANNEL_AB,
417                 .cycleCounterFiltering = 0,
418                 .isTx = FALSE,
419                 .maxPayload = 127,
420                 .msgBufferInterrupt = FALSE, // Recomended for FIFO buffers
421                 .payloadPreambleIndicatorTr = FALSE,
422                 .rejectNullFrames = TRUE,
423                 .rejectStaticSegment = FALSE,
424                 .singleTransmit = FALSE,
425                 .slotId = 12
426         },
427         {
428                 .channel = FR_CHANNEL_AB,
429                 .cycleCounterFiltering = 0,
430                 .isTx = FALSE,
431                 .maxPayload = 127,
432                 .msgBufferInterrupt = FALSE, // Recomended for FIFO buffers
433                 .payloadPreambleIndicatorTr = FALSE,
434                 .rejectNullFrames = TRUE,
435                 .rejectStaticSegment = FALSE,
436                 .singleTransmit = FALSE,
437                 .slotId = 12
438         }
439 };
440
441 static Fr_TMS570LS_BufferConfigType Fr_node_B_fifo_buffers_config[] = {
442         {
443                 .channel = FR_CHANNEL_AB,
444                 .cycleCounterFiltering = 0,
445                 .isTx = FALSE,
446                 .maxPayload = 64,
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
453         },
454         {
455                 .channel = FR_CHANNEL_AB,
456                 .cycleCounterFiltering = 0,
457                 .isTx = FALSE,
458                 .maxPayload = 64,
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
465         },
466         {
467                 .channel = FR_CHANNEL_AB,
468                 .cycleCounterFiltering = 0,
469                 .isTx = FALSE,
470                 .maxPayload = 64,
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
477         },
478         {
479                 .channel = FR_CHANNEL_AB,
480                 .cycleCounterFiltering = 0,
481                 .isTx = FALSE,
482                 .maxPayload = 64,
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
489         },
490         {
491                 .channel = FR_CHANNEL_AB,
492                 .cycleCounterFiltering = 0,
493                 .isTx = FALSE,
494                 .maxPayload = 64,
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
501         }
502 };
503
504 /**
505  * This is an unifying configuration structure for the node A.
506  * It joins all the configuration structure together.
507  */
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
515 };
516
517 /**
518  * This is an unifying configuration structure for the node A.
519  * It joins all the configuration structure together.
520  */
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
528 };
529
530 /* User configuration */
531
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,
545 };;
546
547 #define USER_CONFIG_NOT_DONE            0x0
548 #define USER_CONFIG_CLUSTER             0x1
549 #define USER_CONFIG_NODE                        0x2
550
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;
555
556 /**
557  * Split string into numbers
558  *
559  * The function takes a string with hexadecimal numbers,
560  * separated by spaces, and converts it into an array of numbers.
561  *
562  * For example "0x2 0xA 0XDD 0xABCD" -> {0x2, 0xA, 0XDD, 0xABCD}
563  *
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
567  *
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.
570  */
571 static int8_t rpp_fr_parse_params(const char* params, uint32_t params_cnt, uint32_t* tmp_params) {
572         char cpy_params[256];
573         char* token;
574         int i;
575
576         if (params == NULL || tmp_params == NULL) {
577                 return FAILURE;
578         }
579         strncpy(cpy_params, params, 256);
580         token = strtok(cpy_params, " ");
581         if (token == NULL) {
582                 return FAILURE;
583         }
584         for (i = 0; i < params_cnt; i++) {
585                 if (sscanf(token, "%i", &tmp_params[i]) == EOF) {       // No number found
586                         return FAILURE;
587                 }
588                 if ((token = strtok(NULL, " ")) == NULL && i < params_cnt-1) {  // Not enough parameters in the string
589                         return FAILURE;
590                 }
591         }
592         return SUCCESS;
593 }
594
595 int8_t rpp_fr_config_cluster_params(const char* params) {
596         uint32_t tmp_params[FR_CLUSTER_PARAMS_CNT];
597
598         if (rpp_fr_parse_params(params, FR_CLUSTER_PARAMS_CNT, tmp_params) == FAILURE) {
599                 return FAILURE;
600         }
601
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];
627
628         user_configuration_state |= USER_CONFIG_CLUSTER;
629         return SUCCESS;
630 }
631
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};
636
637         if (rpp_fr_parse_params(params, FR_NODE_PARAMS_CNT+2, tmp_params) == FAILURE) {
638                 return FAILURE;
639         }
640
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] ];
672
673         user_configuration_state |= USER_CONFIG_NODE;
674         return SUCCESS;
675 }
676
677 int cmd_do_fr_config_bufer(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
678 {
679         Fr_TMS570LS_BufferConfigType *cfg;
680
681         int ret;
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",
685                      &buf_type,
686                      &buffer,
687                      &slot,
688                      channel,
689                      &cycleset,
690                      rxtx,
691                      &maxpayload,
692                      single_continuous,
693                      &preamb,
694                      &intr
695                      );
696
697         if (ret != 10) {
698                 printf("Error parsing parameter %d\n", ret+1);
699                 return -CMDERR_BADPAR;
700         }
701
702         switch (buf_type) {
703         case 'S':
704                 if (buffer >= RPP_FR_MAX_STATIC_BUF_CNT)
705                         return badpar("Buffer index too high\n");
706                 cfg = &user_static_buffer_config[buffer];
707                 break;
708         case 'D':
709                 if (buffer >= RPP_FR_MAX_DYNAMIC_BUF_CNT)
710                         return badpar("Buffer index too high\n");
711                 cfg = &user_dynamic_buffer_config[buffer];
712                 break;
713         default:
714                 return badpar("Invalid buffer type (S, D)\n");
715         }
716
717         if (slot < 1 || slot > 2047)
718                 return badpar("Invalid slot number\n");
719         cfg->slotId = slot;
720
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");
727
728         if (cycleset >= 0x80)
729                 return badpar("Cycle set must be less than 0x80.\n");
730         cfg->cycleCounterFiltering = cycleset;
731
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");
735
736         if (maxpayload >= 128)
737                 return badpar("Maximum payload in half-words must be less than 128\n");
738         cfg->maxPayload = maxpayload;
739
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");
747
748         if (preamb > 1)
749                 return badpar("Payload preamble indicator must be 0 or 1");
750         cfg->payloadPreambleIndicatorTr = preamb;
751
752         if (intr > 1)
753                 return badpar("Interrupt parameter must be 0 or 1");
754         cfg->msgBufferInterrupt = intr;
755
756         switch (buf_type) {
757         case 'S':
758                 if (buffer >= user_static_buffer_configured)
759                         user_static_buffer_configured = buffer + 1;
760                 break;
761         case 'D':
762                 if (buffer >= user_dynamic_buffer_configured)
763                         user_dynamic_buffer_configured = buffer + 1;
764                 break;
765         }
766
767         printf("frbtcfgbuf%c%i slot%i %2s cyc%i %2s max%i %10s ppi%i int%i\n",
768                      buf_type,
769                      buffer,
770                      slot,
771                      channel,
772                      cycleset,
773                      rxtx,
774                      maxpayload,
775                      single_continuous,
776                      preamb,
777                      intr
778                 );
779
780         return 0;
781 }
782
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];
787
788         if (user_fifo_buffer_depth != 0) {
789                 return FAILURE;
790         }
791
792         if (rpp_fr_parse_params(params, FR_FIFO_BUF_PARAMS_CNT+1, tmp_params) == FAILURE) {
793                 return FAILURE;
794         }
795
796         if (tmp_params[0] > RPP_FR_MAX_FIFO_BUF_DEPTH) return FAILURE;
797         if (tmp_params[1] > 2) return FAILURE;
798
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];
806         }
807         user_fifo_buffer_depth = tmp_params[0];
808
809         return SUCCESS;
810 }
811
812
813 /**
814  *      @brief  Do the user configuration of the FlexRay cluster parameters
815  *
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
820  */
821 int cmd_do_fr_user_config(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
822         char* token;
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;
828                 }
829                 rpp_sci_printf("FlexRay cluster configuration accepted.\n");
830         }
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;
835                 }
836                 rpp_sci_printf("FlexRay node configuration accepted.\n");
837         }
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;
842                 }
843                 rpp_sci_printf("FIFO buffer configuration accepted.\n");
844         }
845         else {
846                 return -CMDERR_BADPAR;
847         }
848
849         return 0;
850 }
851
852 /**
853  *      @brief  Initialize the device as FlexRay node.
854  *
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
859  */
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;
864
865         if (*param[1] == 'A') {
866                 Fr_ConfigPtr = &Fr_config_node_A;
867         }
868         else if (*param[1] == 'B') {
869                 Fr_ConfigPtr = &Fr_config_node_B;
870         }
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;
876         }
877         else {
878                 return -CMDERR_BADPAR;
879         }
880
881         retVal = rpp_fr_init_driver(Fr_ConfigPtr, &error);
882         if (retVal == SUCCESS) {
883                 rpp_sci_printf("FlexRay driver initialized.\r\n");
884         }
885         else {
886                 rpp_sci_printf("FlexRay needs to be configured before initialization.\r\n");
887                 return -CMDERR_BADCFG;
888         }
889
890         retVal = rpp_fr_init_controller(0, &error);
891         if (retVal == SUCCESS) {
892                 rpp_sci_printf("FlexRay controller initialized.\r\n");
893         }
894         else {
895                 if (error & FR_INIT_ERR_CLUSTER_CONFIG) {
896                         rpp_sci_printf("Cluster configuration data error: %x\r\n", (retVal & 0x3FFFFFE) >> 1 );
897                 }
898                 else if (error & FR_INIT_ERR_NODE_CONFIG) {
899                         rpp_sci_printf("Node configuration data error: %x\r\n", (retVal & 0x3FFFFFE) >> 1 );
900                 }
901                 else if (error & FR_INIT_ERR_MSGRAM_CONFIG) {
902                         rpp_sci_printf("Message RAM configuration data error: %x\r\n", (retVal & 0x3FFFFFE) >> 1 );
903                 }
904                 else if (error & FR_INIT_ERR_BUFFPARAM_CONFIG) {
905                         rpp_sci_printf("Buffer configuration data error: %x\r\n", (retVal & 0x3FFFFFE) >> 1 );
906                 }
907                 else if (error & (uint32_t)FR_INIT_ERR_BUFF_CONFIG) {
908                         rpp_sci_printf("Buffer configuration error: %x\r\n", (retVal & 0x3FFFFFE) >> 1 );
909                 }
910                 else {
911                         rpp_sci_printf("POC state switching error.\r\n");
912                 }
913                 return -CMDERR_BADCFG;
914         }
915         return 0;
916 }
917
918 /**
919  *      @brief  Starts FlexRay communication
920  *
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
925  */
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;
929
930         retVal = rpp_fr_start_communication(0, &error);
931         if (retVal == SUCCESS) {
932                 rpp_sci_printf("FlexRay communication is running.\r\n");
933         }
934         else {
935                 if (error & FR_STARTUP_ERR_SW_STUP_FOLLOW) {
936                         rpp_sci_printf("Can not switch POC to RUN state.\r\n");
937                 }
938                 else if (error & FR_STARTUP_ERR_CSINH_DIS) {
939                         rpp_sci_printf("Cold start inhibit disabled error.\r\n");
940                 }
941                 else if (error & FR_STARTUP_ERR_SW_STUP_READY) {
942                         rpp_sci_printf("Can not switch back to READY from STARTUP.\r\n");
943                 }
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");
946                 }
947                 else {
948                         rpp_sci_printf("General error.\r\n");
949                 }
950                 return -CMDERR_BADCFG;
951         }
952         return 0;
953 }
954
955 /**
956  *      @brief  Invokes POC command ALL_SLOTS
957  *
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
962  */
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");
968         }
969         else {
970                 rpp_sci_printf("General error.\r\n");
971                 return -CMDERR_BADCFG;
972         }
973         return 0;
974 }
975
976 /**
977  *      @brief  Halt FlexRay communication
978  *
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
983  */
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");
989         }
990         else {
991                 rpp_sci_printf("General error.\r\n");
992                 return -CMDERR_BADCFG;
993         }
994         return 0;
995 }
996
997 /**
998  *      @brief  Abort FlexRay communication
999  *
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
1004  */
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");
1010         }
1011         else {
1012                 rpp_sci_printf("General error.\r\n");
1013                 return -CMDERR_BADCFG;
1014         }
1015         return 0;
1016 }
1017
1018 /**
1019  *      @brief  Send wake up pattern
1020  *
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
1025  */
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");
1031         }
1032         else {
1033                 rpp_sci_printf("General error.\r\n");
1034                 return -CMDERR_BADCFG;
1035         }
1036         return 0;
1037 }
1038
1039 /**
1040  *      @brief  Set channel for wake up pattern sending.
1041  *
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
1046  */
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;
1050
1051         if (*param[1] == 'A') {
1052                 channel = FR_CHANNEL_A;
1053         }
1054         else if (*param[1] == 'B') {
1055                 channel = FR_CHANNEL_B;
1056         }
1057         else {
1058                 return -CMDERR_BADPAR;
1059         }
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");
1063         }
1064         else {
1065                 rpp_sci_printf("General error.\r\n");
1066                 return -CMDERR_BADCFG;
1067         }
1068         return 0;
1069 }
1070
1071 /**
1072  *      @brief  Get and print POC status of the FlexRay controller.
1073  *
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
1078  */
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",
1088                         "PREPARE"
1089         };
1090         char* StateStrings[]  = {
1091                         "CONFIG", "DEFAULT_CONFIG", "HALT", "NORMAL_ACTIVE",
1092                         "NORMAL_PASSIVE", "READY", "STARTUP", "LOOPBACK",
1093                         "MONITOR", "WAKEUP"
1094         };
1095         char* WakeupStatusStrings[]  = {
1096                         "UNDEFINED", "RECEIVED_HEADER", "RECEIVED_WUP", "COLLISION_HEADER",
1097                         "COLLISION_WUP", "COLLISION_UNKNOWN", "TRANSMITTED"
1098         };
1099
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]);
1112         }
1113         else {
1114                 rpp_sci_printf("General error.\r\n");
1115                 return -CMDERR_BADCFG;
1116         }
1117         return 0;
1118 }
1119
1120 /**
1121  *      @brief  Send given data through the FlexRay in selected slot.
1122  *
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
1127  */
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;
1130         uint32_t slotID;
1131         uint8_t dataLength;
1132         int values[MAX_PARAM_VALUES_NUM];
1133         uint8_t data[MAX_PARAM_VALUES_NUM];
1134         char* token = NULL;
1135
1136         if (sscanf(param[1], "%d", &slotID) != 1) {
1137                 return -CMDERR_BADPAR;
1138         }
1139         if (sscanf(param[2], " %2x", &values[0]) != 1) {
1140                 return -CMDERR_BADPAR;
1141         }
1142         data[0] = (uint8_t)values[0];
1143         token = strtok(param[2], " ");
1144         token = strtok(NULL, " ");
1145         dataLength = 1;
1146         while (dataLength < MAX_PARAM_VALUES_NUM && token != NULL) {
1147                 if (sscanf(token, "%2x", &values[dataLength]) == EOF) {
1148                         break;
1149                 }
1150                 data[dataLength] = (uint8_t)values[dataLength];
1151                 token = strtok(NULL, " ");
1152                 dataLength++;
1153         }
1154
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");
1158         }
1159         else {
1160                 rpp_sci_printf("General error.\r\n");
1161                 return -CMDERR_BADCFG;
1162         }
1163         return 0;
1164 }
1165
1166 /**
1167  *      @brief  Cancel the transmission in the selected slot.
1168  *
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
1173  */
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;
1176         uint32_t slotID;
1177
1178         if (sscanf(param[1], "%d", &slotID) != 1) {
1179                 return -CMDERR_BADPAR;
1180         }
1181         if (param[2] != NULL) {
1182                 return -CMDERR_BADPAR;
1183         }
1184
1185         retVal = rpp_fr_cancel_transmit_lpdu(0, slotID);
1186         if (retVal == SUCCESS) {
1187                 rpp_sci_printf("Transmission canceled.\r\n");
1188         }
1189         else {
1190                 rpp_sci_printf("General error.\r\n");
1191                 return -CMDERR_BADCFG;
1192         }
1193         return 0;
1194 }
1195
1196 /**
1197  *      @brief  Receive data from selected slot.
1198  *
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
1203  */
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;
1206         uint32_t slotID;
1207         uint8_t data[cPayloadLengthMax];
1208         Fr_RxLPduStatusType status;
1209         uint8_t receivedLength = 0;
1210         uint8_t i;
1211
1212         if (sscanf(param[1], "%d", &slotID) != 1) {
1213                 return -CMDERR_BADPAR;
1214         }
1215         if (param[2] != NULL) {
1216                 return -CMDERR_BADPAR;
1217         }
1218
1219         retVal = rpp_fr_receive_lpdu(0, slotID, data, &status, &receivedLength);
1220         if (retVal == SUCCESS) {
1221                 switch (status) {
1222                 case FR_RECEIVED_MORE_DATA_AVAILABLE:
1223                         rpp_sci_printf("More messages are still in FIFO:\r\n");
1224                 case FR_RECEIVED:
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]);
1228                         }
1229                         rpp_sci_printf("\r\n");
1230                         break;
1231                 default:
1232                         rpp_sci_printf("No message received.\r\n");
1233                         break;
1234                 }
1235         }
1236         else {
1237                 rpp_sci_printf("General error.\r\n");
1238                 return -CMDERR_BADCFG;
1239         }
1240         return 0;
1241 }
1242
1243 /**
1244  *      @brief  Returns TX LPdu status.
1245  *
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
1250  */
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;
1253         uint32_t slotID;
1254         Fr_TxLPduStatusType status;
1255         char* statusStrings[] = {"is not", "is"};
1256
1257         if (sscanf(param[1], "%d", &slotID) != 1) {
1258                 return -CMDERR_BADPAR;
1259         }
1260         if (param[2] != NULL) {
1261                 return -CMDERR_BADPAR;
1262         }
1263
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]);
1267         }
1268         else {
1269                 rpp_sci_printf("General error.\r\n");
1270                 return -CMDERR_BADCFG;
1271         }
1272         return 0;
1273 }
1274
1275 /**
1276  *      @brief  Disable buffer.
1277  *
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
1282  */
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;
1285         uint32_t slotID;
1286
1287         if (sscanf(param[1], "%d", &slotID) != 1) {
1288                 return -CMDERR_BADPAR;
1289         }
1290         if (param[2] != NULL) {
1291                 return -CMDERR_BADPAR;
1292         }
1293
1294         retVal = rpp_fr_disable_lpdu(0, slotID);
1295         if (retVal == SUCCESS) {
1296                 rpp_sci_printf("Buffer disabled.\r\n");
1297         }
1298         else {
1299                 rpp_sci_printf("General error.\r\n");
1300                 return -CMDERR_BADCFG;
1301         }
1302         return 0;
1303 }
1304
1305 /**
1306  *      @brief  Print global time of the FlexRay network.
1307  *
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
1312  */
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;
1315         uint8_t cycle = 0;
1316         uint16_t macroTick = 0;
1317
1318         retVal = rpp_fr_get_global_time(0, &cycle, &macroTick);
1319         if (retVal == SUCCESS) {
1320                 rpp_sci_printf("Cycle number: %d\r\nMacrotick number: %d\r\n", cycle, macroTick);
1321         }
1322         else {
1323                 rpp_sci_printf("General error.\r\n");
1324                 return -CMDERR_BADCFG;
1325         }
1326         return 0;
1327 }
1328
1329 /**
1330  *      @brief  Print network management vector of the FlexRay node.
1331  *
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
1336  */
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];
1340         uint8_t i;
1341
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]);
1347                 }
1348                 rpp_sci_printf("\r\n");
1349         }
1350         else {
1351                 rpp_sci_printf("General error.\r\n");
1352                 return -CMDERR_BADCFG;
1353         }
1354         return 0;
1355 }
1356
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];
1360         uint8_t i;
1361
1362         // Calculate wait time in OS ticks
1363         static const portTickType freq_ticks = 100 /* ms */ / portTICK_RATE_MS;
1364         portTickType last_wake_time = xTaskGetTickCount();
1365
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]);
1372                         }
1373                         rpp_sci_printf("\r");
1374                 }
1375                 else {
1376                         rpp_sci_printf("General error.\r\n");
1377                         return -CMDERR_BADCFG;
1378                 }
1379                 vTaskDelayUntil(&last_wake_time, freq_ticks);
1380         }
1381         rpp_sci_printf("\n");
1382         return 0;
1383 }
1384
1385 /**
1386  *      @brief  Print both channels status of the FlexRay node.
1387  *
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
1392  */
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;
1395         uint8_t index;
1396         uint8_t channel;
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",
1404                         "Not used (0)",
1405                         "Not used (0)",
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",
1412                         "Not used (0)",
1413                         "Not used (0)"
1414         };
1415         char* channelNames[] = {"A", "B"};
1416         char* boolStrings[] = {"FALSE", "TRUE"};
1417         uint16_t channelStatuses[2];
1418
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 ] );
1425                         }
1426                 }
1427         }
1428         else {
1429                 rpp_sci_printf("General error.\r\n");
1430                 return -CMDERR_BADCFG;
1431         }
1432         return 0;
1433 }
1434
1435 /**
1436  *      @brief  Print clock correction of the FlexRay node
1437  *
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
1442  */
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;
1447
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);
1451         }
1452         else {
1453                 rpp_sci_printf("General error.\r\n");
1454                 return -CMDERR_BADCFG;
1455         }
1456         return 0;
1457 }
1458
1459 /**
1460  *      @brief  Print list of syncframec transmitted on both channels via the even and odd cycle.
1461  *
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
1466  */
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;
1474         uint8_t i;
1475
1476         if (sscanf(param[1], "%d", &listSize) != 1) {
1477                 return -CMDERR_BADPAR;
1478         }
1479         if (param[2] != NULL) {
1480                 return -CMDERR_BADPAR;
1481         }
1482         if (listSize > FR_MAX_SYNC_FRAME_LIST_SIZE) {
1483                 return -CMDERR_BADPAR;
1484         }
1485
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]);
1492                 }
1493                 rpp_sci_printf("|----------------|----------------|----------------|----------------|\r\n");
1494
1495         }
1496         else {
1497                 rpp_sci_printf("General error.\r\n");
1498                 return -CMDERR_BADCFG;
1499         }
1500         return 0;
1501 }
1502
1503 /**
1504  *      @brief  Print status of wakeup on each channels (wakeup received on channel or not yet received).
1505  *
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
1510  */
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;
1513         uint8_t status = 0;
1514         char* statusStrings[] = {"was not yet", "was"};
1515         char* channelNames[] = {"A", "B"};
1516         uint8_t i;
1517
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]);
1522                 }
1523         }
1524         else {
1525                 rpp_sci_printf("General error.\r\n");
1526                 return -CMDERR_BADCFG;
1527         }
1528         return 0;
1529 }
1530
1531 /**
1532  *      @brief  Set and start absolute timer.
1533  *
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
1538  */
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;
1541         int timer = 0;
1542         int cycle = 0;
1543         int offset = 0;
1544
1545         if (sscanf(param[1], "%i %i %i", &timer, &cycle, &offset) != 3) {
1546                 return -CMDERR_BADPAR;
1547         }
1548
1549         retVal = rpp_fr_set_timer(0, timer, cycle, offset);
1550         if (retVal == SUCCESS) {
1551                 uint8_t i = 0x40;
1552                 while (i && (cycle & i) == 0)
1553                         i >>= 1;
1554                 if (!i)
1555                         i = 1;
1556
1557                 rpp_sci_printf("Timer was set for every %d-th cycle, offset %d, macrotick %d\n",
1558                                i, cycle & ~i, offset);
1559         }
1560         else {
1561                 rpp_sci_printf("General error.\r\n");
1562                 return -CMDERR_BADCFG;
1563         }
1564         return 0;
1565 }
1566
1567 /**
1568  *      @brief  Cancel selected timer
1569  *
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
1574  */
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;
1577         int timer = 0;
1578
1579         if (sscanf(param[1], "%d", &timer) != 1) {
1580                 return -CMDERR_BADPAR;
1581         }
1582
1583         if (param[2] != NULL) {
1584                 return -CMDERR_BADPAR;
1585         }
1586
1587         retVal = rpp_fr_cancel_timer(0, timer);
1588         if (retVal == SUCCESS) {
1589                 rpp_sci_printf("Timer was canceled.\r\n");
1590         }
1591         else {
1592                 rpp_sci_printf("General error.\r\n");
1593                 return -CMDERR_BADCFG;
1594         }
1595         return 0;
1596 }
1597
1598 /**
1599  *      @brief  Enable/disable, acknowledge, get timer IRQ
1600  *
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
1605  */
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;
1608         int timer = 0;
1609         char str[4];
1610         boolean_t status = FALSE;
1611         char* boolStrings[] = {"FALSE", "TRUE"};
1612
1613
1614         if (sscanf(param[1], "%d", &timer) != 1) {
1615                 return -CMDERR_BADPAR;
1616         }
1617
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]);
1622                 }
1623                 else {
1624                         rpp_sci_printf("General error.\r\n");
1625                         return -CMDERR_BADCFG;
1626                 }
1627         }
1628         else {  // Some set action
1629                 if (sscanf(param[2], "%4s", str) != 1) {
1630                         return -CMDERR_BADPAR;
1631                 }
1632                 if (strcmp(str, "EN") == 0) { // Enable IRQ
1633                         retVal = SUCCESS;       // No interrupts imlemented
1634                 }
1635                 else if (strcmp(str, "DIS") == 0) { // Disable IRQ
1636                         retVal = SUCCESS;       // No interrupts implemented
1637                 }
1638                 else if  (strcmp(str, "ACK") == 0) { // Clear IRQ
1639                         retVal = rpp_fr_clear_timer_irq(0, timer);
1640                 }
1641                 else {  // Bad argument
1642                         return -CMDERR_BADPAR;
1643                 }
1644
1645                 if (retVal == SUCCESS) {
1646                         rpp_sci_printf("OK\r\n");
1647                 }
1648                 else {
1649                         rpp_sci_printf("General error.\r\n");
1650                         return -CMDERR_BADCFG;
1651                 }
1652         }
1653         return 0;
1654 }
1655
1656 /**
1657  *      @brief  Print FlexRay driver version info.
1658  *
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
1663  */
1664 int cmd_do_fr_getversioninfo(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1665         Std_VersionInfoType versionInfo;
1666
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);
1673
1674         return 0;
1675 }
1676
1677 /**
1678  *      @brief  Print value of FlexRay configuratoin parameter.
1679  *
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
1684  */
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;
1687         int index = 0;
1688         uint32_t value = 0;
1689
1690         if (sscanf(param[1], "%d", &index) != 1) {
1691                 return -CMDERR_BADPAR;
1692         }
1693
1694         if (param[2] != NULL) {
1695                 return -CMDERR_BADPAR;
1696         }
1697
1698         retVal = rpp_fr_read_com_ctrl_config(0, index, &value);
1699         if (retVal == SUCCESS) {
1700                 rpp_sci_printf("Value = %#x\r\n", value);
1701         }
1702         else {
1703                 rpp_sci_printf("General error.\r\n");
1704                 return -CMDERR_BADCFG;
1705         }
1706         return 0;
1707 }
1708
1709 #endif  /* DOCGEN */
1710
1711 /** Command descriptor for FlexRay user config cluster command */
1712 cmd_des_t const cmd_des_fr_user_config={
1713         0, 0,
1714         "frbtconfig*","Set the user configuration parameters",
1715                 "=== Command syntax ===\n"
1716         "\n"
1717         "   frbtconfig<TYPE> <PARAMS>\n"
1718         "where\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"
1721         "\n"
1722         "=== Description ===\n"
1723         "\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"
1730         "\n"
1731         "The type of the parameters can be selected by the <TYPE> selector.\n"
1732         "\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"
1751         "* 17) gdNIT\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"
1760         "\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"
1773         "* 11) pLatestTx\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"
1791         "\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"
1794         "order:\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"
1801         "*7) slotId\n"
1802         "\n"
1803         "=== Example ===\n"
1804         "\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
1810 };
1811
1812 cmd_des_t const cmd_des_fr_config_buffer={
1813         0, 0,
1814         "frbtcfgbuf?*","Configure a message buffer in the user configuration",
1815         "=== Command syntax ===\n"
1816         "\n"
1817         "   frbtcfgbuf<TYPE><NUM> slot<SLOT> <CHN> cyc<CYC> <RXTX> max<MAX> <REP> ppi<PPI> int<INT>\n"
1818         "where\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"
1829         "\n"
1830         "=== Description ===\n"
1831         "\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"
1836         "\n"
1837         "=== Example ===\n"
1838         "\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
1848 };
1849
1850
1851 /** Command descriptor for FlexRay init command */
1852 cmd_des_t const cmd_des_fr_init={
1853         0, 0,
1854         "frbtinit?","Initialize a FlexRay node",
1855         "=== Command syntax ===\n"
1856         "\n"
1857         "   frbtinit<CFG>\n"
1858         "\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"
1862         "\n"
1863         "=== Description ===\n"
1864         "\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"
1878         "\n"
1879         "=== Example ===\n"
1880         "\n"
1881         "   --> frbtinitA\n"
1882         "   FlexRay driver initialized.\n"
1883         "   FlexRay controller initialized.\n",
1884         CMD_HANDLER(cmd_do_fr_init), (void *)&cmd_list_fr_basic_test
1885 };
1886
1887 /** Command descriptor for FlexRay controller init command */
1888 cmd_des_t const cmd_des_fr_start={
1889         0, 0,
1890         "frbtstart","Start a new FlexRay network or join to the existing one",
1891         "=== Command syntax ===\n"
1892         "\n"
1893         "   frbtstart\n"
1894         "\n"
1895         "=== Description ===\n"
1896         "\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"
1906         "\n"
1907         "The command should be called after the frbtinit command.\n"
1908         "\n"
1909         "=== Example ===\n"
1910         "\n"
1911         "   --> frbtstart\n"
1912         "   FlexRay communication is running.\n",
1913         CMD_HANDLER(cmd_do_fr_start), (void *)&cmd_list_fr_basic_test
1914 };
1915
1916 /** Command descriptor for FlexRay controller all slots command */
1917 cmd_des_t const cmd_des_fr_allslots={
1918         0, 0,
1919         "frbtallslots","Enables communication for all frames",
1920         "=== Command syntax ===\n"
1921         "\n"
1922         "   frbtallslots\n"
1923         "\n"
1924         "=== Description ===\n"
1925         "\n"
1926         "The command stands for Fr_AllSlots function from the Autosar\n"
1927         "specification.\n"
1928         "\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"
1934         "initialization.\n"
1935         "\n"
1936         "=== Example ===\n"
1937         "\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
1941 };
1942
1943 /** Command descriptor for FlexRay controller halt command */
1944 cmd_des_t const cmd_des_fr_halt={
1945         0, 0,
1946         "frbthalt","Halt FlexRay communication after the end of the actual communication cycle",
1947         "=== Command syntax ===\n"
1948         "\n"
1949         "   frbthalt\n"
1950         "\n"
1951         "=== Description ===\n"
1952         "\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"
1959         "\n"
1960         "=== Example ===\n"
1961         "\n"
1962         "   --> frbthalt\n"
1963         "   FlexRay node communication halted.\n",
1964         CMD_HANDLER(cmd_do_fr_halt), (void *)&cmd_list_fr_basic_test
1965 };
1966
1967 /** Command descriptor for FlexRay controller abort command */
1968 cmd_des_t const cmd_des_fr_abort={
1969         0, 0,
1970         "frbtabort","Abort FlexRay communication immediately",
1971         "=== Command syntax ===\n"
1972         "\n"
1973         "   frbtabort\n"
1974         "\n"
1975         "=== Description ===\n"
1976         "\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"
1983         "\n"
1984         "=== Example ===\n"
1985         "\n"
1986         "   --> frbtabort\n"
1987         "   FlexRay node communication aborted.\n",
1988         CMD_HANDLER(cmd_do_fr_abort), (void *)&cmd_list_fr_basic_test
1989 };
1990
1991 /** Command descriptor for FlexRay controller send wake up pattern command */
1992 cmd_des_t const cmd_des_fr_sendwup={
1993         0, 0,
1994         "frbtwup","Initiate the wake up procedure",
1995         "=== Command syntax ===\n"
1996         "\n"
1997         "   frbtwup\n"
1998         "\n"
1999         "=== Description ===\n"
2000         "\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"
2004         "\n"
2005         "=== Example ===\n"
2006         "\n"
2007         "   --> frbtwup\n"
2008         "   Wake up pattern has been sent.\n",
2009         CMD_HANDLER(cmd_do_fr_sendwup), (void *)&cmd_list_fr_basic_test
2010 };
2011
2012 /** Command descriptor for FlexRay controller sent wake up pattern channel command */
2013 cmd_des_t const cmd_des_fr_setwuchannel={
2014         0, 0,
2015         "frbtsetwuch?","Set wake up channel",
2016         "=== Command syntax ===\n"
2017         "\n"
2018         "   frbtsetwuch<CHANNEL>\n"
2019         "\n"
2020         "where <CHANNEL> is a character A or B, specifying the channel.\n"
2021         "\n"
2022         "=== Description ===\n"
2023         "\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"
2029         "\n"
2030         "=== Example ===\n"
2031         "\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
2035 };
2036
2037 /** Command descriptor for FlexRay controller get POC status command */
2038 cmd_des_t const cmd_des_fr_getpocstatus={
2039         0, 0,
2040         "frbtgetpocst","Print FlexRay POC status",
2041         "=== Command syntax ===\n"
2042         "\n"
2043         "   frbtgetpocst\n"
2044         "\n"
2045         "=== Description ===\n"
2046         "\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"
2050         "command.\n"
2051         "\n"
2052         "=== Example ===\n"
2053         "\n"
2054         "   --> frbtgetpocst\n"
2055         "   POC status:\n"
2056         "   CHIHaltRequest: FALSE\n"
2057         "   CHIReadyRequest: FALSE\n"
2058         "   ColdstartNoise: FALSE\n"
2059         "   Freeze: FALSE\n"
2060         "   ErrorMode: ACTIVE\n"
2061         "   SlotMode: ALL\n"
2062         "   StartupState: UNDEFINED\n"
2063         "   State: READY\n"
2064         "   WakeupStatus: UNDEFINED\n",
2065         CMD_HANDLER(cmd_do_fr_getpocstatus), (void *)&cmd_list_fr_basic_test
2066 };
2067
2068 /** Command descriptor for FlexRay transmit tx lpdu command */
2069 cmd_des_t const cmd_des_fr_transmittxlpdu={
2070         0, 0,
2071         "frbttransmit*","Transmit data in selected frame",
2072         "=== Command syntax ===\n"
2073         "\n"
2074         "   frbttransmit<FRID> <DATA>\n"
2075         "where\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"
2078         "\n"
2079         "=== Description ===\n"
2080         "\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"
2087         "\n"
2088         "=== Example ===\n"
2089         "\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
2093 };
2094
2095 /** Command descriptor for FlexRay cancel tx lpdu command */
2096 cmd_des_t const cmd_des_fr_canceltxlpdu={
2097         0, 0,
2098         "frbtcanceltx*","Stop the transmission of the frame",
2099         "=== Command syntax ===\n"
2100         "\n"
2101         "   frbtcanceltx<FRID>\n"
2102         "\n"
2103         "where <FRID> is a decimal number specifying the ID of the frame for\n"
2104         "which a buffer has been configured.\n"
2105         "\n"
2106         "=== Description ===\n"
2107         "\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"
2114         "\n"
2115         "=== Example ===\n"
2116         "\n"
2117         "   --> frbtcanceltx3\n"
2118         "   Transmission canceled.\n",
2119         CMD_HANDLER(cmd_do_fr_canceltxlpdu), (void *)&cmd_list_fr_basic_test
2120 };
2121
2122 /** Command descriptor for FlexRay receive rx lpdu command */
2123 cmd_des_t const cmd_des_fr_receiverxlpdu={
2124         0, 0,
2125         "frbtreceive*","Receive a new message",
2126         "=== Command syntax ===\n"
2127         "\n"
2128         "   frbtreceive<FRID>\n"
2129         "\n"
2130         "where <FRID> is a decimal number specifying the ID of the frame for\n"
2131         "which a buffer was configured.\n"
2132         "\n"
2133         "=== Description ===\n"
2134         "\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"
2143         "\n"
2144         "=== Example ===\n"
2145         "\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
2151 };
2152
2153 /** Command descriptor for FlexRay check TX LPdu status command */
2154 cmd_des_t const cmd_des_fr_checktxlpdustatus={
2155         0, 0,
2156         "frbtchecktx*","Print the status of the transmit buffer",
2157         "=== Command syntax ===\n"
2158         "\n"
2159         "   frbtchecktx<FRID>\n"
2160         "\n"
2161         "where <FRID> is a decimal number specifying the ID of the frame for\n"
2162         "which a buffer has been configured.\n"
2163         "\n"
2164         "=== Description ===\n"
2165         "\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"
2172         "\n"
2173         "=== Example ===\n"
2174         "\n"
2175         "   --> frbtchecktx1\n"
2176         "   Message transmission is not pending.\n",
2177         CMD_HANDLER(cmd_do_fr_checktxlpdustatus), (void *)&cmd_list_fr_basic_test
2178 };
2179
2180 /** Command descriptor for FlexRay disable LPdu command */
2181 cmd_des_t const cmd_des_fr_disablelpdu={
2182         0, 0,
2183         "frbtdisable*","Disable the buffers assigned to the frame",
2184         "=== Command syntax ===\n"
2185         "\n"
2186         "   frbtdisable<FRID>\n"
2187         "\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"
2190         "\n"
2191         "=== Description ===\n"
2192         "\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"
2199         "\n"
2200         "=== Example ===\n"
2201         "\n"
2202         "   --> frbtdisable3\n"
2203         "   Buffer disabled.\n",
2204         CMD_HANDLER(cmd_do_fr_disablelpdu), (void *)&cmd_list_fr_basic_test
2205 };
2206
2207 /** Command descriptor for FlexRay get global time command */
2208 cmd_des_t const cmd_des_fr_getglobaltime={
2209         0, 0,
2210         "frbtglobtime","Print actual global time of the network",
2211         "=== Command syntax ===\n"
2212         "\n"
2213         "   frbtglobtime\n"
2214         "\n"
2215         "=== Description ===\n"
2216         "\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"
2220         "\n"
2221         "=== Example ===\n"
2222         "\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
2227 };
2228
2229 /** Command descriptor for FlexRay get network management vector command */
2230 cmd_des_t const cmd_des_fr_getnmvector={
2231         0, 0,
2232         "frbtnmvector","Print network management vector of the node",
2233         "=== Command syntax ===\n"
2234         "\n"
2235         "   frbtnmvector\n"
2236         "\n"
2237         "=== Description ===\n"
2238         "\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"
2242         "\n"
2243         "=== Example ===\n"
2244         "\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
2248 };
2249
2250 /** Command descriptor for FlexRay get network management vector command */
2251 cmd_des_t const cmd_des_fr_nmwatch={
2252         0, 0,
2253         "frbtnmwatch","Watch the changes of the network managment vector in real-time",
2254         "=== Command syntax ===\n"
2255         "\n"
2256         "   frbtnmwatch\n"
2257         "\n"
2258         "=== Description ===\n"
2259         "\n"
2260         "Reads the network management vector every 100 ms and prints it out.\n"
2261         "\n"
2262         "=== Example ===\n"
2263         "\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
2267 };
2268
2269 /** Command descriptor for FlexRay get channel status command */
2270 cmd_des_t const cmd_des_fr_getchannelstatus={
2271         0, 0,
2272         "frbtchstat","Print channel A and B status",
2273         "=== Command syntax ===\n"
2274         "\n"
2275         "   frbtchstat\n"
2276         "\n"
2277         "=== Description ===\n"
2278         "\n"
2279         "The command stands for Fr_GetChannelStatus function from the Autosar\n"
2280         "specification.\n"
2281         "\n"
2282         "=== Example ===\n"
2283         "\n"
2284         "   --> frbtchstat\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
2320 };
2321
2322 /** Command descriptor for FlexRay get clock correction command */
2323 cmd_des_t const cmd_des_fr_getclockcorrection={
2324         0, 0,
2325         "frbtclkcor","Print clock correction (rate and offset)",
2326         "=== Command syntax ===\n"
2327         "\n"
2328         "   frbtclkcor\n"
2329         "\n"
2330         "=== Description ===\n"
2331         "\n"
2332         "The command stands for Fr_GetClockCorrection function from the Autosar\n"
2333         "specification.\n"
2334         "\n"
2335         "=== Example ===\n"
2336         "\n"
2337         "   --> frbtclkcor\n"
2338         "   Rate correction: 0\n"
2339         "   Offset correction: 0\n",
2340         CMD_HANDLER(cmd_do_fr_getclockcorrection), (void *)&cmd_list_fr_basic_test
2341 };
2342
2343 /** Command descriptor for FlexRay get sync frame list command */
2344 cmd_des_t const cmd_des_fr_getsyncframelist={
2345         0, 0,
2346         "frbtgetsyncfrlist*","Print the list of sync frames transmitted on both channels via the odd and even communication cycle",
2347         "=== Command syntax ===\n"
2348         "\n"
2349         "   frbtgetsyncfrlist<LENGTH>\n"
2350         "\n"
2351         "where <LENGTH> is a decimal number in range 0 - 15, specifying the\n"
2352         "length of the list to be printed.\n"
2353         "\n"
2354         "=== Description ===\n"
2355         "\n"
2356         "The command stands for Fr_GetSyncFrameList function from the Autosar\n"
2357         "specification.\n"
2358         "\n"
2359         "=== Example ===\n"
2360         "\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
2368 };
2369
2370 /** Command descriptor for FlexRay get sync frame list command */
2371 cmd_des_t const cmd_des_fr_getwakeuprxstatus={
2372         0, 0,
2373         "frbtgetwurxstat","Prints whether the wake up pattern has been or has not been received",
2374         "=== Command syntax ===\n"
2375         "\n"
2376         "   frbtgetwurxstat\n"
2377         "\n"
2378         "=== Description ===\n"
2379         "\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"
2383         "\n"
2384         "=== Example ===\n"
2385         "\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
2390 };
2391
2392 /** Command descriptor for FlexRay set absolute timer command */
2393 cmd_des_t const cmd_des_fr_settimer={
2394         0, 0,
2395         "frbtsettimer*","Set and start timer",
2396         "=== Command syntax ===\n"
2397         "\n"
2398         "   frbtsettimer<TMID> <CYCLE> <OFFSET>\n"
2399         "where\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"
2403         "\n"
2404         "=== Description ===\n"
2405         "\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"
2410         "\n"
2411         "Before using this command, FlexRay communication has to be started\n"
2412         "(see frbtstart).\n"
2413         "\n"
2414         "=== Example ===\n"
2415         "\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
2423 };
2424
2425 /** Command descriptor for FlexRay cancel absolute timer command */
2426 cmd_des_t const cmd_des_fr_canceltimer={
2427         0, 0,
2428         "frbtcanceltimer*","Stop the timer",
2429         "=== Command syntax ===\n"
2430         "\n"
2431         "   frbtcanceltimer<TMID>\n"
2432         "where <TMID> is a number (0 or 1) specifying the timer.\n"
2433         "\n"
2434         "=== Description ===\n"
2435         "\n"
2436         "The command stands for Fr_CancelAbsoluteTimer function from the\n"
2437         "Autosar specification. It stops the timer selected by the parameter.\n"
2438         "\n"
2439         "=== Example ===\n"
2440         "\n"
2441         "   --> frbtcanceltimer0\n"
2442         "   Timer was canceled.\n",
2443         CMD_HANDLER(cmd_do_fr_canceltimer), (void *)&cmd_list_fr_basic_test
2444 };
2445
2446 /** Command descriptor for FlexRay absolute timer irq manipulation command */
2447 cmd_des_t const cmd_des_fr_timerirq={
2448         0, 0,
2449         "frbttimerirq*","Perform selected action on the timer IRQ",
2450         "=== Command syntax ===\n"
2451         "\n"
2452         "   frbttimerirq<TMID> <ACTION> - Run the <ACTION> on specified timer\n"
2453         "   frbttimerirq<TMID> - Get timer IRQ status\n"
2454         "\n"
2455         "where\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"
2458         "\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"
2463         "\n"
2464         "=== Description ===\n"
2465         "\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"
2472         "\n"
2473         "=== Example ===\n"
2474         "\n"
2475         "   --> frbttimerirq0\n"
2476         "   IRQ = FALSE\n"
2477         "\n"
2478         "   --> frbttimerirq0 EN\n"
2479         "   OK\n",
2480         CMD_HANDLER(cmd_do_fr_timerirq), (void *)&cmd_list_fr_basic_test
2481 };
2482
2483 /** Command descriptor for FlexRay get version info command */
2484 cmd_des_t const cmd_des_fr_getversioninfo={
2485         0, 0,
2486         "frbtversion","Print FlexRay driver version information",
2487         "=== Command syntax ===\n"
2488         "\n"
2489         "   frbtversion\n"
2490         "\n"
2491         "=== Description ===\n"
2492         "\n"
2493         "The command stands for Fr_GetVersionInfo function from the Autosar\n"
2494         "specification.\n"
2495         "It reads and prints the information about vendor, module and version of\n"
2496         "the FlexRay driver\n"
2497         "\n"
2498         "=== Example ===\n"
2499         "\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
2507 };
2508
2509 /** Command descriptor for FlexRay get controller configuration command */
2510 cmd_des_t const cmd_des_fr_readcconfig={
2511         0, 0,
2512         "frbtccconfig*","Print value of a FlexRay cluster and node configuration parameter",
2513         "=== Command syntax ===\n"
2514         "\n"
2515         "   frbtccconfig<INDEX>\n"
2516         "\n"
2517         "where <INDEX> is an identifier of the parameter.\n"
2518         "\n"
2519         "=== Description ===\n"
2520         "\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"
2527         "\n"
2528         "=== Example ===\n"
2529         "\n"
2530         "   --> frbtccconfig1\n"
2531         "   Value = 0x1\n",
2532         CMD_HANDLER(cmd_do_fr_readcconfig), (void *)&cmd_list_fr_basic_test
2533 };
2534
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,
2539   &cmd_des_fr_init,
2540   &cmd_des_fr_start,
2541   &cmd_des_fr_allslots,
2542   &cmd_des_fr_halt,
2543   &cmd_des_fr_abort,
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,
2564   NULL
2565 };