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