]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blob - rpp-test-sw/commands/cmd_fr_basic_test.c
Change license to MIT
[pes-rpp/rpp-test-sw.git] / rpp-test-sw / 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  * Permission is hereby granted, free of charge, to any person
10  * obtaining a copy of this software and associated documentation
11  * files (the "Software"), to deal in the Software without
12  * restriction, including without limitation the rights to use,
13  * copy, modify, merge, publish, distribute, sublicense, and/or sell
14  * copies of the Software, and to permit persons to whom the
15  * Software is furnished to do so, subject to the following
16  * conditions:
17  *
18  * The above copyright notice and this permission notice shall be
19  * included in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28  * OTHER DEALINGS IN THE SOFTWARE.
29  *
30  * File : cmd_fr_basic_test.c
31  *
32  * Abstract:
33  *              The file contains a set of commands to control the FlexRay driver.
34  *              Those commands can be used to configure RPP board as a FlexRay node,
35  *              configure a set of TX and RX buffers, get status of the buffers and
36  *              the FlexRay controller, manipulate with timers and control the transmission
37  *              of messages.
38  */
39
40
41 #include "cmd_fr_basic_test.h"
42
43 #ifndef DOCGEN
44
45 #include <string.h>
46 #include "cmdproc_utils.h"
47 #include "rpp/rpp.h"
48 #include "stdio.h"
49
50 #define printf rpp_sci_printf
51
52 static inline int badpar(const char *msg)
53 {
54         printf("%s", msg);
55         return -CMDERR_BADPAR;
56 }
57
58 /**
59  * Flag to recognize whether the FlexRay driver was already initialized. If it was, no further configuration is allowed.
60  */
61 static boolean_t fr_initialized = FALSE;
62
63 /**
64  * This structure contains global FlexRay configuration.
65  * All nodes in the network have to use the same values for
66  * all parameters of this structure.
67  */
68 static Fr_TMS570LS_ClusterConfigType Fr_cluster_config = {
69         .gColdStartAttempts = 0x2,
70         .gListenNoise = 0xF,
71         .gMacroPerCycle = 0x15E0,   // (cycle period, 5.6us)
72         .gMaxWithoutClockCorrectionFatal = 0xF,
73         .gMaxWithoutClockCorrectionPassive = 0xF,
74         .gNetworkManagementVectorLength = 12,
75         .gNumberOfMinislots = 0x15A,
76         .gNumberOfStaticSlots = 0x8,
77         .gOffsetCorrectionStart = 0xAE4,
78         .gPayloadLengthStatic = 0x9,
79         .gSyncNodeMax = 0xF,
80         .gdActionPointOffset = 0x4,
81         .gdCASRxLowMax = 0x43,
82         .gdDynamicSlotIdlePhase = 0x1,
83         .gdMinislot = 0x4,
84         .gdMinislotActionPointOffset = 0x2,
85         .gdNIT = 0xAE3,
86         .gdSampleClockPeriod = 0,       // 10mbit/sec
87         .gdStaticSlot = 0x56,
88         .gdTSSTransmitter = 0xA,
89         .gdWakeupSymbolRxIdle = 18,
90         .gdWakeupSymbolRxLow = 18,
91         .gdWakeupSymbolRxWindow = 76,
92         .gdWakeupSymbolTxIdle = 180,
93         .gdWakeupSymbolTxLow = 60
94 };
95
96 /**
97  * This structure contains local configuration of the FlexRay node A.
98  * All nodes in the network shall have their own local configuraion,
99  * but it does not matters if they share some together, until their
100  * buffer configuration differs.
101  */
102 static Fr_TMS570LS_NodeConfigType Fr_node_A_config = {
103         .pAllowHaltDueToClock = 0,
104         .pAllowPassiveToActive = 0xF,
105         .pChannels = FR_CHANNEL_AB,
106         .pClusterDriftDamping = 0x1,
107         .pDelayCompensationA = 0x3,
108         .pDelayCompensationB = 0x3,
109         .pExternOffsetCorrection = 0,
110         .pExternRateCorrection = 0,
111         .pKeySlotUsedForStartup = TRUE,
112         .pKeySlotUsedForSync = TRUE,
113         .pLatestTx = 0x10D,
114         .pMacroInitialOffsetA = 0x6,
115         .pMacroInitialOffsetB = 0x6,
116         .pMicroInitialOffsetA = 0x18,
117         .pMicroInitialOffsetB = 0x18,
118         .pMicroPerCycle = 0x36B00,
119         .pRateCorrectionOut = 0xCD,
120         .pOffsetCorrectionOut = 0x151,
121         .pSamplesPerMicrotick = 0,      // 10 mbit/sec
122         .pSingleSlotEnabled = TRUE,
123         .pWakeupChannel = FR_CHANNEL_A,
124         .pWakeupPattern = 2,
125         .pdAcceptedStartupRange = 0x81,
126         .pdListenTimeout = 0x36DA2,
127         .pdMaxDrift = 0x151,
128         .pDecodingCorrection = 0x33
129 };
130
131 /**
132  * This structure contains local configuration of the FlexRay node B.
133  * All nodes in the network shall have their own local configuraion,
134  * but it does not matters if they share some together, until their
135  * buffer configuration differs.
136  */
137 static Fr_TMS570LS_NodeConfigType Fr_node_B_config = {
138         .pAllowHaltDueToClock = 0,
139         .pAllowPassiveToActive = 0xF,
140         .pChannels = FR_CHANNEL_AB,
141         .pClusterDriftDamping = 0x1,
142         .pDelayCompensationA = 0x3,
143         .pDelayCompensationB = 0x3,
144         .pExternOffsetCorrection = 0,
145         .pExternRateCorrection = 0,
146         .pKeySlotUsedForStartup = TRUE,
147         .pKeySlotUsedForSync = TRUE,
148         .pLatestTx = 0x10D,
149         .pMacroInitialOffsetA = 0x6,
150         .pMacroInitialOffsetB = 0x6,
151         .pMicroInitialOffsetA = 0x18,
152         .pMicroInitialOffsetB = 0x18,
153         .pMicroPerCycle = 0x36B00,
154         .pRateCorrectionOut = 0xCD,
155         .pOffsetCorrectionOut = 0x151,
156         .pSamplesPerMicrotick = 0,          // 10 mbit/sec
157         .pSingleSlotEnabled = TRUE,
158         .pWakeupChannel = FR_CHANNEL_A,
159         .pWakeupPattern = 2,
160         .pdAcceptedStartupRange = 0x81,
161         .pdListenTimeout = 0x36DA2,
162         .pdMaxDrift = 0x151,
163         .pDecodingCorrection = 0x33
164 };
165
166 static Fr_TMS570LS_MsgRAMConfig Fr_node_A_msgRAM_config = {
167         .dynSegmentBufferCount = 3,
168         .fifoBufferCount = 5,
169         .secureBuffers = FR_SB_RECONFIG_ENABLED,
170         .statSegmentBufferCount = 5,
171         .syncFramePayloadMultiplexEnabled = 0
172 };
173
174 static Fr_TMS570LS_MsgRAMConfig Fr_node_B_msgRAM_config = {
175         .dynSegmentBufferCount = 3,
176         .fifoBufferCount = 5,
177         .secureBuffers = FR_SB_RECONFIG_ENABLED,
178         .statSegmentBufferCount = 5,
179         .syncFramePayloadMultiplexEnabled = 0
180 };
181
182 static Fr_TMS570LS_BufferConfigType Fr_node_A_static_buffers_config[] = {
183         {
184                 .channel = FR_CHANNEL_AB,
185                 .cycleCounterFiltering = 0,
186                 .fidMask = 0,
187                 .isTx = TRUE,
188                 .maxPayload = 9,
189                 .msgBufferInterrupt = TRUE,
190                 .payloadPreambleIndicatorTr = FALSE,
191                 .rejectNullFrames = FALSE,
192                 .rejectStaticSegment = FALSE,
193                 .singleTransmit = FALSE,
194                 .slotId = 1
195         },
196         {
197                 .channel = FR_CHANNEL_AB,
198                 .cycleCounterFiltering = 0,
199                 .fidMask = 0,
200                 .isTx = FALSE,
201                 .maxPayload = 9,
202                 .msgBufferInterrupt = TRUE,
203                 .payloadPreambleIndicatorTr = FALSE,
204                 .rejectNullFrames = FALSE,
205                 .rejectStaticSegment = FALSE,
206                 .singleTransmit = FALSE,
207                 .slotId = 2
208         },
209         {
210                 .channel = FR_CHANNEL_AB,
211                 .cycleCounterFiltering = 0,
212                 .fidMask = 0,
213                 .isTx = TRUE,
214                 .maxPayload = 9,
215                 .msgBufferInterrupt = TRUE,
216                 .payloadPreambleIndicatorTr = FALSE,
217                 .rejectNullFrames = FALSE,
218                 .rejectStaticSegment = FALSE,
219                 .singleTransmit = TRUE,
220                 .slotId = 3
221         },
222         {
223                 .channel = FR_CHANNEL_AB,
224                 .cycleCounterFiltering = 0,
225                 .fidMask = 0,
226                 .isTx = FALSE,
227                 .maxPayload = 9,
228                 .msgBufferInterrupt = TRUE,
229                 .payloadPreambleIndicatorTr = FALSE,
230                 .rejectNullFrames = FALSE,
231                 .rejectStaticSegment = FALSE,
232                 .singleTransmit = TRUE,
233                 .slotId = 4
234         },
235         {
236                 .channel = FR_CHANNEL_AB,
237                 .cycleCounterFiltering = 0,
238                 .fidMask = 0,
239                 .isTx = TRUE,
240                 .maxPayload = 9,
241                 .msgBufferInterrupt = TRUE,
242                 .payloadPreambleIndicatorTr = TRUE,
243                 .rejectNullFrames = FALSE,
244                 .rejectStaticSegment = FALSE,
245                 .singleTransmit = FALSE,
246                 .slotId = 5
247         }
248
249 };
250
251 static Fr_TMS570LS_BufferConfigType Fr_node_B_static_buffers_config[] = {
252         {
253                 .channel = FR_CHANNEL_AB,
254                 .cycleCounterFiltering = 0,
255                 .fidMask = 0,
256                 .isTx = TRUE,
257                 .maxPayload = 9,
258                 .msgBufferInterrupt = TRUE,
259                 .payloadPreambleIndicatorTr = FALSE,
260                 .rejectNullFrames = FALSE,
261                 .rejectStaticSegment = FALSE,
262                 .singleTransmit = FALSE,
263                 .slotId = 2
264         },
265         {
266                 .channel = FR_CHANNEL_AB,
267                 .cycleCounterFiltering = 0,
268                 .fidMask = 0,
269                 .isTx = FALSE,
270                 .maxPayload = 9,
271                 .msgBufferInterrupt = TRUE,
272                 .payloadPreambleIndicatorTr = FALSE,
273                 .rejectNullFrames = FALSE,
274                 .rejectStaticSegment = FALSE,
275                 .singleTransmit = FALSE,
276                 .slotId = 1
277         },
278         {
279                 .channel = FR_CHANNEL_AB,
280                 .cycleCounterFiltering = 0,
281                 .fidMask = 0,
282                 .isTx = TRUE,
283                 .maxPayload = 9,
284                 .msgBufferInterrupt = TRUE,
285                 .payloadPreambleIndicatorTr = FALSE,
286                 .rejectNullFrames = FALSE,
287                 .rejectStaticSegment = FALSE,
288                 .singleTransmit = TRUE,
289                 .slotId = 4
290         },
291         {
292                 .channel = FR_CHANNEL_AB,
293                 .cycleCounterFiltering = 0,
294                 .fidMask = 0,
295                 .isTx = FALSE,
296                 .maxPayload = 9,
297                 .msgBufferInterrupt = TRUE,
298                 .payloadPreambleIndicatorTr = FALSE,
299                 .rejectNullFrames = FALSE,
300                 .rejectStaticSegment = FALSE,
301                 .singleTransmit = TRUE,
302                 .slotId = 3
303         },
304         {
305                 .channel = FR_CHANNEL_AB,
306                 .cycleCounterFiltering = 0,
307                 .fidMask = 0,
308                 .isTx = FALSE,
309                 .maxPayload = 9,
310                 .msgBufferInterrupt = TRUE,
311                 .payloadPreambleIndicatorTr = TRUE,
312                 .rejectNullFrames = FALSE,
313                 .rejectStaticSegment = FALSE,
314                 .singleTransmit = FALSE,
315                 .slotId = 5
316         }
317 };
318
319 static Fr_TMS570LS_BufferConfigType Fr_node_A_dynamic_buffers_config[] = {
320         {
321                 .channel = FR_CHANNEL_A,
322                 .cycleCounterFiltering = 0,
323                 .fidMask = 0,
324                 .isTx = TRUE,
325                 .maxPayload = 64,
326                 .msgBufferInterrupt = TRUE,
327                 .payloadPreambleIndicatorTr = FALSE,
328                 .rejectNullFrames = FALSE,
329                 .rejectStaticSegment = FALSE,
330                 .singleTransmit = FALSE,
331                 .slotId = 9
332         },
333         {
334                 .channel = FR_CHANNEL_B,
335                 .cycleCounterFiltering = 0,
336                 .fidMask = 0,
337                 .isTx = FALSE,
338                 .maxPayload = 32,
339                 .msgBufferInterrupt = TRUE,
340                 .payloadPreambleIndicatorTr = FALSE,
341                 .rejectNullFrames = FALSE,
342                 .rejectStaticSegment = FALSE,
343                 .singleTransmit = FALSE,
344                 .slotId = 10
345         },
346         {
347                 .channel = FR_CHANNEL_A,
348                 .cycleCounterFiltering = 0,
349                 .fidMask = 0,
350                 .isTx = TRUE,
351                 .maxPayload = 16,
352                 .msgBufferInterrupt = TRUE,
353                 .payloadPreambleIndicatorTr = FALSE,
354                 .rejectNullFrames = FALSE,
355                 .rejectStaticSegment = FALSE,
356                 .singleTransmit = TRUE,
357                 .slotId = 11
358         }
359 };
360
361
362 static Fr_TMS570LS_BufferConfigType Fr_node_B_dynamic_buffers_config[] = {
363         {
364                 .channel = FR_CHANNEL_B,
365                 .cycleCounterFiltering = 0,
366                 .fidMask = 0,
367                 .isTx = TRUE,
368                 .maxPayload = 32,
369                 .msgBufferInterrupt = TRUE,
370                 .payloadPreambleIndicatorTr = FALSE,
371                 .rejectNullFrames = FALSE,
372                 .rejectStaticSegment = FALSE,
373                 .singleTransmit = TRUE,
374                 .slotId = 10
375         },
376         {
377                 .channel = FR_CHANNEL_A,
378                 .cycleCounterFiltering = 0,
379                 .fidMask = 0,
380                 .isTx = FALSE,
381                 .maxPayload = 64,
382                 .msgBufferInterrupt = TRUE,
383                 .payloadPreambleIndicatorTr = FALSE,
384                 .rejectNullFrames = FALSE,
385                 .rejectStaticSegment = FALSE,
386                 .singleTransmit = TRUE,
387                 .slotId = 9
388         },
389         {
390                 .channel = FR_CHANNEL_A,
391                 .cycleCounterFiltering = 0,
392                 .fidMask = 0,
393                 .isTx = TRUE,
394                 .maxPayload = 9,
395                 .msgBufferInterrupt = TRUE,
396                 .payloadPreambleIndicatorTr = FALSE,
397                 .rejectNullFrames = FALSE,
398                 .rejectStaticSegment = FALSE,
399                 .singleTransmit = TRUE,
400                 .slotId = 12
401         }
402 };
403
404 static Fr_TMS570LS_BufferConfigType Fr_node_A_fifo_buffers_config[] = {
405         {
406                 .channel = FR_CHANNEL_AB,
407                 .cycleCounterFiltering = 0,
408                 .fidMask = 0,
409                 .isTx = FALSE,
410                 .maxPayload = 127,
411                 .msgBufferInterrupt = FALSE, // Recomended for FIFO buffers
412                 .payloadPreambleIndicatorTr = FALSE,
413                 .rejectNullFrames = TRUE,
414                 .rejectStaticSegment = FALSE,
415                 .singleTransmit = FALSE,
416                 .slotId = 12
417         },
418         {
419                 .channel = FR_CHANNEL_AB,
420                 .cycleCounterFiltering = 0,
421                 .fidMask = 0,
422                 .isTx = FALSE,
423                 .maxPayload = 127,
424                 .msgBufferInterrupt = FALSE, // Recomended for FIFO buffers
425                 .payloadPreambleIndicatorTr = FALSE,
426                 .rejectNullFrames = TRUE,
427                 .rejectStaticSegment = FALSE,
428                 .singleTransmit = FALSE,
429                 .slotId = 12
430         },
431         {
432                 .channel = FR_CHANNEL_AB,
433                 .cycleCounterFiltering = 0,
434                 .fidMask = 0,
435                 .isTx = FALSE,
436                 .maxPayload = 127,
437                 .msgBufferInterrupt = FALSE, // Recomended for FIFO buffers
438                 .payloadPreambleIndicatorTr = FALSE,
439                 .rejectNullFrames = TRUE,
440                 .rejectStaticSegment = FALSE,
441                 .singleTransmit = FALSE,
442                 .slotId = 12
443         },
444         {
445                 .channel = FR_CHANNEL_AB,
446                 .cycleCounterFiltering = 0,
447                 .fidMask = 0,
448                 .isTx = FALSE,
449                 .maxPayload = 127,
450                 .msgBufferInterrupt = FALSE, // Recomended for FIFO buffers
451                 .payloadPreambleIndicatorTr = FALSE,
452                 .rejectNullFrames = TRUE,
453                 .rejectStaticSegment = FALSE,
454                 .singleTransmit = FALSE,
455                 .slotId = 12
456         },
457         {
458                 .channel = FR_CHANNEL_AB,
459                 .cycleCounterFiltering = 0,
460                 .fidMask = 0,
461                 .isTx = FALSE,
462                 .maxPayload = 127,
463                 .msgBufferInterrupt = FALSE, // Recomended for FIFO buffers
464                 .payloadPreambleIndicatorTr = FALSE,
465                 .rejectNullFrames = TRUE,
466                 .rejectStaticSegment = FALSE,
467                 .singleTransmit = FALSE,
468                 .slotId = 12
469         }
470 };
471
472 static Fr_TMS570LS_BufferConfigType Fr_node_B_fifo_buffers_config[] = {
473         {
474                 .channel = FR_CHANNEL_AB,
475                 .cycleCounterFiltering = 0,
476                 .fidMask = 0,
477                 .isTx = FALSE,
478                 .maxPayload = 64,
479                 .msgBufferInterrupt = FALSE, // Recommended for FIFO buffers
480                 .payloadPreambleIndicatorTr = FALSE,
481                 .rejectNullFrames = TRUE,
482                 .rejectStaticSegment = FALSE,
483                 .singleTransmit = FALSE,
484                 .slotId = 0 // No Frame is rejected
485         },
486         {
487                 .channel = FR_CHANNEL_AB,
488                 .cycleCounterFiltering = 0,
489                 .fidMask = 0,
490                 .isTx = FALSE,
491                 .maxPayload = 64,
492                 .msgBufferInterrupt = FALSE, // Recommended for FIFO buffers
493                 .payloadPreambleIndicatorTr = FALSE,
494                 .rejectNullFrames = TRUE,
495                 .rejectStaticSegment = FALSE,
496                 .singleTransmit = FALSE,
497                 .slotId = 0 // No Frame is rejected
498         },
499         {
500                 .channel = FR_CHANNEL_AB,
501                 .cycleCounterFiltering = 0,
502                 .fidMask = 0,
503                 .isTx = FALSE,
504                 .maxPayload = 64,
505                 .msgBufferInterrupt = FALSE, // Recommended for FIFO buffers
506                 .payloadPreambleIndicatorTr = FALSE,
507                 .rejectNullFrames = TRUE,
508                 .rejectStaticSegment = FALSE,
509                 .singleTransmit = FALSE,
510                 .slotId = 0 // No Frame is rejected
511         },
512         {
513                 .channel = FR_CHANNEL_AB,
514                 .cycleCounterFiltering = 0,
515                 .fidMask = 0,
516                 .isTx = FALSE,
517                 .maxPayload = 64,
518                 .msgBufferInterrupt = FALSE, // Recommended for FIFO buffers
519                 .payloadPreambleIndicatorTr = FALSE,
520                 .rejectNullFrames = TRUE,
521                 .rejectStaticSegment = FALSE,
522                 .singleTransmit = FALSE,
523                 .slotId = 0 // No Frame is rejected
524         },
525         {
526                 .channel = FR_CHANNEL_AB,
527                 .cycleCounterFiltering = 0,
528                 .fidMask = 0,
529                 .isTx = FALSE,
530                 .maxPayload = 64,
531                 .msgBufferInterrupt = FALSE, // Recommended for FIFO buffers
532                 .payloadPreambleIndicatorTr = FALSE,
533                 .rejectNullFrames = TRUE,
534                 .rejectStaticSegment = FALSE,
535                 .singleTransmit = FALSE,
536                 .slotId = 0 // No Frame is rejected
537         }
538 };
539
540 /**
541  * This is an unifying configuration structure for the node A.
542  * It joins all the configuration structure together.
543  */
544 static Fr_ConfigType Fr_config_node_A = {
545         .clusterConfiguration = &Fr_cluster_config,
546         .dynamicBufferConfigs = Fr_node_A_dynamic_buffers_config,
547         .fifoBufferConfigs = Fr_node_A_fifo_buffers_config,
548         .msgRAMConfig = &Fr_node_A_msgRAM_config,
549         .nodeConfiguration = &Fr_node_A_config,
550         .staticBufferConfigs = Fr_node_A_static_buffers_config
551 };
552
553 /**
554  * This is an unifying configuration structure for the node A.
555  * It joins all the configuration structure together.
556  */
557 static Fr_ConfigType Fr_config_node_B = {
558         .clusterConfiguration = &Fr_cluster_config,
559         .dynamicBufferConfigs = Fr_node_B_dynamic_buffers_config,
560         .fifoBufferConfigs = Fr_node_B_fifo_buffers_config,
561         .msgRAMConfig = &Fr_node_B_msgRAM_config,
562         .nodeConfiguration = &Fr_node_B_config,
563         .staticBufferConfigs = Fr_node_B_static_buffers_config
564 };
565
566 /* User configuration */
567
568 static Fr_TMS570LS_ClusterConfigType user_cluster_config;
569 static Fr_TMS570LS_NodeConfigType user_node_config;
570 static Fr_TMS570LS_MsgRAMConfig user_msg_ram_config;
571 static Fr_TMS570LS_BufferConfigType user_static_buffer_config[RPP_FR_MAX_STATIC_BUF_CNT];
572 static Fr_TMS570LS_BufferConfigType user_dynamic_buffer_config[RPP_FR_MAX_DYNAMIC_BUF_CNT];
573 static Fr_TMS570LS_BufferConfigType user_fifo_buffer_config[RPP_FR_MAX_FIFO_BUF_DEPTH];
574 static Fr_ConfigType user_configuration = {
575         .clusterConfiguration = &user_cluster_config,
576         .nodeConfiguration = &user_node_config,
577         .msgRAMConfig = &user_msg_ram_config,
578         .staticBufferConfigs = user_static_buffer_config,
579         .dynamicBufferConfigs = user_dynamic_buffer_config,
580         .fifoBufferConfigs = user_fifo_buffer_config,
581 };
582 ;
583
584 #define USER_CONFIG_NOT_DONE        0x0
585 #define USER_CONFIG_CLUSTER         0x1
586 #define USER_CONFIG_NODE            0x2
587
588 static uint8_t user_configuration_state = USER_CONFIG_NOT_DONE;
589 static uint8_t user_static_buffer_configured = 0;
590 static uint8_t user_dynamic_buffer_configured = 0;
591 static uint8_t user_fifo_buffer_depth = 0;
592
593 /**
594  * Split string into numbers
595  *
596  * The function takes a string with hexadecimal numbers,
597  * separated by spaces, and converts it into an array of numbers.
598  *
599  * For example "0x2 0xA 0XDD 0xABCD" -> {0x2, 0xA, 0XDD, 0xABCD}
600  *
601  * @param [in] params Address of the string which will be converted
602  * @param [in] params_cnt A number of parameters, which should be found and converted from the string params
603  * @param [out] tmp_params Address, where converted array of numbers will be stored
604  *
605  * @return SUCCESS when all parameters were converted to the array of numbers,
606  *         FAILURE when the string was too short, too long or some other error occurred.
607  */
608 static int8_t cmd_fr_parse_params(const char *params, uint32_t params_cnt, uint32_t *tmp_params)
609 {
610         char cpy_params[256];
611         char *token;
612         int i;
613
614         if (params == NULL || tmp_params == NULL)
615                 return FAILURE;
616         strncpy(cpy_params, params, 256);
617         token = strtok(cpy_params, " ");
618         if (token == NULL)
619                 return FAILURE;
620         for (i = 0; i < params_cnt; i++) {
621                 if (sscanf(token, "%i", &tmp_params[i]) == EOF)     // No number found
622                         return FAILURE;
623                 if ((token = strtok(NULL, " ")) == NULL && i < params_cnt-1)    // Not enough parameters in the string
624                         return FAILURE;
625         }
626         return SUCCESS;
627 }
628
629 int8_t cmd_fr_config_cluster_params(const char *params)
630 {
631         uint32_t tmp_params[FR_CLUSTER_PARAMS_CNT];
632
633         if (cmd_fr_parse_params(params, FR_CLUSTER_PARAMS_CNT, tmp_params) == FAILURE)
634                 return FAILURE;
635
636         user_cluster_config.gColdStartAttempts = tmp_params[0];
637         user_cluster_config.gListenNoise = tmp_params[1];
638         user_cluster_config.gMacroPerCycle = tmp_params[2];
639         user_cluster_config.gMaxWithoutClockCorrectionFatal = tmp_params[3];
640         user_cluster_config.gMaxWithoutClockCorrectionPassive = tmp_params[4];
641         user_cluster_config.gNetworkManagementVectorLength = tmp_params[5];
642         user_cluster_config.gNumberOfMinislots = tmp_params[6];
643         user_cluster_config.gNumberOfStaticSlots = tmp_params[7];
644         user_cluster_config.gOffsetCorrectionStart = tmp_params[8];
645         user_cluster_config.gPayloadLengthStatic = tmp_params[9];
646         user_cluster_config.gSyncNodeMax = tmp_params[10];
647         user_cluster_config.gdActionPointOffset = tmp_params[11];
648         user_cluster_config.gdCASRxLowMax = tmp_params[12];
649         user_cluster_config.gdDynamicSlotIdlePhase = tmp_params[13];
650         user_cluster_config.gdMinislot = tmp_params[14];
651         user_cluster_config.gdMinislotActionPointOffset = tmp_params[15];
652         user_cluster_config.gdNIT = tmp_params[16];
653         user_cluster_config.gdSampleClockPeriod = tmp_params[17];
654         user_cluster_config.gdStaticSlot = tmp_params[18];
655         user_cluster_config.gdTSSTransmitter = tmp_params[19];
656         user_cluster_config.gdWakeupSymbolRxIdle = tmp_params[20];
657         user_cluster_config.gdWakeupSymbolRxLow = tmp_params[21];
658         user_cluster_config.gdWakeupSymbolRxWindow = tmp_params[22];
659         user_cluster_config.gdWakeupSymbolTxIdle = tmp_params[23];
660         user_cluster_config.gdWakeupSymbolTxLow = tmp_params[24];
661
662         user_configuration_state |= USER_CONFIG_CLUSTER;
663         return SUCCESS;
664 }
665
666 int8_t cmd_fr_config_node_params(const char *params)
667 {
668         uint32_t tmp_params[FR_NODE_PARAMS_CNT+2];  // +2 because two more parameters from message RAM structure are expected in the string.
669         Fr_ChannelType channels[3] = {FR_CHANNEL_A, FR_CHANNEL_B, FR_CHANNEL_AB};
670         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};
671
672         if (cmd_fr_parse_params(params, FR_NODE_PARAMS_CNT+2, tmp_params) == FAILURE)
673                 return FAILURE;
674
675         user_node_config.pAllowHaltDueToClock = tmp_params[0];
676         user_node_config.pAllowPassiveToActive = tmp_params[1];
677         if (tmp_params[2] > 2) return FAILURE;
678         user_node_config.pChannels = channels[ tmp_params[2] ];
679         user_node_config.pClusterDriftDamping = tmp_params[3];
680         user_node_config.pDelayCompensationA = tmp_params[4];
681         user_node_config.pDelayCompensationB = tmp_params[5];
682         user_node_config.pExternOffsetCorrection = tmp_params[6];
683         user_node_config.pExternRateCorrection = tmp_params[7];
684         user_node_config.pKeySlotUsedForStartup = tmp_params[8];
685         user_node_config.pKeySlotUsedForSync = tmp_params[9];
686         user_node_config.pLatestTx = tmp_params[10];
687         user_node_config.pMacroInitialOffsetA = tmp_params[11];
688         user_node_config.pMacroInitialOffsetB = tmp_params[12];
689         user_node_config.pMicroInitialOffsetA = tmp_params[13];
690         user_node_config.pMicroInitialOffsetB = tmp_params[14];
691         user_node_config.pMicroPerCycle = tmp_params[15];
692         user_node_config.pRateCorrectionOut = tmp_params[16];
693         user_node_config.pOffsetCorrectionOut = tmp_params[17];
694         user_node_config.pSamplesPerMicrotick = tmp_params[18];
695         user_node_config.pSingleSlotEnabled = tmp_params[19];
696         if (tmp_params[20] > 1) return FAILURE;
697         user_node_config.pWakeupChannel = channels[ tmp_params[20] ];
698         user_node_config.pWakeupPattern = tmp_params[21];
699         user_node_config.pdAcceptedStartupRange = tmp_params[22];
700         user_node_config.pdListenTimeout = tmp_params[23];
701         user_node_config.pdMaxDrift = tmp_params[24];
702         user_node_config.pDecodingCorrection = tmp_params[25];
703         user_msg_ram_config.syncFramePayloadMultiplexEnabled = tmp_params[26];
704         if (tmp_params[27] > 3) return FAILURE;
705         user_msg_ram_config.secureBuffers = secure[ tmp_params[27] ];
706
707         user_configuration_state |= USER_CONFIG_NODE;
708         return SUCCESS;
709 }
710
711 int cmd_do_fr_config_fifo(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
712 {
713         Fr_TMS570LS_BufferConfigType *fifo_buffer_ptr = &user_fifo_buffer_config[0];
714         int ret, i;
715         char channel[3], rej_static_frames[8], rej_null_frames[8];
716         unsigned depth, slot, cycleset, maxpayload, mask;
717         Fr_TMS570LS_BufferConfigType tmp_buffer;
718
719         if (fr_initialized) {
720                 rpp_sci_printf("FlexRay configuration can not be modified after frbtinit was called.\n");
721                 return -CMDERR_BADCFG;
722         }
723
724         ret = sscanf(param[2], "rejslot%i slotmask%i depth%i %2s cyc%i max%i %10s %10s",
725                                  &slot,
726                                  &mask,
727                                  &depth,
728                                  channel,
729                                  &cycleset,
730                                  &maxpayload,
731                                  rej_null_frames,
732                                  rej_static_frames
733                                  );
734         if (ret != 8) {
735                 printf("Error parsing parameter %d\n", ret+1);
736                 return -CMDERR_BADPAR;
737         }
738
739         if (depth < 1 || depth >= RPP_FR_MAX_FIFO_BUF_DEPTH)
740                 return badpar("Depth too high\n");
741         user_fifo_buffer_depth = depth;
742
743         if (slot > 2047)
744                 return badpar("Invalid slot number\n");
745         tmp_buffer.slotId = slot;
746         if (slot > 2047)
747                 return badpar("Invalid mask\n");
748         tmp_buffer.fidMask = mask;
749         if (strcmp(channel, "A") == 0) tmp_buffer.channel = FR_CHANNEL_A;
750         else if (strcmp(channel, "B") == 0) tmp_buffer.channel = FR_CHANNEL_B;
751         else if (strcmp(channel, "AB") == 0) tmp_buffer.channel = FR_CHANNEL_AB;
752         else return badpar("Channel parsing error\n");
753
754         if (cycleset >= 0x80)
755                 return badpar("Cycle set must be less than 0x80.\n");
756         tmp_buffer.cycleCounterFiltering = cycleset;
757
758         if (maxpayload >= 128)
759                 return badpar("Maximum payload in half-words must be less than 128\n");
760         tmp_buffer.maxPayload = maxpayload;
761
762         if (strcmp(rej_null_frames, "rejnull") == 0) tmp_buffer.rejectNullFrames = true;
763         else if (strcmp(rej_null_frames, "accnull") == 0) tmp_buffer.rejectNullFrames = false;
764         else return badpar("Reject/accept NULL frames parsing error\n");
765
766         if (strcmp(rej_static_frames, "rejstat") == 0)
767                 tmp_buffer.rejectStaticSegment = true;
768         else if (strcmp(rej_static_frames, "accstat") == 0)
769                 tmp_buffer.rejectStaticSegment = false;
770         else return badpar("Invalid reject/accept static frame parameter");
771
772         for (i = 0; i < user_fifo_buffer_depth; i++) {
773                 fifo_buffer_ptr[i].slotId = tmp_buffer.slotId;
774                 fifo_buffer_ptr[i].fidMask = tmp_buffer.fidMask;
775                 fifo_buffer_ptr[i].maxPayload = tmp_buffer.maxPayload;
776                 fifo_buffer_ptr[i].channel = tmp_buffer.channel;
777                 fifo_buffer_ptr[i].cycleCounterFiltering = tmp_buffer.cycleCounterFiltering;
778                 fifo_buffer_ptr[i].isTx = FALSE;
779                 fifo_buffer_ptr[i].singleTransmit = FALSE;
780                 fifo_buffer_ptr[i].payloadPreambleIndicatorTr = FALSE;
781                 fifo_buffer_ptr[i].rejectNullFrames = tmp_buffer.rejectNullFrames;
782                 fifo_buffer_ptr[i].rejectStaticSegment = tmp_buffer.rejectStaticSegment;
783                 fifo_buffer_ptr[i].msgBufferInterrupt = 0;
784         }
785
786         printf("frbtcfgfifo rejslot%i slotmask%i depth%i %2s cyc%i max%i %10s %10s\n",
787                    slot,
788                    mask,
789                    depth,
790                    channel,
791                    cycleset,
792                    maxpayload,
793                    rej_null_frames,
794                    rej_static_frames
795                    );
796
797         return SUCCESS;
798 }
799
800 int cmd_do_fr_config_bufer(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
801 {
802         Fr_TMS570LS_BufferConfigType *cfg;
803
804         int ret;
805         char buf_type, channel[3],rxtx[3], single_continuous[11];
806         unsigned buffer, slot, cycleset, maxpayload, intr, preamb;
807
808         if (fr_initialized) {
809                 rpp_sci_printf("FlexRay configuration can not be modified after frbtinit was called.\n");
810                 return -CMDERR_BADCFG;
811         }
812
813         ret = sscanf(param[1], "%c%i slot%i %2s cyc%i %2s max%i %10s ppi%i int%i",
814                                  &buf_type,
815                                  &buffer,
816                                  &slot,
817                                  channel,
818                                  &cycleset,
819                                  rxtx,
820                                  &maxpayload,
821                                  single_continuous,
822                                  &preamb,
823                                  &intr
824                                  );
825         if (ret != 10) {
826                 printf("Error parsing parameter %d\n", ret+1);
827                 return -CMDERR_BADPAR;
828
829         }
830
831         switch (buf_type) {
832         case 'S':
833                 if (buffer >= RPP_FR_MAX_STATIC_BUF_CNT)
834                         return badpar("Buffer index too high\n");
835                 cfg = &user_static_buffer_config[buffer];
836                 break;
837         case 'D':
838                 if (buffer >= RPP_FR_MAX_DYNAMIC_BUF_CNT)
839                         return badpar("Buffer index too high\n");
840                 cfg = &user_dynamic_buffer_config[buffer];
841                 break;
842         default:
843                 return badpar("Invalid buffer type (S, D)\n");
844         }
845
846         if (slot < 1 || slot > 2047)
847                 return badpar("Invalid slot number\n");
848         cfg->slotId = slot;
849
850         if (strcmp(channel, "A") == 0) cfg->channel = FR_CHANNEL_A;
851         else if (strcmp(channel, "B") == 0) cfg->channel = FR_CHANNEL_B;
852         else if (strcmp(channel, "AB") == 0) cfg->channel = FR_CHANNEL_AB;
853         else return badpar("Channel parsing error\n");
854         if (buf_type == 'D' && cfg->channel == FR_CHANNEL_AB)
855                 return badpar("Dynamic segment buffers cannot have AB channels.\n");
856
857         if (cycleset >= 0x80)
858                 return badpar("Cycle set must be less than 0x80.\n");
859         cfg->cycleCounterFiltering = cycleset;
860
861         if (strcmp(rxtx, "tx") == 0) cfg->isTx = true;
862         else if (strcmp(rxtx, "rx") == 0) cfg->isTx = false;
863         else return badpar("RX/TX parsing error\n");
864
865         if (maxpayload >= 128)
866                 return badpar("Maximum payload in half-words must be less than 128\n");
867         cfg->maxPayload = maxpayload;
868
869         if (0 == strcmp(single_continuous, "single") ||
870                 0 == strcmp(single_continuous, "s"))
871                 cfg->singleTransmit = true;
872         else if (0 == strcmp(single_continuous, "continuous") ||
873                          0 == strcmp(single_continuous, "c"))
874                 cfg->singleTransmit = false;
875         else return badpar("Invalid single/continuous parameter");
876
877         if (preamb > 1)
878                 return badpar("Payload preamble indicator must be 0 or 1");
879         cfg->payloadPreambleIndicatorTr = preamb;
880
881         if (intr > 1)
882                 return badpar("Interrupt parameter must be 0 or 1");
883         cfg->msgBufferInterrupt = intr;
884
885         switch (buf_type) {
886         case 'S':
887                 if (buffer >= user_static_buffer_configured)
888                         user_static_buffer_configured = buffer + 1;
889                 break;
890         case 'D':
891                 if (buffer >= user_dynamic_buffer_configured)
892                         user_dynamic_buffer_configured = buffer + 1;
893                 break;
894         }
895
896         printf("frbtcfgbuf%c%i slot%i %2s cyc%i %2s max%i %10s ppi%i int%i\n",
897                    buf_type,
898                    buffer,
899                    slot,
900                    channel,
901                    cycleset,
902                    rxtx,
903                    maxpayload,
904                    single_continuous,
905                    preamb,
906                    intr
907                    );
908
909         return 0;
910 }
911
912
913
914 /**
915  *  @brief      Do the user configuration of the FlexRay cluster parameters
916  *
917  * @param[in]   cmd_io  Pointer to IO stack
918  * @param[in]   des             Pointer to command descriptor
919  * @param[in]   param   Parameters of command
920  * @return      0 when OK or error code
921  */
922 int cmd_do_fr_user_config(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
923 {
924         char *token;
925
926         if (fr_initialized) {
927                 rpp_sci_printf("FlexRay configuration can not be modified after frbtinit was called.\n");
928                 return -CMDERR_BADCFG;
929         }
930
931         token = strtok(param[1], " ");
932         if (strcmp(token, "cluster") == 0) {
933                 if (cmd_fr_config_cluster_params(param[2]) == FAILURE) {
934                         rpp_sci_printf("FlexRay cluster configuration not accepted.\n");
935                         return -CMDERR_BADPAR;
936                 }
937                 rpp_sci_printf("FlexRay cluster configuration accepted.\n");
938         }
939         else if (strcmp(token, "node") == 0) {
940                 if (cmd_fr_config_node_params(param[2]) == FAILURE) {
941                         rpp_sci_printf("FlexRay node configuration not accepted.\n");
942                         return -CMDERR_BADPAR;
943                 }
944                 rpp_sci_printf("FlexRay node configuration accepted.\n");
945         }
946         else
947                 return -CMDERR_BADPAR;
948
949         return 0;
950 }
951
952 /**
953  *  @brief      Initialize the device as FlexRay node.
954  *
955  * @param[in]   cmd_io  Pointer to IO stack
956  * @param[in]   des             Pointer to command descriptor
957  * @param[in]   param   Parameters of command
958  * @return      0 when OK or error code
959  */
960 int cmd_do_fr_init(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
961 {
962         const Fr_ConfigType *Fr_ConfigPtr = NULL;
963         int8_t retVal = SUCCESS;
964         uint32_t error = ERR_PARAM_NO_ERROR;
965
966         if (*param[1] == 'A')
967                 Fr_ConfigPtr = &Fr_config_node_A;
968         else if (*param[1] == 'B')
969                 Fr_ConfigPtr = &Fr_config_node_B;
970         else if (*param[1] == 'U') {    // Select the user configuration  -  call config commands first
971                 user_msg_ram_config.statSegmentBufferCount = user_static_buffer_configured;
972                 user_msg_ram_config.dynSegmentBufferCount = user_dynamic_buffer_configured;
973                 user_msg_ram_config.fifoBufferCount = user_fifo_buffer_depth;
974                 Fr_ConfigPtr = &user_configuration;
975         }
976         else
977                 return -CMDERR_BADPAR;
978
979         retVal = rpp_fr_init_driver(Fr_ConfigPtr, &error);
980         if (retVal == SUCCESS) {
981                 rpp_sci_printf("FlexRay driver initialized.\r\n");
982                 fr_initialized = TRUE;
983         }
984         else {
985                 retVal = rpp_fr_init_controller(0, &error);
986                 if (retVal == SUCCESS) {
987                         rpp_sci_printf("FlexRay controller reinitialized.\r\n");
988                         return 0;
989                 }
990                 else {
991                         rpp_sci_printf("FlexRay needs to be configured before initialization.\r\n");
992                         return -CMDERR_BADCFG;
993                 }
994         }
995
996         retVal = rpp_fr_init_controller(0, &error);
997         if (retVal == SUCCESS)
998                 rpp_sci_printf("FlexRay controller initialized.\r\n");
999         else {
1000                 if (error & FR_INIT_ERR_CLUSTER_CONFIG)
1001                         rpp_sci_printf("Cluster configuration data error: %x\r\n", (retVal & 0x3FFFFFE) >> 1 );
1002                 else if (error & FR_INIT_ERR_NODE_CONFIG)
1003                         rpp_sci_printf("Node configuration data error: %x\r\n", (retVal & 0x3FFFFFE) >> 1 );
1004                 else if (error & FR_INIT_ERR_MSGRAM_CONFIG)
1005                         rpp_sci_printf("Message RAM configuration data error: %x\r\n", (retVal & 0x3FFFFFE) >> 1 );
1006                 else if (error & FR_INIT_ERR_BUFFPARAM_CONFIG)
1007                         rpp_sci_printf("Buffer configuration data error: %x\r\n", (retVal & 0x3FFFFFE) >> 1 );
1008                 else if (error & (uint32_t)FR_INIT_ERR_BUFF_CONFIG)
1009                         rpp_sci_printf("Buffer configuration error: %x\r\n", (retVal & 0x3FFFFFE) >> 1 );
1010                 else
1011                         rpp_sci_printf("POC state switching error.\r\n");
1012                 return -CMDERR_BADCFG;
1013         }
1014         return 0;
1015 }
1016
1017 /**
1018  *  @brief      Starts FlexRay communication
1019  *
1020  * @param[in]   cmd_io  Pointer to IO stack
1021  * @param[in]   des             Pointer to command descriptor
1022  * @param[in]   param   Parameters of command
1023  * @return      0 when OK or error code
1024  */
1025 int cmd_do_fr_start(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
1026 {
1027         int8_t retVal = SUCCESS;
1028         uint32_t error = ERR_PARAM_NO_ERROR;
1029
1030         retVal = rpp_fr_start_communication(0, &error);
1031         if (retVal == SUCCESS)
1032                 rpp_sci_printf("FlexRay communication is running.\r\n");
1033         else {
1034                 if (error & FR_STARTUP_ERR_SW_STUP_FOLLOW)
1035                         rpp_sci_printf("Can not switch POC to RUN state.\r\n");
1036                 else if (error & FR_STARTUP_ERR_CSINH_DIS)
1037                         rpp_sci_printf("Cold start inhibit disabled error.\r\n");
1038                 else if (error & FR_STARTUP_ERR_SW_STUP_READY)
1039                         rpp_sci_printf("Can not switch back to READY from STARTUP.\r\n");
1040                 else if (error & FR_STARTUP_ERR_SW_STUP_AS_NCOLD)
1041                         rpp_sci_printf("Can not switch to STARTUP as non-coldstarter.\r\n");
1042                 else
1043                         rpp_sci_printf("General error.\r\n");
1044                 return -CMDERR_BADCFG;
1045         }
1046         return 0;
1047 }
1048
1049 /**
1050  *  @brief      Invokes POC command ALL_SLOTS
1051  *
1052  * @param[in]   cmd_io  Pointer to IO stack
1053  * @param[in]   des             Pointer to command descriptor
1054  * @param[in]   param   Parameters of command
1055  * @return      0 when OK or error code
1056  */
1057 int cmd_do_fr_allslots(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
1058 {
1059         int8_t retVal = ERR_PARAM_NO_ERROR;
1060
1061         retVal = rpp_fr_all_slots(0);
1062         if (retVal == SUCCESS)
1063                 rpp_sci_printf("FlexRay node started communication in all slots.\r\n");
1064         else {
1065                 rpp_sci_printf("General error.\r\n");
1066                 return -CMDERR_BADCFG;
1067         }
1068         return 0;
1069 }
1070
1071 /**
1072  *  @brief      Halt FlexRay communication
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_halt(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
1080 {
1081         int8_t retVal = ERR_PARAM_NO_ERROR;
1082
1083         retVal = rpp_fr_halt_communication(0);
1084         if (retVal == SUCCESS)
1085                 rpp_sci_printf("FlexRay node communication halted.\r\n");
1086         else {
1087                 rpp_sci_printf("General error.\r\n");
1088                 return -CMDERR_BADCFG;
1089         }
1090         return 0;
1091 }
1092
1093 /**
1094  *  @brief      Abort FlexRay communication
1095  *
1096  * @param[in]   cmd_io  Pointer to IO stack
1097  * @param[in]   des             Pointer to command descriptor
1098  * @param[in]   param   Parameters of command
1099  * @return      0 when OK or error code
1100  */
1101 int cmd_do_fr_abort(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
1102 {
1103         int8_t retVal = ERR_PARAM_NO_ERROR;
1104
1105         retVal = rpp_fr_abort_communication(0);
1106         if (retVal == SUCCESS)
1107                 rpp_sci_printf("FlexRay node communication aborted.\r\n");
1108         else {
1109                 rpp_sci_printf("General error.\r\n");
1110                 return -CMDERR_BADCFG;
1111         }
1112         return 0;
1113 }
1114
1115 /**
1116  *  @brief      Send wake up pattern
1117  *
1118  * @param[in]   cmd_io  Pointer to IO stack
1119  * @param[in]   des             Pointer to command descriptor
1120  * @param[in]   param   Parameters of command
1121  * @return      0 when OK or error code
1122  */
1123 int cmd_do_fr_sendwup(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
1124 {
1125         int8_t retVal = ERR_PARAM_NO_ERROR;
1126
1127         retVal = rpp_fr_send_wup(0);
1128         if (retVal == SUCCESS)
1129                 rpp_sci_printf("Wake up pattern has been sent.\r\n");
1130         else {
1131                 rpp_sci_printf("General error.\r\n");
1132                 return -CMDERR_BADCFG;
1133         }
1134         return 0;
1135 }
1136
1137 /**
1138  *  @brief      Set channel for wake up pattern sending.
1139  *
1140  * @param[in]   cmd_io  Pointer to IO stack
1141  * @param[in]   des             Pointer to command descriptor
1142  * @param[in]   param   Parameters of command
1143  * @return      0 when OK or error code
1144  */
1145 int cmd_do_fr_setwuchannel(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
1146 {
1147         int8_t retVal = ERR_PARAM_NO_ERROR;
1148         Fr_ChannelType channel = FR_CHANNEL_A;
1149
1150         if (*param[1] == 'A')
1151                 channel = FR_CHANNEL_A;
1152         else if (*param[1] == 'B')
1153                 channel = FR_CHANNEL_B;
1154         else
1155                 return -CMDERR_BADPAR;
1156         retVal = rpp_fr_set_wu_channel(0, channel);
1157         if (retVal == SUCCESS)
1158                 rpp_sci_printf("Wake up channel has been set.\r\n");
1159         else {
1160                 rpp_sci_printf("General error.\r\n");
1161                 return -CMDERR_BADCFG;
1162         }
1163         return 0;
1164 }
1165
1166 /**
1167  *  @brief      Get and print POC status of the FlexRay controller.
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_getpocstatus(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
1175 {
1176         int8_t retVal = ERR_PARAM_NO_ERROR;
1177         Fr_POCStatusType status;
1178         char *ErrorModeStrings[] = {"ACTIVE", "HALT", "PASSIVE"};
1179         char *SlotModeStrings[]  = {"KEYSLOT", "ALL_PENDING", "ALL"};
1180         char *StartupStateStrings[]  = {
1181                 "UNDEFINED", "COLDSTART_LISTEN", "COLDSTART_CHECK", "COLDSTART_JOIN",
1182                 "COLDSTART_CONSISTENCY_CHECK", "INTEGRATION_LISTEN", "INITIALIZE_SCHEDULE", "INTEGRATION_CONSISTENCY_CHECK",
1183                 "COLDSTART_GAP", "EXTERNAL_STARTUP", "ABORT", "COLDSTART_COLLISION_RESOLUTION",
1184                 "PREPARE"
1185         };
1186         char *StateStrings[]  = {
1187                 "CONFIG", "DEFAULT_CONFIG", "HALT", "NORMAL_ACTIVE",
1188                 "NORMAL_PASSIVE", "READY", "STARTUP", "LOOPBACK",
1189                 "MONITOR", "WAKEUP"
1190         };
1191         char *WakeupStatusStrings[]  = {
1192                 "UNDEFINED", "RECEIVED_HEADER", "RECEIVED_WUP", "COLLISION_HEADER",
1193                 "COLLISION_WUP", "COLLISION_UNKNOWN", "TRANSMITTED"
1194         };
1195
1196         retVal = rpp_fr_get_poc_status(0, &status);
1197         if (retVal == SUCCESS) {
1198                 rpp_sci_printf("POC status:\r\n");
1199                 rpp_sci_printf("CHIHaltRequest: %s\r\n", (status.CHIHaltRequest == TRUE) ? "TRUE" : "FALSE");
1200                 rpp_sci_printf("CHIReadyRequest: %s\r\n", (status.CHIReadyRequest == TRUE) ? "TRUE" : "FALSE");
1201                 rpp_sci_printf("ColdstartNoise: %s\r\n", (status.ColdstartNoise == TRUE) ? "TRUE" : "FALSE");
1202                 rpp_sci_printf("Freeze: %s\r\n", (status.Freeze == TRUE) ? "TRUE" : "FALSE");
1203                 rpp_sci_printf("ErrorMode: %s\r\n", ErrorModeStrings[status.ErrorMode]);
1204                 rpp_sci_printf("SlotMode: %s\r\n", SlotModeStrings[status.SlotMode]);
1205                 rpp_sci_printf("StartupState: %s\r\n", StartupStateStrings[status.StartupState]);
1206                 rpp_sci_printf("State: %s\r\n", StateStrings[status.State]);
1207                 rpp_sci_printf("WakeupStatus: %s\r\n", WakeupStatusStrings[status.WakeupStatus]);
1208         }
1209         else {
1210                 rpp_sci_printf("General error.\r\n");
1211                 return -CMDERR_BADCFG;
1212         }
1213         return 0;
1214 }
1215
1216 /**
1217  *  @brief      Send given data through the FlexRay in selected slot.
1218  *
1219  * @param[in]   cmd_io  Pointer to IO stack
1220  * @param[in]   des             Pointer to command descriptor
1221  * @param[in]   param   Parameters of command
1222  * @return      0 when OK or error code
1223  */
1224 int cmd_do_fr_transmittxlpdu(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
1225 {
1226         int8_t retVal = ERR_PARAM_NO_ERROR;
1227         uint32_t bufferID;
1228         uint8_t dataLength;
1229         int values[MAX_PARAM_VALUES_NUM];
1230         uint8_t data[MAX_PARAM_VALUES_NUM];
1231         char *token = NULL;
1232
1233         if (sscanf(param[1], "%d", &bufferID) != 1)
1234                 return -CMDERR_BADPAR;
1235         if (sscanf(param[2], " %2x", &values[0]) != 1)
1236                 return -CMDERR_BADPAR;
1237         data[0] = (uint8_t)values[0];
1238         token = strtok(param[2], " ");
1239         token = strtok(NULL, " ");
1240         dataLength = 1;
1241         while (dataLength < MAX_PARAM_VALUES_NUM && token != NULL) {
1242                 if (sscanf(token, "%2x", &values[dataLength]) == EOF)
1243                         break;
1244                 data[dataLength] = (uint8_t)values[dataLength];
1245                 token = strtok(NULL, " ");
1246                 dataLength++;
1247         }
1248
1249         retVal = rpp_fr_transmit_lpdu(0, bufferID, data, dataLength);
1250         if (retVal == SUCCESS)
1251                 rpp_sci_printf("Data were set for transmission.\r\n");
1252         else {
1253                 rpp_sci_printf("General error.\r\n");
1254                 return -CMDERR_BADCFG;
1255         }
1256         return 0;
1257 }
1258
1259 /**
1260  *  @brief      Cancel the transmission in the selected slot.
1261  *
1262  * @param[in]   cmd_io  Pointer to IO stack
1263  * @param[in]   des             Pointer to command descriptor
1264  * @param[in]   param   Parameters of command
1265  * @return      0 when OK or error code
1266  */
1267 int cmd_do_fr_canceltxlpdu(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
1268 {
1269         int8_t retVal = ERR_PARAM_NO_ERROR;
1270         uint32_t bufferID;
1271
1272         if (sscanf(param[1], "%d", &bufferID) != 1)
1273                 return -CMDERR_BADPAR;
1274         if (param[2] != NULL)
1275                 return -CMDERR_BADPAR;
1276
1277         retVal = rpp_fr_cancel_transmit_lpdu(0, bufferID);
1278         if (retVal == SUCCESS)
1279                 rpp_sci_printf("Transmission canceled.\r\n");
1280         else {
1281                 rpp_sci_printf("General error.\r\n");
1282                 return -CMDERR_BADCFG;
1283         }
1284         return 0;
1285 }
1286
1287 /**
1288  *  @brief      Receive data from selected slot.
1289  *
1290  * @param[in]   cmd_io  Pointer to IO stack
1291  * @param[in]   des             Pointer to command descriptor
1292  * @param[in]   param   Parameters of command
1293  * @return      0 when OK or error code
1294  */
1295 int cmd_do_fr_receiverxlpdu(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
1296 {
1297         int8_t retVal = ERR_PARAM_NO_ERROR;
1298         uint32_t bufferID;
1299         uint8_t data[cPayloadLengthMax];
1300         Fr_RxLPduStatusType status;
1301         uint8_t receivedLength = 0;
1302         uint8_t i;
1303
1304         if (sscanf(param[1], "%d", &bufferID) != 1)
1305                 return -CMDERR_BADPAR;
1306         if (param[2] != NULL)
1307                 return -CMDERR_BADPAR;
1308
1309         memset(data, 0, sizeof(data));
1310
1311         retVal = rpp_fr_receive_lpdu(0, bufferID, data, &status, &receivedLength);
1312         if (retVal == SUCCESS) {
1313                 switch (status) {
1314                 case FR_RECEIVED_MORE_DATA_AVAILABLE:
1315                         rpp_sci_printf("More messages are still in FIFO:\r\n");
1316                 case FR_RECEIVED:
1317                         rpp_sci_printf("Received message (%d B):\r\n", receivedLength);
1318                         for (i = 0; i < receivedLength; i++) {
1319                                 rpp_sci_printf(" %02x", data[i]);
1320                         }
1321                         rpp_sci_printf("\r\n");
1322                         break;
1323                 default:
1324                         rpp_sci_printf("No message received.\r\n");
1325                         break;
1326                 }
1327         }
1328         else {
1329                 rpp_sci_printf("General error.\r\n");
1330                 return -CMDERR_BADCFG;
1331         }
1332         return 0;
1333 }
1334
1335 /**
1336  *  @brief      Returns TX LPdu status.
1337  *
1338  * @param[in]   cmd_io  Pointer to IO stack
1339  * @param[in]   des             Pointer to command descriptor
1340  * @param[in]   param   Parameters of command
1341  * @return      0 when OK or error code
1342  */
1343 int cmd_do_fr_checktxlpdustatus(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
1344 {
1345         int8_t retVal = ERR_PARAM_NO_ERROR;
1346         uint32_t bufferID;
1347         Fr_TxLPduStatusType status;
1348         char *statusStrings[] = {"is not", "is"};
1349
1350         if (sscanf(param[1], "%d", &bufferID) != 1)
1351                 return -CMDERR_BADPAR;
1352         if (param[2] != NULL)
1353                 return -CMDERR_BADPAR;
1354
1355         retVal = rpp_fr_check_tx_lpdu_status(0, bufferID, &status);
1356         if (retVal == SUCCESS)
1357                 rpp_sci_printf("Message transmission %s pending.\r\n", statusStrings[status]);
1358         else {
1359                 rpp_sci_printf("General error.\r\n");
1360                 return -CMDERR_BADCFG;
1361         }
1362         return 0;
1363 }
1364
1365 /**
1366  *  @brief      Disable buffer.
1367  *
1368  * @param[in]   cmd_io  Pointer to IO stack
1369  * @param[in]   des             Pointer to command descriptor
1370  * @param[in]   param   Parameters of command
1371  * @return      0 when OK or error code
1372  */
1373 int cmd_do_fr_disablelpdu(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
1374 {
1375         int8_t retVal = ERR_PARAM_NO_ERROR;
1376         uint32_t bufferID;
1377
1378         if (sscanf(param[1], "%d", &bufferID) != 1)
1379                 return -CMDERR_BADPAR;
1380         if (param[2] != NULL)
1381                 return -CMDERR_BADPAR;
1382
1383         retVal = rpp_fr_disable_lpdu(0, bufferID);
1384         if (retVal == SUCCESS)
1385                 rpp_sci_printf("Buffer disabled.\r\n");
1386         else {
1387                 rpp_sci_printf("General error.\r\n");
1388                 return -CMDERR_BADCFG;
1389         }
1390         return 0;
1391 }
1392
1393 /**
1394  *  @brief      Print global time of the FlexRay network.
1395  *
1396  * @param[in]   cmd_io  Pointer to IO stack
1397  * @param[in]   des             Pointer to command descriptor
1398  * @param[in]   param   Parameters of command
1399  * @return      0 when OK or error code
1400  */
1401 int cmd_do_fr_getglobaltime(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
1402 {
1403         int8_t retVal = ERR_PARAM_NO_ERROR;
1404         uint8_t cycle = 0;
1405         uint16_t macroTick = 0;
1406
1407         retVal = rpp_fr_get_global_time(0, &cycle, &macroTick);
1408         if (retVal == SUCCESS)
1409                 rpp_sci_printf("Cycle number: %d\r\nMacrotick number: %d\r\n", cycle, macroTick);
1410         else {
1411                 rpp_sci_printf("General error.\r\n");
1412                 return -CMDERR_BADCFG;
1413         }
1414         return 0;
1415 }
1416
1417 /**
1418  *  @brief      Print network management vector of the FlexRay node.
1419  *
1420  * @param[in]   cmd_io  Pointer to IO stack
1421  * @param[in]   des             Pointer to command descriptor
1422  * @param[in]   param   Parameters of command
1423  * @return      0 when OK or error code
1424  */
1425 int cmd_do_fr_getnmvector(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
1426 {
1427         int8_t retVal = ERR_PARAM_NO_ERROR;
1428         uint8_t nmVector[12];
1429         uint8_t i;
1430
1431         retVal = rpp_fr_get_network_management_vector(0, nmVector);
1432         if (retVal == SUCCESS) {
1433                 rpp_sci_printf("Network management vector:");
1434                 for (i = 0; i < Fr_cluster_config.gNetworkManagementVectorLength; i++) {
1435                         rpp_sci_printf(" %x", nmVector[i]);
1436                 }
1437                 rpp_sci_printf("\r\n");
1438         }
1439         else {
1440                 rpp_sci_printf("General error.\r\n");
1441                 return -CMDERR_BADCFG;
1442         }
1443         return 0;
1444 }
1445
1446 int cmd_do_fr_nmwatch(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
1447 {
1448         int8_t retVal = ERR_PARAM_NO_ERROR;
1449         uint8_t nmVector[12];
1450         uint8_t i;
1451
1452         // Calculate wait time in OS ticks
1453         static const portTickType freq_ticks = 100 /* ms */ / portTICK_RATE_MS;
1454         portTickType last_wake_time = xTaskGetTickCount();
1455
1456         while (cmd_io->getc(cmd_io) < 0) {
1457                 retVal = rpp_fr_get_network_management_vector(0, nmVector);
1458                 if (retVal == SUCCESS) {
1459                         rpp_sci_printf("Network management vector:");
1460                         for (i = 0; i < Fr_cluster_config.gNetworkManagementVectorLength; i++) {
1461                                 rpp_sci_printf(" %02x", nmVector[i]);
1462                         }
1463                         rpp_sci_printf("\r");
1464                 }
1465                 else {
1466                         rpp_sci_printf("General error.\r\n");
1467                         return -CMDERR_BADCFG;
1468                 }
1469                 vTaskDelayUntil(&last_wake_time, freq_ticks);
1470         }
1471         rpp_sci_printf("\n");
1472         return 0;
1473 }
1474
1475 /**
1476  *  @brief      Print both channels status of the FlexRay node.
1477  *
1478  * @param[in]   cmd_io  Pointer to IO stack
1479  * @param[in]   des             Pointer to command descriptor
1480  * @param[in]   param   Parameters of command
1481  * @return      0 when OK or error code
1482  */
1483 int cmd_do_fr_getchannelstatus(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
1484 {
1485         int8_t retVal = ERR_PARAM_NO_ERROR;
1486         uint8_t index;
1487         uint8_t channel;
1488         char *decodeStrings[] = {
1489                 "aggregated channel status vSS!ValidFrame",
1490                 "aggregated channel status vSS!SyntaxError",
1491                 "aggregated channel status vSS!ContentError",
1492                 "aggregated channel status additional communication",
1493                 "aggregated channel status vSS!Bviolation",
1494                 "aggregated channel status vSS!TxConflict",
1495                 "Not used (0)",
1496                 "Not used (0)",
1497                 "symbol window status data vSS!ValidMTS",
1498                 "symbol window status data vSS!SyntaxError",
1499                 "symbol window status data vSS!Bviolation",
1500                 "symbol window status data vSS!TxConflict",
1501                 "NIT status data vSS!SyntaxError",
1502                 "NIT status data vSS!Bviolation",
1503                 "Not used (0)",
1504                 "Not used (0)"
1505         };
1506         char *channelNames[] = {"A", "B"};
1507         char *boolStrings[] = {"FALSE", "TRUE"};
1508         uint16_t channelStatuses[2];
1509
1510         retVal = rpp_fr_get_channel_status(0, &channelStatuses[0], &channelStatuses[1]);
1511         if (retVal == SUCCESS)
1512                 for (channel = 0; channel < 2; channel++) {
1513                         rpp_sci_printf("Channel %s status:\r\n", channelNames[channel]);
1514                         for (index = 0; index < 16; index++) {
1515                                 rpp_sci_printf("\t%s: %s\r\n", decodeStrings[index], boolStrings[ (channelStatuses[channel] >> index) & 0x1 ] );
1516                         }
1517                 }
1518         else {
1519                 rpp_sci_printf("General error.\r\n");
1520                 return -CMDERR_BADCFG;
1521         }
1522         return 0;
1523 }
1524
1525 /**
1526  *  @brief      Print clock correction of the FlexRay node
1527  *
1528  * @param[in]   cmd_io  Pointer to IO stack
1529  * @param[in]   des             Pointer to command descriptor
1530  * @param[in]   param   Parameters of command
1531  * @return      0 when OK or error code
1532  */
1533 int cmd_do_fr_getclockcorrection(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
1534 {
1535         int8_t retVal = ERR_PARAM_NO_ERROR;
1536         int16_t rateCorrection;
1537         int32_t offsetCorrection;
1538
1539         retVal = rpp_fr_get_clock_correction(0, &rateCorrection, &offsetCorrection);
1540         if (retVal == SUCCESS)
1541                 rpp_sci_printf("Rate correction: %d\r\nOffset correction: %d\r\n", rateCorrection, offsetCorrection);
1542         else {
1543                 rpp_sci_printf("General error.\r\n");
1544                 return -CMDERR_BADCFG;
1545         }
1546         return 0;
1547 }
1548
1549 /**
1550  *  @brief      Print list of syncframec transmitted on both channels via the even and odd cycle.
1551  *
1552  * @param[in]   cmd_io  Pointer to IO stack
1553  * @param[in]   des             Pointer to command descriptor
1554  * @param[in]   param   Parameters of command
1555  * @return      0 when OK or error code
1556  */
1557 int cmd_do_fr_getsyncframelist(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
1558 {
1559         int8_t retVal = ERR_PARAM_NO_ERROR;
1560         uint16_t channelAEvenList[FR_MAX_SYNC_FRAME_LIST_SIZE];
1561         uint16_t channelBEvenList[FR_MAX_SYNC_FRAME_LIST_SIZE];
1562         uint16_t channelAOddList[FR_MAX_SYNC_FRAME_LIST_SIZE];
1563         uint16_t channelBOddList[FR_MAX_SYNC_FRAME_LIST_SIZE];
1564         uint32_t listSize = 0;
1565         uint8_t i;
1566
1567         if (sscanf(param[1], "%d", &listSize) != 1)
1568                 return -CMDERR_BADPAR;
1569         if (param[2] != NULL)
1570                 return -CMDERR_BADPAR;
1571         if (listSize > FR_MAX_SYNC_FRAME_LIST_SIZE)
1572                 return -CMDERR_BADPAR;
1573
1574         retVal = rpp_fr_get_sync_frame_list(0, listSize, channelAEvenList, channelBEvenList, channelAOddList, channelBOddList);
1575         if (retVal == SUCCESS) {
1576                 rpp_sci_printf("| Channel A even | channel B even | channel A odd  | channel B odd  |\r\n");
1577                 rpp_sci_printf("|----------------|----------------|----------------|----------------|\r\n");
1578                 for (i = 0; i < listSize; i++) {
1579                         rpp_sci_printf("| %-14x | %-14x | %-14x | %-14x |\r\n", channelAEvenList[i], channelBEvenList[i], channelAOddList[i], channelBOddList[i]);
1580                 }
1581                 rpp_sci_printf("|----------------|----------------|----------------|----------------|\r\n");
1582
1583         }
1584         else {
1585                 rpp_sci_printf("General error.\r\n");
1586                 return -CMDERR_BADCFG;
1587         }
1588         return 0;
1589 }
1590
1591 /**
1592  *  @brief      Print status of wakeup on each channels (wakeup received on channel or not yet received).
1593  *
1594  * @param[in]   cmd_io  Pointer to IO stack
1595  * @param[in]   des             Pointer to command descriptor
1596  * @param[in]   param   Parameters of command
1597  * @return      0 when OK or error code
1598  */
1599 int cmd_do_fr_getwakeuprxstatus(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
1600 {
1601         int8_t retVal = ERR_PARAM_NO_ERROR;
1602         uint8_t status = 0;
1603         char *statusStrings[] = {"was not yet", "was"};
1604         char *channelNames[] = {"A", "B"};
1605         uint8_t i;
1606
1607         retVal = rpp_fr_get_wakeup_rx_status(0, &status);
1608         if (retVal == SUCCESS)
1609                 for (i = 0; i < 2; i++) {
1610                         rpp_sci_printf("Wake up pattern %s received on channel %s.\r\n", statusStrings[(status >> i) & 0x1], channelNames[i]);
1611                 }
1612         else {
1613                 rpp_sci_printf("General error.\r\n");
1614                 return -CMDERR_BADCFG;
1615         }
1616         return 0;
1617 }
1618
1619 /**
1620  *  @brief      Set and start absolute timer.
1621  *
1622  * @param[in]   cmd_io  Pointer to IO stack
1623  * @param[in]   des             Pointer to command descriptor
1624  * @param[in]   param   Parameters of command
1625  * @return      0 when OK or error code
1626  */
1627 int cmd_do_fr_settimer(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
1628 {
1629         int8_t retVal = ERR_PARAM_NO_ERROR;
1630         int timer = 0;
1631         int cycle = 0;
1632         int offset = 0;
1633
1634         if (sscanf(param[1], "%i %i %i", &timer, &cycle, &offset) != 3)
1635                 return -CMDERR_BADPAR;
1636
1637         retVal = rpp_fr_set_timer(0, timer, cycle, offset);
1638         if (retVal == SUCCESS) {
1639                 uint8_t i = 0x40;
1640                 while (i && (cycle & i) == 0)
1641                         i >>= 1;
1642                 if (!i)
1643                         i = 1;
1644
1645                 rpp_sci_printf("Timer was set for every %d-th cycle, offset %d, macrotick %d\n",
1646                                            i, cycle & ~i, offset);
1647         }
1648         else {
1649                 rpp_sci_printf("General error.\r\n");
1650                 return -CMDERR_BADCFG;
1651         }
1652         return 0;
1653 }
1654
1655 /**
1656  *  @brief      Cancel selected timer
1657  *
1658  * @param[in]   cmd_io  Pointer to IO stack
1659  * @param[in]   des             Pointer to command descriptor
1660  * @param[in]   param   Parameters of command
1661  * @return      0 when OK or error code
1662  */
1663 int cmd_do_fr_canceltimer(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
1664 {
1665         int8_t retVal = ERR_PARAM_NO_ERROR;
1666         int timer = 0;
1667
1668         if (sscanf(param[1], "%d", &timer) != 1)
1669                 return -CMDERR_BADPAR;
1670
1671         if (param[2] != NULL)
1672                 return -CMDERR_BADPAR;
1673
1674         retVal = rpp_fr_cancel_timer(0, timer);
1675         if (retVal == SUCCESS)
1676                 rpp_sci_printf("Timer was canceled.\r\n");
1677         else {
1678                 rpp_sci_printf("General error.\r\n");
1679                 return -CMDERR_BADCFG;
1680         }
1681         return 0;
1682 }
1683
1684 /**
1685  *  @brief      Enable/disable, acknowledge, get timer IRQ
1686  *
1687  * @param[in]   cmd_io  Pointer to IO stack
1688  * @param[in]   des             Pointer to command descriptor
1689  * @param[in]   param   Parameters of command
1690  * @return      0 when OK or error code
1691  */
1692 int cmd_do_fr_timerirq(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
1693 {
1694         int8_t retVal = ERR_PARAM_NO_ERROR;
1695         int timer = 0;
1696         char str[4];
1697         boolean_t status = FALSE;
1698         char *boolStrings[] = {"FALSE", "TRUE"};
1699
1700
1701         if (sscanf(param[1], "%d", &timer) != 1)
1702                 return -CMDERR_BADPAR;
1703
1704         if (param[2] == NULL) {     // Get timer IRQ
1705                 retVal = rpp_fr_get_timer_irq_status(0, timer, &status);
1706                 if (retVal == SUCCESS)
1707                         rpp_sci_printf("IRQ = %s\r\n", boolStrings[status]);
1708                 else {
1709                         rpp_sci_printf("General error.\r\n");
1710                         return -CMDERR_BADCFG;
1711                 }
1712         }
1713         else {  // Some set action
1714                 if (sscanf(param[2], "%4s", str) != 1)
1715                         return -CMDERR_BADPAR;
1716                 if (strcmp(str, "EN") == 0)   // Enable IRQ
1717                         retVal = SUCCESS;   // No interrupts imlemented
1718                 else if (strcmp(str, "DIS") == 0)   // Disable IRQ
1719                         retVal = SUCCESS;   // No interrupts implemented
1720                 else if  (strcmp(str, "ACK") == 0)   // Clear IRQ
1721                         retVal = rpp_fr_clear_timer_irq(0, timer);
1722                 else    // Bad argument
1723                         return -CMDERR_BADPAR;
1724
1725                 if (retVal == SUCCESS)
1726                         rpp_sci_printf("OK\r\n");
1727                 else {
1728                         rpp_sci_printf("General error.\r\n");
1729                         return -CMDERR_BADCFG;
1730                 }
1731         }
1732         return 0;
1733 }
1734
1735 /**
1736  *  @brief      Print FlexRay driver version info.
1737  *
1738  * @param[in]   cmd_io  Pointer to IO stack
1739  * @param[in]   des             Pointer to command descriptor
1740  * @param[in]   param   Parameters of command
1741  * @return      0 when OK or error code
1742  */
1743 int cmd_do_fr_getversioninfo(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
1744 {
1745         Std_VersionInfoType versionInfo;
1746
1747         rpp_fr_get_driver_version(&versionInfo);
1748         rpp_sci_printf("vendorID: %#x\r\n", versionInfo.vendorID);
1749         rpp_sci_printf("moduleID: %#x\r\n", versionInfo.moduleID);
1750         rpp_sci_printf("sw_major_version: %#x\r\n", versionInfo.sw_major_version);
1751         rpp_sci_printf("sw_minor_version: %#x\r\n", versionInfo.sw_minor_version);
1752         rpp_sci_printf("sw_patch_version: %#x\r\n", versionInfo.sw_patch_version);
1753
1754         return 0;
1755 }
1756
1757 /**
1758  *  @brief      Print value of FlexRay configuratoin parameter.
1759  *
1760  * @param[in]   cmd_io  Pointer to IO stack
1761  * @param[in]   des             Pointer to command descriptor
1762  * @param[in]   param   Parameters of command
1763  * @return      0 when OK or error code
1764  */
1765 int cmd_do_fr_readcconfig(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
1766 {
1767         int8_t retVal = ERR_PARAM_NO_ERROR;
1768         int index = 0;
1769         uint32_t value = 0;
1770
1771         if (sscanf(param[1], "%d", &index) != 1)
1772                 return -CMDERR_BADPAR;
1773
1774         if (param[2] != NULL)
1775                 return -CMDERR_BADPAR;
1776
1777         retVal = rpp_fr_read_com_ctrl_config(0, index, &value);
1778         if (retVal == SUCCESS)
1779                 rpp_sci_printf("Value = %#x\r\n", value);
1780         else {
1781                 rpp_sci_printf("General error.\r\n");
1782                 return -CMDERR_BADCFG;
1783         }
1784         return 0;
1785 }
1786
1787 /**
1788  *  @brief      Reconfigure buffer
1789  *
1790  * @param[in]   cmd_io  Pointer to IO stack
1791  * @param[in]   des             Pointer to command descriptor
1792  * @param[in]   param   Parameters of command
1793  * @return      0 when OK or error code
1794  */
1795 int cmd_do_fr_reconfigure_buffer(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
1796 {
1797         int ret;
1798         char channel[3];
1799         unsigned bufferID, slot, maxpayload, cycleset, cycleoffset;
1800         Fr_TMS570LS_BufferConfigType tmp_buffer;
1801         boolean_t is_pow2;
1802         uint8_t pow2;
1803
1804         ret = sscanf(param[2], "id%i slot%i %2s cycset%i cycoffset%i max%i",
1805                                  &bufferID,
1806                                  &slot,
1807                                  channel,
1808                                  &cycleset,
1809                                  &cycleoffset,
1810                                  &maxpayload
1811                                  );
1812         if (ret != 6) {
1813                 printf("Error parsing parameter %d\n", ret+1);
1814                 return -CMDERR_BADPAR;
1815         }
1816
1817         if (slot > 2047 || bufferID > FR_MAX_BUFFERS_CNT)
1818                 return badpar("Invalid slot number\n");
1819         tmp_buffer.slotId = slot;
1820         if (strcmp(channel, "A") == 0) tmp_buffer.channel = FR_CHANNEL_A;
1821         else if (strcmp(channel, "B") == 0) tmp_buffer.channel = FR_CHANNEL_B;
1822         else if (strcmp(channel, "AB") == 0) tmp_buffer.channel = FR_CHANNEL_AB;
1823         else return badpar("Channel parsing error\n");
1824         if (cycleset == 0) cycleset = 1;
1825         for (pow2 = 1, is_pow2 = FALSE; pow2 < 128; pow2 *= 2) {
1826                 if (cycleset == pow2) {
1827                         is_pow2 = TRUE;
1828                         break;
1829                 }
1830         }
1831         if (!is_pow2)
1832                 return badpar("Cycle set must be one of 0, 1, 2, 4, 8, 16, 32, 64.\n");
1833         if (cycleoffset >= cycleset)
1834                 return badpar("Cycle offset must in range 0 - cycset-1.\n");
1835
1836         if (maxpayload >= 256)
1837                 return badpar("Maximum payload in bytes must be less than 256\n");
1838         tmp_buffer.maxPayload = maxpayload;
1839
1840         if (rpp_fr_reconfigure_lpdu(0, bufferID, tmp_buffer.slotId, tmp_buffer.channel, cycleset, cycleoffset, tmp_buffer.maxPayload, 0) == SUCCESS) {
1841                 printf("id%i slot%i %2s cycset%i cycoffset%i max%i\n",
1842                            bufferID,
1843                            slot,
1844                            channel,
1845                            cycleset,
1846                            cycleoffset,
1847                            maxpayload
1848                            );
1849                 return 0;
1850         }
1851         else
1852                 printf("Reconfiguration failed.\n");
1853         return -CMDERR_BADPAR;
1854 }
1855
1856 #endif  /* DOCGEN */
1857
1858 /** Command descriptor for FlexRay user config cluster command */
1859 cmd_des_t const cmd_des_fr_user_config = {
1860         0, 0,
1861         "frbtconfig*","Set the user configuration parameters",
1862         "### Command syntax ###\n"
1863         "\n"
1864         "    frbtconfig<TYPE> <PARAMS>\n"
1865         "where\n"
1866         "\n"
1867         "- `<TYPE>` is a string specifying the type of parameters to be set. It can be: \"cluster\" or  \"node\"\n"
1868         "- `<PARAMS>` is a sequence of numbers separated by spaces. Each number stands for one parameter.\n"
1869         "\n"
1870         "### Description ###\n"
1871         "\n"
1872         "The command takes the configuration parameters in the form of a string\n"
1873         "and sets the appropriate type of the FlexRay parameters. It is\n"
1874         "necessary to configure parameters of at least cluster, and node and\n"
1875         "one static buffer (see frbtcfgbuf command). The parameters set by this\n"
1876         "command are applied by the frbtinitU command. Once frbtinit is called,\n"
1877         "it is no longer possible to change the parameters.\n"
1878         "\n"
1879         "The type of the parameters can be selected by the `<TYPE>` selector.\n"
1880         "\n"
1881         "Type \"cluster\" sets global FlexRay network parameters. It expects a\n"
1882         "sequence of 25 parameters in this order:\n"
1883         "\n"
1884         "- 1) gColdStartAttempts\n"
1885         "- 2) gListenNoise\n"
1886         "- 3) gMacroPerCycle\n"
1887         "- 4) gMaxWithoutClockCorrectionFatal\n"
1888         "- 5) gMaxWithoutClockCorrectionPassive\n"
1889         "- 6) gNetworkManagementVectorLength\n"
1890         "- 7) gNumberOfMinislots\n"
1891         "- 8) gNumberOfStaticSlots\n"
1892         "- 9) gOffsetCorrectionStart\n"
1893         "- 10) gPayloadLengthStatic\n"
1894         "- 11) gSyncNodeMax\n"
1895         "- 12) gdActionPointOffset\n"
1896         "- 13) gdCASRxLowMax\n"
1897         "- 14) gdDynamicSlotIdlePhase\n"
1898         "- 15) gdMinislot\n"
1899         "- 16) gdMinislotActionPointOffset\n"
1900         "- 17) gdNIT\n"
1901         "- 18) gdSampleClockPeriod\n"
1902         "- 19) gdStaticSlot\n"
1903         "- 20) gdTSSTransmitter\n"
1904         "- 21) gdWakeupSymbolRxIdle\n"
1905         "- 22) gdWakeupSymbolRxLow\n"
1906         "- 23) gdWakeupSymbolRxWindow\n"
1907         "- 24) gdWakeupSymbolTxIdle\n"
1908         "- 25) gdWakeupSymbolTxLow\n"
1909         "\n"
1910         "Type \"node\" sets local FlexRay network parameters. It expects a\n"
1911         "sequence of 28 parameters in this order:\n"
1912         "\n"
1913         "- 1) pAllowHaltDueToClock\n"
1914         "- 2) pAllowPassiveToActive\n"
1915         "- 3) pChannels (0 - A, 1 - B, 2 - AB)\n"
1916         "- 4) pClusterDriftDamping\n"
1917         "- 5) pDelayCompensationA\n"
1918         "- 6) pDelayCompensationB\n"
1919         "- 7) pExternOffsetCorrection\n"
1920         "- 8) pExternRateCorrection\n"
1921         "- 9) pKeySlotUsedForStartup\n"
1922         "- 10) pKeySlotUsedForSync\n"
1923         "- 11) pLatestTx\n"
1924         "- 12) pMacroInitialOffsetA\n"
1925         "- 13) pMacroInitialOffsetB\n"
1926         "- 14) pMicroInitialOffsetA\n"
1927         "- 15) pMicroInitialOffsetB\n"
1928         "- 16) pMicroPerCycle\n"
1929         "- 17) pRateCorrectionOut\n"
1930         "- 18) pOffsetCorrectionOut\n"
1931         "- 19) pSamplesPerMicrotick\n"
1932         "- 20) pSingleSlotEnabled\n"
1933         "- 21) pWakeupChannel (0 - A, 1 - B)\n"
1934         "- 22) pWakeupPattern\n"
1935         "- 23) pdAcceptedStartupRange\n"
1936         "- 24) pdListenTimeout\n"
1937         "- 25) pdMaxDrift\n"
1938         "- 26) pDecodingCorrection\n"
1939         "- 27) syncFramePayloadMultiplexEnabled\n"
1940         "- 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"
1941         "\n"
1942         "### Example ###\n"
1943         "\n"
1944         "    --> 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"
1945         "    FlexRay cluster configuration accepted.\n"
1946         "    --> 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"
1947         "    FlexRay node configuration accepted.\n",
1948         CMD_HANDLER(cmd_do_fr_user_config), (void *)&cmd_list_fr_basic_test
1949 };
1950
1951 cmd_des_t const cmd_des_fr_config_buffer = {
1952         0, 0,
1953         "frbtcfgbuf?*","Configure a message buffer in the user configuration",
1954         "### Command syntax ###\n"
1955         "\n"
1956         "    frbtcfgbuf<TYPE><BUFID> slot<SLOT> <CHN> cyc<CYC> <RXTX> max<MAX> <REP> ppi<PPI> int<INT>\n"
1957         "where\n"
1958         "\n"
1959         "- `<TYPE>` is 'S' for static segment buffers and 'D' for dynamic segment buffers,\n"
1960         "- `<BUFID>` is the number of the buffer. Both static and dynamic buffers are numbered independently starting from zero,\n"
1961         "- `<SLOT>` is the number of the slot,\n"
1962         "- `<CHN>` is one of 'A', 'B' or 'AB' and identifies the used channel,\n"
1963         "- `<CYC>` is the cycle set when to send the buffer,\n"
1964         "- `<RXTX>` is either string \"rx\" or \"tx\",\n"
1965         "- `<MAX>` is the number determining the maximum payload (in hald-words),\n"
1966         "- `<REP>` is a string \"s\" or \"single\" for single transmission or \"c\" or \"continuous\" for continuous transmission,\n"
1967         "- `<PPI>` is 0 or 1 determining whether the payload preamble indicator is set,\n"
1968         "- `<INT>` is 0 or 1 and is currently ignored.\n"
1969         "\n"
1970         "### Description ###\n"
1971         "\n"
1972         "The command sets the configuration parameters for static or dynamic\n"
1973         "buffers in user configuration. The parameters set by this command are\n"
1974         "applied by the frbtinitU command. Once frbtinit is called, it is no\n"
1975         "longer possible to change the parameters.\n"
1976         "\n"
1977         "### Example ###\n"
1978         "\n"
1979         "    --> frbtcfgbufS0 slot2 AB cyc0 tx max9 continous ppi0 int1\n"
1980         "    frbtcfgbufS0 slot2 AB cyc0 tx max9  continous ppi0 int1\n"
1981         "    --> frbtcfgbufS1 slot1 AB cyc0 rx max9 continuous ppi0 int1\n"
1982         "    frbtcfgbufS1 slot1 AB cyc0 rx max9 continuous ppi0 int1\n"
1983         "    --> frbtcfgbufD0  slot9  A cyc0 rx max0x40 single ppi0 int0\n"
1984         "    frbtcfgbufD0 slot9  A cyc0 rx max64 single ppi0 int0\n"
1985         "    --> frbtcfgbufD1  slot10 A cyc0 tx max0x40 single ppi0 int0\n"
1986         "    frbtcfgbufD1 slot10  A cyc0 tx max64 single ppi0 int0\n",
1987         CMD_HANDLER(cmd_do_fr_config_bufer), (void *)&cmd_list_fr_basic_test
1988 };
1989
1990 cmd_des_t const cmd_des_fr_config_fifo = {
1991         0, 0,
1992         "frbtcfgfifo*","Configure a RX FIFO message buffer in the user configuration",
1993         "### Command syntax ###\n"
1994         "\n"
1995         "    frbtcfgfifo rejslot<SLOT> slotmask<MASK> depth<DEPTH> <CHN> cyc<CYC> max<MAX> <REJNULL> <REJSTAT>\n"
1996         "where\n"
1997         "- `<SLOT>` is the number of the slot that will be rejected. If it is 0, no slot will be rejected,\n"
1998         "- `<MASK>` is a number specifying which bits of the `<SLOT>` will be ignored,"
1999         "- `<DEPTH>` is a number specifying the depth of the FIFO,\n"
2000         "- `<CHN>` is one of 'A', 'B' or 'AB' and identifies the used channel,\n"
2001         "- `<CYC>` is the cycle set when to send the buffer,\n"
2002         "- `<MAX>` is the number determining the maximum payload (in hald-words),\n"
2003         "- `<REJNULL>` is a string \"rejnull\" for rejecting NULL frames or \"accnull\" for accepting NULL frames,\n"
2004         "- `<REJSTAT>` is a string \"rejstat\" for rejecting frames in static segment or \"accstat\" for accepting frames from static segment,\n"
2005         "\n"
2006         "### Description ###\n"
2007         "\n"
2008         "The command sets the configuration parameters for RX FIFO buffer\n"
2009         "in user configuration. The parameters set by this command are\n"
2010         "applied by the frbtinitU command. Once frbtinit is called, it is no\n"
2011         "longer possible to change the parameters.\n"
2012         "Those messages, which are not accepted by any other buffer and pass the\n"
2013         "FIFO rejection filter will be stored in the RX FIFO buffer.\n"
2014         "\n"
2015         "### Example ###\n"
2016         "\n"
2017         "    --> frbtcfgfifo rejslot6 slotmask6 depth5 AB cyc0 max0x20 rejnull accstat\n"
2018         "    frbtcfgfifo rejslot6 slotmask6 depth5 AB cyc0 max0x20 rejnull accstat\n",
2019         CMD_HANDLER(cmd_do_fr_config_fifo), (void *)&cmd_list_fr_basic_test
2020 };
2021
2022 /** Command descriptor for FlexRay init command */
2023 cmd_des_t const cmd_des_fr_init = {
2024         0, 0,
2025         "frbtinit?","Initialize a FlexRay node",
2026         "### Command syntax ###\n"
2027         "\n"
2028         "    frbtinit<CFG>\n"
2029         "\n"
2030         "where `<CFG>` identifies the configuration to use. It can be one of A, B\n"
2031         "or U. The A and B are predefined configurations. If U is specified,\n"
2032         "the user configuration previously set by frbtconfig command is used.\n"
2033         "\n"
2034         "### Description ###\n"
2035         "\n"
2036         "The command stands for Fr_Init and Fr_ControllerInit functions from\n"
2037         "the Autosar specification. It initializes the internal data structures\n"
2038         "of the driver and then, based on those data, the controller\n"
2039         "configuration is done. During the controller configuration the\n"
2040         "parameters of the cluster, node, message RAM and buffers are checked.\n"
2041         "If anything goes bad, the command returns an error number, which can\n"
2042         "be decoded by macros defined in driver header file fr_tms570.h with\n"
2043         "prefix ERR_PARAM. If all parameters are OK, all necessary registers of\n"
2044         "the controller are initialized according to the specified\n"
2045         "configuration parameters. At the end of the command, the FlexRay\n"
2046         "controller is switched into READY state and all buffers are configured\n"
2047         "to send NULL frames. This command should be called as the very first\n"
2048         "command, when trying to communicate over the FlexRay bus.\n"
2049         "\n"
2050         "### Example ###\n"
2051         "\n"
2052         "    --> frbtinitA\n"
2053         "    FlexRay driver initialized.\n"
2054         "    FlexRay controller initialized.\n",
2055         CMD_HANDLER(cmd_do_fr_init), (void *)&cmd_list_fr_basic_test
2056 };
2057
2058 /** Command descriptor for FlexRay controller init command */
2059 cmd_des_t const cmd_des_fr_start = {
2060         0, 0,
2061         "frbtstart","Start a new FlexRay network or join to the existing one",
2062         "### Command syntax ###\n"
2063         "\n"
2064         "    frbtstart\n"
2065         "\n"
2066         "### Description ###\n"
2067         "\n"
2068         "The command stands for Fr_StartCommunication function from the Autosar\n"
2069         "specification.\n"
2070         "If the FlexRay node is configured as a coldstarter node\n"
2071         "(as for example by frbtinitA/B command), then the command first listen\n"
2072         "on the bus. When it does not detect any existing bus communication, it\n"
2073         "tries to initiate a new network. If the initiation fails, the FlexRay\n"
2074         "controller is switched back to the ready state for another attempt\n"
2075         "(calling frbtstart again). If the FlexRay node is configured as\n"
2076         "non-coldstarter, it is listening on the bus until some existing\n"
2077         "communication is detected.\n"
2078         "\n"
2079         "The command should be called after the frbtinit command.\n"
2080         "\n"
2081         "You may also want to call frbtallslots command to allow the communication\n"
2082         "for all other slots besides the key slots.\n"
2083         "\n"
2084         "### Example ###\n"
2085         "\n"
2086         "    --> frbtstart\n"
2087         "    FlexRay communication is running.\n",
2088         CMD_HANDLER(cmd_do_fr_start), (void *)&cmd_list_fr_basic_test
2089 };
2090
2091 /** Command descriptor for FlexRay controller all slots command */
2092 cmd_des_t const cmd_des_fr_allslots = {
2093         0, 0,
2094         "frbtallslots","Enables communication for all frames",
2095         "### Command syntax ###\n"
2096         "\n"
2097         "    frbtallslots\n"
2098         "\n"
2099         "### Description ###\n"
2100         "\n"
2101         "The command stands for Fr_AllSlots function from the Autosar\n"
2102         "specification.\n"
2103         "\n"
2104         "The node can be configured to communicate only on key frames by\n"
2105         "default (as in the case of frbtinitA/B). This command can be used to\n"
2106         "allow the communication on all configured frames. The command invokes\n"
2107         "the FlexRay POC command ALL_SLOTS which enables the communication on\n"
2108         "all frames. The command can be called after the controller\n"
2109         "initialization.\n"
2110         "\n"
2111         "### Example ###\n"
2112         "\n"
2113         "    --> frbtallslots\n"
2114         "    FlexRay node started communication on all slots.\n",
2115         CMD_HANDLER(cmd_do_fr_allslots), (void *)&cmd_list_fr_basic_test
2116 };
2117
2118 /** Command descriptor for FlexRay controller halt command */
2119 cmd_des_t const cmd_des_fr_halt = {
2120         0, 0,
2121         "frbthalt","Halt FlexRay communication after the end of the actual communication cycle",
2122         "### Command syntax ###\n"
2123         "\n"
2124         "    frbthalt\n"
2125         "\n"
2126         "### Description ###\n"
2127         "\n"
2128         "The command stands for Fr_HaltCommunication function from the Autosar\n"
2129         "specification. The command invokes the FlexRay POC command HALT, which\n"
2130         "means that communication is stopped after the end of the actual\n"
2131         "communication cycle. On the opposite side, there is a frbtfreeze\n"
2132         "command, which stops the communication immediately. To restart the\n"
2133         "communication, the frbtinit and frbtstart commands have to be called.\n"
2134         "\n"
2135         "### Example ###\n"
2136         "\n"
2137         "    --> frbthalt\n"
2138         "    FlexRay node communication halted.\n",
2139         CMD_HANDLER(cmd_do_fr_halt), (void *)&cmd_list_fr_basic_test
2140 };
2141
2142 /** Command descriptor for FlexRay controller abort command */
2143 cmd_des_t const cmd_des_fr_abort = {
2144         0, 0,
2145         "frbtabort","Abort FlexRay communication immediately",
2146         "### Command syntax ###\n"
2147         "\n"
2148         "    frbtabort\n"
2149         "\n"
2150         "### Description ###\n"
2151         "\n"
2152         "The command stands for Fr_AbortCommunication function from the Autosar\n"
2153         "specification. The command invokes the FlexRay POC command FREEZE,\n"
2154         "which means that the communication is stopped immediately. On the\n"
2155         "opposite side there is a frbthalt command, which stops the\n"
2156         "communication after the end of the actual communication cycle. To\n"
2157         "restart the communication, the frbtinit and frbtstart commands have\n"
2158         "to be called.\n"
2159         "\n"
2160         "### Example ###\n"
2161         "\n"
2162         "    --> frbtabort\n"
2163         "    FlexRay node communication aborted.\n",
2164         CMD_HANDLER(cmd_do_fr_abort), (void *)&cmd_list_fr_basic_test
2165 };
2166
2167 /** Command descriptor for FlexRay controller send wake up pattern command */
2168 cmd_des_t const cmd_des_fr_sendwup = {
2169         0, 0,
2170         "frbtwup","Initiate the wake up procedure",
2171         "### Command syntax ###\n"
2172         "\n"
2173         "    frbtwup\n"
2174         "\n"
2175         "### Description ###\n"
2176         "\n"
2177         "The command stands for Fr_SendWUP function from the Autosar\n"
2178         "specification. It initiates the wake up procedure by switching FlexRay\n"
2179         "controller state machine to WAKEUP state.\n"
2180         "\n"
2181         "### Example ###\n"
2182         "\n"
2183         "    --> frbtwup\n"
2184         "    Wake up pattern has been sent.\n",
2185         CMD_HANDLER(cmd_do_fr_sendwup), (void *)&cmd_list_fr_basic_test
2186 };
2187
2188 /** Command descriptor for FlexRay controller sent wake up pattern channel command */
2189 cmd_des_t const cmd_des_fr_setwuchannel = {
2190         0, 0,
2191         "frbtsetwuch?","Set wake up channel",
2192         "### Command syntax ###\n"
2193         "\n"
2194         "    frbtsetwuch<CHANNEL>\n"
2195         "\n"
2196         "where `<CHANNEL>` is a character A or B, specifying the channel.\n"
2197         "\n"
2198         "### Description ###\n"
2199         "\n"
2200         "The command stands for Fr_SetWakeupChannel function from the Autosar\n"
2201         "specification. Wake up channel is the channel, where Wake Up Pattern\n"
2202         "is sent. The channel can be set after the driver and controller are\n"
2203         "initialized and before the communication is running. The actual\n"
2204         "wake-up pattern is sent by the frbtwup command.\n"
2205         "\n"
2206         "### Example ###\n"
2207         "\n"
2208         "    --> frbtsetwuchA\n"
2209         "    Wake up channel has been set.\n",
2210         CMD_HANDLER(cmd_do_fr_setwuchannel), (void *)&cmd_list_fr_basic_test
2211 };
2212
2213 /** Command descriptor for FlexRay controller get POC status command */
2214 cmd_des_t const cmd_des_fr_getpocstatus = {
2215         0, 0,
2216         "frbtgetpocst","Print FlexRay POC status",
2217         "### Command syntax ###\n"
2218         "\n"
2219         "    frbtgetpocst\n"
2220         "\n"
2221         "### Description ###\n"
2222         "\n"
2223         "The command stands for Fr_GetPOCStatus function from the Autosar\n"
2224         "specification. It prints the main FlexRay POC status values in the\n"
2225         "form of a table. The command should be called after the frbtinit\n"
2226         "command.\n"
2227         "\n"
2228         "### Example ###\n"
2229         "\n"
2230         "    --> frbtgetpocst\n"
2231         "    POC status:\n"
2232         "    CHIHaltRequest: FALSE\n"
2233         "    CHIReadyRequest: FALSE\n"
2234         "    ColdstartNoise: FALSE\n"
2235         "    Freeze: FALSE\n"
2236         "    ErrorMode: ACTIVE\n"
2237         "    SlotMode: ALL\n"
2238         "    StartupState: UNDEFINED\n"
2239         "    State: READY\n"
2240         "    WakeupStatus: UNDEFINED\n",
2241         CMD_HANDLER(cmd_do_fr_getpocstatus), (void *)&cmd_list_fr_basic_test
2242 };
2243
2244 /** Command descriptor for FlexRay transmit tx lpdu command */
2245 cmd_des_t const cmd_des_fr_transmittxlpdu = {
2246         0, 0,
2247         "frbttransmit*","Transmit data from the selected frame buffer",
2248         "### Command syntax ###\n"
2249         "\n"
2250         "    frbttransmit<BUFID> <DATA>\n"
2251         "where\n"
2252         "\n"
2253         "- `<BUFID>` is a decimal number specifying the ID of the frame\n"
2254         "            buffer configured for data transmission\n"
2255         "- `<DATA>`  is a sequence of hexadecimal numbers separated by spaces.\n"
2256         "            Each number represents one byte of the message.\n"
2257         "\n"
2258         "### Description ###\n"
2259         "\n"
2260         "The command stands for Fr_TransmitTxLPdu function from the Autosar\n"
2261         "specification. The command copies the given data into the buffers data\n"
2262         "section in the message RAM. Transmit request is set after the data are\n"
2263         "copied, so transmission starts at the next occurrence of the frame in the\n"
2264         "communication cycle.\n"
2265         "\n"
2266         "### Example ###\n"
2267         "\n"
2268         "    --> frbttransmit1 12 34 56 AA BB CC\n"
2269         "    Data were set for transmission.\n",
2270         CMD_HANDLER(cmd_do_fr_transmittxlpdu), (void *)&cmd_list_fr_basic_test
2271 };
2272
2273 /** Command descriptor for FlexRay cancel tx lpdu command */
2274 cmd_des_t const cmd_des_fr_canceltxlpdu = {
2275         0, 0,
2276         "frbtcanceltx*","Stop the transmission from the frame buffer",
2277         "### Command syntax ###\n"
2278         "\n"
2279         "    frbtcanceltx<BUFID>\n"
2280         "\n"
2281         "where `<BUFID>` is a decimal number specifying the ID of a configured\n"
2282         "frame buffer\n"
2283         "\n"
2284         "### Description ###\n"
2285         "\n"
2286         "The command stands for Fr_CancelTxLPdu function from the Autosar\n"
2287         "specification. The command reconfigures the selected buffer to stop\n"
2288         "data transmission. The command finishes successfully only if the\n"
2289         "reconfiguration is allowed in message RAM configuration (secureBuffers\n"
2290         "configuration parameter). Only TX buffers and buffers not used for startup\n"
2291         "frames can be canceled.\n"
2292         "\n"
2293         "### Example ###\n"
2294         "\n"
2295         "    --> frbtcanceltx3\n"
2296         "    Transmission canceled.\n",
2297         CMD_HANDLER(cmd_do_fr_canceltxlpdu), (void *)&cmd_list_fr_basic_test
2298 };
2299
2300 /** Command descriptor for FlexRay receive rx lpdu command */
2301 cmd_des_t const cmd_des_fr_receiverxlpdu = {
2302         0, 0,
2303         "frbtreceive*","Receive a new message",
2304         "### Command syntax ###\n"
2305         "\n"
2306         "    frbtreceive<BUFID>\n"
2307         "\n"
2308         "where `<BUFID>` is a decimal number specifying the ID of a configured\n"
2309         "frame buffer.\n"
2310         "\n"
2311         "### Description ###\n"
2312         "\n"
2313         "The command stands for Fr_ReceiveRxLPdu function from the Autosar\n"
2314         "specification. The command tries to read a new message from the selected\n"
2315         "buffer. If new message is available, it is copied out of the buffer and\n"
2316         "printed. If no message is available, \"No message received\" is printed.\n"
2317         "If a new message was retrieved from a FIFO buffer and more messages are\n"
2318         "available in it, \"More messages are still in FIFO\" is printed.\n"
2319         "\n"
2320         "### Example ###\n"
2321         "\n"
2322         "    --> frbtreceive0\n"
2323         "    More messages are still in FIFO:\n"
2324         "    Received message (32 B):\n"
2325         "     ee ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\n"
2326         "     00 00 00 00 00 00 00 00 00\n",
2327         CMD_HANDLER(cmd_do_fr_receiverxlpdu), (void *)&cmd_list_fr_basic_test
2328 };
2329
2330 /** Command descriptor for FlexRay check TX LPdu status command */
2331 cmd_des_t const cmd_des_fr_checktxlpdustatus = {
2332         0, 0,
2333         "frbtchecktx*","Print the status of the transmit buffer",
2334         "### Command syntax ###\n"
2335         "\n"
2336         "    frbtchecktx<BUFID>\n"
2337         "\n"
2338         "where `<BUFID>` is a decimal number specifying the ID of a configured\n"
2339         "frame buffer.\n"
2340         "\n"
2341         "### Description ###\n"
2342         "\n"
2343         "The command stands for Fr_CheckTxLPduStatus function from the Autosar\n"
2344         "specification. The command reads and prints status of the selected frame buffer.\n"
2345         "The buffer can be in one of the two states:\n"
2346         "\n"
2347         "- Message transmission is pending, which means that the buffer has not yet sent its\n"
2348         "  message in single shot mode or that it is in continuous mode.\n"
2349         "- No message transmission is pending, which means that the buffer is in single shot\n"
2350         "  mode and the message has already been sent.\n"
2351         "\n"
2352         "### Example ###\n"
2353         "\n"
2354         "    --> frbtchecktx1\n"
2355         "    Message transmission is not pending.\n",
2356         CMD_HANDLER(cmd_do_fr_checktxlpdustatus), (void *)&cmd_list_fr_basic_test
2357 };
2358
2359 /** Command descriptor for FlexRay disable LPdu command */
2360 cmd_des_t const cmd_des_fr_disablelpdu = {
2361         0, 0,
2362         "frbtdisable*","Disable the buffers assigned to the frame",
2363         "### Command syntax ###\n"
2364         "\n"
2365         "    frbtdisable<BUFID>\n"
2366         "\n"
2367         "where `<BUFID>` is a decimal number specifying the ID of a frame buffer.\n"
2368         "The buffer configured will be disabled.\n"
2369         "\n"
2370         "### Description ###\n"
2371         "\n"
2372         "The command stands for Fr_DisableLPdu function from the Autosar\n"
2373         "specification. The command disables the selected buffer. This means\n"
2374         "that this buffer will be unavailable for the communication until\n"
2375         "their reconfiguration (which is not yet implemented). Buffers used\n"
2376         "for startup frames and FIFO RX buffers cannot be disabled.\n"
2377         "\n"
2378         "### Example ###\n"
2379         "\n"
2380         "    --> frbtdisable3\n"
2381         "    Buffer disabled.\n",
2382         CMD_HANDLER(cmd_do_fr_disablelpdu), (void *)&cmd_list_fr_basic_test
2383 };
2384
2385 /** Command descriptor for FlexRay get global time command */
2386 cmd_des_t const cmd_des_fr_getglobaltime = {
2387         0, 0,
2388         "frbtglobtime","Print actual global time of the network",
2389         "### Command syntax ###\n"
2390         "\n"
2391         "    frbtglobtime\n"
2392         "\n"
2393         "### Description ###\n"
2394         "\n"
2395         "The command stands for Fr_GetGlobalTime function from the Autosar\n"
2396         "specification. The command prints the time as a number of the current\n"
2397         "cycle and the offset in the cycle in macroticks.\n"
2398         "\n"
2399         "### Example ###\n"
2400         "\n"
2401         "    --> frbtglobtime\n"
2402         "    Cycle number: 23\n"
2403         "    Macrotick number: 6\n",
2404         CMD_HANDLER(cmd_do_fr_getglobaltime), (void *)&cmd_list_fr_basic_test
2405 };
2406
2407 /** Command descriptor for FlexRay get network management vector command */
2408 cmd_des_t const cmd_des_fr_getnmvector = {
2409         0, 0,
2410         "frbtnmvector","Print network management vector of the node",
2411         "### Command syntax ###\n"
2412         "\n"
2413         "    frbtnmvector\n"
2414         "\n"
2415         "### Description ###\n"
2416         "\n"
2417         "The command stands for Fr_GetNmVector function from the Autosar\n"
2418         "specification. It prints the values of the network management vector\n"
2419         "as hexadecimal numbers.\n"
2420         "\n"
2421         "### Example ###\n"
2422         "\n"
2423         "    --> frbtnmvector\n"
2424         "    Network management vector: 0 0 0 0 0 0 0 0 0 0 0 0\n",
2425         CMD_HANDLER(cmd_do_fr_getnmvector), (void *)&cmd_list_fr_basic_test
2426 };
2427
2428 /** Command descriptor for FlexRay get network management vector command */
2429 cmd_des_t const cmd_des_fr_nmwatch = {
2430         0, 0,
2431         "frbtnmwatch","Watch the changes of the network managment vector in real-time",
2432         "### Command syntax ###\n"
2433         "\n"
2434         "    frbtnmwatch\n"
2435         "\n"
2436         "### Description ###\n"
2437         "\n"
2438         "Reads the network management vector every 100 ms and prints it out.\n"
2439         "\n"
2440         "### Example ###\n"
2441         "\n"
2442         "    --> frbtnmwatch\n"
2443         "    Network management vector: 0 0 0 0 0 0 0 0 0 0 0 0\n",
2444         CMD_HANDLER(cmd_do_fr_nmwatch), (void *)&cmd_list_fr_basic_test
2445 };
2446
2447 /** Command descriptor for FlexRay get channel status command */
2448 cmd_des_t const cmd_des_fr_getchannelstatus = {
2449         0, 0,
2450         "frbtchstat","Print channel A and B status",
2451         "### Command syntax ###\n"
2452         "\n"
2453         "    frbtchstat\n"
2454         "\n"
2455         "### Description ###\n"
2456         "\n"
2457         "The command stands for Fr_GetChannelStatus function from the Autosar\n"
2458         "specification.\n"
2459         "\n"
2460         "### Example ###\n"
2461         "\n"
2462         "    --> frbtchstat\n"
2463         "    Channel A status:\n"
2464         "       aggregated channel status vSS!ValidFrame: TRUE\n"
2465         "       aggregated channel status vSS!SyntaxError: FALSE\n"
2466         "       aggregated channel status vSS!ContentError: FALSE\n"
2467         "       aggregated channel status additional communication: FALSE\n"
2468         "       aggregated channel status vSS!Bviolation: FALSE\n"
2469         "       aggregated channel status vSS!TxConflict: FALSE\n"
2470         "       Not used (0): FALSE\n"
2471         "       Not used (0): FALSE\n"
2472         "       symbol window status data vSS!ValidMTS: FALSE\n"
2473         "       symbol window status data vSS!SyntaxError: FALSE\n"
2474         "       symbol window status data vSS!Bviolation: FALSE\n"
2475         "       symbol window status data vSS!TxConflict: FALSE\n"
2476         "       NIT status data vSS!SyntaxError: FALSE\n"
2477         "       NIT status data vSS!Bviolation: FALSE\n"
2478         "       Not used (0): FALSE\n"
2479         "       Not used (0): FALSE\n"
2480         "    Channel B status:\n"
2481         "       aggregated channel status vSS!ValidFrame: TRUE\n"
2482         "       aggregated channel status vSS!SyntaxError: FALSE\n"
2483         "       aggregated channel status vSS!ContentError: FALSE\n"
2484         "       aggregated channel status additional communication: FALSE\n"
2485         "       aggregated channel status vSS!Bviolation: FALSE\n"
2486         "       aggregated channel status vSS!TxConflict: FALSE\n"
2487         "       Not used (0): FALSE\n"
2488         "       Not used (0): FALSE\n"
2489         "       symbol window status data vSS!ValidMTS: FALSE\n"
2490         "       symbol window status data vSS!SyntaxError: FALSE\n"
2491         "       symbol window status data vSS!Bviolation: FALSE\n"
2492         "       symbol window status data vSS!TxConflict: FALSE\n"
2493         "       NIT status data vSS!SyntaxError: FALSE\n"
2494         "       NIT status data vSS!Bviolation: FALSE\n"
2495         "       Not used (0): FALSE\n"
2496         "       Not used (0): FALSE\n",
2497         CMD_HANDLER(cmd_do_fr_getchannelstatus), (void *)&cmd_list_fr_basic_test
2498 };
2499
2500 /** Command descriptor for FlexRay get clock correction command */
2501 cmd_des_t const cmd_des_fr_getclockcorrection = {
2502         0, 0,
2503         "frbtclkcor","Print clock correction (rate and offset)",
2504         "### Command syntax ###\n"
2505         "\n"
2506         "    frbtclkcor\n"
2507         "\n"
2508         "### Description ###\n"
2509         "\n"
2510         "The command stands for Fr_GetClockCorrection function from the Autosar\n"
2511         "specification.\n"
2512         "\n"
2513         "### Example ###\n"
2514         "\n"
2515         "    --> frbtclkcor\n"
2516         "    Rate correction: 0\n"
2517         "    Offset correction: 0\n",
2518         CMD_HANDLER(cmd_do_fr_getclockcorrection), (void *)&cmd_list_fr_basic_test
2519 };
2520
2521 /** Command descriptor for FlexRay get sync frame list command */
2522 cmd_des_t const cmd_des_fr_getsyncframelist = {
2523         0, 0,
2524         "frbtgetsyncfrlist*","Print the list of sync frames transmitted on both channels via the odd and even communication cycle",
2525         "### Command syntax ###\n"
2526         "\n"
2527         "    frbtgetsyncfrlist<LENGTH>\n"
2528         "\n"
2529         "where `<LENGTH>` is a decimal number in range 0 - 15, specifying the\n"
2530         "length of the list to be printed.\n"
2531         "\n"
2532         "### Description ###\n"
2533         "\n"
2534         "The command stands for Fr_GetSyncFrameList function from the Autosar\n"
2535         "specification.\n"
2536         "\n"
2537         "### Example ###\n"
2538         "\n"
2539         "    --> frbtgetsyncfrlist2\n"
2540         "    | Channel A even | channel B even | channel A odd  | channel B odd  |\n"
2541         "    |----------------|----------------|----------------|----------------|\n"
2542         "    | 1              | 1              | 1              | 1              |\n"
2543         "    | 2              | 2              | 2              | 2              |\n"
2544         "    |----------------|----------------|----------------|----------------|\n",
2545         CMD_HANDLER(cmd_do_fr_getsyncframelist), (void *)&cmd_list_fr_basic_test
2546 };
2547
2548 /** Command descriptor for FlexRay get sync frame list command */
2549 cmd_des_t const cmd_des_fr_getwakeuprxstatus = {
2550         0, 0,
2551         "frbtgetwurxstat","Prints whether the wake up pattern has been or has not been received",
2552         "### Command syntax ###\n"
2553         "\n"
2554         "    frbtgetwurxstat\n"
2555         "\n"
2556         "### Description ###\n"
2557         "\n"
2558         "The command stands for Fr_GetWakeupRxStatus function from the Autosar\n"
2559         "specification. The status of the wake up receiving is bitcoded in the\n"
2560         "controller. This command decodes and prints it in a readable format.\n"
2561         "\n"
2562         "### Example ###\n"
2563         "\n"
2564         "    --> frbtgetwurxstat\n"
2565         "    Wake up pattern was not yet received on channel A.\n"
2566         "    Wake up pattern was not yet received on channel B.\n",
2567         CMD_HANDLER(cmd_do_fr_getwakeuprxstatus), (void *)&cmd_list_fr_basic_test
2568 };
2569
2570 /** Command descriptor for FlexRay set absolute timer command */
2571 cmd_des_t const cmd_des_fr_settimer = {
2572         0, 0,
2573         "frbtsettimer*","Set and start timer",
2574         "### Command syntax ###\n"
2575         "\n"
2576         "    frbtsettimer<TMID> <CYCLE> <OFFSET>\n"
2577         "where\n"
2578         "\n"
2579         "- `<TMID>` is a number (0, 1) specifying the timer.\n"
2580         "- `<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"
2581         "- `<OFFSET>` is a decimal number (0 - 16383) specifying the offset in macroticks, where precisely in the cycle should be the timer interrupt requested.\n"
2582         "\n"
2583         "### Description ###\n"
2584         "\n"
2585         "The command is similar to Fr_SetAbsoluteTimer function from the\n"
2586         "Autosar specification. The difference is that the command allows to\n"
2587         "specify a set of cycles, not only one of 64 cycles. It sets the timer\n"
2588         "selected by the parameter and enables it.\n"
2589         "\n"
2590         "Before using this command, FlexRay communication has to be started\n"
2591         "(see frbtstart).\n"
2592         "\n"
2593         "### Example ###\n"
2594         "\n"
2595         "    --> frbtsettimer0 32 50\n"
2596         "    Timer was set for every 32-th cycle, offset 0, macrotick 50\n"
2597         "    --> frbtsettimer0 31 50\n"
2598         "    Timer was set for every 16-th cycle, offset 15, macrotick 50\n"
2599         "    --> frbtsettimer0 0x42 0\n"
2600         "    Timer was set for every 64-th cycle, offset 2, macrotick 0\n",
2601         CMD_HANDLER(cmd_do_fr_settimer), (void *)&cmd_list_fr_basic_test
2602 };
2603
2604 /** Command descriptor for FlexRay cancel absolute timer command */
2605 cmd_des_t const cmd_des_fr_canceltimer = {
2606         0, 0,
2607         "frbtcanceltimer*","Stop the timer",
2608         "### Command syntax ###\n"
2609         "\n"
2610         "    frbtcanceltimer<TMID>\n"
2611         "where `<TMID>` is a number (0 or 1) specifying the timer.\n"
2612         "\n"
2613         "### Description ###\n"
2614         "\n"
2615         "The command stands for Fr_CancelAbsoluteTimer function from the\n"
2616         "Autosar specification. It stops the timer selected by the parameter.\n"
2617         "\n"
2618         "### Example ###\n"
2619         "\n"
2620         "    --> frbtcanceltimer0\n"
2621         "    Timer was canceled.\n",
2622         CMD_HANDLER(cmd_do_fr_canceltimer), (void *)&cmd_list_fr_basic_test
2623 };
2624
2625 /** Command descriptor for FlexRay absolute timer irq manipulation command */
2626 cmd_des_t const cmd_des_fr_timerirq = {
2627         0, 0,
2628         "frbttimerirq*","Perform selected action on the timer IRQ",
2629         "### Command syntax ###\n"
2630         "\n"
2631         "    frbttimerirq<TMID> <ACTION> - Run the <ACTION> on specified timer\n"
2632         "    frbttimerirq<TMID> - Get timer IRQ status\n"
2633         "\n"
2634         "where\n"
2635         "\n"
2636         "- `<TMID>` is a number (0, 1) specifying the timer.\n"
2637         "- where `<ACTION>` is a string specifying the action  to be performed on the selected timer IRQ.\n"
2638         "\n"
2639         "`<ACTIONS>` can be one of:\n"
2640         "\n"
2641         "- EN - Enable the IRQ on the selected timer\n"
2642         "- DIS - Disable the IRQ on the selected timer\n"
2643         "- ACK - Acknowledge the IRQ on the selected timer (reset flag in the register).\n"
2644         "\n"
2645         "### Description ###\n"
2646         "\n"
2647         "The command stands for Fr_EnableAbsoluteTimerIRQ,\n"
2648         "Fr_AckAbsoluteTimerIRQ, Fr_DisableAbsoluteTimerIRQ and\n"
2649         "Fr_GetAbsoluteTimerIRQStatus functions from the Autosar specification.\n"
2650         "It masks or demasks the IRQ for the timer, or acknowledges the\n"
2651         "interrupt request. If no action is specified it prints whether the IRQ\n"
2652         "is pending for the timer.\n"
2653         "\n"
2654         "### Example ###\n"
2655         "\n"
2656         "    --> frbttimerirq0\n"
2657         "    IRQ = FALSE\n"
2658         "\n"
2659         "    --> frbttimerirq0 EN\n"
2660         "    OK\n",
2661         CMD_HANDLER(cmd_do_fr_timerirq), (void *)&cmd_list_fr_basic_test
2662 };
2663
2664 /** Command descriptor for FlexRay get version info command */
2665 cmd_des_t const cmd_des_fr_getversioninfo = {
2666         0, 0,
2667         "frbtversion","Print FlexRay driver version information",
2668         "### Command syntax ###\n"
2669         "\n"
2670         "    frbtversion\n"
2671         "\n"
2672         "### Description ###\n"
2673         "\n"
2674         "The command stands for Fr_GetVersionInfo function from the Autosar\n"
2675         "specification.\n"
2676         "It reads and prints the information about vendor, module and version of\n"
2677         "the FlexRay driver\n"
2678         "\n"
2679         "### Example ###\n"
2680         "\n"
2681         "    --> frbtversion\n"
2682         "    vendorID: 0xAAAA\n"
2683         "    moduleID: 0xBBBB\n"
2684         "    sw_major_version: 0x1\n"
2685         "    sw_minor_version: 0x2\n"
2686         "    sw_patch_version: 0x4\n",
2687         CMD_HANDLER(cmd_do_fr_getversioninfo), (void *)&cmd_list_fr_basic_test
2688 };
2689
2690 /** Command descriptor for FlexRay get controller configuration command */
2691 cmd_des_t const cmd_des_fr_readcconfig = {
2692         0, 0,
2693         "frbtccconfig*","Print value of a FlexRay cluster and node configuration parameter",
2694         "### Command syntax ###\n"
2695         "\n"
2696         "    frbtccconfig<INDEX>\n"
2697         "\n"
2698         "where `<INDEX>` is an identifier of the parameter.\n"
2699         "\n"
2700         "### Description ###\n"
2701         "\n"
2702         "The command stands for Fr_ReadCCConfig function from the Autosar\n"
2703         "specification. The driver stores the configuration parameters as an\n"
2704         "array. Each parameter can be indexed and returned by this command. See\n"
2705         "Autosar specification of the FlexRay driver\n"
2706         "(http://www.autosar.org/download/R4.1/AUTOSAR_SWS_FlexRayDriver.pdf),\n"
2707         "section 8.2.1 for parameter indexes.\n"
2708         "\n"
2709         "### Example ###\n"
2710         "\n"
2711         "    --> frbtccconfig1\n"
2712         "    Value = 0x1\n",
2713         CMD_HANDLER(cmd_do_fr_readcconfig), (void *)&cmd_list_fr_basic_test
2714 };
2715
2716 /** Command descriptor for FlexRay reconfigure buffer command */
2717 cmd_des_t const cmd_des_fr_reconfigure_buffer = {
2718         0, 0,
2719         "frbtreconfigurebuf*","Reconfigure a buffer to communicate in another slot",
2720         "### Command syntax ###\n"
2721         "\n"
2722         "    frbtreconfigurebuf id<BUFID> slot<SLOT> <CHN> cycset<CYCS> cycoffset<CYCO> max<MAX>\n"
2723         "where\n"
2724         "\n"
2725         "- `<BUFID>` is a number specifying a slot, where the buffer is currently communicating,\n"
2726         "- `<SLOT>` is a number, where buffer will be communicating after the reconfiguration,\n"
2727         "- `<CHN>` is one of 'A', 'B' or 'AB' and identifies the used channel,\n"
2728         "- `<CYCS>` is the cycle set. It has to be one of 0, 1, 2, 4, 8, 16, 32, 64. It specifies together with `<CYCO>` the cycle filtering.\n"
2729         "- `<CYCO>` is the cycle offset. It has to be in range 0 - `<CYCS>`-1"
2730         "- `<MAX>` is the number determining the maximum payload (in hald-words).\n"
2731         "\n"
2732         "### Description ###\n"
2733         "\n"
2734         "The command stands for Fr_ReconfigLPDu function from the Autosar\n"
2735         "specification. It reconfigures specified buffer to communicate in\n"
2736         "different slot.\n"
2737         "The reconfiguration must be allowed in node configuration parameter\n"
2738         "secureBuffers. Buffers used for synchronization or assigned to the FIFO\n"
2739         "are not reconfigurable.\n"
2740         "The command can be called any time when the communication is running.\n"
2741         "\n"
2742         "### Example ###\n"
2743         "\n"
2744         "    --> frbtreconfigurebuf id2 slot3 AB cycset1 cycoffset0 max9\n"
2745         "    frbtreconfigurebuf id2 slot3 AB cycset1 cycoffset0 max9\n",
2746         CMD_HANDLER(cmd_do_fr_reconfigure_buffer), (void *)&cmd_list_fr_basic_test
2747 };
2748
2749
2750 /** List of commands for flexRay, defined as external */
2751 cmd_des_t const *cmd_list_fr_basic_test[] = {
2752         &cmd_des_fr_user_config,
2753         &cmd_des_fr_config_buffer,
2754         &cmd_des_fr_config_fifo,
2755         &cmd_des_fr_init,
2756         &cmd_des_fr_start,
2757         &cmd_des_fr_allslots,
2758         &cmd_des_fr_halt,
2759         &cmd_des_fr_abort,
2760         &cmd_des_fr_sendwup,
2761         &cmd_des_fr_setwuchannel,
2762         &cmd_des_fr_getpocstatus,
2763         &cmd_des_fr_transmittxlpdu,
2764         &cmd_des_fr_canceltxlpdu,
2765         &cmd_des_fr_receiverxlpdu,
2766         &cmd_des_fr_checktxlpdustatus,
2767         &cmd_des_fr_disablelpdu,
2768         &cmd_des_fr_getglobaltime,
2769         &cmd_des_fr_getnmvector,
2770         &cmd_des_fr_nmwatch,
2771         &cmd_des_fr_getchannelstatus,
2772         &cmd_des_fr_getclockcorrection,
2773         &cmd_des_fr_getsyncframelist,
2774         &cmd_des_fr_getwakeuprxstatus,
2775         &cmd_des_fr_settimer,
2776         &cmd_des_fr_canceltimer,
2777         &cmd_des_fr_timerirq,
2778         &cmd_des_fr_getversioninfo,
2779         &cmd_des_fr_readcconfig,
2780         &cmd_des_fr_reconfigure_buffer,
2781         NULL
2782 };