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