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