]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blob - commands/cmd_fr_basic_test.c
Merge remote-tracking branch 'origin/flexray'
[pes-rpp/rpp-test-sw.git] / commands / cmd_fr_basic_test.c
1 /*
2  * cmd_fr_basic_test.c
3  *
4  *  Created on: 6.8.2013
5  *      Author: michal
6  */
7
8 #include "cmd_fr_basic_test.h"
9
10 #ifndef DOCGEN
11
12 #include "cmdproc_utils.h"
13 #include "drv/drv.h"
14 #include "rpp/rpp.h"
15 #include "hal/hal.h"
16 #include "stdio.h"
17
18 /**
19  * This structure contains global FlexRay configuration.
20  * All nodes in the network have to use the same values for
21  * all parameters of this structure.
22  */
23 static Fr_TMS570LS_ClusterConfigType Fr_cluster_config = {
24         .gColdStartAttempts = 0x2,
25         .gListenNoise = 0xF,
26         .gMacroPerCycle = 0x15E0,       // (cycle period, 5.6us)
27         .gMaxWithoutClockCorrectionFatal = 0xF,
28         .gMaxWithoutClockCorrectionPassive = 0xF,
29         .gNetworkManagementVectorLength = 12,
30         .gNumberOfMinislots = 0x15A,
31         .gNumberOfStaticSlots = 0x8,
32         .gOffsetCorrectionStart = 0xAE4,
33         .gPayloadLengthStatic = 0x9,
34         .gSyncNodeMax = 0xF,
35         .gdActionPointOffset = 0x4,
36         .gdCASRxLowMax = 0x43,
37         .gdDynamicSlotIdlePhase = 0x1,
38         .gdMinislot = 0x4,
39         .gdMinislotActionPointOffset = 0x2,
40         .gdNIT = 0xAE3,
41         .gdSampleClockPeriod = 0,               // 10mbit/sec
42         .gdStaticSlot = 0x56,
43         .gdTSSTransmitter = 0xA,
44         .gdWakeupSymbolRxIdle = 18,
45         .gdWakeupSymbolRxLow = 18,
46         .gdWakeupSymbolRxWindow = 76,
47         .gdWakeupSymbolTxIdle = 180,
48         .gdWakeupSymbolTxLow = 60
49 };
50
51 /**
52  * This structure contains local configuration of the FlexRay node A.
53  * All nodes in the network shall have their own local configuraion,
54  * but it does not matters if they share some together, until their
55  * buffer configuration differs.
56  */
57 static Fr_TMS570LS_NodeConfigType Fr_node_A_config = {
58         .pAllowHaltDueToClock = 0,
59         .pAllowPassiveToActive = FALSE,
60         .pChannels = FR_CHANNEL_AB,
61         .pClusterDriftDamping = 0x1,
62         .pDelayCompensationA = 0x3,
63         .pDelayCompensationB = 0x3,
64         .pExternOffsetCorrection = 0,
65         .pExternRateCorrection = 0,
66         .pKeySlotUsedForStartup = TRUE,
67         .pKeySlotUsedForSync = TRUE,
68         .pLatestTx = 0x10D,
69         .pMacroInitialOffsetA = 0x6,
70         .pMacroInitialOffsetB = 0x6,
71         .pMicroInitialOffsetA = 0x18,
72         .pMicroInitialOffsetB = 0x18,
73         .pMicroPerCycle = 0x36B00,
74         .pRateCorrectionOut = 0xCD,
75         .pOffsetCorrectionOut = 0x151,
76         .pSamplesPerMicrotick = 0,              // 10 mbit/sec
77         .pSingleSlotEnabled = TRUE,
78         .pWakeupChannel = FR_CHANNEL_A,
79         .pWakeupPattern = 2,
80         .pdAcceptedStartupRange = 0x81,
81         .pdListenTimeout = 0x36DA2,
82         .pdMaxDrift = 0x151,
83         .pDecodingCorrection = 0x33
84 };
85
86 /**
87  * This structure contains local configuration of the FlexRay node B.
88  * All nodes in the network shall have their own local configuraion,
89  * but it does not matters if they share some together, until their
90  * buffer configuration differs.
91  */
92 static Fr_TMS570LS_NodeConfigType Fr_node_B_config = {
93                 .pAllowHaltDueToClock = 0,
94                 .pAllowPassiveToActive = FALSE,
95                 .pChannels = FR_CHANNEL_AB,
96                 .pClusterDriftDamping = 0x1,
97                 .pDelayCompensationA = 0x3,
98                 .pDelayCompensationB = 0x3,
99                 .pExternOffsetCorrection = 0,
100                 .pExternRateCorrection = 0,
101                 .pKeySlotUsedForStartup = TRUE,
102                 .pKeySlotUsedForSync = TRUE,
103                 .pLatestTx = 0x10D,
104                 .pMacroInitialOffsetA = 0x6,
105                 .pMacroInitialOffsetB = 0x6,
106                 .pMicroInitialOffsetA = 0x18,
107                 .pMicroInitialOffsetB = 0x18,
108                 .pMicroPerCycle = 0x36B00,
109                 .pRateCorrectionOut = 0xCD,
110                 .pOffsetCorrectionOut = 0x151,
111                 .pSamplesPerMicrotick = 0,              // 10 mbit/sec
112                 .pSingleSlotEnabled = TRUE,
113                 .pWakeupChannel = FR_CHANNEL_A,
114                 .pWakeupPattern = 2,
115                 .pdAcceptedStartupRange = 0x81,
116                 .pdListenTimeout = 0x36DA2,
117                 .pdMaxDrift = 0x151,
118                 .pDecodingCorrection = 0x33
119 };
120
121 static Fr_TMS570LS_MsgRAMConfig Fr_node_A_msgRAM_config = {
122         .dynSegmentBufferCount = 3,
123         .fifoBufferCount = 5,
124         .secureBuffers = FR_SB_RECONFIG_ENABLED,
125         .statSegmentBufferCount = 5,
126         .syncFramePayloadMultiplexEnabled = 0
127 };
128
129 static Fr_TMS570LS_MsgRAMConfig Fr_node_B_msgRAM_config = {
130         .dynSegmentBufferCount = 3,
131         .fifoBufferCount = 5,
132         .secureBuffers = FR_SB_RECONFIG_ENABLED,
133         .statSegmentBufferCount = 5,
134         .syncFramePayloadMultiplexEnabled = 0
135 };
136
137 static Fr_TMS570LS_BufferConfigType Fr_node_A_static_buffers_config[] = {
138         {
139                 .channel = FR_CHANNEL_AB,
140                 .cycleCounterFiltering = 0,
141                 .isTx = TRUE,
142                 .maxPayload = 9,
143                 .msgBufferInterrupt = TRUE,
144                 .payloadPreambleIndicatorTr = FALSE,
145                 .rejectNullFrames = FALSE,
146                 .rejectStaticSegment = FALSE,
147                 .singleTransmit = FALSE,
148                 .slotId = 1
149         },
150         {
151                 .channel = FR_CHANNEL_AB,
152                 .cycleCounterFiltering = 0,
153                 .isTx = FALSE,
154                 .maxPayload = 9,
155                 .msgBufferInterrupt = TRUE,
156                 .payloadPreambleIndicatorTr = FALSE,
157                 .rejectNullFrames = FALSE,
158                 .rejectStaticSegment = FALSE,
159                 .singleTransmit = FALSE,
160                 .slotId = 2
161         },
162         {
163                 .channel = FR_CHANNEL_AB,
164                 .cycleCounterFiltering = 0,
165                 .isTx = TRUE,
166                 .maxPayload = 9,
167                 .msgBufferInterrupt = TRUE,
168                 .payloadPreambleIndicatorTr = FALSE,
169                 .rejectNullFrames = FALSE,
170                 .rejectStaticSegment = FALSE,
171                 .singleTransmit = TRUE,
172                 .slotId = 3
173         },
174         {
175                 .channel = FR_CHANNEL_AB,
176                 .cycleCounterFiltering = 0,
177                 .isTx = FALSE,
178                 .maxPayload = 9,
179                 .msgBufferInterrupt = TRUE,
180                 .payloadPreambleIndicatorTr = FALSE,
181                 .rejectNullFrames = FALSE,
182                 .rejectStaticSegment = FALSE,
183                 .singleTransmit = TRUE,
184                 .slotId = 4
185         },
186         {
187                 .channel = FR_CHANNEL_AB,
188                 .cycleCounterFiltering = 0,
189                 .isTx = TRUE,
190                 .maxPayload = 9,
191                 .msgBufferInterrupt = TRUE,
192                 .payloadPreambleIndicatorTr = TRUE,
193                 .rejectNullFrames = FALSE,
194                 .rejectStaticSegment = FALSE,
195                 .singleTransmit = FALSE,
196                 .slotId = 5
197         }
198
199 };
200
201 static Fr_TMS570LS_BufferConfigType Fr_node_B_static_buffers_config[] = {
202         {
203                 .channel = FR_CHANNEL_AB,
204                 .cycleCounterFiltering = 0,
205                 .isTx = TRUE,
206                 .maxPayload = 9,
207                 .msgBufferInterrupt = TRUE,
208                 .payloadPreambleIndicatorTr = FALSE,
209                 .rejectNullFrames = FALSE,
210                 .rejectStaticSegment = FALSE,
211                 .singleTransmit = FALSE,
212                 .slotId = 2
213         },
214         {
215                 .channel = FR_CHANNEL_AB,
216                 .cycleCounterFiltering = 0,
217                 .isTx = FALSE,
218                 .maxPayload = 9,
219                 .msgBufferInterrupt = TRUE,
220                 .payloadPreambleIndicatorTr = FALSE,
221                 .rejectNullFrames = FALSE,
222                 .rejectStaticSegment = FALSE,
223                 .singleTransmit = FALSE,
224                 .slotId = 1
225         },
226         {
227                 .channel = FR_CHANNEL_AB,
228                 .cycleCounterFiltering = 0,
229                 .isTx = TRUE,
230                 .maxPayload = 9,
231                 .msgBufferInterrupt = TRUE,
232                 .payloadPreambleIndicatorTr = FALSE,
233                 .rejectNullFrames = FALSE,
234                 .rejectStaticSegment = FALSE,
235                 .singleTransmit = TRUE,
236                 .slotId = 4
237         },
238         {
239                 .channel = FR_CHANNEL_AB,
240                 .cycleCounterFiltering = 0,
241                 .isTx = FALSE,
242                 .maxPayload = 9,
243                 .msgBufferInterrupt = TRUE,
244                 .payloadPreambleIndicatorTr = FALSE,
245                 .rejectNullFrames = FALSE,
246                 .rejectStaticSegment = FALSE,
247                 .singleTransmit = TRUE,
248                 .slotId = 3
249         },
250         {
251                 .channel = FR_CHANNEL_AB,
252                 .cycleCounterFiltering = 0,
253                 .isTx = FALSE,
254                 .maxPayload = 9,
255                 .msgBufferInterrupt = TRUE,
256                 .payloadPreambleIndicatorTr = TRUE,
257                 .rejectNullFrames = FALSE,
258                 .rejectStaticSegment = FALSE,
259                 .singleTransmit = FALSE,
260                 .slotId = 5
261         }
262 };
263
264 static Fr_TMS570LS_BufferConfigType Fr_node_A_dynamic_buffers_config[] = {
265         {
266                 .channel = FR_CHANNEL_A,
267                 .cycleCounterFiltering = 0,
268                 .isTx = TRUE,
269                 .maxPayload = 64,
270                 .msgBufferInterrupt = TRUE,
271                 .payloadPreambleIndicatorTr = FALSE,
272                 .rejectNullFrames = FALSE,
273                 .rejectStaticSegment = FALSE,
274                 .singleTransmit = FALSE,
275                 .slotId = 9
276         },
277         {
278                 .channel = FR_CHANNEL_B,
279                 .cycleCounterFiltering = 0,
280                 .isTx = FALSE,
281                 .maxPayload = 32,
282                 .msgBufferInterrupt = TRUE,
283                 .payloadPreambleIndicatorTr = FALSE,
284                 .rejectNullFrames = FALSE,
285                 .rejectStaticSegment = FALSE,
286                 .singleTransmit = FALSE,
287                 .slotId = 10
288         },
289         {
290                 .channel = FR_CHANNEL_A,
291                 .cycleCounterFiltering = 0,
292                 .isTx = TRUE,
293                 .maxPayload = 16,
294                 .msgBufferInterrupt = TRUE,
295                 .payloadPreambleIndicatorTr = FALSE,
296                 .rejectNullFrames = FALSE,
297                 .rejectStaticSegment = FALSE,
298                 .singleTransmit = TRUE,
299                 .slotId = 11
300         }
301 };
302
303
304 static Fr_TMS570LS_BufferConfigType Fr_node_B_dynamic_buffers_config[] = {
305         {
306                 .channel = FR_CHANNEL_B,
307                 .cycleCounterFiltering = 0,
308                 .isTx = TRUE,
309                 .maxPayload = 32,
310                 .msgBufferInterrupt = TRUE,
311                 .payloadPreambleIndicatorTr = FALSE,
312                 .rejectNullFrames = FALSE,
313                 .rejectStaticSegment = FALSE,
314                 .singleTransmit = TRUE,
315                 .slotId = 10
316         },
317         {
318                 .channel = FR_CHANNEL_A,
319                 .cycleCounterFiltering = 0,
320                 .isTx = FALSE,
321                 .maxPayload = 64,
322                 .msgBufferInterrupt = TRUE,
323                 .payloadPreambleIndicatorTr = FALSE,
324                 .rejectNullFrames = FALSE,
325                 .rejectStaticSegment = FALSE,
326                 .singleTransmit = TRUE,
327                 .slotId = 9
328         },
329         {
330                 .channel = FR_CHANNEL_A,
331                 .cycleCounterFiltering = 0,
332                 .isTx = TRUE,
333                 .maxPayload = 9,
334                 .msgBufferInterrupt = TRUE,
335                 .payloadPreambleIndicatorTr = FALSE,
336                 .rejectNullFrames = FALSE,
337                 .rejectStaticSegment = FALSE,
338                 .singleTransmit = TRUE,
339                 .slotId = 12
340         }
341 };
342
343 static Fr_TMS570LS_BufferConfigType Fr_node_A_fifo_buffers_config[] = {
344         {
345                 .channel = FR_CHANNEL_AB,
346                 .cycleCounterFiltering = 0,
347                 .isTx = FALSE,
348                 .maxPayload = 127,
349                 .msgBufferInterrupt = FALSE, // Recomended for FIFO buffers
350                 .payloadPreambleIndicatorTr = FALSE,
351                 .rejectNullFrames = TRUE,
352                 .rejectStaticSegment = FALSE,
353                 .singleTransmit = FALSE,
354                 .slotId = 12
355         },
356         {
357                 .channel = FR_CHANNEL_AB,
358                 .cycleCounterFiltering = 0,
359                 .isTx = FALSE,
360                 .maxPayload = 127,
361                 .msgBufferInterrupt = FALSE, // Recomended for FIFO buffers
362                 .payloadPreambleIndicatorTr = FALSE,
363                 .rejectNullFrames = TRUE,
364                 .rejectStaticSegment = FALSE,
365                 .singleTransmit = FALSE,
366                 .slotId = 12
367         },
368         {
369                 .channel = FR_CHANNEL_AB,
370                 .cycleCounterFiltering = 0,
371                 .isTx = FALSE,
372                 .maxPayload = 127,
373                 .msgBufferInterrupt = FALSE, // Recomended for FIFO buffers
374                 .payloadPreambleIndicatorTr = FALSE,
375                 .rejectNullFrames = TRUE,
376                 .rejectStaticSegment = FALSE,
377                 .singleTransmit = FALSE,
378                 .slotId = 12
379         },
380         {
381                 .channel = FR_CHANNEL_AB,
382                 .cycleCounterFiltering = 0,
383                 .isTx = FALSE,
384                 .maxPayload = 127,
385                 .msgBufferInterrupt = FALSE, // Recomended for FIFO buffers
386                 .payloadPreambleIndicatorTr = FALSE,
387                 .rejectNullFrames = TRUE,
388                 .rejectStaticSegment = FALSE,
389                 .singleTransmit = FALSE,
390                 .slotId = 12
391         },
392         {
393                 .channel = FR_CHANNEL_AB,
394                 .cycleCounterFiltering = 0,
395                 .isTx = FALSE,
396                 .maxPayload = 127,
397                 .msgBufferInterrupt = FALSE, // Recomended for FIFO buffers
398                 .payloadPreambleIndicatorTr = FALSE,
399                 .rejectNullFrames = TRUE,
400                 .rejectStaticSegment = FALSE,
401                 .singleTransmit = FALSE,
402                 .slotId = 12
403         }
404 };
405
406 static Fr_TMS570LS_BufferConfigType Fr_node_B_fifo_buffers_config[] = {
407         {
408                 .channel = FR_CHANNEL_AB,
409                 .cycleCounterFiltering = 0,
410                 .isTx = FALSE,
411                 .maxPayload = 64,
412                 .msgBufferInterrupt = FALSE, // Recomended for FIFO buffers
413                 .payloadPreambleIndicatorTr = FALSE,
414                 .rejectNullFrames = TRUE,
415                 .rejectStaticSegment = FALSE,
416                 .singleTransmit = FALSE,
417                 .slotId = 0     // No Frame is rejected
418         },
419         {
420                 .channel = FR_CHANNEL_AB,
421                 .cycleCounterFiltering = 0,
422                 .isTx = FALSE,
423                 .maxPayload = 64,
424                 .msgBufferInterrupt = FALSE, // Recomended for FIFO buffers
425                 .payloadPreambleIndicatorTr = FALSE,
426                 .rejectNullFrames = TRUE,
427                 .rejectStaticSegment = FALSE,
428                 .singleTransmit = FALSE,
429                 .slotId = 0     // No Frame is rejected
430         },
431         {
432                 .channel = FR_CHANNEL_AB,
433                 .cycleCounterFiltering = 0,
434                 .isTx = FALSE,
435                 .maxPayload = 64,
436                 .msgBufferInterrupt = FALSE, // Recomended for FIFO buffers
437                 .payloadPreambleIndicatorTr = FALSE,
438                 .rejectNullFrames = TRUE,
439                 .rejectStaticSegment = FALSE,
440                 .singleTransmit = FALSE,
441                 .slotId = 0     // No Frame is rejected
442         },
443         {
444                 .channel = FR_CHANNEL_AB,
445                 .cycleCounterFiltering = 0,
446                 .isTx = FALSE,
447                 .maxPayload = 64,
448                 .msgBufferInterrupt = FALSE, // Recomended for FIFO buffers
449                 .payloadPreambleIndicatorTr = FALSE,
450                 .rejectNullFrames = TRUE,
451                 .rejectStaticSegment = FALSE,
452                 .singleTransmit = FALSE,
453                 .slotId = 0     // No Frame is rejected
454         },
455         {
456                 .channel = FR_CHANNEL_AB,
457                 .cycleCounterFiltering = 0,
458                 .isTx = FALSE,
459                 .maxPayload = 64,
460                 .msgBufferInterrupt = FALSE, // Recomended for FIFO buffers
461                 .payloadPreambleIndicatorTr = FALSE,
462                 .rejectNullFrames = TRUE,
463                 .rejectStaticSegment = FALSE,
464                 .singleTransmit = FALSE,
465                 .slotId = 0     // No Frame is rejected
466         }
467 };
468
469
470 static Fr_ConfigType Fr_config_node_A= {
471         .clusterConfiguration = &Fr_cluster_config,
472         .dynamicBufferConfigs = Fr_node_A_dynamic_buffers_config,
473         .fifoBufferConfigs = Fr_node_A_fifo_buffers_config,
474         .msgRAMConfig = &Fr_node_A_msgRAM_config,
475         .nodeConfiguration = &Fr_node_A_config,
476         .staticBufferConfigs = Fr_node_A_static_buffers_config
477 };
478
479 static Fr_ConfigType Fr_config_node_B= {
480         .clusterConfiguration = &Fr_cluster_config,
481         .dynamicBufferConfigs = Fr_node_B_dynamic_buffers_config,
482         .fifoBufferConfigs = Fr_node_B_fifo_buffers_config,
483         .msgRAMConfig = &Fr_node_B_msgRAM_config,
484         .nodeConfiguration = &Fr_node_B_config,
485         .staticBufferConfigs = Fr_node_B_static_buffers_config
486 };
487
488 /**
489  *      @brief  Do the user configuration of the FlexRay cluster parameters
490  *
491  * @param[in]   cmd_io  Pointer to IO stack
492  * @param[in]   des             Pointer to command descriptor
493  * @param[in]   param   Parameters of command
494  * @return      0 when OK or error code
495  */
496 int cmd_do_fr_user_config(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
497         char* token;
498         token = strtok(param[1], " ");
499         if (strcmp(token, "cluster") == 0) {
500                 if (rpp_fr_config_cluster_params(param[2]) == FAILURE) {
501                         rpp_sci_printf("FlexRay cluster configuration not accepted.\n");
502                         return -CMDERR_BADPAR;
503                 }
504                 rpp_sci_printf("FlexRay cluster configuration accepted.\n");
505         }
506         else if (strcmp(token, "node") == 0) {
507                 if (rpp_fr_config_node_params(param[2]) == FAILURE) {
508                         rpp_sci_printf("FlexRay node configuration not accepted.\n");
509                         return -CMDERR_BADPAR;
510                 }
511                 rpp_sci_printf("FlexRay node configuration accepted.\n");
512         }
513         else if (strcmp(token, "stat") == 0) {
514                 if (rpp_fr_config_static_buffer(param[2]) == FAILURE) {
515                         rpp_sci_printf("Static buffer configuration not accepted.\n");
516                         return -CMDERR_BADPAR;
517                 }
518                 rpp_sci_printf("Static buffer configuration accepted.\n");
519         }
520         else if (strcmp(token, "dyn") == 0) {
521                 if (rpp_fr_config_dynamic_buffer(param[2]) == FAILURE) {
522                         rpp_sci_printf("Dynamic buffer configuration not accepted.\n");
523                         return -CMDERR_BADPAR;
524                 }
525                 rpp_sci_printf("Dynamic buffer configuration accepted.\n");
526
527         }
528         else if (strcmp(token, "fifo") == 0) {
529                 if (rpp_fr_config_fifo_buffer(param[2]) == FAILURE) {
530                         rpp_sci_printf("FIFO buffer configuration not accepted.\n");
531                         return -CMDERR_BADPAR;
532                 }
533                 rpp_sci_printf("FIFO buffer configuration accepted.\n");
534         }
535         else {
536                 return -CMDERR_BADPAR;
537         }
538
539         return 0;
540 }
541
542 /**
543  *      @brief  Initialize the device as FlexRay node.
544  *
545  * @param[in]   cmd_io  Pointer to IO stack
546  * @param[in]   des             Pointer to command descriptor
547  * @param[in]   param   Parameters of command
548  * @return      0 when OK or error code
549  */
550 int cmd_do_fr_init(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
551         const Fr_ConfigType* Fr_ConfigPtr = NULL;
552         int8_t retVal = SUCCESS;
553         uint32_t error = ERR_PARAM_NO_ERROR;
554
555         if (*param[1] == 'A') {
556                 Fr_ConfigPtr = &Fr_config_node_A;
557         }
558         else if (*param[1] == 'B') {
559                 Fr_ConfigPtr = &Fr_config_node_B;
560         }
561         else if (*param[1] == 'U') {    // Select the user configuration  -  call config commands first
562                 Fr_ConfigPtr = NULL;
563         }
564         else {
565                 return -CMDERR_BADPAR;
566         }
567
568         retVal = rpp_fr_init_driver(Fr_ConfigPtr, &error);
569         if (retVal == SUCCESS) {
570                 rpp_sci_printf("FlexRay driver initialized.\r\n");
571         }
572         else {
573                 rpp_sci_printf("FlexRay needs to be configured before initialization.\r\n");
574                 return -CMDERR_BADCFG;
575         }
576
577         retVal = rpp_fr_init_controller(0, &error);
578         if (retVal == SUCCESS) {
579                 rpp_sci_printf("FlexRay controller initialized.\r\n");
580         }
581         else {
582                 if (error & FR_INIT_ERR_CLUSTER_CONFIG) {
583                         rpp_sci_printf("Cluster configuration data error: %x\r\n", (retVal & 0x3FFFFFE) >> 1 );
584                 }
585                 else if (error & FR_INIT_ERR_NODE_CONFIG) {
586                         rpp_sci_printf("Node configuration data error: %x\r\n", (retVal & 0x3FFFFFE) >> 1 );
587                 }
588                 else if (error & FR_INIT_ERR_MSGRAM_CONFIG) {
589                         rpp_sci_printf("Message RAM configuration data error: %x\r\n", (retVal & 0x3FFFFFE) >> 1 );
590                 }
591                 else if (error & FR_INIT_ERR_BUFFPARAM_CONFIG) {
592                         rpp_sci_printf("Buffer configuration data error: %x\r\n", (retVal & 0x3FFFFFE) >> 1 );
593                 }
594                 else if (error & (uint32_t)FR_INIT_ERR_BUFF_CONFIG) {
595                         rpp_sci_printf("Buffer configuration error: %x\r\n", (retVal & 0x3FFFFFE) >> 1 );
596                 }
597                 else {
598                         rpp_sci_printf("POC state switching error.\r\n");
599                 }
600                 return -CMDERR_BADCFG;
601         }
602         return 0;
603 }
604
605 /**
606  *      @brief  Starts FlexRay communication
607  *
608  * @param[in]   cmd_io  Pointer to IO stack
609  * @param[in]   des             Pointer to command descriptor
610  * @param[in]   param   Parameters of command
611  * @return      0 when OK or error code
612  */
613 int cmd_do_fr_start(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
614         int8_t retVal = SUCCESS;
615         uint32_t error = ERR_PARAM_NO_ERROR;
616
617         retVal = rpp_fr_start_communication(0, &error);
618         if (retVal == SUCCESS) {
619                 rpp_sci_printf("FlexRay communication is running.\r\n");
620         }
621         else {
622                 if (error & FR_STARTUP_ERR_SW_STUP_FOLLOW) {
623                         rpp_sci_printf("Can not switch POC to RUN state.\r\n");
624                 }
625                 else if (error & FR_STARTUP_ERR_CSINH_DIS) {
626                         rpp_sci_printf("Cold start inhibit disabled error.\r\n");
627                 }
628                 else if (error & FR_STARTUP_ERR_SW_STUP_READY) {
629                         rpp_sci_printf("Can not switch back to READY from STARTUP.\r\n");
630                 }
631                 else if (error & FR_STARTUP_ERR_SW_STUP_AS_NCOLD) {
632                         rpp_sci_printf("Can not switch to STARTUP as non-coldstarter.\r\n");
633                 }
634                 else {
635                         rpp_sci_printf("General error.\r\n");
636                 }
637                 return -CMDERR_BADCFG;
638         }
639         return 0;
640 }
641
642 /**
643  *      @brief  Invokes POC command ALL_SLOTS
644  *
645  * @param[in]   cmd_io  Pointer to IO stack
646  * @param[in]   des             Pointer to command descriptor
647  * @param[in]   param   Parameters of command
648  * @return      0 when OK or error code
649  */
650 int cmd_do_fr_allslots(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
651         int8_t retVal = ERR_PARAM_NO_ERROR;
652         retVal = rpp_fr_all_slots(0);
653         if (retVal == SUCCESS) {
654                 rpp_sci_printf("FlexRay node is communicating in all slots.\r\n");
655         }
656         else {
657                 rpp_sci_printf("General error.\r\n");
658                 return -CMDERR_BADCFG;
659         }
660         return 0;
661 }
662
663 /**
664  *      @brief  Halt FlexRay communication
665  *
666  * @param[in]   cmd_io  Pointer to IO stack
667  * @param[in]   des             Pointer to command descriptor
668  * @param[in]   param   Parameters of command
669  * @return      0 when OK or error code
670  */
671 int cmd_do_fr_halt(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
672         int8_t retVal = ERR_PARAM_NO_ERROR;
673         retVal = rpp_fr_halt_communication(0);
674         if (retVal == SUCCESS) {
675                 rpp_sci_printf("FlexRay node communication halted.\r\n");
676         }
677         else {
678                 rpp_sci_printf("General error.\r\n");
679                 return -CMDERR_BADCFG;
680         }
681         return 0;
682 }
683
684 /**
685  *      @brief  Abort FlexRay communication
686  *
687  * @param[in]   cmd_io  Pointer to IO stack
688  * @param[in]   des             Pointer to command descriptor
689  * @param[in]   param   Parameters of command
690  * @return      0 when OK or error code
691  */
692 int cmd_do_fr_abort(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
693         int8_t retVal = ERR_PARAM_NO_ERROR;
694         retVal = rpp_fr_abort_communication(0);
695         if (retVal == SUCCESS) {
696                 rpp_sci_printf("FlexRay node communication aborted.\r\n");
697         }
698         else {
699                 rpp_sci_printf("General error.\r\n");
700                 return -CMDERR_BADCFG;
701         }
702         return 0;
703 }
704
705 /**
706  *      @brief  Send wake up pattern
707  *
708  * @param[in]   cmd_io  Pointer to IO stack
709  * @param[in]   des             Pointer to command descriptor
710  * @param[in]   param   Parameters of command
711  * @return      0 when OK or error code
712  */
713 int cmd_do_fr_sendwup(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
714         int8_t retVal = ERR_PARAM_NO_ERROR;
715         retVal = rpp_fr_send_wup(0);
716         if (retVal == SUCCESS) {
717                 rpp_sci_printf("Wake up pattern has been sent.\r\n");
718         }
719         else {
720                 rpp_sci_printf("General error.\r\n");
721                 return -CMDERR_BADCFG;
722         }
723         return 0;
724 }
725
726 /**
727  *      @brief  Set channel for wake up pattern sending.
728  *
729  * @param[in]   cmd_io  Pointer to IO stack
730  * @param[in]   des             Pointer to command descriptor
731  * @param[in]   param   Parameters of command
732  * @return      0 when OK or error code
733  */
734 int cmd_do_fr_setwuchannel(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
735         int8_t retVal = ERR_PARAM_NO_ERROR;
736         Fr_ChannelType channel = FR_CHANNEL_A;
737
738         if (*param[1] == 'A') {
739                 channel = FR_CHANNEL_A;
740         }
741         else if (*param[1] == 'B') {
742                 channel = FR_CHANNEL_B;
743         }
744         else {
745                 return -CMDERR_BADPAR;
746         }
747         retVal = rpp_fr_set_wu_channel(0, channel);
748         if (retVal == SUCCESS) {
749                 rpp_sci_printf("Wake up channel has been set.\r\n");
750         }
751         else {
752                 rpp_sci_printf("General error.\r\n");
753                 return -CMDERR_BADCFG;
754         }
755         return 0;
756 }
757
758 /**
759  *      @brief  Get and print POC status of the FlexRay controller.
760  *
761  * @param[in]   cmd_io  Pointer to IO stack
762  * @param[in]   des             Pointer to command descriptor
763  * @param[in]   param   Parameters of command
764  * @return      0 when OK or error code
765  */
766 int cmd_do_fr_getpocstatus(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
767         int8_t retVal = ERR_PARAM_NO_ERROR;
768         Fr_POCStatusType status;
769         char* ErrorModeStrings[] = {"ACTIVE", "HALT", "PASSIVE"};
770         char* SlotModeStrings[]  = {"KEYSLOT", "ALL_PENDING", "ALL"};
771         char* StartupStateStrings[]  = {
772                         "UNDEFINED", "COLDSTART_LISTEN", "COLDSTART_CHECK", "COLDSTART_JOIN",
773                         "COLDSTART_CONSISTENCY_CHECK", "INTEGRATION_LISTEN", "INITIALIZE_SCHEDULE", "INTEGRATION_CONSISTENCY_CHECK",
774                         "COLDSTART_GAP", "EXTERNAL_STARTUP", "ABORT", "COLDSTART_COLLISION_RESOLUTION",
775                         "PREPARE"
776         };
777         char* StateStrings[]  = {
778                         "CONFIG", "DEFAULT_CONFIG", "HALT", "NORMAL_ACTIVE",
779                         "NORMAL_PASSIVE", "READY", "STARTUP", "LOOPBACK",
780                         "MONITOR", "WAKEUP"
781         };
782         char* WakeupStatusStrings[]  = {
783                         "UNDEFINED", "RECEIVED_HEADER", "RECEIVED_WUP", "COLLISION_HEADER",
784                         "COLLISION_WUP", "COLLISION_UNKNOWN", "TRANSMITTED"
785         };
786
787         retVal = rpp_fr_get_poc_status(0, &status);
788         if (retVal == SUCCESS) {
789                 rpp_sci_printf("POC status:\r\n");
790                 rpp_sci_printf("CHIHaltRequest: %s\r\n", (status.CHIHaltRequest == TRUE) ? "TRUE" : "FALSE");
791                 rpp_sci_printf("CHIReadyRequest: %s\r\n", (status.CHIReadyRequest == TRUE) ? "TRUE" : "FALSE");
792                 rpp_sci_printf("ColdstartNoise: %s\r\n", (status.ColdstartNoise == TRUE) ? "TRUE" : "FALSE");
793                 rpp_sci_printf("Freeze: %s\r\n", (status.Freeze == TRUE) ? "TRUE" : "FALSE");
794                 rpp_sci_printf("ErrorMode: %s\r\n", ErrorModeStrings[status.ErrorMode]);
795                 rpp_sci_printf("SlotMode: %s\r\n", SlotModeStrings[status.SlotMode]);
796                 rpp_sci_printf("StartupState: %s\r\n", StartupStateStrings[status.StartupState]);
797                 rpp_sci_printf("State: %s\r\n", StateStrings[status.State]);
798                 rpp_sci_printf("WakeupStatus: %s\r\n", WakeupStatusStrings[status.WakeupStatus]);
799         }
800         else {
801                 rpp_sci_printf("General error.\r\n");
802                 return -CMDERR_BADCFG;
803         }
804         return 0;
805 }
806
807 /**
808  *      @brief  Send given data through the FlexRay in selected slot.
809  *
810  * @param[in]   cmd_io  Pointer to IO stack
811  * @param[in]   des             Pointer to command descriptor
812  * @param[in]   param   Parameters of command
813  * @return      0 when OK or error code
814  */
815 int cmd_do_fr_transmittxlpdu(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
816         int8_t retVal = ERR_PARAM_NO_ERROR;
817         uint32_t slotID;
818         uint8_t dataLength;
819         int values[MAX_PARAM_VALUES_NUM];
820         uint8_t data[MAX_PARAM_VALUES_NUM];
821         char* token = NULL;
822
823         if (sscanf(param[1], "%d", &slotID) != 1) {
824                 return -CMDERR_BADPAR;
825         }
826         if (sscanf(param[2], " %2x", &values[0]) != 1) {
827                 return -CMDERR_BADPAR;
828         }
829         data[0] = (uint8_t)values[0];
830         token = strtok(param[2], " ");
831         token = strtok(NULL, " ");
832         dataLength = 1;
833         while (dataLength < MAX_PARAM_VALUES_NUM && token != NULL) {
834                 if (sscanf(token, "%2x", &values[dataLength]) == EOF) {
835                         break;
836                 }
837                 data[dataLength] = (uint8_t)values[dataLength];
838                 token = strtok(NULL, " ");
839                 dataLength++;
840         }
841
842         retVal = rpp_fr_transmit_lpdu(0, slotID, data, dataLength);
843         if (retVal == SUCCESS) {
844                 rpp_sci_printf("Data were sent.\r\n");
845         }
846         else {
847                 rpp_sci_printf("General error.\r\n");
848                 return -CMDERR_BADCFG;
849         }
850         return 0;
851 }
852
853 /**
854  *      @brief  Cancel the transmission in the selected slot.
855  *
856  * @param[in]   cmd_io  Pointer to IO stack
857  * @param[in]   des             Pointer to command descriptor
858  * @param[in]   param   Parameters of command
859  * @return      0 when OK or error code
860  */
861 int cmd_do_fr_canceltxlpdu(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
862         int8_t retVal = ERR_PARAM_NO_ERROR;
863         uint32_t slotID;
864
865         if (sscanf(param[1], "%d", &slotID) != 1) {
866                 return -CMDERR_BADPAR;
867         }
868         if (param[2] != NULL) {
869                 return -CMDERR_BADPAR;
870         }
871
872         retVal = rpp_fr_cancel_transmit_lpdu(0, slotID);
873         if (retVal == SUCCESS) {
874                 rpp_sci_printf("Transmission canceled.\r\n");
875         }
876         else {
877                 rpp_sci_printf("General error.\r\n");
878                 return -CMDERR_BADCFG;
879         }
880         return 0;
881 }
882
883 /**
884  *      @brief  Receive data from selected slot.
885  *
886  * @param[in]   cmd_io  Pointer to IO stack
887  * @param[in]   des             Pointer to command descriptor
888  * @param[in]   param   Parameters of command
889  * @return      0 when OK or error code
890  */
891 int cmd_do_fr_receiverxlpdu(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
892         int8_t retVal = ERR_PARAM_NO_ERROR;
893         uint32_t slotID;
894         uint8_t data[cPayloadLengthMax];
895         Fr_RxLPduStatusType status;
896         uint8_t receivedLength = 0;
897         uint8_t i;
898
899         if (sscanf(param[1], "%d", &slotID) != 1) {
900                 return -CMDERR_BADPAR;
901         }
902         if (param[2] != NULL) {
903                 return -CMDERR_BADPAR;
904         }
905
906         retVal = rpp_fr_receive_lpdu(0, slotID, data, &status, &receivedLength);
907         if (retVal == SUCCESS) {
908                 switch (status) {
909                 case FR_RECEIVED_MORE_DATA_AVAILABLE:
910                         rpp_sci_printf("More messages are still in FIFO:\r\n");
911                 case FR_RECEIVED:
912                         rpp_sci_printf("Received message (%d B):\r\n", receivedLength);
913                         for (i = 0; i < receivedLength; i++) {
914                                 rpp_sci_printf(" %x", data[i]);
915                         }
916                         rpp_sci_printf("\r\n");
917                         break;
918                 default:
919                         rpp_sci_printf("No message received.\r\n");
920                         break;
921                 }
922         }
923         else {
924                 rpp_sci_printf("General error.\r\n");
925                 return -CMDERR_BADCFG;
926         }
927         return 0;
928 }
929
930 /**
931  *      @brief  Returns TX LPdu status.
932  *
933  * @param[in]   cmd_io  Pointer to IO stack
934  * @param[in]   des             Pointer to command descriptor
935  * @param[in]   param   Parameters of command
936  * @return      0 when OK or error code
937  */
938 int cmd_do_fr_checktxlpdustatus(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
939         int8_t retVal = ERR_PARAM_NO_ERROR;
940         uint32_t slotID;
941         Fr_TxLPduStatusType status;
942         char* statusStrings[] = {"is not", "is"};
943
944         if (sscanf(param[1], "%d", &slotID) != 1) {
945                 return -CMDERR_BADPAR;
946         }
947         if (param[2] != NULL) {
948                 return -CMDERR_BADPAR;
949         }
950
951         retVal = rpp_fr_check_tx_lpdu_status(0, slotID, &status);
952         if (retVal == SUCCESS) {
953                 rpp_sci_printf("Message transmission %s pending.\r\n", statusStrings[status]);
954         }
955         else {
956                 rpp_sci_printf("General error.\r\n");
957                 return -CMDERR_BADCFG;
958         }
959         return 0;
960 }
961
962 /**
963  *      @brief  Disable buffer.
964  *
965  * @param[in]   cmd_io  Pointer to IO stack
966  * @param[in]   des             Pointer to command descriptor
967  * @param[in]   param   Parameters of command
968  * @return      0 when OK or error code
969  */
970 int cmd_do_fr_disablelpdu(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
971         int8_t retVal = ERR_PARAM_NO_ERROR;
972         uint32_t slotID;
973
974         if (sscanf(param[1], "%d", &slotID) != 1) {
975                 return -CMDERR_BADPAR;
976         }
977         if (param[2] != NULL) {
978                 return -CMDERR_BADPAR;
979         }
980
981         retVal = rpp_fr_disable_lpdu(0, slotID);
982         if (retVal == SUCCESS) {
983                 rpp_sci_printf("Buffer disabled.\r\n");
984         }
985         else {
986                 rpp_sci_printf("General error.\r\n");
987                 return -CMDERR_BADCFG;
988         }
989         return 0;
990 }
991
992 /**
993  *      @brief  Print global time of the FlexRay network.
994  *
995  * @param[in]   cmd_io  Pointer to IO stack
996  * @param[in]   des             Pointer to command descriptor
997  * @param[in]   param   Parameters of command
998  * @return      0 when OK or error code
999  */
1000 int cmd_do_fr_getglobaltime(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1001         int8_t retVal = ERR_PARAM_NO_ERROR;
1002         uint8_t cycle = 0;
1003         uint16_t macroTick = 0;
1004
1005         retVal = rpp_fr_get_global_time(0, &cycle, &macroTick);
1006         if (retVal == SUCCESS) {
1007                 rpp_sci_printf("Cycle number: %d\r\nMacrotick number: %d\r\n", cycle, macroTick);
1008         }
1009         else {
1010                 rpp_sci_printf("General error.\r\n");
1011                 return -CMDERR_BADCFG;
1012         }
1013         return 0;
1014 }
1015
1016 /**
1017  *      @brief  Print network management vector of the FlexRay node.
1018  *
1019  * @param[in]   cmd_io  Pointer to IO stack
1020  * @param[in]   des             Pointer to command descriptor
1021  * @param[in]   param   Parameters of command
1022  * @return      0 when OK or error code
1023  */
1024 int cmd_do_fr_getnmvector(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1025         int8_t retVal = ERR_PARAM_NO_ERROR;
1026         uint8_t nmVector[12];
1027         uint8_t i;
1028
1029         retVal = rpp_fr_get_network_management_vector(0, nmVector);
1030         if (retVal == SUCCESS) {
1031                 rpp_sci_printf("Network management vector:");
1032                 for (i = 0; i < Fr_cluster_config.gNetworkManagementVectorLength; i++) {
1033                         rpp_sci_printf(" %x", nmVector[i]);
1034                 }
1035                 rpp_sci_printf("\r\n");
1036         }
1037         else {
1038                 rpp_sci_printf("General error.\r\n");
1039                 return -CMDERR_BADCFG;
1040         }
1041         return 0;
1042 }
1043
1044 /**
1045  *      @brief  Print both channels status of the FlexRay node.
1046  *
1047  * @param[in]   cmd_io  Pointer to IO stack
1048  * @param[in]   des             Pointer to command descriptor
1049  * @param[in]   param   Parameters of command
1050  * @return      0 when OK or error code
1051  */
1052 int cmd_do_fr_getchannelstatus(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1053         int8_t retVal = ERR_PARAM_NO_ERROR;
1054         uint8_t index;
1055         uint8_t channel;
1056         char* decodeStrings[] = {
1057                         "aggregated channel status vSS!ValidFrame",
1058                         "aggregated channel status vSS!SyntaxError",
1059                         "aggregated channel status vSS!ContentError",
1060                         "aggregated channel status additional communication",
1061                         "aggregated channel status vSS!Bviolation",
1062                         "aggregated channel status vSS!TxConflict",
1063                         "Not used (0)",
1064                         "Not used (0)",
1065                         "symbol window status data vSS!ValidMTS",
1066                         "symbol window status data vSS!SyntaxError",
1067                         "symbol window status data vSS!Bviolation",
1068                         "symbol window status data vSS!TxConflict",
1069                         "NIT status data vSS!SyntaxError",
1070                         "NIT status data vSS!Bviolation",
1071                         "Not used (0)",
1072                         "Not used (0)"
1073         };
1074         char* channelNames[] = {"A", "B"};
1075         char* boolStrings[] = {"FALSE", "TRUE"};
1076         uint16_t channelStatuses[2];
1077
1078         retVal = rpp_fr_get_channel_status(0, &channelStatuses[0], &channelStatuses[1]);
1079         if (retVal == SUCCESS) {
1080                 for (channel = 0; channel < 2; channel++) {
1081                         rpp_sci_printf("Channel %s status:\r\n", channelNames[channel]);
1082                         for (index = 0; index < 16; index++) {
1083                                 rpp_sci_printf("\t%s: %s\r\n", decodeStrings[index], boolStrings[ (channelStatuses[channel] >> index) & 0x1 ] );
1084                         }
1085                 }
1086         }
1087         else {
1088                 rpp_sci_printf("General error.\r\n");
1089                 return -CMDERR_BADCFG;
1090         }
1091         return 0;
1092 }
1093
1094 /**
1095  *      @brief  Print clock correction of the FlexRay node
1096  *
1097  * @param[in]   cmd_io  Pointer to IO stack
1098  * @param[in]   des             Pointer to command descriptor
1099  * @param[in]   param   Parameters of command
1100  * @return      0 when OK or error code
1101  */
1102 int cmd_do_fr_getclockcorrection(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1103         int8_t retVal = ERR_PARAM_NO_ERROR;
1104         int16_t rateCorrection;
1105         int32_t offsetCorrection;
1106
1107         retVal = rpp_fr_get_clock_correction(0, &rateCorrection, &offsetCorrection);
1108         if (retVal == SUCCESS) {
1109                 rpp_sci_printf("Rate correction: %d\r\nOffset correction: %d\r\n", rateCorrection, offsetCorrection);
1110         }
1111         else {
1112                 rpp_sci_printf("General error.\r\n");
1113                 return -CMDERR_BADCFG;
1114         }
1115         return 0;
1116 }
1117
1118 /**
1119  *      @brief  Print list of syncframec transmitted on both channels via the even and odd cycle.
1120  *
1121  * @param[in]   cmd_io  Pointer to IO stack
1122  * @param[in]   des             Pointer to command descriptor
1123  * @param[in]   param   Parameters of command
1124  * @return      0 when OK or error code
1125  */
1126 int cmd_do_fr_getsyncframelist(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1127         int8_t retVal = ERR_PARAM_NO_ERROR;
1128         uint16_t channelAEvenList[FR_MAX_SYNC_FRAME_LIST_SIZE];
1129         uint16_t channelBEvenList[FR_MAX_SYNC_FRAME_LIST_SIZE];
1130         uint16_t channelAOddList[FR_MAX_SYNC_FRAME_LIST_SIZE];
1131         uint16_t channelBOddList[FR_MAX_SYNC_FRAME_LIST_SIZE];
1132         uint32_t listSize = 0;
1133         uint8_t i;
1134
1135         if (sscanf(param[1], "%d", &listSize) != 1) {
1136                 return -CMDERR_BADPAR;
1137         }
1138         if (param[2] != NULL) {
1139                 return -CMDERR_BADPAR;
1140         }
1141         if (listSize > FR_MAX_SYNC_FRAME_LIST_SIZE) {
1142                 return -CMDERR_BADPAR;
1143         }
1144
1145         retVal = rpp_fr_get_sync_frame_list(0, listSize, channelAEvenList, channelBEvenList, channelAOddList, channelBOddList);
1146         if (retVal == SUCCESS) {
1147                 rpp_sci_printf("| Channel A even | channel B even | channel A odd  | channel B odd  |\r\n");
1148                 rpp_sci_printf("|----------------|----------------|----------------|----------------|\r\n");
1149                 for (i = 0; i < listSize; i++) {
1150                         rpp_sci_printf("| %-14x | %-14x | %-14x | %-14x |\r\n", channelAEvenList[i], channelBEvenList[i], channelAOddList[i], channelBOddList[i]);
1151                 }
1152                 rpp_sci_printf("|----------------|----------------|----------------|----------------|\r\n");
1153
1154         }
1155         else {
1156                 rpp_sci_printf("General error.\r\n");
1157                 return -CMDERR_BADCFG;
1158         }
1159         return 0;
1160 }
1161
1162 /**
1163  *      @brief  Print status of wakeup on each channels (wakeup received on channel or not yet received).
1164  *
1165  * @param[in]   cmd_io  Pointer to IO stack
1166  * @param[in]   des             Pointer to command descriptor
1167  * @param[in]   param   Parameters of command
1168  * @return      0 when OK or error code
1169  */
1170 int cmd_do_fr_getwakeuprxstatus(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1171         int8_t retVal = ERR_PARAM_NO_ERROR;
1172         uint8_t status = 0;
1173         char* statusStrings[] = {"was not yet", "was"};
1174         char* channelNames[] = {"A", "B"};
1175         uint8_t i;
1176
1177         retVal = rpp_fr_get_wakeup_rx_status(0, &status);
1178         if (retVal == SUCCESS) {
1179                 for (i = 0; i < 2; i++) {
1180                         rpp_sci_printf("Wake up pattern %s received on channel %s.\r\n", statusStrings[(status >> i) & 0x1], channelNames[i]);
1181                 }
1182         }
1183         else {
1184                 rpp_sci_printf("General error.\r\n");
1185                 return -CMDERR_BADCFG;
1186         }
1187         return 0;
1188 }
1189
1190 /**
1191  *      @brief  Set and start absolute timer.
1192  *
1193  * @param[in]   cmd_io  Pointer to IO stack
1194  * @param[in]   des             Pointer to command descriptor
1195  * @param[in]   param   Parameters of command
1196  * @return      0 when OK or error code
1197  */
1198 int cmd_do_fr_settimer(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1199         int8_t retVal = ERR_PARAM_NO_ERROR;
1200         int timer = 0;
1201         int cycle = 0;
1202         int offset = 0;
1203         char* token = NULL;
1204
1205         if (sscanf(param[1], "%d", &timer) != 1) {
1206                 return -CMDERR_BADPAR;
1207         }
1208         if ((token = strtok(param[2], " ")) == NULL) {
1209                 return -CMDERR_BADPAR;
1210         }
1211         if (sscanf(token, " %d", &cycle) != 1) {
1212                 return -CMDERR_BADPAR;
1213         }
1214         if ((token = strtok(NULL, " ")) == NULL) {
1215                 return -CMDERR_BADPAR;
1216         }
1217         if (sscanf(token, " %d", &offset) != 1) {
1218                 return -CMDERR_BADPAR;
1219         }
1220         if ((token = strtok(NULL, " ")) != NULL) {
1221                 return -CMDERR_BADPAR;
1222         }
1223
1224         retVal = rpp_fr_set_timer(0, timer, cycle, offset);
1225         if (retVal == SUCCESS) {
1226                 rpp_sci_printf("Timer was set.\r\n");
1227         }
1228         else {
1229                 rpp_sci_printf("General error.\r\n");
1230                 return -CMDERR_BADCFG;
1231         }
1232         return 0;
1233 }
1234
1235 /**
1236  *      @brief  Cancel selected timer
1237  *
1238  * @param[in]   cmd_io  Pointer to IO stack
1239  * @param[in]   des             Pointer to command descriptor
1240  * @param[in]   param   Parameters of command
1241  * @return      0 when OK or error code
1242  */
1243 int cmd_do_fr_canceltimer(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1244         int8_t retVal = ERR_PARAM_NO_ERROR;
1245         int timer = 0;
1246
1247         if (sscanf(param[1], "%d", &timer) != 1) {
1248                 return -CMDERR_BADPAR;
1249         }
1250
1251         if (param[2] != NULL) {
1252                 return -CMDERR_BADPAR;
1253         }
1254
1255         retVal = rpp_fr_cancel_timer(0, timer);
1256         if (retVal == SUCCESS) {
1257                 rpp_sci_printf("Timer was canceled.\r\n");
1258         }
1259         else {
1260                 rpp_sci_printf("General error.\r\n");
1261                 return -CMDERR_BADCFG;
1262         }
1263         return 0;
1264 }
1265
1266 /**
1267  *      @brief  Enable/disable, acknowledge, get timer IRQ
1268  *
1269  * @param[in]   cmd_io  Pointer to IO stack
1270  * @param[in]   des             Pointer to command descriptor
1271  * @param[in]   param   Parameters of command
1272  * @return      0 when OK or error code
1273  */
1274 int cmd_do_fr_timerirq(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1275         int8_t retVal = ERR_PARAM_NO_ERROR;
1276         int timer = 0;
1277         char str[4];
1278         boolean_t status = FALSE;
1279         char* boolStrings[] = {"FALSE", "TRUE"};
1280
1281
1282         if (sscanf(param[1], "%d", &timer) != 1) {
1283                 return -CMDERR_BADPAR;
1284         }
1285
1286         if (param[2] == NULL) {         // Get timer IRQ
1287                 retVal = rpp_fr_get_timer_irq_status(0, timer, &status);
1288                 if (retVal == SUCCESS) {
1289                         rpp_sci_printf("IRQ = %s\r\n", boolStrings[status]);
1290                 }
1291                 else {
1292                         rpp_sci_printf("General error.\r\n");
1293                         return -CMDERR_BADCFG;
1294                 }
1295         }
1296         else {  // Some set action
1297                 if (sscanf(param[2], "%4s", str) != 1) {
1298                         return -CMDERR_BADPAR;
1299                 }
1300                 if (strcmp(str, "EN") == 0) { // Enable IRQ
1301                         retVal = SUCCESS;       // No interrupts imlemented
1302                 }
1303                 else if (strcmp(str, "DIS") == 0) { // Disable IRQ
1304                         retVal = SUCCESS;       // No interrupts implemented
1305                 }
1306                 else if  (strcmp(str, "ACK") == 0) { // Clear IRQ
1307                         retVal = rpp_fr_clear_timer_irq(0, timer);
1308                 }
1309                 else {  // Bad argument
1310                         return -CMDERR_BADPAR;
1311                 }
1312
1313                 if (retVal == SUCCESS) {
1314                         rpp_sci_printf("OK\r\n");
1315                 }
1316                 else {
1317                         rpp_sci_printf("General error.\r\n");
1318                         return -CMDERR_BADCFG;
1319                 }
1320         }
1321         return 0;
1322 }
1323
1324 /**
1325  *      @brief  Print FlexRay driver version info.
1326  *
1327  * @param[in]   cmd_io  Pointer to IO stack
1328  * @param[in]   des             Pointer to command descriptor
1329  * @param[in]   param   Parameters of command
1330  * @return      0 when OK or error code
1331  */
1332 int cmd_do_fr_getversioninfo(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1333         Std_VersionInfoType versionInfo;
1334
1335         rpp_fr_get_driver_version(&versionInfo);
1336         rpp_sci_printf("vendorID: %#x\r\n", versionInfo.vendorID);
1337         rpp_sci_printf("moduleID: %#x\r\n", versionInfo.moduleID);
1338         rpp_sci_printf("sw_major_version: %#x\r\n", versionInfo.sw_major_version);
1339         rpp_sci_printf("sw_minor_version: %#x\r\n", versionInfo.sw_minor_version);
1340         rpp_sci_printf("sw_patch_version: %#x\r\n", versionInfo.sw_patch_version);
1341
1342         return 0;
1343 }
1344
1345 /**
1346  *      @brief  Print value of FlexRay configuratoin parameter.
1347  *
1348  * @param[in]   cmd_io  Pointer to IO stack
1349  * @param[in]   des             Pointer to command descriptor
1350  * @param[in]   param   Parameters of command
1351  * @return      0 when OK or error code
1352  */
1353 int cmd_do_fr_readcconfig(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1354         int8_t retVal = ERR_PARAM_NO_ERROR;
1355         int index = 0;
1356         uint32_t value = 0;
1357
1358         if (sscanf(param[1], "%d", &index) != 1) {
1359                 return -CMDERR_BADPAR;
1360         }
1361
1362         if (param[2] != NULL) {
1363                 return -CMDERR_BADPAR;
1364         }
1365
1366         retVal = rpp_fr_read_com_ctrl_config(0, index, &value);
1367         if (retVal == SUCCESS) {
1368                 rpp_sci_printf("Value = %#x\r\n", value);
1369         }
1370         else {
1371                 rpp_sci_printf("General error.\r\n");
1372                 return -CMDERR_BADCFG;
1373         }
1374         return 0;
1375 }
1376
1377 #endif  /* DOCGEN */
1378
1379 /** Command descriptor for FlexRay user config cluster command */
1380 cmd_des_t const cmd_des_fr_user_config={
1381         0, 0,
1382         "frbtuser*","Set the user configuration parameters",
1383         "=== Command syntax ===\n"
1384         "\n"
1385         "   frbtuser<TYPE> <PARAMS>\n"
1386         "where\n"
1387         "* <TYPE> is a string, which is selecting the type of parameters to be set. It can be: \"cluster\", \"node\", \"stat\", \"fifo\" or \"dyn\"\n"
1388         "* <PARAMS> is a string, containing hexadecimal numbers separated by spaces. Each number stands for one parameter.\n"
1389         "\n"
1390         "=== Description ===\n"
1391         "\n"
1392         "The command takes the configuration parameters in form of string and set the\n"
1393         "appropriate type of the FlexRay parameters.\n"
1394         "It is necessary to configure at least cluster, node and one static buffer.\n"
1395         "The type of the parameters can be selected by <TYPE> selector.\n"
1396         "The type \"cluster\" sets global FlexRay network parameters. 25 parameters in\n"
1397         "the string is expected in this order:\n"
1398         "1) gColdStartAttempts\n"
1399         "2) gdActionPointOffset\n"
1400         "3) gdCASRxLowMax\n"
1401         "4) gdDynamicSlotIdlePhase\n"
1402         "5) gdMinislot\n"
1403         "6) gdMinislotActionPointOffset\n"
1404         "7) gdStaticSlot\n"
1405         "8) gdTSSTransmitter\n"
1406         "9) gdWakeupSymbolRxIdle\n"
1407         "10) gdWakeupSymbolRxLow\n"
1408         "11) gdWakeupSymbolRxWindow\n"
1409         "12) gdWakeupSymbolTxIdle\n"
1410         "13) gdWakeupSymbolTxLow\n"
1411         "14) gListenNoise\n"
1412         "15) gMacroPerCycle\n"
1413         "16) gMaxWithoutClockCorrectionFatal\n"
1414         "17) gMaxWithoutClockCorrectionPassive\n"
1415         "18) gNumberOfMinislots\n"
1416         "19) gNumberOfStaticSlots\n"
1417         "20) gOffsetCorrectionStart\n"
1418         "21) gPayloadLengthStatic\n"
1419         "22) gSyncNodeMax\n"
1420         "23) gdNIT\n"
1421         "24) gdSampleClockPeriod\n"
1422         "25) gNetworkManagementVectorLength\n"
1423         "\n"
1424         "The type \"node\" sets local FlexRay network parameters. 28 parameters in\n"
1425         "the string is expected in this order:\n"
1426         "1) pAllowHaltDueToClock\n"
1427         "2) pAllowPassiveToActive\n"
1428         "3) pChannels (0 - A, 1 - B, 2 - AB)\n"
1429         "4) pClusterDriftDamping\n"
1430         "5) pDelayCompensationA\n"
1431         "6) pDelayCompensationB\n"
1432         "7) pExternOffsetCorrection\n"
1433         "8) pExternRateCorrection\n"
1434         "9) pKeySlotUsedForStartup\n"
1435         "10) pKeySlotUsedForSync\n"
1436         "11) pLatestTx\n"
1437         "12) pMacroInitialOffsetA\n"
1438         "13) pMacroInitialOffsetB\n"
1439         "14) pMicroInitialOffsetA\n"
1440         "15) pMicroInitialOffsetB\n"
1441         "16) pMicroPerCycle\n"
1442         "17) pRateCorrectionOut\n"
1443         "18) pOffsetCorrectionOut\n"
1444         "19) pSamplesPerMicrotick\n"
1445         "20) pSingleSlotEnabled\n"
1446         "21) pWakeupChannel (0 - A, 1 - B)\n"
1447         "22) pWakeupPattern\n"
1448         "23) pdAcceptedStartupRange\n"
1449         "24) pdListenTimeout\n"
1450         "25) pdMaxDrift\n"
1451         "25) pDecodingCorrection\n"
1452         "25) syncFramePayloadMultiplexEnabled\n"
1453         "25) 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"
1454         "\n"
1455         "The type \"stat\" adds new static buffer. At least one buffer must be configured.\n"
1456         "8 parameters in the string is expected in this order:\n"
1457         "1) channel (0 - A, 1 - B, 2 - AB)\n"
1458         "2) cycleCounterFiltering\n"
1459         "3) isTx\n"
1460         "4) maxPayload (number of 16b words)\n"
1461         "5) msgBufferInterrupt\n"
1462         "6) payloadPreambleIndicatorTr\n"
1463         "7) singleTransmit\n"
1464         "8) slotId\n"
1465         "\n"
1466         "The type \"dyn\" adds new dynamic buffer. No dynamic buffer is obligatory.\n"
1467         "8 parameters in the string is expected in this order:\n"
1468         "1) channel (0 - A, 1 - B)\n"
1469         "2) cycleCounterFiltering\n"
1470         "3) isTx\n"
1471         "4) maxPayload (number of 16b words)\n"
1472         "5) msgBufferInterrupt\n"
1473         "6) payloadPreambleIndicatorTr\n"
1474         "7) singleTransmit\n"
1475         "8) slotId\n"
1476         "\n"
1477         "The type \"fifo\" adds new FIFO buffer. No dynamic buffer is obligatory.\n"
1478         "7 parameters in the string is expected in this order:\n"
1479         "1) depth of the FIFO\n"
1480         "2) channel (0 - A, 1 - B, 2 - AB)\n"
1481         "3) cycleCounterFiltering\n"
1482         "4) maxPayload (number of 16b words)\n"
1483         "5) rejectNullFrames\n"
1484         "6) rejectStaticSegment\n"
1485         "7) slotId\n"
1486         "\n"
1487         "=== Example ===\n"
1488         "\n"
1489         "   --> frbtusercluster 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"
1490         "   FlexRay cluster configuration accepted.\n"
1491         "   --> frbtusernode 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"
1492         "   FlexRay node configuration accepted.\n"
1493         "   --> frbtuserstat 0x2 0x0 0x1 0x9 0x1 0x0 0x0 0x1\n"
1494         "   Static buffer configuration accepted.\n",
1495         CMD_HANDLER(cmd_do_fr_user_config), (void *)&cmd_list_fr_basic_test
1496 };
1497
1498
1499 /** Command descriptor for FlexRay init command */
1500 cmd_des_t const cmd_des_fr_init={
1501         0, 0,
1502         "frbtinit?","Initialize FlexRay node",
1503         "=== Command syntax ===\n"
1504         "\n"
1505         "   frbtinit<NODE>\n"
1506         "where\n"
1507         "* <NODE> is an identificator of the node. It can be A, B or U. The A and B are using default configuration, if U specified, user configuration (frbtuser command) must be done before calling this command.\n"
1508         "\n"
1509         "=== Description ===\n"
1510         "\n"
1511         "The command stands for Fr_Init and Fr_ControllerInit functions\n"
1512         "from the Autosar specification.\n"
1513         "It initializes the internal data structures of the driver and then,\n"
1514         "based on those data, the controller configuration is done.\n"
1515         "During the controller configuration the parameters of the cluster, node,\n"
1516         "message RAM and buffers are checked. If anything goes bad, the command\n"
1517         "returns an error number, which can be decoded by macros defined in driver\n"
1518         "header file fr_tms570.h with prefix ERR_PARAM.\n"
1519         "If all parameters are OK, all necessary registers of the controller are\n"
1520         "initialized by those parameters."
1521         "At the end of the command, the FlexRay controller is switched into READY state\n"
1522         "and all buffers are configured to send NULL frames.\n"
1523         "This command should be called as the very first command, when trying to\n"
1524         "communicate over the FlexRay bus.\n"
1525         "\n"
1526         "=== Example ===\n"
1527         "\n"
1528         "   --> frbtinitA\n"
1529         "   FlexRay driver initialized.\n"
1530         "   FlexRay controller initialized.\n",
1531         CMD_HANDLER(cmd_do_fr_init), (void *)&cmd_list_fr_basic_test
1532 };
1533
1534 /** Command descriptor for FlexRay controller init command */
1535 cmd_des_t const cmd_des_fr_start={
1536         0, 0,
1537         "frbtstart","Initiate new FlexRay network or join to the existing one",
1538         "=== Command syntax ===\n"
1539         "\n"
1540         "   frbtstart\n"
1541         "\n"
1542         "=== Description ===\n"
1543         "\n"
1544         "The command stands for Fr_StartCommunication function from the Autosar\n"
1545         "specification.\n"
1546         "If the FlexRay node is configured as a coldstarter, then the command tries to listen\n"
1547         "on the bus at first. When it does not detect any existing bus communication,\n"
1548         "it tries to initiate the new network. If the initiation fails, the FlexRay\n"
1549         "controller is switched back to ready state for another attempt.\n"
1550         "If the FlexRay node is configured as non-coldstarter, it is listening on the\n"
1551         "bus until some existing communication is detected.\n"
1552         "\n"
1553         "The command should be called after the frbtinit command\n"
1554         "\n"
1555         "=== Example ===\n"
1556         "\n"
1557         "   --> frbtstart\n"
1558         "   FlexRay communication is running.\n",
1559         CMD_HANDLER(cmd_do_fr_start), (void *)&cmd_list_fr_basic_test
1560 };
1561
1562 /** Command descriptor for FlexRay controller all slots command */
1563 cmd_des_t const cmd_des_fr_allslots={
1564         0, 0,
1565         "frbtallslots","Enables communication for all frames",
1566         "=== Command syntax ===\n"
1567         "\n"
1568         "   frbtallslots\n"
1569         "\n"
1570         "=== Description ===\n"
1571         "\n"
1572         "The command stands for Fr_AllSlots function from the Autosar\n"
1573         "specification.\n"
1574         "The node can be configured to communicate only on key frames\n"
1575         "by default. This command can be used to allow communication on all\n"
1576         "configured frames.\n"
1577         "The command invokes the FlexRay POC command ALL_SLOTS which\n"
1578         "allows communication on all frames.\n"
1579         "The command can be called after controller initialization.\n"
1580         "\n"
1581         "=== Example ===\n"
1582         "\n"
1583         "   --> frbtallslots\n"
1584         "   FlexRay node is communicating on all slots.\n",
1585         CMD_HANDLER(cmd_do_fr_allslots), (void *)&cmd_list_fr_basic_test
1586 };
1587
1588 /** Command descriptor for FlexRay controller halt command */
1589 cmd_des_t const cmd_des_fr_halt={
1590         0, 0,
1591         "frbthalt","Halt FlexRay communication after the end of actual communication cycle",
1592         "=== Command syntax ===\n"
1593         "\n"
1594         "   frbthalt\n"
1595         "\n"
1596         "=== Description ===\n"
1597         "\n"
1598         "The command stands for Fr_HaltCommunication function from the Autosar\n"
1599         "specification.\n"
1600         "The command invokes the FlexRay POC command HALT, which means that\n"
1601         "communication is stopped after the end of actual communication cycle.\n"
1602         "On the opposite side, there is a freeze command, which stops communication\n"
1603         "immediately.\n"
1604         "To start the communication again, the device has to be reseted.\n"
1605         "\n"
1606         "=== Example ===\n"
1607         "\n"
1608         "   --> frbthalt\n"
1609         "   FlexRay node communication halted.\n",
1610         CMD_HANDLER(cmd_do_fr_halt), (void *)&cmd_list_fr_basic_test
1611 };
1612
1613 /** Command descriptor for FlexRay controller abort command */
1614 cmd_des_t const cmd_des_fr_abort={
1615         0, 0,
1616         "frbtabort","Abort FlexRay communication immediately",
1617         "=== Command syntax ===\n"
1618         "\n"
1619         "   frbtabort\n"
1620         "\n"
1621         "=== Description ===\n"
1622         "\n"
1623         "The command stands for Fr_AbortCommunication function from the Autosar\n"
1624         "specification.\n"
1625         "The command invokes the FlexRay POC command FREEZE, which means that\n"
1626         "communication is stopped immediately.\n"
1627         "On the opposite side there is a halt command, which stops communication after\n"
1628         "the end of actual communication cycle.\n"
1629         "To start the communication again, the device has to be reseted.\n"
1630         "\n"
1631         "=== Example ===\n"
1632         "\n"
1633         "   --> frbtabort\n"
1634         "   FlexRay node communication aborted.\n",
1635         CMD_HANDLER(cmd_do_fr_abort), (void *)&cmd_list_fr_basic_test
1636 };
1637
1638 /** Command descriptor for FlexRay controller send wake up pattern command */
1639 cmd_des_t const cmd_des_fr_sendwup={
1640         0, 0,
1641         "frbtwup","Initiates the wake up procedure",
1642         "=== Command syntax ===\n"
1643         "\n"
1644         "   frbtwup\n"
1645         "\n"
1646         "=== Description ===\n"
1647         "\n"
1648         "The command stands for Fr_SendWUP function from the Autosar\n"
1649         "specification.\n"
1650         "It initiates the wake up procedure by switching FlexRay controller\n"
1651         "state machine in WAKEUP state.\n"
1652         "\n"
1653         "=== Example ===\n"
1654         "\n"
1655         "   --> frbtwup\n"
1656         "   Wake up pattern has been sent.\n",
1657         CMD_HANDLER(cmd_do_fr_sendwup), (void *)&cmd_list_fr_basic_test
1658 };
1659
1660 /** Command descriptor for FlexRay controller sent wake up pattern channel command */
1661 cmd_des_t const cmd_des_fr_setwuchannel={
1662         0, 0,
1663         "frbtsetwuch?","Set wake up channel",
1664         "=== Command syntax ===\n"
1665         "\n"
1666         "   frbtsetwuch<CHANNEL>\n"
1667         "where\n"
1668         "* <CHANNEL> is a character A or B, specifying the channel.\n"
1669         "\n"
1670         "=== Description ===\n"
1671         "\n"
1672         "The command stands for Fr_SetWakeupChannel function from the Autosar\n"
1673         "specification.\n"
1674         "Wake up channel is the channel, where Wake Up Pattern is sent.\n"
1675         "The channel can be set after driver and controller are initialized\n"
1676         "and before communication is running.\n"
1677         "\n"
1678         "=== Example ===\n"
1679         "\n"
1680         "   --> frbtsetwuchA\n"
1681         "   Wake up channel has been set.\n",
1682         CMD_HANDLER(cmd_do_fr_setwuchannel), (void *)&cmd_list_fr_basic_test
1683 };
1684
1685 /** Command descriptor for FlexRay controller get POC status command */
1686 cmd_des_t const cmd_des_fr_getpocstatus={
1687         0, 0,
1688         "frbtgetpocst","Print FlexRay POC status",
1689         "=== Command syntax ===\n"
1690         "\n"
1691         "   frbtgetpocst\n"
1692         "\n"
1693         "=== Description ===\n"
1694         "\n"
1695         "The command stands for Fr_GetPOCStatus function from the Autosar\n"
1696         "specification.\n"
1697         "It prints the main FlexRay POC status values in form of table.\n"
1698         "The command should be called after the frbtctrlinit command.\n"
1699         "\n"
1700         "=== Example ===\n"
1701         "\n"
1702         "   --> frbtgetpocst\n"
1703         "   POC status:\n"
1704         "   CHIHaltRequest: FALSE\n"
1705         "   CHIReadyRequest: FALSE\n"
1706         "   ColdstartNoise: FALSE\n"
1707         "   Freeze: FALSE\n"
1708         "   ErrorMode: ACTIVE\n"
1709         "   SlotMode: ALL\n"
1710         "   StartupState: UNDEFINED\n"
1711         "   State: READY\n"
1712         "   WakeupStatus: UNDEFINED\n",
1713         CMD_HANDLER(cmd_do_fr_getpocstatus), (void *)&cmd_list_fr_basic_test
1714 };
1715
1716 /** Command descriptor for FlexRay transmit tx lpdu command */
1717 cmd_des_t const cmd_des_fr_transmittxlpdu={
1718         0, 0,
1719         "frbttransmit*","Transmit data in selected frame",
1720         "=== Command syntax ===\n"
1721         "\n"
1722         "   frbttransmit<FRID> <DATA>\n"
1723         "where\n"
1724         "* <FRID> is a decimal number specifying the ID of the frame to which the buffer is assigned.\n"
1725         "* <DATA> are 8 bit hexadecimal numbers separated by spaces. Each number represents one byte of the message.\n"
1726         "\n"
1727         "=== Description ===\n"
1728         "\n"
1729         "The command stands for Fr_TransmitTxLPdu function from the Autosar\n"
1730         "specification.\n"
1731         "The command finds the first buffer assigned to the specified frame ID\n"
1732         "and copies given data into its data section in the message RAM.\n"
1733         "Transmit request is set after data are copied, so transmission starts\n"
1734         "in next occurrence of the frame in the communication cycle.\n"
1735         "\n"
1736         "=== Example ===\n"
1737         "\n"
1738         "   --> frbttransmit1 12 34 56 AA BB CC\n"
1739         "   Data were sent.\n",
1740         CMD_HANDLER(cmd_do_fr_transmittxlpdu), (void *)&cmd_list_fr_basic_test
1741 };
1742
1743 /** Command descriptor for FlexRay cancel tx lpdu command */
1744 cmd_des_t const cmd_des_fr_canceltxlpdu={
1745         0, 0,
1746         "frbtcanceltx*","Stop the transmission of the frame",
1747         "=== Command syntax ===\n"
1748         "\n"
1749         "   frbtcanceltx<FRID>\n"
1750         "where\n"
1751         "* <FRID> is a decimal number specifying the ID of the frame to which\n"
1752         "the buffers are assigned.\n"
1753         "\n"
1754         "=== Description ===\n"
1755         "\n"
1756         "The command stands for Fr_CancelTxLPdu function from the Autosar\n"
1757         "specification.\n"
1758         "The command finds all buffers assigned to the specified frame ID\n"
1759         "and reconfigures them to stop transmitting data.\n"
1760         "The command finishes successfully only if reconfiguration is allowed\n"
1761         "in message RAM configuration (secureBuffers parameter).\n"
1762         "Only TX buffers and buffers not used in startup frames can be canceled.\n"
1763         "\n"
1764         "=== Example ===\n"
1765         "\n"
1766         "   --> frbtcanceltx3\n"
1767         "   Transmission canceled.\n",
1768         CMD_HANDLER(cmd_do_fr_canceltxlpdu), (void *)&cmd_list_fr_basic_test
1769 };
1770
1771 /** Command descriptor for FlexRay receive rx lpdu command */
1772 cmd_des_t const cmd_des_fr_receiverxlpdu={
1773         0, 0,
1774         "frbtreceive*","Receive new message",
1775         "=== Command syntax ===\n"
1776         "\n"
1777         "   frbtreceive<FRID>\n"
1778         "where\n"
1779         "* <FRID> is a decimal number specifying the ID of the frame to which the buffer is assigned.\n"
1780         "\n"
1781         "=== Description ===\n"
1782         "\n"
1783         "The command stands for Fr_ReceiveRxLPdu function from the Autosar\n"
1784         "specification.\n"
1785         "The command finds the first buffer assigned to the specified frame ID,\n"
1786         "determines if new message has been received and reads it out of the buffer.\n"
1787         "If no message was received, \"No message received\" is printed\n"
1788         "If new message was received, all message data are printed as a hexadecimal values.\n"
1789         "If new message was retrieved from a FIFO buffer and more messages are available\n"
1790         "in it, \"More messages are still in FIFO\" is printed.\n"
1791         "\n"
1792         "=== Example ===\n"
1793         "\n"
1794         "   --> frbtreceive0\n"
1795         "   More messages are still in FIFO:\n"
1796         "   Received message (32 B):\n"
1797         "    ee ff 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
1798         CMD_HANDLER(cmd_do_fr_receiverxlpdu), (void *)&cmd_list_fr_basic_test
1799 };
1800
1801 /** Command descriptor for FlexRay check TX LPdu status command */
1802 cmd_des_t const cmd_des_fr_checktxlpdustatus={
1803         0, 0,
1804         "frbtchecktx*","Print status of the transmit buffer",
1805         "=== Command syntax ===\n"
1806         "\n"
1807         "   frbtchecktx<FRID>\n"
1808         "where\n"
1809         "* <FRID> is a decimal number specifying the ID of the frame to which the buffer is assigned.\n"
1810         "\n"
1811         "=== Description ===\n"
1812         "\n"
1813         "The command stands for Fr_CheckTxLPduStatus function from the Autosar\n"
1814         "specification.\n"
1815         "The command finds the first buffer assigned to the specified frame ID,\n"
1816         "reads its status and prints it.\n"
1817         "The buffer can be in one of the two states:\n"
1818         "* Some message transmission is pending, which means that the buffer has not yet sent its message in single shot mode or that it is in continuous mode.\n"
1819         "* No message transmission is pending, which means that the buffer is in single shot mode and the message has been already sent.\n"
1820         "\n"
1821         "=== Example ===\n"
1822         "\n"
1823         "   --> frbtchecktx1\n"
1824         "   Message transmission is not pending.\n",
1825         CMD_HANDLER(cmd_do_fr_checktxlpdustatus), (void *)&cmd_list_fr_basic_test
1826 };
1827
1828 /** Command descriptor for FlexRay disable LPdu command */
1829 cmd_des_t const cmd_des_fr_disablelpdu={
1830         0, 0,
1831         "frbtdisable*","Disables buffers assigned to the frame",
1832         "=== Command syntax ===\n"
1833         "\n"
1834         "   frbtdisable<FRID>\n"
1835         "where\n"
1836         "* <FRID> is a decimal number specifying the ID of the frame. The buffers assigned to this frame will be disabled.\n"
1837         "\n"
1838         "=== Description ===\n"
1839         "\n"
1840         "The command stands for Fr_DisableLPdu function from the Autosar\n"
1841         "specification.\n"
1842         "The command finds all buffer assigned to the specified frame ID and\n"
1843         "disables them. This means that those buffers will be unavailable for the\n"
1844         "communication until their reconfiguration (which is not yet implemented).\n"
1845         "Buffers used in startup frames and FIFO RX buffers can not be disabled.\n"
1846         "\n"
1847         "=== Example ===\n"
1848         "\n"
1849         "   --> frbtdisable3\n"
1850         "   Buffer disabled.\n",
1851         CMD_HANDLER(cmd_do_fr_disablelpdu), (void *)&cmd_list_fr_basic_test
1852 };
1853
1854 /** Command descriptor for FlexRay get global time command */
1855 cmd_des_t const cmd_des_fr_getglobaltime={
1856         0, 0,
1857         "frbtglobtime","Prints actual global time of the network.",
1858         "=== Command syntax ===\n"
1859         "\n"
1860         "   frbtglobtime\n"
1861         "\n"
1862         "=== Description ===\n"
1863         "\n"
1864         "The command stands for Fr_GetGlobalTime function from the Autosar\n"
1865         "specification.\n"
1866         "The command prints time as number of the cycle and offset in the cycle\n"
1867         "in macroticks.\n"
1868         "\n"
1869         "=== Example ===\n"
1870         "\n"
1871         "   --> frbtglobtime\n"
1872         "   Cycle number: 23\n"
1873         "   Macrotick number: 6\n",
1874         CMD_HANDLER(cmd_do_fr_getglobaltime), (void *)&cmd_list_fr_basic_test
1875 };
1876
1877 /** Command descriptor for FlexRay get network management vector command */
1878 cmd_des_t const cmd_des_fr_getnmvector={
1879         0, 0,
1880         "frbtnmvector","Prints network management vector of the node",
1881         "=== Command syntax ===\n"
1882         "\n"
1883         "   frbtnmvector\n"
1884         "\n"
1885         "=== Description ===\n"
1886         "\n"
1887         "The command stands for Fr_GetNmVector function from the Autosar\n"
1888         "specification.\n"
1889         "\n"
1890         "=== Example ===\n"
1891         "\n"
1892         "   --> frbtnmvector\n"
1893         "   Network management vector: 0 0 0 0 0 0 0 0 0 0 0 0\n",
1894         CMD_HANDLER(cmd_do_fr_getnmvector), (void *)&cmd_list_fr_basic_test
1895 };
1896
1897 /** Command descriptor for FlexRay get channel status command */
1898 cmd_des_t const cmd_des_fr_getchannelstatus={
1899         0, 0,
1900         "frbtchstat","Prints channel A and B status",
1901         "=== Command syntax ===\n"
1902         "\n"
1903         "   frbtchstat\n"
1904         "\n"
1905         "=== Description ===\n"
1906         "\n"
1907         "The command stands for Fr_GetChannelStatus function from the Autosar\n"
1908         "specification.\n"
1909         "\n"
1910         "=== Example ===\n"
1911         "\n"
1912         "   --> frbtclkcor\n"
1913         "   Channel A status:\n"
1914         "       aggregated channel status vSS!ValidFrame: TRUE\n"
1915         "       aggregated channel status vSS!SyntaxError: FALSE\n"
1916         "       aggregated channel status vSS!ContentError: FALSE\n"
1917         "       aggregated channel status additional communication: FALSE\n"
1918         "       aggregated channel status vSS!Bviolation: FALSE\n"
1919         "       aggregated channel status vSS!TxConflict: FALSE\n"
1920         "       Not used (0): FALSE\n"
1921         "       Not used (0): FALSE\n"
1922         "       symbol window status data vSS!ValidMTS: FALSE\n"
1923         "       symbol window status data vSS!SyntaxError: FALSE\n"
1924         "       symbol window status data vSS!Bviolation: FALSE\n"
1925         "       symbol window status data vSS!TxConflict: FALSE\n"
1926         "       NIT status data vSS!SyntaxError: FALSE\n"
1927         "       NIT status data vSS!Bviolation: FALSE\n"
1928         "       Not used (0): FALSE\n"
1929         "       Not used (0): FALSE\n"
1930         "   Channel B status:\n"
1931         "       aggregated channel status vSS!ValidFrame: TRUE\n"
1932         "       aggregated channel status vSS!SyntaxError: FALSE\n"
1933         "       aggregated channel status vSS!ContentError: FALSE\n"
1934         "       aggregated channel status additional communication: FALSE\n"
1935         "       aggregated channel status vSS!Bviolation: FALSE\n"
1936         "       aggregated channel status vSS!TxConflict: FALSE\n"
1937         "       Not used (0): FALSE\n"
1938         "       Not used (0): FALSE\n"
1939         "       symbol window status data vSS!ValidMTS: FALSE\n"
1940         "       symbol window status data vSS!SyntaxError: FALSE\n"
1941         "       symbol window status data vSS!Bviolation: FALSE\n"
1942         "       symbol window status data vSS!TxConflict: FALSE\n"
1943         "       NIT status data vSS!SyntaxError: FALSE\n"
1944         "       NIT status data vSS!Bviolation: FALSE\n"
1945         "       Not used (0): FALSE\n"
1946         "       Not used (0): FALSE\n",
1947         CMD_HANDLER(cmd_do_fr_getchannelstatus), (void *)&cmd_list_fr_basic_test
1948 };
1949
1950 /** Command descriptor for FlexRay get clock correction command */
1951 cmd_des_t const cmd_des_fr_getclockcorrection={
1952         0, 0,
1953         "frbtclkcor","Prints clock correction (rate and offset)",
1954         "=== Command syntax ===\n"
1955         "\n"
1956         "   frbtclkcor\n"
1957         "\n"
1958         "=== Description ===\n"
1959         "\n"
1960         "The command stands for Fr_GetClockCorrection function from the Autosar\n"
1961         "specification.\n"
1962         "\n"
1963         "=== Example ===\n"
1964         "\n"
1965         "   --> frbtclkcor\n"
1966         "   Rate correction: 0\n"
1967         "   Offset correction: 0\n",
1968         CMD_HANDLER(cmd_do_fr_getclockcorrection), (void *)&cmd_list_fr_basic_test
1969 };
1970
1971 /** Command descriptor for FlexRay get sync frame list command */
1972 cmd_des_t const cmd_des_fr_getsyncframelist={
1973         0, 0,
1974         "frbtgetsyncfrlist*","Prints list of sync frames transmitted on both channels via the odd and even communication cycle",
1975         "=== Command syntax ===\n"
1976         "\n"
1977         "   frbtgetsyncfrlist<LENGTH>\n"
1978         "where\n"
1979         "* <LENGTH> is a decimal number in range 0 - 15, specifying the length of the list to be printed.\n"
1980         "\n"
1981         "=== Description ===\n"
1982         "\n"
1983         "The command stands for Fr_GetSyncFrameList function from the Autosar\n"
1984         "specification.\n"
1985         "\n"
1986         "=== Example ===\n"
1987         "\n"
1988         "   --> frbtgetsyncfrlist2\n"
1989         "   | Channel A even | channel B even | channel A odd  | channel B odd  |\n"
1990         "   |----------------|----------------|----------------|----------------|\n"
1991         "   | 1              | 1              | 1              | 1              |\n"
1992         "   | 2              | 2              | 2              | 2              |\n"
1993         "   |----------------|----------------|----------------|----------------|\n",
1994         CMD_HANDLER(cmd_do_fr_getsyncframelist), (void *)&cmd_list_fr_basic_test
1995 };
1996
1997 /** Command descriptor for FlexRay get sync frame list command */
1998 cmd_des_t const cmd_des_fr_getwakeuprxstatus={
1999         0, 0,
2000         "frbtgetwurxstat","Prints if wake up pattern was or was not received",
2001         "=== Command syntax ===\n"
2002         "\n"
2003         "   frbtgetwurxstat\n"
2004         "\n"
2005         "=== Description ===\n"
2006         "\n"
2007         "The command stands for Fr_GetWakeupRxStatus function from the Autosar\n"
2008         "specification.\n"
2009         "The status of the wake up receiving is bitcoded in the controller. This\n"
2010         "command decodes and prints it in readable format.\n"
2011         "\n"
2012         "=== Example ===\n"
2013         "\n"
2014         "   --> frbtgetwurxstat\n"
2015         "   Wake up pattern was not yet received on channel A.\n"
2016         "   Wake up pattern was not yet received on channel B.\n",
2017         CMD_HANDLER(cmd_do_fr_getwakeuprxstatus), (void *)&cmd_list_fr_basic_test
2018 };
2019
2020 /** Command descriptor for FlexRay set absolute timer command */
2021 cmd_des_t const cmd_des_fr_settimer={
2022         0, 0,
2023         "frbtsettimer*","Set and start timer",
2024         "=== Command syntax ===\n"
2025         "\n"
2026         "   frbtsettimer<TMID> <CYCLE> <OFFSET>"
2027         "where\n"
2028         "* <TMID> is a decimal number (0 - 1) specifying the number of the timer.\n"
2029         "* <CYCLE> is a decimal number (0 - 255) specifying the number of the cycle, in which timer interrupt should be requested.\n"
2030         "* <OFFSET> is a decimal number (0 - 16383) specifying the offset in macroticks, where precisly in the cycle should be the  timer interrupt requested.\n"
2031         "\n"
2032         "=== Description ===\n"
2033         "\n"
2034         "The command stands for Fr_SetAbsoluteTimer function from the Autosar\n"
2035         "specification.\n"
2036         "It sets the timer selected by the parameter and enables it.\n"
2037         "\n"
2038         "=== Example ===\n"
2039         "\n"
2040         "   --> frbtsettimer0 32 50\n"
2041         "   Timer was set.\n",
2042         CMD_HANDLER(cmd_do_fr_settimer), (void *)&cmd_list_fr_basic_test
2043 };
2044
2045 /** Command descriptor for FlexRay cancel absolute timer command */
2046 cmd_des_t const cmd_des_fr_canceltimer={
2047         0, 0,
2048         "frbtcanceltimer*","Stop the timer",
2049         "=== Command syntax ===\n"
2050         "\n"
2051         "   frbtcanceltimer<TMID>\n"
2052         "where\n"
2053         "* <TMID> is a decimal number (0 - 1) specifying the number of the timer.\n"
2054         "\n"
2055         "=== Description ===\n"
2056         "\n"
2057         "The command stands for Fr_CancelAbsoluteTimer function from the Autosar\n"
2058         "specification.\n"
2059         "It stops the timer selected by the parameter.\n"
2060         "\n"
2061         "=== Example ===\n"
2062         "\n"
2063         "   --> frbtcanceltimer0\n"
2064         "   Timer was canceled.\n",
2065         CMD_HANDLER(cmd_do_fr_canceltimer), (void *)&cmd_list_fr_basic_test
2066 };
2067
2068 /** Command descriptor for FlexRay absolute timer irq manipulation command */
2069 cmd_des_t const cmd_des_fr_timerirq={
2070         0, 0,
2071         "frbttimerirq*","Do something with the timer IRQ",
2072         "=== Command syntax ===\n"
2073         "\n"
2074         "   frbttimerirq<TMID> <ACTION> - Run the <ACTION> on specified timer\n"
2075         "   frbttimerirq<TMID> - Get timet IRQ status\n"
2076         "\n"
2077         "where\n"
2078         "* <TMID> is a decimal number (0 - 1) specifying the number of the timer.\n"
2079         "* where <ACTION> is a string if the action to be processed on the selected timer.\n"
2080         "<ACTIONS> can be one of these strings\n"
2081         "* EN - Enable IRQ on selected timer\n"
2082         "* DIS - Disable IRQ on selected timer\n"
2083         "* ACK - Acknowledge IRQ on selected timer (Reset flag in the register).\n"
2084         "\n"
2085         "=== Description ===\n"
2086         "\n"
2087         "The command stands for Fr_EnableAbsoluteTimerIRQ,  Fr_AckAbsoluteTimerIRQ,\n"
2088         "Fr_DisableAbsoluteTimerIRQ and Fr_GetAbsoluteTimerIRQStatus functions from\n"
2089         "the Autosar specification.\n"
2090         "It enables or disables masking of the IRQ for the timer, or acknowledges the\n"
2091         "interrupt request when processed by clearing its flag in the register, or gets\n"
2092         "whether the IRQ is pending for the timer.\n"
2093         "\n"
2094         "=== Example ===\n"
2095         "\n"
2096         "   --> frbttimerirq0\n"
2097         "   IRQ = FALSE\n"
2098         "\n"
2099         "   --> frbttimerirq0 EN\n"
2100         "   OK\n",
2101         CMD_HANDLER(cmd_do_fr_timerirq), (void *)&cmd_list_fr_basic_test
2102 };
2103
2104 /** Command descriptor for FlexRay get version info command */
2105 cmd_des_t const cmd_des_fr_getversioninfo={
2106         0, 0,
2107         "frbtversion","Prints FlexRay driver version information",
2108         "=== Command syntax ===\n"
2109         "\n"
2110         "   frbtversion\n"
2111         "\n"
2112         "=== Description ===\n"
2113         "\n"
2114         "The command stands for Fr_GetVersionInfo function from the Autosar\n"
2115         "specification.\n"
2116         "It reads and prints the information about vendor, module and version of\n"
2117         "the FlexRay driver\n"
2118         "\n"
2119         "=== Example ===\n"
2120         "\n"
2121         "   --> frbtversion\n"
2122         "   vendorID: 0xAAAA\n"
2123         "   moduleID: 0xBBBB\n"
2124         "   sw_major_version: 0x1\n"
2125         "   sw_minor_version: 0x2\n"
2126         "   sw_patch_version: 0x4\n",
2127         CMD_HANDLER(cmd_do_fr_getversioninfo), (void *)&cmd_list_fr_basic_test
2128 };
2129
2130 /** Command descriptor for FlexRay get controller configuration command */
2131 cmd_des_t const cmd_des_fr_readcconfig={
2132         0, 0,
2133         "frbtccconfig*","Print value of a FlexRay cluster and node configuration parameter",
2134         "=== Command syntax ===\n"
2135         "\n"
2136         "   frbtccconfig<INDEX>\n"
2137         "\n"
2138         "where\n"
2139         "* <INDEX> is an identificator of the parameter, specified by Autosar specification in section 8.2.1.\n"
2140         "\n"
2141         "=== Description ===\n"
2142         "\n"
2143         "The command stands for Fr_ReadCCConfig function from the Autosar\n"
2144         "specification.\n"
2145         "The driver stores configuration parameters as an array. Each parameter\n"
2146         "can be indexed and returned by this command.\n"
2147         "See Autosar specification of the FlexRay driver, section 8.2.1 for\n"
2148         "parameter indexes.\n"
2149         "\n"
2150         "=== Example ===\n"
2151         "\n"
2152         "   --> frbtccconfig1\n"
2153         "   Value = 0x1\n",
2154         CMD_HANDLER(cmd_do_fr_readcconfig), (void *)&cmd_list_fr_basic_test
2155 };
2156
2157 /** List of commands for flexRay, defined as external */
2158 cmd_des_t const *cmd_list_fr_basic_test[]={
2159   &cmd_des_fr_user_config,
2160   &cmd_des_fr_init,
2161   &cmd_des_fr_start,
2162   &cmd_des_fr_allslots,
2163   &cmd_des_fr_halt,
2164   &cmd_des_fr_abort,
2165   &cmd_des_fr_sendwup,
2166   &cmd_des_fr_setwuchannel,
2167   &cmd_des_fr_getpocstatus,
2168   &cmd_des_fr_transmittxlpdu,
2169   &cmd_des_fr_canceltxlpdu,
2170   &cmd_des_fr_receiverxlpdu,
2171   &cmd_des_fr_checktxlpdustatus,
2172   &cmd_des_fr_disablelpdu,
2173   &cmd_des_fr_getglobaltime,
2174   &cmd_des_fr_getnmvector,
2175   &cmd_des_fr_getchannelstatus,
2176   &cmd_des_fr_getclockcorrection,
2177   &cmd_des_fr_getsyncframelist,
2178   &cmd_des_fr_getwakeuprxstatus,
2179   &cmd_des_fr_settimer,
2180   &cmd_des_fr_canceltimer,
2181   &cmd_des_fr_timerirq,
2182   &cmd_des_fr_getversioninfo,
2183   &cmd_des_fr_readcconfig,
2184   NULL
2185 };