]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blob - commands/cmd_fr_basic_test.c
New command for FlexRay FIFO creation.
[pes-rpp/rpp-test-sw.git] / commands / cmd_fr_basic_test.c
1 /*
2  * Copyright (C) 2012-2013 Czech Technical University in Prague
3  *
4  * Created on: 6.8.2013
5  *
6  * Authors:
7  *     - Michal Horn
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * File : cmd_fr_basic_test.c
23  *
24  * Abstract:
25  *              The file contains a set of commands to control the FlexRay driver.
26  *              Those commands can be used to configure RPP board as a FlexRay node,
27  *              configure a set of TX and RX buffers, get status of the buffers and
28  *              the FlexRay controller, manipulate with timers and control the transmission
29  *              of messages.
30  */
31
32
33 #include "cmd_fr_basic_test.h"
34
35 #ifndef DOCGEN
36
37 #include <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 cmd_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 cmd_fr_config_cluster_params(const char* params) {
596         uint32_t tmp_params[FR_CLUSTER_PARAMS_CNT];
597
598         if (cmd_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 cmd_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 (cmd_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_fifo(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
678         Fr_TMS570LS_BufferConfigType* fifo_buffer_ptr = &user_fifo_buffer_config[0];
679         int ret, i;
680         char channel[3], rej_static_frames[8], rej_null_frames[8];
681         unsigned depth, slot, cycleset, maxpayload, intr;
682         Fr_TMS570LS_BufferConfigType tmp_buffer;
683
684         ret = sscanf(param[2], "slot%i depth%i %2s cyc%i max%i %10s %10s int%i",
685                      &slot,
686                      &depth,
687                      channel,
688                      &cycleset,
689                      &maxpayload,
690                      rej_null_frames,
691                      rej_static_frames,
692                      &intr
693                      );
694         if (ret != 8) {
695                 printf("Error parsing parameter %d\n", ret+1);
696                 return -CMDERR_BADPAR;
697         }
698
699         if (depth < 1 || depth >= RPP_FR_MAX_FIFO_BUF_DEPTH)
700                 return badpar("Depth too high\n");
701         user_fifo_buffer_depth = depth;
702
703         if (slot > 2047)
704                 return badpar("Invalid slot number\n");
705         tmp_buffer.slotId = slot;
706         if (strcmp(channel, "A") == 0) tmp_buffer.channel = FR_CHANNEL_A;
707         else if (strcmp(channel, "B") == 0) tmp_buffer.channel = FR_CHANNEL_B;
708         else if (strcmp(channel, "AB") == 0) tmp_buffer.channel = FR_CHANNEL_AB;
709         else return badpar("Channel parsing error\n");
710         
711         if (cycleset >= 0x80)
712                 return badpar("Cycle set must be less than 0x80.\n");
713         tmp_buffer.cycleCounterFiltering = cycleset;
714
715         if (maxpayload >= 128)
716                 return badpar("Maximum payload in half-words must be less than 128\n");
717         tmp_buffer.maxPayload = maxpayload;
718         
719         if (strcmp(rej_null_frames, "rejnull") == 0) tmp_buffer.rejectNullFrames = true;
720         else if (strcmp(rej_null_frames, "accnull") == 0) tmp_buffer.rejectNullFrames = false;
721         else return badpar("Reject/accept NULL frames parsing error\n");
722
723         if (strcmp(rej_static_frames, "rejstat") == 0)
724                 tmp_buffer.rejectStaticSegment = true;
725         else if (strcmp(rej_static_frames, "accstat") == 0)
726                 tmp_buffer.rejectStaticSegment = false;
727         else return badpar("Invalid reject/accept static frame parameter");
728
729         if (intr > 1)
730                 return badpar("Interrupt parameter must be 0 or 1");
731         tmp_buffer.msgBufferInterrupt = intr;
732
733         for (i = 0; i < user_fifo_buffer_depth; i++) {
734                 fifo_buffer_ptr[i].slotId = tmp_buffer.slotId;  
735                 fifo_buffer_ptr[i].maxPayload = tmp_buffer.maxPayload;
736                 fifo_buffer_ptr[i].channel= tmp_buffer.channel;
737                 fifo_buffer_ptr[i].cycleCounterFiltering = tmp_buffer.cycleCounterFiltering;
738                 fifo_buffer_ptr[i].isTx = FALSE;
739                 fifo_buffer_ptr[i].singleTransmit = FALSE;
740                 fifo_buffer_ptr[i].payloadPreambleIndicatorTr = FALSE;
741                 fifo_buffer_ptr[i].rejectNullFrames = tmp_buffer.rejectNullFrames;
742                 fifo_buffer_ptr[i].rejectStaticSegment = tmp_buffer.rejectStaticSegment;
743                 fifo_buffer_ptr[i].msgBufferInterrupt = tmp_buffer.msgBufferInterrupt;
744         }
745
746         printf("frbtcfgfifo slot%i depth%i %2s cyc%i max%i %10s %10s int%i\n",
747                      slot,
748                      depth,
749                      channel,
750                      cycleset,
751                      maxpayload,
752                      rej_null_frames,
753                      rej_static_frames,
754                      intr
755                 );
756         
757         return SUCCESS;
758 }
759
760 int cmd_do_fr_config_bufer(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
761 {
762         Fr_TMS570LS_BufferConfigType *cfg;
763
764         int ret;
765         char buf_type, channel[3],rxtx[3], single_continuous[11];
766         unsigned buffer, slot, cycleset, maxpayload, intr, preamb;
767         
768         ret = sscanf(param[1], "%c%i slot%i %2s cyc%i %2s max%i %10s ppi%i int%i",
769                      &buf_type,
770                      &buffer,
771                      &slot,
772                      channel,
773                      &cycleset,
774                      rxtx,
775                      &maxpayload,
776                      single_continuous,
777                      &preamb,
778                      &intr
779                      );
780         if (ret != 10) {
781                 printf("Error parsing parameter %d\n", ret+1);
782                 return -CMDERR_BADPAR;
783         
784         }
785         
786         switch (buf_type) {
787         case 'S':
788                 if (buffer >= RPP_FR_MAX_STATIC_BUF_CNT)
789                         return badpar("Buffer index too high\n");
790                 cfg = &user_static_buffer_config[buffer];
791                 break;
792         case 'D':
793                 if (buffer >= RPP_FR_MAX_DYNAMIC_BUF_CNT)
794                         return badpar("Buffer index too high\n");
795                 cfg = &user_dynamic_buffer_config[buffer];
796                 break;
797         default:
798                 return badpar("Invalid buffer type (S, D)\n");
799         }
800
801         if (slot < 1 || slot > 2047)
802                 return badpar("Invalid slot number\n");
803         cfg->slotId = slot;
804
805         if (strcmp(channel, "A") == 0) cfg->channel = FR_CHANNEL_A;
806         else if (strcmp(channel, "B") == 0) cfg->channel = FR_CHANNEL_B;
807         else if (strcmp(channel, "AB") == 0) cfg->channel = FR_CHANNEL_AB;
808         else return badpar("Channel parsing error\n");
809         if (buf_type == 'D' && cfg->channel == FR_CHANNEL_AB)
810                 return badpar("Dynamic segment buffers cannot have AB channels.\n");
811
812         if (cycleset >= 0x80)
813                 return badpar("Cycle set must be less than 0x80.\n");
814         cfg->cycleCounterFiltering = cycleset;
815
816         if (strcmp(rxtx, "tx") == 0) cfg->isTx = true;
817         else if (strcmp(rxtx, "rx") == 0) cfg->isTx = false;
818         else return badpar("RX/TX parsing error\n");
819
820         if (maxpayload >= 128)
821                 return badpar("Maximum payload in half-words must be less than 128\n");
822         cfg->maxPayload = maxpayload;
823
824         if (0 == strcmp(single_continuous, "single") ||
825             0 == strcmp(single_continuous, "s"))
826                 cfg->singleTransmit = true;
827         else if (0 == strcmp(single_continuous, "continuous") ||
828             0 == strcmp(single_continuous, "c"))
829                 cfg->singleTransmit = false;
830         else return badpar("Invalid single/continuous parameter");
831
832         if (preamb > 1)
833                 return badpar("Payload preamble indicator must be 0 or 1");
834         cfg->payloadPreambleIndicatorTr = preamb;
835
836         if (intr > 1)
837                 return badpar("Interrupt parameter must be 0 or 1");
838         cfg->msgBufferInterrupt = intr;
839
840         switch (buf_type) {
841         case 'S':
842                 if (buffer >= user_static_buffer_configured)
843                         user_static_buffer_configured = buffer + 1;
844                 break;
845         case 'D':
846                 if (buffer >= user_dynamic_buffer_configured)
847                         user_dynamic_buffer_configured = buffer + 1;
848                 break;
849         }
850
851         printf("frbtcfgbuf%c%i slot%i %2s cyc%i %2s max%i %10s ppi%i int%i\n",
852                      buf_type,
853                      buffer,
854                      slot,
855                      channel,
856                      cycleset,
857                      rxtx,
858                      maxpayload,
859                      single_continuous,
860                      preamb,
861                      intr
862                 );
863
864         return 0;
865 }
866
867
868
869 /**
870  *      @brief  Do the user configuration of the FlexRay cluster parameters
871  *
872  * @param[in]   cmd_io  Pointer to IO stack
873  * @param[in]   des             Pointer to command descriptor
874  * @param[in]   param   Parameters of command
875  * @return      0 when OK or error code
876  */
877 int cmd_do_fr_user_config(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
878         char* token;
879         token = strtok(param[1], " ");
880         if (strcmp(token, "cluster") == 0) {
881                 if (cmd_fr_config_cluster_params(param[2]) == FAILURE) {
882                         rpp_sci_printf("FlexRay cluster configuration not accepted.\n");
883                         return -CMDERR_BADPAR;
884                 }
885                 rpp_sci_printf("FlexRay cluster configuration accepted.\n");
886         }
887         else if (strcmp(token, "node") == 0) {
888                 if (cmd_fr_config_node_params(param[2]) == FAILURE) {
889                         rpp_sci_printf("FlexRay node configuration not accepted.\n");
890                         return -CMDERR_BADPAR;
891                 }
892                 rpp_sci_printf("FlexRay node configuration accepted.\n");
893         }
894         else {
895                 return -CMDERR_BADPAR;
896         }
897
898         return 0;
899 }
900
901 /**
902  *      @brief  Initialize the device as FlexRay node.
903  *
904  * @param[in]   cmd_io  Pointer to IO stack
905  * @param[in]   des             Pointer to command descriptor
906  * @param[in]   param   Parameters of command
907  * @return      0 when OK or error code
908  */
909 int cmd_do_fr_init(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
910         const Fr_ConfigType* Fr_ConfigPtr = NULL;
911         int8_t retVal = SUCCESS;
912         uint32_t error = ERR_PARAM_NO_ERROR;
913
914         if (*param[1] == 'A') {
915                 Fr_ConfigPtr = &Fr_config_node_A;
916         }
917         else if (*param[1] == 'B') {
918                 Fr_ConfigPtr = &Fr_config_node_B;
919         }
920         else if (*param[1] == 'U') {    // Select the user configuration  -  call config commands first
921                 user_msg_ram_config.statSegmentBufferCount = user_static_buffer_configured;
922                 user_msg_ram_config.dynSegmentBufferCount = user_dynamic_buffer_configured;
923                 user_msg_ram_config.fifoBufferCount= user_fifo_buffer_depth;
924                 Fr_ConfigPtr = &user_configuration;
925         }
926         else {
927                 return -CMDERR_BADPAR;
928         }
929
930         retVal = rpp_fr_init_driver(Fr_ConfigPtr, &error);
931         if (retVal == SUCCESS) {
932                 rpp_sci_printf("FlexRay driver initialized.\r\n");
933         }
934         else {
935                 rpp_sci_printf("FlexRay needs to be configured before initialization.\r\n");
936                 return -CMDERR_BADCFG;
937         }
938
939         retVal = rpp_fr_init_controller(0, &error);
940         if (retVal == SUCCESS) {
941                 rpp_sci_printf("FlexRay controller initialized.\r\n");
942         }
943         else {
944                 if (error & FR_INIT_ERR_CLUSTER_CONFIG) {
945                         rpp_sci_printf("Cluster configuration data error: %x\r\n", (retVal & 0x3FFFFFE) >> 1 );
946                 }
947                 else if (error & FR_INIT_ERR_NODE_CONFIG) {
948                         rpp_sci_printf("Node configuration data error: %x\r\n", (retVal & 0x3FFFFFE) >> 1 );
949                 }
950                 else if (error & FR_INIT_ERR_MSGRAM_CONFIG) {
951                         rpp_sci_printf("Message RAM configuration data error: %x\r\n", (retVal & 0x3FFFFFE) >> 1 );
952                 }
953                 else if (error & FR_INIT_ERR_BUFFPARAM_CONFIG) {
954                         rpp_sci_printf("Buffer configuration data error: %x\r\n", (retVal & 0x3FFFFFE) >> 1 );
955                 }
956                 else if (error & (uint32_t)FR_INIT_ERR_BUFF_CONFIG) {
957                         rpp_sci_printf("Buffer configuration error: %x\r\n", (retVal & 0x3FFFFFE) >> 1 );
958                 }
959                 else {
960                         rpp_sci_printf("POC state switching error.\r\n");
961                 }
962                 return -CMDERR_BADCFG;
963         }
964         return 0;
965 }
966
967 /**
968  *      @brief  Starts FlexRay communication
969  *
970  * @param[in]   cmd_io  Pointer to IO stack
971  * @param[in]   des             Pointer to command descriptor
972  * @param[in]   param   Parameters of command
973  * @return      0 when OK or error code
974  */
975 int cmd_do_fr_start(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
976         int8_t retVal = SUCCESS;
977         uint32_t error = ERR_PARAM_NO_ERROR;
978
979         retVal = rpp_fr_start_communication(0, &error);
980         if (retVal == SUCCESS) {
981                 rpp_sci_printf("FlexRay communication is running.\r\n");
982         }
983         else {
984                 if (error & FR_STARTUP_ERR_SW_STUP_FOLLOW) {
985                         rpp_sci_printf("Can not switch POC to RUN state.\r\n");
986                 }
987                 else if (error & FR_STARTUP_ERR_CSINH_DIS) {
988                         rpp_sci_printf("Cold start inhibit disabled error.\r\n");
989                 }
990                 else if (error & FR_STARTUP_ERR_SW_STUP_READY) {
991                         rpp_sci_printf("Can not switch back to READY from STARTUP.\r\n");
992                 }
993                 else if (error & FR_STARTUP_ERR_SW_STUP_AS_NCOLD) {
994                         rpp_sci_printf("Can not switch to STARTUP as non-coldstarter.\r\n");
995                 }
996                 else {
997                         rpp_sci_printf("General error.\r\n");
998                 }
999                 return -CMDERR_BADCFG;
1000         }
1001         return 0;
1002 }
1003
1004 /**
1005  *      @brief  Invokes POC command ALL_SLOTS
1006  *
1007  * @param[in]   cmd_io  Pointer to IO stack
1008  * @param[in]   des             Pointer to command descriptor
1009  * @param[in]   param   Parameters of command
1010  * @return      0 when OK or error code
1011  */
1012 int cmd_do_fr_allslots(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1013         int8_t retVal = ERR_PARAM_NO_ERROR;
1014         retVal = rpp_fr_all_slots(0);
1015         if (retVal == SUCCESS) {
1016                 rpp_sci_printf("FlexRay node started communication in all slots.\r\n");
1017         }
1018         else {
1019                 rpp_sci_printf("General error.\r\n");
1020                 return -CMDERR_BADCFG;
1021         }
1022         return 0;
1023 }
1024
1025 /**
1026  *      @brief  Halt FlexRay communication
1027  *
1028  * @param[in]   cmd_io  Pointer to IO stack
1029  * @param[in]   des             Pointer to command descriptor
1030  * @param[in]   param   Parameters of command
1031  * @return      0 when OK or error code
1032  */
1033 int cmd_do_fr_halt(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1034         int8_t retVal = ERR_PARAM_NO_ERROR;
1035         retVal = rpp_fr_halt_communication(0);
1036         if (retVal == SUCCESS) {
1037                 rpp_sci_printf("FlexRay node communication halted.\r\n");
1038         }
1039         else {
1040                 rpp_sci_printf("General error.\r\n");
1041                 return -CMDERR_BADCFG;
1042         }
1043         return 0;
1044 }
1045
1046 /**
1047  *      @brief  Abort FlexRay communication
1048  *
1049  * @param[in]   cmd_io  Pointer to IO stack
1050  * @param[in]   des             Pointer to command descriptor
1051  * @param[in]   param   Parameters of command
1052  * @return      0 when OK or error code
1053  */
1054 int cmd_do_fr_abort(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1055         int8_t retVal = ERR_PARAM_NO_ERROR;
1056         retVal = rpp_fr_abort_communication(0);
1057         if (retVal == SUCCESS) {
1058                 rpp_sci_printf("FlexRay node communication aborted.\r\n");
1059         }
1060         else {
1061                 rpp_sci_printf("General error.\r\n");
1062                 return -CMDERR_BADCFG;
1063         }
1064         return 0;
1065 }
1066
1067 /**
1068  *      @brief  Send wake up pattern
1069  *
1070  * @param[in]   cmd_io  Pointer to IO stack
1071  * @param[in]   des             Pointer to command descriptor
1072  * @param[in]   param   Parameters of command
1073  * @return      0 when OK or error code
1074  */
1075 int cmd_do_fr_sendwup(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1076         int8_t retVal = ERR_PARAM_NO_ERROR;
1077         retVal = rpp_fr_send_wup(0);
1078         if (retVal == SUCCESS) {
1079                 rpp_sci_printf("Wake up pattern has been sent.\r\n");
1080         }
1081         else {
1082                 rpp_sci_printf("General error.\r\n");
1083                 return -CMDERR_BADCFG;
1084         }
1085         return 0;
1086 }
1087
1088 /**
1089  *      @brief  Set channel for wake up pattern sending.
1090  *
1091  * @param[in]   cmd_io  Pointer to IO stack
1092  * @param[in]   des             Pointer to command descriptor
1093  * @param[in]   param   Parameters of command
1094  * @return      0 when OK or error code
1095  */
1096 int cmd_do_fr_setwuchannel(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1097         int8_t retVal = ERR_PARAM_NO_ERROR;
1098         Fr_ChannelType channel = FR_CHANNEL_A;
1099
1100         if (*param[1] == 'A') {
1101                 channel = FR_CHANNEL_A;
1102         }
1103         else if (*param[1] == 'B') {
1104                 channel = FR_CHANNEL_B;
1105         }
1106         else {
1107                 return -CMDERR_BADPAR;
1108         }
1109         retVal = rpp_fr_set_wu_channel(0, channel);
1110         if (retVal == SUCCESS) {
1111                 rpp_sci_printf("Wake up channel has been set.\r\n");
1112         }
1113         else {
1114                 rpp_sci_printf("General error.\r\n");
1115                 return -CMDERR_BADCFG;
1116         }
1117         return 0;
1118 }
1119
1120 /**
1121  *      @brief  Get and print POC status of the FlexRay controller.
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_getpocstatus(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1129         int8_t retVal = ERR_PARAM_NO_ERROR;
1130         Fr_POCStatusType status;
1131         char* ErrorModeStrings[] = {"ACTIVE", "HALT", "PASSIVE"};
1132         char* SlotModeStrings[]  = {"KEYSLOT", "ALL_PENDING", "ALL"};
1133         char* StartupStateStrings[]  = {
1134                         "UNDEFINED", "COLDSTART_LISTEN", "COLDSTART_CHECK", "COLDSTART_JOIN",
1135                         "COLDSTART_CONSISTENCY_CHECK", "INTEGRATION_LISTEN", "INITIALIZE_SCHEDULE", "INTEGRATION_CONSISTENCY_CHECK",
1136                         "COLDSTART_GAP", "EXTERNAL_STARTUP", "ABORT", "COLDSTART_COLLISION_RESOLUTION",
1137                         "PREPARE"
1138         };
1139         char* StateStrings[]  = {
1140                         "CONFIG", "DEFAULT_CONFIG", "HALT", "NORMAL_ACTIVE",
1141                         "NORMAL_PASSIVE", "READY", "STARTUP", "LOOPBACK",
1142                         "MONITOR", "WAKEUP"
1143         };
1144         char* WakeupStatusStrings[]  = {
1145                         "UNDEFINED", "RECEIVED_HEADER", "RECEIVED_WUP", "COLLISION_HEADER",
1146                         "COLLISION_WUP", "COLLISION_UNKNOWN", "TRANSMITTED"
1147         };
1148
1149         retVal = rpp_fr_get_poc_status(0, &status);
1150         if (retVal == SUCCESS) {
1151                 rpp_sci_printf("POC status:\r\n");
1152                 rpp_sci_printf("CHIHaltRequest: %s\r\n", (status.CHIHaltRequest == TRUE) ? "TRUE" : "FALSE");
1153                 rpp_sci_printf("CHIReadyRequest: %s\r\n", (status.CHIReadyRequest == TRUE) ? "TRUE" : "FALSE");
1154                 rpp_sci_printf("ColdstartNoise: %s\r\n", (status.ColdstartNoise == TRUE) ? "TRUE" : "FALSE");
1155                 rpp_sci_printf("Freeze: %s\r\n", (status.Freeze == TRUE) ? "TRUE" : "FALSE");
1156                 rpp_sci_printf("ErrorMode: %s\r\n", ErrorModeStrings[status.ErrorMode]);
1157                 rpp_sci_printf("SlotMode: %s\r\n", SlotModeStrings[status.SlotMode]);
1158                 rpp_sci_printf("StartupState: %s\r\n", StartupStateStrings[status.StartupState]);
1159                 rpp_sci_printf("State: %s\r\n", StateStrings[status.State]);
1160                 rpp_sci_printf("WakeupStatus: %s\r\n", WakeupStatusStrings[status.WakeupStatus]);
1161         }
1162         else {
1163                 rpp_sci_printf("General error.\r\n");
1164                 return -CMDERR_BADCFG;
1165         }
1166         return 0;
1167 }
1168
1169 /**
1170  *      @brief  Send given data through the FlexRay in selected slot.
1171  *
1172  * @param[in]   cmd_io  Pointer to IO stack
1173  * @param[in]   des             Pointer to command descriptor
1174  * @param[in]   param   Parameters of command
1175  * @return      0 when OK or error code
1176  */
1177 int cmd_do_fr_transmittxlpdu(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1178         int8_t retVal = ERR_PARAM_NO_ERROR;
1179         uint32_t slotID;
1180         uint8_t dataLength;
1181         int values[MAX_PARAM_VALUES_NUM];
1182         uint8_t data[MAX_PARAM_VALUES_NUM];
1183         char* token = NULL;
1184
1185         if (sscanf(param[1], "%d", &slotID) != 1) {
1186                 return -CMDERR_BADPAR;
1187         }
1188         if (sscanf(param[2], " %2x", &values[0]) != 1) {
1189                 return -CMDERR_BADPAR;
1190         }
1191         data[0] = (uint8_t)values[0];
1192         token = strtok(param[2], " ");
1193         token = strtok(NULL, " ");
1194         dataLength = 1;
1195         while (dataLength < MAX_PARAM_VALUES_NUM && token != NULL) {
1196                 if (sscanf(token, "%2x", &values[dataLength]) == EOF) {
1197                         break;
1198                 }
1199                 data[dataLength] = (uint8_t)values[dataLength];
1200                 token = strtok(NULL, " ");
1201                 dataLength++;
1202         }
1203
1204         retVal = rpp_fr_transmit_lpdu(0, slotID, data, dataLength);
1205         if (retVal == SUCCESS) {
1206                 rpp_sci_printf("Data were set for transmission.\r\n");
1207         }
1208         else {
1209                 rpp_sci_printf("General error.\r\n");
1210                 return -CMDERR_BADCFG;
1211         }
1212         return 0;
1213 }
1214
1215 /**
1216  *      @brief  Cancel the transmission in the selected slot.
1217  *
1218  * @param[in]   cmd_io  Pointer to IO stack
1219  * @param[in]   des             Pointer to command descriptor
1220  * @param[in]   param   Parameters of command
1221  * @return      0 when OK or error code
1222  */
1223 int cmd_do_fr_canceltxlpdu(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1224         int8_t retVal = ERR_PARAM_NO_ERROR;
1225         uint32_t slotID;
1226
1227         if (sscanf(param[1], "%d", &slotID) != 1) {
1228                 return -CMDERR_BADPAR;
1229         }
1230         if (param[2] != NULL) {
1231                 return -CMDERR_BADPAR;
1232         }
1233
1234         retVal = rpp_fr_cancel_transmit_lpdu(0, slotID);
1235         if (retVal == SUCCESS) {
1236                 rpp_sci_printf("Transmission canceled.\r\n");
1237         }
1238         else {
1239                 rpp_sci_printf("General error.\r\n");
1240                 return -CMDERR_BADCFG;
1241         }
1242         return 0;
1243 }
1244
1245 /**
1246  *      @brief  Receive data from selected slot.
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_receiverxlpdu(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         uint8_t data[cPayloadLengthMax];
1257         Fr_RxLPduStatusType status;
1258         uint8_t receivedLength = 0;
1259         uint8_t i;
1260
1261         if (sscanf(param[1], "%d", &slotID) != 1) {
1262                 return -CMDERR_BADPAR;
1263         }
1264         if (param[2] != NULL) {
1265                 return -CMDERR_BADPAR;
1266         }
1267
1268         memset(data, 0, sizeof(data));
1269
1270         retVal = rpp_fr_receive_lpdu(0, slotID, data, &status, &receivedLength);
1271         if (retVal == SUCCESS) {
1272                 switch (status) {
1273                 case FR_RECEIVED_MORE_DATA_AVAILABLE:
1274                         rpp_sci_printf("More messages are still in FIFO:\r\n");
1275                 case FR_RECEIVED:
1276                         rpp_sci_printf("Received message (%d B):\r\n", receivedLength);
1277                         for (i = 0; i < receivedLength; i++) {
1278                                 rpp_sci_printf(" %02x", data[i]);
1279                         }
1280                         rpp_sci_printf("\r\n");
1281                         break;
1282                 default:
1283                         rpp_sci_printf("No message received.\r\n");
1284                         break;
1285                 }
1286         }
1287         else {
1288                 rpp_sci_printf("General error.\r\n");
1289                 return -CMDERR_BADCFG;
1290         }
1291         return 0;
1292 }
1293
1294 /**
1295  *      @brief  Returns TX LPdu status.
1296  *
1297  * @param[in]   cmd_io  Pointer to IO stack
1298  * @param[in]   des             Pointer to command descriptor
1299  * @param[in]   param   Parameters of command
1300  * @return      0 when OK or error code
1301  */
1302 int cmd_do_fr_checktxlpdustatus(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1303         int8_t retVal = ERR_PARAM_NO_ERROR;
1304         uint32_t slotID;
1305         Fr_TxLPduStatusType status;
1306         char* statusStrings[] = {"is not", "is"};
1307
1308         if (sscanf(param[1], "%d", &slotID) != 1) {
1309                 return -CMDERR_BADPAR;
1310         }
1311         if (param[2] != NULL) {
1312                 return -CMDERR_BADPAR;
1313         }
1314
1315         retVal = rpp_fr_check_tx_lpdu_status(0, slotID, &status);
1316         if (retVal == SUCCESS) {
1317                 rpp_sci_printf("Message transmission %s pending.\r\n", statusStrings[status]);
1318         }
1319         else {
1320                 rpp_sci_printf("General error.\r\n");
1321                 return -CMDERR_BADCFG;
1322         }
1323         return 0;
1324 }
1325
1326 /**
1327  *      @brief  Disable buffer.
1328  *
1329  * @param[in]   cmd_io  Pointer to IO stack
1330  * @param[in]   des             Pointer to command descriptor
1331  * @param[in]   param   Parameters of command
1332  * @return      0 when OK or error code
1333  */
1334 int cmd_do_fr_disablelpdu(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1335         int8_t retVal = ERR_PARAM_NO_ERROR;
1336         uint32_t slotID;
1337
1338         if (sscanf(param[1], "%d", &slotID) != 1) {
1339                 return -CMDERR_BADPAR;
1340         }
1341         if (param[2] != NULL) {
1342                 return -CMDERR_BADPAR;
1343         }
1344
1345         retVal = rpp_fr_disable_lpdu(0, slotID);
1346         if (retVal == SUCCESS) {
1347                 rpp_sci_printf("Buffer disabled.\r\n");
1348         }
1349         else {
1350                 rpp_sci_printf("General error.\r\n");
1351                 return -CMDERR_BADCFG;
1352         }
1353         return 0;
1354 }
1355
1356 /**
1357  *      @brief  Print global time of the FlexRay network.
1358  *
1359  * @param[in]   cmd_io  Pointer to IO stack
1360  * @param[in]   des             Pointer to command descriptor
1361  * @param[in]   param   Parameters of command
1362  * @return      0 when OK or error code
1363  */
1364 int cmd_do_fr_getglobaltime(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1365         int8_t retVal = ERR_PARAM_NO_ERROR;
1366         uint8_t cycle = 0;
1367         uint16_t macroTick = 0;
1368
1369         retVal = rpp_fr_get_global_time(0, &cycle, &macroTick);
1370         if (retVal == SUCCESS) {
1371                 rpp_sci_printf("Cycle number: %d\r\nMacrotick number: %d\r\n", cycle, macroTick);
1372         }
1373         else {
1374                 rpp_sci_printf("General error.\r\n");
1375                 return -CMDERR_BADCFG;
1376         }
1377         return 0;
1378 }
1379
1380 /**
1381  *      @brief  Print network management vector of the FlexRay node.
1382  *
1383  * @param[in]   cmd_io  Pointer to IO stack
1384  * @param[in]   des             Pointer to command descriptor
1385  * @param[in]   param   Parameters of command
1386  * @return      0 when OK or error code
1387  */
1388 int cmd_do_fr_getnmvector(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1389         int8_t retVal = ERR_PARAM_NO_ERROR;
1390         uint8_t nmVector[12];
1391         uint8_t i;
1392
1393         retVal = rpp_fr_get_network_management_vector(0, nmVector);
1394         if (retVal == SUCCESS) {
1395                 rpp_sci_printf("Network management vector:");
1396                 for (i = 0; i < Fr_cluster_config.gNetworkManagementVectorLength; i++) {
1397                         rpp_sci_printf(" %x", nmVector[i]);
1398                 }
1399                 rpp_sci_printf("\r\n");
1400         }
1401         else {
1402                 rpp_sci_printf("General error.\r\n");
1403                 return -CMDERR_BADCFG;
1404         }
1405         return 0;
1406 }
1407
1408 int cmd_do_fr_nmwatch(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1409         int8_t retVal = ERR_PARAM_NO_ERROR;
1410         uint8_t nmVector[12];
1411         uint8_t i;
1412
1413         // Calculate wait time in OS ticks
1414         static const portTickType freq_ticks = 100 /* ms */ / portTICK_RATE_MS;
1415         portTickType last_wake_time = xTaskGetTickCount();
1416
1417         while(cmd_io->getc(cmd_io) < 0) {
1418                 retVal = rpp_fr_get_network_management_vector(0, nmVector);
1419                 if (retVal == SUCCESS) {
1420                         rpp_sci_printf("Network management vector:");
1421                         for (i = 0; i < Fr_cluster_config.gNetworkManagementVectorLength; i++) {
1422                                 rpp_sci_printf(" %02x", nmVector[i]);
1423                         }
1424                         rpp_sci_printf("\r");
1425                 }
1426                 else {
1427                         rpp_sci_printf("General error.\r\n");
1428                         return -CMDERR_BADCFG;
1429                 }
1430                 vTaskDelayUntil(&last_wake_time, freq_ticks);
1431         }
1432         rpp_sci_printf("\n");
1433         return 0;
1434 }
1435
1436 /**
1437  *      @brief  Print both channels status of the FlexRay node.
1438  *
1439  * @param[in]   cmd_io  Pointer to IO stack
1440  * @param[in]   des             Pointer to command descriptor
1441  * @param[in]   param   Parameters of command
1442  * @return      0 when OK or error code
1443  */
1444 int cmd_do_fr_getchannelstatus(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1445         int8_t retVal = ERR_PARAM_NO_ERROR;
1446         uint8_t index;
1447         uint8_t channel;
1448         char* decodeStrings[] = {
1449                         "aggregated channel status vSS!ValidFrame",
1450                         "aggregated channel status vSS!SyntaxError",
1451                         "aggregated channel status vSS!ContentError",
1452                         "aggregated channel status additional communication",
1453                         "aggregated channel status vSS!Bviolation",
1454                         "aggregated channel status vSS!TxConflict",
1455                         "Not used (0)",
1456                         "Not used (0)",
1457                         "symbol window status data vSS!ValidMTS",
1458                         "symbol window status data vSS!SyntaxError",
1459                         "symbol window status data vSS!Bviolation",
1460                         "symbol window status data vSS!TxConflict",
1461                         "NIT status data vSS!SyntaxError",
1462                         "NIT status data vSS!Bviolation",
1463                         "Not used (0)",
1464                         "Not used (0)"
1465         };
1466         char* channelNames[] = {"A", "B"};
1467         char* boolStrings[] = {"FALSE", "TRUE"};
1468         uint16_t channelStatuses[2];
1469
1470         retVal = rpp_fr_get_channel_status(0, &channelStatuses[0], &channelStatuses[1]);
1471         if (retVal == SUCCESS) {
1472                 for (channel = 0; channel < 2; channel++) {
1473                         rpp_sci_printf("Channel %s status:\r\n", channelNames[channel]);
1474                         for (index = 0; index < 16; index++) {
1475                                 rpp_sci_printf("\t%s: %s\r\n", decodeStrings[index], boolStrings[ (channelStatuses[channel] >> index) & 0x1 ] );
1476                         }
1477                 }
1478         }
1479         else {
1480                 rpp_sci_printf("General error.\r\n");
1481                 return -CMDERR_BADCFG;
1482         }
1483         return 0;
1484 }
1485
1486 /**
1487  *      @brief  Print clock correction of the FlexRay node
1488  *
1489  * @param[in]   cmd_io  Pointer to IO stack
1490  * @param[in]   des             Pointer to command descriptor
1491  * @param[in]   param   Parameters of command
1492  * @return      0 when OK or error code
1493  */
1494 int cmd_do_fr_getclockcorrection(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1495         int8_t retVal = ERR_PARAM_NO_ERROR;
1496         int16_t rateCorrection;
1497         int32_t offsetCorrection;
1498
1499         retVal = rpp_fr_get_clock_correction(0, &rateCorrection, &offsetCorrection);
1500         if (retVal == SUCCESS) {
1501                 rpp_sci_printf("Rate correction: %d\r\nOffset correction: %d\r\n", rateCorrection, offsetCorrection);
1502         }
1503         else {
1504                 rpp_sci_printf("General error.\r\n");
1505                 return -CMDERR_BADCFG;
1506         }
1507         return 0;
1508 }
1509
1510 /**
1511  *      @brief  Print list of syncframec transmitted on both channels via the even and odd cycle.
1512  *
1513  * @param[in]   cmd_io  Pointer to IO stack
1514  * @param[in]   des             Pointer to command descriptor
1515  * @param[in]   param   Parameters of command
1516  * @return      0 when OK or error code
1517  */
1518 int cmd_do_fr_getsyncframelist(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1519         int8_t retVal = ERR_PARAM_NO_ERROR;
1520         uint16_t channelAEvenList[FR_MAX_SYNC_FRAME_LIST_SIZE];
1521         uint16_t channelBEvenList[FR_MAX_SYNC_FRAME_LIST_SIZE];
1522         uint16_t channelAOddList[FR_MAX_SYNC_FRAME_LIST_SIZE];
1523         uint16_t channelBOddList[FR_MAX_SYNC_FRAME_LIST_SIZE];
1524         uint32_t listSize = 0;
1525         uint8_t i;
1526
1527         if (sscanf(param[1], "%d", &listSize) != 1) {
1528                 return -CMDERR_BADPAR;
1529         }
1530         if (param[2] != NULL) {
1531                 return -CMDERR_BADPAR;
1532         }
1533         if (listSize > FR_MAX_SYNC_FRAME_LIST_SIZE) {
1534                 return -CMDERR_BADPAR;
1535         }
1536
1537         retVal = rpp_fr_get_sync_frame_list(0, listSize, channelAEvenList, channelBEvenList, channelAOddList, channelBOddList);
1538         if (retVal == SUCCESS) {
1539                 rpp_sci_printf("| Channel A even | channel B even | channel A odd  | channel B odd  |\r\n");
1540                 rpp_sci_printf("|----------------|----------------|----------------|----------------|\r\n");
1541                 for (i = 0; i < listSize; i++) {
1542                         rpp_sci_printf("| %-14x | %-14x | %-14x | %-14x |\r\n", channelAEvenList[i], channelBEvenList[i], channelAOddList[i], channelBOddList[i]);
1543                 }
1544                 rpp_sci_printf("|----------------|----------------|----------------|----------------|\r\n");
1545
1546         }
1547         else {
1548                 rpp_sci_printf("General error.\r\n");
1549                 return -CMDERR_BADCFG;
1550         }
1551         return 0;
1552 }
1553
1554 /**
1555  *      @brief  Print status of wakeup on each channels (wakeup received on channel or not yet received).
1556  *
1557  * @param[in]   cmd_io  Pointer to IO stack
1558  * @param[in]   des             Pointer to command descriptor
1559  * @param[in]   param   Parameters of command
1560  * @return      0 when OK or error code
1561  */
1562 int cmd_do_fr_getwakeuprxstatus(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1563         int8_t retVal = ERR_PARAM_NO_ERROR;
1564         uint8_t status = 0;
1565         char* statusStrings[] = {"was not yet", "was"};
1566         char* channelNames[] = {"A", "B"};
1567         uint8_t i;
1568
1569         retVal = rpp_fr_get_wakeup_rx_status(0, &status);
1570         if (retVal == SUCCESS) {
1571                 for (i = 0; i < 2; i++) {
1572                         rpp_sci_printf("Wake up pattern %s received on channel %s.\r\n", statusStrings[(status >> i) & 0x1], channelNames[i]);
1573                 }
1574         }
1575         else {
1576                 rpp_sci_printf("General error.\r\n");
1577                 return -CMDERR_BADCFG;
1578         }
1579         return 0;
1580 }
1581
1582 /**
1583  *      @brief  Set and start absolute timer.
1584  *
1585  * @param[in]   cmd_io  Pointer to IO stack
1586  * @param[in]   des             Pointer to command descriptor
1587  * @param[in]   param   Parameters of command
1588  * @return      0 when OK or error code
1589  */
1590 int cmd_do_fr_settimer(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1591         int8_t retVal = ERR_PARAM_NO_ERROR;
1592         int timer = 0;
1593         int cycle = 0;
1594         int offset = 0;
1595
1596         if (sscanf(param[1], "%i %i %i", &timer, &cycle, &offset) != 3) {
1597                 return -CMDERR_BADPAR;
1598         }
1599
1600         retVal = rpp_fr_set_timer(0, timer, cycle, offset);
1601         if (retVal == SUCCESS) {
1602                 uint8_t i = 0x40;
1603                 while (i && (cycle & i) == 0)
1604                         i >>= 1;
1605                 if (!i)
1606                         i = 1;
1607
1608                 rpp_sci_printf("Timer was set for every %d-th cycle, offset %d, macrotick %d\n",
1609                                i, cycle & ~i, offset);
1610         }
1611         else {
1612                 rpp_sci_printf("General error.\r\n");
1613                 return -CMDERR_BADCFG;
1614         }
1615         return 0;
1616 }
1617
1618 /**
1619  *      @brief  Cancel selected timer
1620  *
1621  * @param[in]   cmd_io  Pointer to IO stack
1622  * @param[in]   des             Pointer to command descriptor
1623  * @param[in]   param   Parameters of command
1624  * @return      0 when OK or error code
1625  */
1626 int cmd_do_fr_canceltimer(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1627         int8_t retVal = ERR_PARAM_NO_ERROR;
1628         int timer = 0;
1629
1630         if (sscanf(param[1], "%d", &timer) != 1) {
1631                 return -CMDERR_BADPAR;
1632         }
1633
1634         if (param[2] != NULL) {
1635                 return -CMDERR_BADPAR;
1636         }
1637
1638         retVal = rpp_fr_cancel_timer(0, timer);
1639         if (retVal == SUCCESS) {
1640                 rpp_sci_printf("Timer was canceled.\r\n");
1641         }
1642         else {
1643                 rpp_sci_printf("General error.\r\n");
1644                 return -CMDERR_BADCFG;
1645         }
1646         return 0;
1647 }
1648
1649 /**
1650  *      @brief  Enable/disable, acknowledge, get timer IRQ
1651  *
1652  * @param[in]   cmd_io  Pointer to IO stack
1653  * @param[in]   des             Pointer to command descriptor
1654  * @param[in]   param   Parameters of command
1655  * @return      0 when OK or error code
1656  */
1657 int cmd_do_fr_timerirq(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1658         int8_t retVal = ERR_PARAM_NO_ERROR;
1659         int timer = 0;
1660         char str[4];
1661         boolean_t status = FALSE;
1662         char* boolStrings[] = {"FALSE", "TRUE"};
1663
1664
1665         if (sscanf(param[1], "%d", &timer) != 1) {
1666                 return -CMDERR_BADPAR;
1667         }
1668
1669         if (param[2] == NULL) {         // Get timer IRQ
1670                 retVal = rpp_fr_get_timer_irq_status(0, timer, &status);
1671                 if (retVal == SUCCESS) {
1672                         rpp_sci_printf("IRQ = %s\r\n", boolStrings[status]);
1673                 }
1674                 else {
1675                         rpp_sci_printf("General error.\r\n");
1676                         return -CMDERR_BADCFG;
1677                 }
1678         }
1679         else {  // Some set action
1680                 if (sscanf(param[2], "%4s", str) != 1) {
1681                         return -CMDERR_BADPAR;
1682                 }
1683                 if (strcmp(str, "EN") == 0) { // Enable IRQ
1684                         retVal = SUCCESS;       // No interrupts imlemented
1685                 }
1686                 else if (strcmp(str, "DIS") == 0) { // Disable IRQ
1687                         retVal = SUCCESS;       // No interrupts implemented
1688                 }
1689                 else if  (strcmp(str, "ACK") == 0) { // Clear IRQ
1690                         retVal = rpp_fr_clear_timer_irq(0, timer);
1691                 }
1692                 else {  // Bad argument
1693                         return -CMDERR_BADPAR;
1694                 }
1695
1696                 if (retVal == SUCCESS) {
1697                         rpp_sci_printf("OK\r\n");
1698                 }
1699                 else {
1700                         rpp_sci_printf("General error.\r\n");
1701                         return -CMDERR_BADCFG;
1702                 }
1703         }
1704         return 0;
1705 }
1706
1707 /**
1708  *      @brief  Print FlexRay driver version info.
1709  *
1710  * @param[in]   cmd_io  Pointer to IO stack
1711  * @param[in]   des             Pointer to command descriptor
1712  * @param[in]   param   Parameters of command
1713  * @return      0 when OK or error code
1714  */
1715 int cmd_do_fr_getversioninfo(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1716         Std_VersionInfoType versionInfo;
1717
1718         rpp_fr_get_driver_version(&versionInfo);
1719         rpp_sci_printf("vendorID: %#x\r\n", versionInfo.vendorID);
1720         rpp_sci_printf("moduleID: %#x\r\n", versionInfo.moduleID);
1721         rpp_sci_printf("sw_major_version: %#x\r\n", versionInfo.sw_major_version);
1722         rpp_sci_printf("sw_minor_version: %#x\r\n", versionInfo.sw_minor_version);
1723         rpp_sci_printf("sw_patch_version: %#x\r\n", versionInfo.sw_patch_version);
1724
1725         return 0;
1726 }
1727
1728 /**
1729  *      @brief  Print value of FlexRay configuratoin parameter.
1730  *
1731  * @param[in]   cmd_io  Pointer to IO stack
1732  * @param[in]   des             Pointer to command descriptor
1733  * @param[in]   param   Parameters of command
1734  * @return      0 when OK or error code
1735  */
1736 int cmd_do_fr_readcconfig(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
1737         int8_t retVal = ERR_PARAM_NO_ERROR;
1738         int index = 0;
1739         uint32_t value = 0;
1740
1741         if (sscanf(param[1], "%d", &index) != 1) {
1742                 return -CMDERR_BADPAR;
1743         }
1744
1745         if (param[2] != NULL) {
1746                 return -CMDERR_BADPAR;
1747         }
1748
1749         retVal = rpp_fr_read_com_ctrl_config(0, index, &value);
1750         if (retVal == SUCCESS) {
1751                 rpp_sci_printf("Value = %#x\r\n", value);
1752         }
1753         else {
1754                 rpp_sci_printf("General error.\r\n");
1755                 return -CMDERR_BADCFG;
1756         }
1757         return 0;
1758 }
1759
1760 #endif  /* DOCGEN */
1761
1762 /** Command descriptor for FlexRay user config cluster command */
1763 cmd_des_t const cmd_des_fr_user_config={
1764         0, 0,
1765         "frbtconfig*","Set the user configuration parameters",
1766                 "=== Command syntax ===\n"
1767         "\n"
1768         "   frbtconfig<TYPE> <PARAMS>\n"
1769         "where\n"
1770         "* <TYPE> is a string specifying the type of parameters to be set. It can be: \"cluster\" or  \"node\"\n"
1771         "* <PARAMS> is a sequence of numbers separated by spaces. Each number stands for one parameter.\n"
1772         "\n"
1773         "=== Description ===\n"
1774         "\n"
1775         "The command takes the configuration parameters in the form of a string\n"
1776         "and sets the appropriate type of the FlexRay parameters. It is\n"
1777         "necessary to configure parameters of at least cluster, and node and\n"
1778         "one static buffer (see frbtcfgbuf command). The parameters set by this\n"
1779         "command are applied by the frbtinitU command. Once frbtinit is called,\n"
1780         "it is no longer possible to change the parameters.\n"
1781         "\n"
1782         "The type of the parameters can be selected by the <TYPE> selector.\n"
1783         "\n"
1784         "Type \"cluster\" sets global FlexRay network parameters. It expects a\n"
1785         "sequence of 25 parameters in this order:\n"
1786         "* 1) gColdStartAttempts\n"
1787         "* 2) gListenNoise\n"
1788         "* 3) gMacroPerCycle\n"
1789         "* 4) gMaxWithoutClockCorrectionFatal\n"
1790         "* 5) gMaxWithoutClockCorrectionPassive\n"
1791         "* 6) gNetworkManagementVectorLength\n"
1792         "* 7) gNumberOfMinislots\n"
1793         "* 8) gNumberOfStaticSlots\n"
1794         "* 9) gOffsetCorrectionStart\n"
1795         "* 10) gPayloadLengthStatic\n"
1796         "* 11) gSyncNodeMax\n"
1797         "* 12) gdActionPointOffset\n"
1798         "* 13) gdCASRxLowMax\n"
1799         "* 14) gdDynamicSlotIdlePhase\n"
1800         "* 15) gdMinislot\n"
1801         "* 16) gdMinislotActionPointOffset\n"
1802         "* 17) gdNIT\n"
1803         "* 18) gdSampleClockPeriod\n"
1804         "* 19) gdStaticSlot\n"
1805         "* 20) gdTSSTransmitter\n"
1806         "* 21) gdWakeupSymbolRxIdle\n"
1807         "* 22) gdWakeupSymbolRxLow\n"
1808         "* 23) gdWakeupSymbolRxWindow\n"
1809         "* 24) gdWakeupSymbolTxIdle\n"
1810         "* 25) gdWakeupSymbolTxLow\n"
1811         "\n"
1812         "Type \"node\" sets local FlexRay network parameters. It expects a\n"
1813         "sequence of 28 parameters in this order:\n"
1814         "* 1) pAllowHaltDueToClock\n"
1815         "* 2) pAllowPassiveToActive\n"
1816         "* 3) pChannels (0 - A, 1 - B, 2 - AB)\n"
1817         "* 4) pClusterDriftDamping\n"
1818         "* 5) pDelayCompensationA\n"
1819         "* 6) pDelayCompensationB\n"
1820         "* 7) pExternOffsetCorrection\n"
1821         "* 8) pExternRateCorrection\n"
1822         "* 9) pKeySlotUsedForStartup\n"
1823         "* 10) pKeySlotUsedForSync\n"
1824         "* 11) pLatestTx\n"
1825         "* 12) pMacroInitialOffsetA\n"
1826         "* 13) pMacroInitialOffsetB\n"
1827         "* 14) pMicroInitialOffsetA\n"
1828         "* 15) pMicroInitialOffsetB\n"
1829         "* 16) pMicroPerCycle\n"
1830         "* 17) pRateCorrectionOut\n"
1831         "* 18) pOffsetCorrectionOut\n"
1832         "* 19) pSamplesPerMicrotick\n"
1833         "* 20) pSingleSlotEnabled\n"
1834         "* 21) pWakeupChannel (0 - A, 1 - B)\n"
1835         "* 22) pWakeupPattern\n"
1836         "* 23) pdAcceptedStartupRange\n"
1837         "* 24) pdListenTimeout\n"
1838         "* 25) pdMaxDrift\n"
1839         "* 26) pDecodingCorrection\n"
1840         "* 27) syncFramePayloadMultiplexEnabled\n"
1841         "* 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"
1842         "\n"
1843         "=== Example ===\n"
1844         "\n"
1845         "   --> 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"
1846         "   FlexRay cluster configuration accepted.\n"
1847         "   --> 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"
1848         "   FlexRay node configuration accepted.\n",
1849         CMD_HANDLER(cmd_do_fr_user_config), (void *)&cmd_list_fr_basic_test
1850 };
1851
1852 cmd_des_t const cmd_des_fr_config_buffer={
1853         0, 0,
1854         "frbtcfgbuf?*","Configure a message buffer in the user configuration",
1855         "=== Command syntax ===\n"
1856         "\n"
1857         "   frbtcfgbuf<TYPE><NUM> slot<SLOT> <CHN> cyc<CYC> <RXTX> max<MAX> <REP> ppi<PPI> int<INT>\n"
1858         "where\n"
1859         "* <TYPE> is 'S' for static segment buffers and 'D' for dynamic segment buffers,\n"
1860         "* <NUM> is the number of the buffer. Both static and dynamic buffers are numbered independently starting from zero,\n"
1861         "* <SLOT> is the number of the slot,\n"
1862         "* <CHN> is one of 'A', 'B' or 'AB' and identifies the used channel,\n"
1863         "* <CYC> is the cycle set when to send the buffer,\n"
1864         "* <RXTX> is either string \"rx\" or \"tx\",\n"
1865         "* <MAX> is the number determining the maximum payload (in hald-words),\n"
1866         "* <REP> is a string \"s\" or \"single\" for single transmission or \"c\" or \"continuous\" for continuous transmission,\n"
1867         "* <PPI> is 0 or 1 determining whether the payload preamble indicator is set,\n"
1868         "* <INT> is 0 or 1 and is currently ignored.\n"
1869         "\n"
1870         "=== Description ===\n"
1871         "\n"
1872         "The command sets the configuration parameters for static or dynamic\n"
1873         "buffers in user configuration. The parameters set by this command are\n"
1874         "applied by the frbtinitU command. Once frbtinit is called, it is no\n"
1875         "longer possible to change the parameters.\n"
1876         "\n"
1877         "=== Example ===\n"
1878         "\n"
1879         "   --> frbtcfgbufS0 slot2 AB cyc0 tx max9 continous ppi0 int1\n"
1880         "   frbtcfgbufS0 slot2 AB cyc0 tx max9  continous ppi0 int1\n"
1881         "   --> frbtcfgbufS1 slot1 AB cyc0 rx max9 continuous ppi0 int1\n"
1882         "   frbtcfgbufS1 slot1 AB cyc0 rx max9 continuous ppi0 int1\n"
1883         "   --> frbtcfgbufD0  slot9  A cyc0 rx max0x40 single ppi0 int0\n"
1884         "   frbtcfgbufD0 slot9  A cyc0 rx max64 single ppi0 int0\n"
1885         "   --> frbtcfgbufD1  slot10 A cyc0 tx max0x40 single ppi0 int0\n"
1886         "   frbtcfgbufD1 slot10  A cyc0 tx max64 single ppi0 int0\n",
1887         CMD_HANDLER(cmd_do_fr_config_bufer), (void *)&cmd_list_fr_basic_test
1888 };
1889
1890 cmd_des_t const cmd_des_fr_config_fifo={
1891         0, 0,
1892         "frbtcfgfifo*","Configure a RX FIFO message buffer in the user configuration",
1893         "=== Command syntax ===\n"
1894         "\n"
1895         "   frbtcfgfifo slot<SLOT> depth<DEPTH> <CHN> cyc<CYC> max<MAX> <REJNULL> <REJSTAT> int<INT>\n"
1896         "where\n"
1897         "* <SLOT> is the number of the slot,\n"
1898         "* <DEPTH> is a number specifying the depth of the FIFO,\n"
1899         "* <CHN> is one of 'A', 'B' or 'AB' and identifies the used channel,\n"
1900         "* <CYC> is the cycle set when to send the buffer,\n"
1901         "* <MAX> is the number determining the maximum payload (in hald-words),\n"
1902         "* <REJNULL> is a string \"rejnull\" for rejecting NULL frames or \"accnull\" for accepting NULL frames,\n"
1903         "* <REJSTAT> is a string \"rejstat\" for rejecting frames in static segment or \"accstat\" for accepting frames from static segment,\n"
1904         "* <INT> is 0 or 1 and is currently ignored.\n"
1905         "\n"
1906         "=== Description ===\n"
1907         "\n"
1908         "The command sets the configuration parameters for RX FIFO buffer\n"
1909         "in user configuration. The parameters set by this command are\n"
1910         "applied by the frbtinitU command. Once frbtinit is called, it is no\n"
1911         "longer possible to change the parameters.\n"
1912         "\n"
1913         "=== Example ===\n"
1914         "\n"
1915         "   --> frbtcfgfifo slot0 depth5 AB cyc0 max20 rejnull accstat int1\n"
1916         "   frbtcfgfifo slot0 depth5 AB cyc0 max20  rejnull accstat int1\n",
1917         CMD_HANDLER(cmd_do_fr_config_fifo), (void *)&cmd_list_fr_basic_test
1918 };
1919
1920 /** Command descriptor for FlexRay init command */
1921 cmd_des_t const cmd_des_fr_init={
1922         0, 0,
1923         "frbtinit?","Initialize a FlexRay node",
1924         "=== Command syntax ===\n"
1925         "\n"
1926         "   frbtinit<CFG>\n"
1927         "\n"
1928         "where <CFG> identifies the configuration to use. It can be one of A, B\n"
1929         "or U. The A and B are predefined configurations. If U is specified,\n"
1930         "the user configuration previously set by frbtconfig command is used.\n"
1931         "\n"
1932         "=== Description ===\n"
1933         "\n"
1934         "The command stands for Fr_Init and Fr_ControllerInit functions from\n"
1935         "the Autosar specification. It initializes the internal data structures\n"
1936         "of the driver and then, based on those data, the controller\n"
1937         "configuration is done. During the controller configuration the\n"
1938         "parameters of the cluster, node, message RAM and buffers are checked.\n"
1939         "If anything goes bad, the command returns an error number, which can\n"
1940         "be decoded by macros defined in driver header file fr_tms570.h with\n"
1941         "prefix ERR_PARAM. If all parameters are OK, all necessary registers of\n"
1942         "the controller are initialized according to the specified\n"
1943         "configuration parameters. At the end of the command, the FlexRay\n"
1944         "controller is switched into READY state and all buffers are configured\n"
1945         "to send NULL frames. This command should be called as the very first\n"
1946         "command, when trying to communicate over the FlexRay bus.\n"
1947         "\n"
1948         "=== Example ===\n"
1949         "\n"
1950         "   --> frbtinitA\n"
1951         "   FlexRay driver initialized.\n"
1952         "   FlexRay controller initialized.\n",
1953         CMD_HANDLER(cmd_do_fr_init), (void *)&cmd_list_fr_basic_test
1954 };
1955
1956 /** Command descriptor for FlexRay controller init command */
1957 cmd_des_t const cmd_des_fr_start={
1958         0, 0,
1959         "frbtstart","Start a new FlexRay network or join to the existing one",
1960         "=== Command syntax ===\n"
1961         "\n"
1962         "   frbtstart\n"
1963         "\n"
1964         "=== Description ===\n"
1965         "\n"
1966         "The command stands for Fr_StartCommunication function from the Autosar\n"
1967         "specification. If the FlexRay node is configured as a coldstarter node\n"
1968         "(as for example by frbtinitA/B command), then the command first listen\n"
1969         "on the bus. When it does not detect any existing bus communication, it\n"
1970         "tries to initiate a new network. If the initiation fails, the FlexRay\n"
1971         "controller is switched back to the ready state for another attempt\n"
1972         "(calling frbtstart again). If the FlexRay node is configured as\n"
1973         "non-coldstarter, it is listening on the bus until some existing\n"
1974         "communication is detected.\n"
1975         "\n"
1976         "The command should be called after the frbtinit command.\n"
1977         "\n"
1978         "=== Example ===\n"
1979         "\n"
1980         "   --> frbtstart\n"
1981         "   FlexRay communication is running.\n",
1982         CMD_HANDLER(cmd_do_fr_start), (void *)&cmd_list_fr_basic_test
1983 };
1984
1985 /** Command descriptor for FlexRay controller all slots command */
1986 cmd_des_t const cmd_des_fr_allslots={
1987         0, 0,
1988         "frbtallslots","Enables communication for all frames",
1989         "=== Command syntax ===\n"
1990         "\n"
1991         "   frbtallslots\n"
1992         "\n"
1993         "=== Description ===\n"
1994         "\n"
1995         "The command stands for Fr_AllSlots function from the Autosar\n"
1996         "specification.\n"
1997         "\n"
1998         "The node can be configured to communicate only on key frames by\n"
1999         "default (as in the case of frbtinitA/B). This command can be used to\n"
2000         "allow the communication on all configured frames. The command invokes\n"
2001         "the FlexRay POC command ALL_SLOTS which enables the communication on\n"
2002         "all frames. The command can be called after the controller\n"
2003         "initialization.\n"
2004         "\n"
2005         "=== Example ===\n"
2006         "\n"
2007         "   --> frbtallslots\n"
2008         "   FlexRay node started communication on all slots.\n",
2009         CMD_HANDLER(cmd_do_fr_allslots), (void *)&cmd_list_fr_basic_test
2010 };
2011
2012 /** Command descriptor for FlexRay controller halt command */
2013 cmd_des_t const cmd_des_fr_halt={
2014         0, 0,
2015         "frbthalt","Halt FlexRay communication after the end of the actual communication cycle",
2016         "=== Command syntax ===\n"
2017         "\n"
2018         "   frbthalt\n"
2019         "\n"
2020         "=== Description ===\n"
2021         "\n"
2022         "The command stands for Fr_HaltCommunication function from the Autosar\n"
2023         "specification. The command invokes the FlexRay POC command HALT, which\n"
2024         "means that communication is stopped after the end of the actual\n"
2025         "communication cycle. On the opposite side, there is a frbtfreeze\n"
2026         "command, which stops the communication immediately. To start the\n"
2027         "communication again, the device has to be reset.\n"
2028         "\n"
2029         "=== Example ===\n"
2030         "\n"
2031         "   --> frbthalt\n"
2032         "   FlexRay node communication halted.\n",
2033         CMD_HANDLER(cmd_do_fr_halt), (void *)&cmd_list_fr_basic_test
2034 };
2035
2036 /** Command descriptor for FlexRay controller abort command */
2037 cmd_des_t const cmd_des_fr_abort={
2038         0, 0,
2039         "frbtabort","Abort FlexRay communication immediately",
2040         "=== Command syntax ===\n"
2041         "\n"
2042         "   frbtabort\n"
2043         "\n"
2044         "=== Description ===\n"
2045         "\n"
2046         "The command stands for Fr_AbortCommunication function from the Autosar\n"
2047         "specification. The command invokes the FlexRay POC command FREEZE,\n"
2048         "which means that the communication is stopped immediately. On the\n"
2049         "opposite side there is a frbthalt command, which stops the\n"
2050         "communication after the end of the actual communication cycle. To\n"
2051         "start the communication again, the device has to be reset.\n"
2052         "\n"
2053         "=== Example ===\n"
2054         "\n"
2055         "   --> frbtabort\n"
2056         "   FlexRay node communication aborted.\n",
2057         CMD_HANDLER(cmd_do_fr_abort), (void *)&cmd_list_fr_basic_test
2058 };
2059
2060 /** Command descriptor for FlexRay controller send wake up pattern command */
2061 cmd_des_t const cmd_des_fr_sendwup={
2062         0, 0,
2063         "frbtwup","Initiate the wake up procedure",
2064         "=== Command syntax ===\n"
2065         "\n"
2066         "   frbtwup\n"
2067         "\n"
2068         "=== Description ===\n"
2069         "\n"
2070         "The command stands for Fr_SendWUP function from the Autosar\n"
2071         "specification. It initiates the wake up procedure by switching FlexRay\n"
2072         "controller state machine to WAKEUP state.\n"
2073         "\n"
2074         "=== Example ===\n"
2075         "\n"
2076         "   --> frbtwup\n"
2077         "   Wake up pattern has been sent.\n",
2078         CMD_HANDLER(cmd_do_fr_sendwup), (void *)&cmd_list_fr_basic_test
2079 };
2080
2081 /** Command descriptor for FlexRay controller sent wake up pattern channel command */
2082 cmd_des_t const cmd_des_fr_setwuchannel={
2083         0, 0,
2084         "frbtsetwuch?","Set wake up channel",
2085         "=== Command syntax ===\n"
2086         "\n"
2087         "   frbtsetwuch<CHANNEL>\n"
2088         "\n"
2089         "where <CHANNEL> is a character A or B, specifying the channel.\n"
2090         "\n"
2091         "=== Description ===\n"
2092         "\n"
2093         "The command stands for Fr_SetWakeupChannel function from the Autosar\n"
2094         "specification. Wake up channel is the channel, where Wake Up Pattern\n"
2095         "is sent. The channel can be set after the driver and controller are\n"
2096         "initialized and before the communication is running. The actual\n"
2097         "wake-up pattern is sent by the frbtwup command.\n"
2098         "\n"
2099         "=== Example ===\n"
2100         "\n"
2101         "   --> frbtsetwuchA\n"
2102         "   Wake up channel has been set.\n",
2103         CMD_HANDLER(cmd_do_fr_setwuchannel), (void *)&cmd_list_fr_basic_test
2104 };
2105
2106 /** Command descriptor for FlexRay controller get POC status command */
2107 cmd_des_t const cmd_des_fr_getpocstatus={
2108         0, 0,
2109         "frbtgetpocst","Print FlexRay POC status",
2110         "=== Command syntax ===\n"
2111         "\n"
2112         "   frbtgetpocst\n"
2113         "\n"
2114         "=== Description ===\n"
2115         "\n"
2116         "The command stands for Fr_GetPOCStatus function from the Autosar\n"
2117         "specification. It prints the main FlexRay POC status values in the\n"
2118         "form of a table. The command should be called after the frbtinit\n"
2119         "command.\n"
2120         "\n"
2121         "=== Example ===\n"
2122         "\n"
2123         "   --> frbtgetpocst\n"
2124         "   POC status:\n"
2125         "   CHIHaltRequest: FALSE\n"
2126         "   CHIReadyRequest: FALSE\n"
2127         "   ColdstartNoise: FALSE\n"
2128         "   Freeze: FALSE\n"
2129         "   ErrorMode: ACTIVE\n"
2130         "   SlotMode: ALL\n"
2131         "   StartupState: UNDEFINED\n"
2132         "   State: READY\n"
2133         "   WakeupStatus: UNDEFINED\n",
2134         CMD_HANDLER(cmd_do_fr_getpocstatus), (void *)&cmd_list_fr_basic_test
2135 };
2136
2137 /** Command descriptor for FlexRay transmit tx lpdu command */
2138 cmd_des_t const cmd_des_fr_transmittxlpdu={
2139         0, 0,
2140         "frbttransmit*","Transmit data in selected frame",
2141         "=== Command syntax ===\n"
2142         "\n"
2143         "   frbttransmit<FRID> <DATA>\n"
2144         "where\n"
2145         "* <FRID> is a decimal number specifying the ID of the frame for which a buffer has been configured.\n"
2146         "* <DATA> is a sequence of hexadecimal numbers separated by spaces. Each number represents one byte of the message.\n"
2147         "\n"
2148         "=== Description ===\n"
2149         "\n"
2150         "The command stands for Fr_TransmitTxLPdu function from the Autosar\n"
2151         "specification. The command finds the first buffer assigned to the\n"
2152         "specified frame ID and copies the given data into its data section in\n"
2153         "the message RAM. Transmit request is set after the data are copied, so\n"
2154         "transmission starts at the next occurrence of the frame in the\n"
2155         "communication cycle.\n"
2156         "\n"
2157         "=== Example ===\n"
2158         "\n"
2159         "   --> frbttransmit1 12 34 56 AA BB CC\n"
2160         "   Data were set for transmission.\n",
2161         CMD_HANDLER(cmd_do_fr_transmittxlpdu), (void *)&cmd_list_fr_basic_test
2162 };
2163
2164 /** Command descriptor for FlexRay cancel tx lpdu command */
2165 cmd_des_t const cmd_des_fr_canceltxlpdu={
2166         0, 0,
2167         "frbtcanceltx*","Stop the transmission of the frame",
2168         "=== Command syntax ===\n"
2169         "\n"
2170         "   frbtcanceltx<FRID>\n"
2171         "\n"
2172         "where <FRID> is a decimal number specifying the ID of the frame for\n"
2173         "which a buffer has been configured.\n"
2174         "\n"
2175         "=== Description ===\n"
2176         "\n"
2177         "The command stands for Fr_CancelTxLPdu function from the Autosar\n"
2178         "specification. The command finds all buffers assigned to the specified\n"
2179         "frame ID and reconfigures them to stop transmitting data. The command\n"
2180         "finishes successfully only if reconfiguration is allowed in message\n"
2181         "RAM configuration (secureBuffers configuration parameter). Only TX\n"
2182         "buffers and buffers not used for startup frames can be canceled.\n"
2183         "\n"
2184         "=== Example ===\n"
2185         "\n"
2186         "   --> frbtcanceltx3\n"
2187         "   Transmission canceled.\n",
2188         CMD_HANDLER(cmd_do_fr_canceltxlpdu), (void *)&cmd_list_fr_basic_test
2189 };
2190
2191 /** Command descriptor for FlexRay receive rx lpdu command */
2192 cmd_des_t const cmd_des_fr_receiverxlpdu={
2193         0, 0,
2194         "frbtreceive*","Receive a new message",
2195         "=== Command syntax ===\n"
2196         "\n"
2197         "   frbtreceive<FRID>\n"
2198         "\n"
2199         "where <FRID> is a decimal number specifying the ID of the frame for\n"
2200         "which a buffer was configured.\n"
2201         "\n"
2202         "=== Description ===\n"
2203         "\n"
2204         "The command stands for Fr_ReceiveRxLPdu function from the Autosar\n"
2205         "specification. The command finds the first buffer assigned to the\n"
2206         "specified frame ID, determines if a new message has been received and\n"
2207         "reads it out of the buffer. If no message was received, \"No message\n"
2208         "received\" is printed. If a new message was received, all message data\n"
2209         "are printed as a hexadecimal values. If a new message was retrieved\n"
2210         "from a FIFO buffer and more messages are available in it, \"More\n"
2211         "messages are still in FIFO\" is printed.\n"
2212         "\n"
2213         "=== Example ===\n"
2214         "\n"
2215         "   --> frbtreceive0\n"
2216         "   More messages are still in FIFO:\n"
2217         "   Received message (32 B):\n"
2218         "    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",
2219         CMD_HANDLER(cmd_do_fr_receiverxlpdu), (void *)&cmd_list_fr_basic_test
2220 };
2221
2222 /** Command descriptor for FlexRay check TX LPdu status command */
2223 cmd_des_t const cmd_des_fr_checktxlpdustatus={
2224         0, 0,
2225         "frbtchecktx*","Print the status of the transmit buffer",
2226         "=== Command syntax ===\n"
2227         "\n"
2228         "   frbtchecktx<FRID>\n"
2229         "\n"
2230         "where <FRID> is a decimal number specifying the ID of the frame for\n"
2231         "which a buffer has been configured.\n"
2232         "\n"
2233         "=== Description ===\n"
2234         "\n"
2235         "The command stands for Fr_CheckTxLPduStatus function from the Autosar\n"
2236         "specification. The command finds the first buffer assigned to the\n"
2237         "specified frame ID, reads its status and prints it. The buffer can be\n"
2238         "in one of the two states:\n"
2239         "* 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"
2240         "* No message transmission is pending, which means that the buffer is in single shot mode and the message has already been sent.\n"
2241         "\n"
2242         "=== Example ===\n"
2243         "\n"
2244         "   --> frbtchecktx1\n"
2245         "   Message transmission is not pending.\n",
2246         CMD_HANDLER(cmd_do_fr_checktxlpdustatus), (void *)&cmd_list_fr_basic_test
2247 };
2248
2249 /** Command descriptor for FlexRay disable LPdu command */
2250 cmd_des_t const cmd_des_fr_disablelpdu={
2251         0, 0,
2252         "frbtdisable*","Disable the buffers assigned to the frame",
2253         "=== Command syntax ===\n"
2254         "\n"
2255         "   frbtdisable<FRID>\n"
2256         "\n"
2257         "where <FRID> is a decimal number specifying the ID of a frame. The\n"
2258         "buffers configure for this frame will be disabled.\n"
2259         "\n"
2260         "=== Description ===\n"
2261         "\n"
2262         "The command stands for Fr_DisableLPdu function from the Autosar\n"
2263         "specification. The command finds all buffers assigned to the specified\n"
2264         "frame ID and disables them. This means that those buffers will be\n"
2265         "unavailable for the communication until their reconfiguration (which\n"
2266         "is not yet implemented). Buffers used for startup frames and FIFO RX\n"
2267         "buffers cannot be disabled.\n"
2268         "\n"
2269         "=== Example ===\n"
2270         "\n"
2271         "   --> frbtdisable3\n"
2272         "   Buffer disabled.\n",
2273         CMD_HANDLER(cmd_do_fr_disablelpdu), (void *)&cmd_list_fr_basic_test
2274 };
2275
2276 /** Command descriptor for FlexRay get global time command */
2277 cmd_des_t const cmd_des_fr_getglobaltime={
2278         0, 0,
2279         "frbtglobtime","Print actual global time of the network",
2280         "=== Command syntax ===\n"
2281         "\n"
2282         "   frbtglobtime\n"
2283         "\n"
2284         "=== Description ===\n"
2285         "\n"
2286         "The command stands for Fr_GetGlobalTime function from the Autosar\n"
2287         "specification. The command prints the time as a number of the current\n"
2288         "cycle and the offset in the cycle in macroticks.\n"
2289         "\n"
2290         "=== Example ===\n"
2291         "\n"
2292         "   --> frbtglobtime\n"
2293         "   Cycle number: 23\n"
2294         "   Macrotick number: 6\n",
2295         CMD_HANDLER(cmd_do_fr_getglobaltime), (void *)&cmd_list_fr_basic_test
2296 };
2297
2298 /** Command descriptor for FlexRay get network management vector command */
2299 cmd_des_t const cmd_des_fr_getnmvector={
2300         0, 0,
2301         "frbtnmvector","Print network management vector of the node",
2302         "=== Command syntax ===\n"
2303         "\n"
2304         "   frbtnmvector\n"
2305         "\n"
2306         "=== Description ===\n"
2307         "\n"
2308         "The command stands for Fr_GetNmVector function from the Autosar\n"
2309         "specification. It prints the values of the network management vector\n"
2310         "as hexadecimal numbers.\n"
2311         "\n"
2312         "=== Example ===\n"
2313         "\n"
2314         "   --> frbtnmvector\n"
2315         "   Network management vector: 0 0 0 0 0 0 0 0 0 0 0 0\n",
2316         CMD_HANDLER(cmd_do_fr_getnmvector), (void *)&cmd_list_fr_basic_test
2317 };
2318
2319 /** Command descriptor for FlexRay get network management vector command */
2320 cmd_des_t const cmd_des_fr_nmwatch={
2321         0, 0,
2322         "frbtnmwatch","Watch the changes of the network managment vector in real-time",
2323         "=== Command syntax ===\n"
2324         "\n"
2325         "   frbtnmwatch\n"
2326         "\n"
2327         "=== Description ===\n"
2328         "\n"
2329         "Reads the network management vector every 100 ms and prints it out.\n"
2330         "\n"
2331         "=== Example ===\n"
2332         "\n"
2333         "   --> frbtnmwatch\n"
2334         "   Network management vector: 0 0 0 0 0 0 0 0 0 0 0 0\n",
2335         CMD_HANDLER(cmd_do_fr_nmwatch), (void *)&cmd_list_fr_basic_test
2336 };
2337
2338 /** Command descriptor for FlexRay get channel status command */
2339 cmd_des_t const cmd_des_fr_getchannelstatus={
2340         0, 0,
2341         "frbtchstat","Print channel A and B status",
2342         "=== Command syntax ===\n"
2343         "\n"
2344         "   frbtchstat\n"
2345         "\n"
2346         "=== Description ===\n"
2347         "\n"
2348         "The command stands for Fr_GetChannelStatus function from the Autosar\n"
2349         "specification.\n"
2350         "\n"
2351         "=== Example ===\n"
2352         "\n"
2353         "   --> frbtchstat\n"
2354         "   Channel A status:\n"
2355         "       aggregated channel status vSS!ValidFrame: TRUE\n"
2356         "       aggregated channel status vSS!SyntaxError: FALSE\n"
2357         "       aggregated channel status vSS!ContentError: FALSE\n"
2358         "       aggregated channel status additional communication: FALSE\n"
2359         "       aggregated channel status vSS!Bviolation: FALSE\n"
2360         "       aggregated channel status vSS!TxConflict: FALSE\n"
2361         "       Not used (0): FALSE\n"
2362         "       Not used (0): FALSE\n"
2363         "       symbol window status data vSS!ValidMTS: FALSE\n"
2364         "       symbol window status data vSS!SyntaxError: FALSE\n"
2365         "       symbol window status data vSS!Bviolation: FALSE\n"
2366         "       symbol window status data vSS!TxConflict: FALSE\n"
2367         "       NIT status data vSS!SyntaxError: FALSE\n"
2368         "       NIT status data vSS!Bviolation: FALSE\n"
2369         "       Not used (0): FALSE\n"
2370         "       Not used (0): FALSE\n"
2371         "   Channel B status:\n"
2372         "       aggregated channel status vSS!ValidFrame: TRUE\n"
2373         "       aggregated channel status vSS!SyntaxError: FALSE\n"
2374         "       aggregated channel status vSS!ContentError: FALSE\n"
2375         "       aggregated channel status additional communication: FALSE\n"
2376         "       aggregated channel status vSS!Bviolation: FALSE\n"
2377         "       aggregated channel status vSS!TxConflict: FALSE\n"
2378         "       Not used (0): FALSE\n"
2379         "       Not used (0): FALSE\n"
2380         "       symbol window status data vSS!ValidMTS: FALSE\n"
2381         "       symbol window status data vSS!SyntaxError: FALSE\n"
2382         "       symbol window status data vSS!Bviolation: FALSE\n"
2383         "       symbol window status data vSS!TxConflict: FALSE\n"
2384         "       NIT status data vSS!SyntaxError: FALSE\n"
2385         "       NIT status data vSS!Bviolation: FALSE\n"
2386         "       Not used (0): FALSE\n"
2387         "       Not used (0): FALSE\n",
2388         CMD_HANDLER(cmd_do_fr_getchannelstatus), (void *)&cmd_list_fr_basic_test
2389 };
2390
2391 /** Command descriptor for FlexRay get clock correction command */
2392 cmd_des_t const cmd_des_fr_getclockcorrection={
2393         0, 0,
2394         "frbtclkcor","Print clock correction (rate and offset)",
2395         "=== Command syntax ===\n"
2396         "\n"
2397         "   frbtclkcor\n"
2398         "\n"
2399         "=== Description ===\n"
2400         "\n"
2401         "The command stands for Fr_GetClockCorrection function from the Autosar\n"
2402         "specification.\n"
2403         "\n"
2404         "=== Example ===\n"
2405         "\n"
2406         "   --> frbtclkcor\n"
2407         "   Rate correction: 0\n"
2408         "   Offset correction: 0\n",
2409         CMD_HANDLER(cmd_do_fr_getclockcorrection), (void *)&cmd_list_fr_basic_test
2410 };
2411
2412 /** Command descriptor for FlexRay get sync frame list command */
2413 cmd_des_t const cmd_des_fr_getsyncframelist={
2414         0, 0,
2415         "frbtgetsyncfrlist*","Print the list of sync frames transmitted on both channels via the odd and even communication cycle",
2416         "=== Command syntax ===\n"
2417         "\n"
2418         "   frbtgetsyncfrlist<LENGTH>\n"
2419         "\n"
2420         "where <LENGTH> is a decimal number in range 0 - 15, specifying the\n"
2421         "length of the list to be printed.\n"
2422         "\n"
2423         "=== Description ===\n"
2424         "\n"
2425         "The command stands for Fr_GetSyncFrameList function from the Autosar\n"
2426         "specification.\n"
2427         "\n"
2428         "=== Example ===\n"
2429         "\n"
2430         "   --> frbtgetsyncfrlist2\n"
2431         "   | Channel A even | channel B even | channel A odd  | channel B odd  |\n"
2432         "   |----------------|----------------|----------------|----------------|\n"
2433         "   | 1              | 1              | 1              | 1              |\n"
2434         "   | 2              | 2              | 2              | 2              |\n"
2435         "   |----------------|----------------|----------------|----------------|\n",
2436         CMD_HANDLER(cmd_do_fr_getsyncframelist), (void *)&cmd_list_fr_basic_test
2437 };
2438
2439 /** Command descriptor for FlexRay get sync frame list command */
2440 cmd_des_t const cmd_des_fr_getwakeuprxstatus={
2441         0, 0,
2442         "frbtgetwurxstat","Prints whether the wake up pattern has been or has not been received",
2443         "=== Command syntax ===\n"
2444         "\n"
2445         "   frbtgetwurxstat\n"
2446         "\n"
2447         "=== Description ===\n"
2448         "\n"
2449         "The command stands for Fr_GetWakeupRxStatus function from the Autosar\n"
2450         "specification. The status of the wake up receiving is bitcoded in the\n"
2451         "controller. This command decodes and prints it in a readable format.\n"
2452         "\n"
2453         "=== Example ===\n"
2454         "\n"
2455         "   --> frbtgetwurxstat\n"
2456         "   Wake up pattern was not yet received on channel A.\n"
2457         "   Wake up pattern was not yet received on channel B.\n",
2458         CMD_HANDLER(cmd_do_fr_getwakeuprxstatus), (void *)&cmd_list_fr_basic_test
2459 };
2460
2461 /** Command descriptor for FlexRay set absolute timer command */
2462 cmd_des_t const cmd_des_fr_settimer={
2463         0, 0,
2464         "frbtsettimer*","Set and start timer",
2465         "=== Command syntax ===\n"
2466         "\n"
2467         "   frbtsettimer<TMID> <CYCLE> <OFFSET>\n"
2468         "where\n"
2469         "* <TMID> is a number (0, 1) specifying the timer.\n"
2470         "* <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"
2471         "* <OFFSET> is a decimal number (0 - 16383) specifying the offset in macroticks, where precisely in the cycle should be the timer interrupt requested.\n"
2472         "\n"
2473         "=== Description ===\n"
2474         "\n"
2475         "The command is similar to Fr_SetAbsoluteTimer function from the\n"
2476         "Autosar specification. The difference is that the command allows to\n"
2477         "specify a set of cycles, not only one of 64 cycles. It sets the timer\n"
2478         "selected by the parameter and enables it.\n"
2479         "\n"
2480         "Before using this command, FlexRay communication has to be started\n"
2481         "(see frbtstart).\n"
2482         "\n"
2483         "=== Example ===\n"
2484         "\n"
2485         "   --> frbtsettimer0 32 50\n"
2486         "   Timer was set for every 32-th cycle, offset 0, macrotick 50\n"
2487         "   --> frbtsettimer0 31 50\n"
2488         "   Timer was set for every 16-th cycle, offset 15, macrotick 50\n"
2489         "   --> frbtsettimer0 0x42 0\n"
2490         "   Timer was set for every 64-th cycle, offset 2, macrotick 0\n",
2491         CMD_HANDLER(cmd_do_fr_settimer), (void *)&cmd_list_fr_basic_test
2492 };
2493
2494 /** Command descriptor for FlexRay cancel absolute timer command */
2495 cmd_des_t const cmd_des_fr_canceltimer={
2496         0, 0,
2497         "frbtcanceltimer*","Stop the timer",
2498         "=== Command syntax ===\n"
2499         "\n"
2500         "   frbtcanceltimer<TMID>\n"
2501         "where <TMID> is a number (0 or 1) specifying the timer.\n"
2502         "\n"
2503         "=== Description ===\n"
2504         "\n"
2505         "The command stands for Fr_CancelAbsoluteTimer function from the\n"
2506         "Autosar specification. It stops the timer selected by the parameter.\n"
2507         "\n"
2508         "=== Example ===\n"
2509         "\n"
2510         "   --> frbtcanceltimer0\n"
2511         "   Timer was canceled.\n",
2512         CMD_HANDLER(cmd_do_fr_canceltimer), (void *)&cmd_list_fr_basic_test
2513 };
2514
2515 /** Command descriptor for FlexRay absolute timer irq manipulation command */
2516 cmd_des_t const cmd_des_fr_timerirq={
2517         0, 0,
2518         "frbttimerirq*","Perform selected action on the timer IRQ",
2519         "=== Command syntax ===\n"
2520         "\n"
2521         "   frbttimerirq<TMID> <ACTION> - Run the <ACTION> on specified timer\n"
2522         "   frbttimerirq<TMID> - Get timer IRQ status\n"
2523         "\n"
2524         "where\n"
2525         "* <TMID> is a number (0, 1) specifying the timer.\n"
2526         "* where <ACTION> is a string specifying the action  to be performed on the selected timer IRQ.\n"
2527         "\n"
2528         "<ACTIONS> can be one of:\n"
2529         "* EN - Enable the IRQ on the selected timer\n"
2530         "* DIS - Disable the IRQ on the selected timer\n"
2531         "* ACK - Acknowledge the IRQ on the selected timer (reset flag in the register).\n"
2532         "\n"
2533         "=== Description ===\n"
2534         "\n"
2535         "The command stands for Fr_EnableAbsoluteTimerIRQ,\n"
2536         "Fr_AckAbsoluteTimerIRQ, Fr_DisableAbsoluteTimerIRQ and\n"
2537         "Fr_GetAbsoluteTimerIRQStatus functions from the Autosar specification.\n"
2538         "It masks or demasks the IRQ for the timer, or acknowledges the\n"
2539         "interrupt request. If no action is specified it prints whether the IRQ\n"
2540         "is pending for the timer.\n"
2541         "\n"
2542         "=== Example ===\n"
2543         "\n"
2544         "   --> frbttimerirq0\n"
2545         "   IRQ = FALSE\n"
2546         "\n"
2547         "   --> frbttimerirq0 EN\n"
2548         "   OK\n",
2549         CMD_HANDLER(cmd_do_fr_timerirq), (void *)&cmd_list_fr_basic_test
2550 };
2551
2552 /** Command descriptor for FlexRay get version info command */
2553 cmd_des_t const cmd_des_fr_getversioninfo={
2554         0, 0,
2555         "frbtversion","Print FlexRay driver version information",
2556         "=== Command syntax ===\n"
2557         "\n"
2558         "   frbtversion\n"
2559         "\n"
2560         "=== Description ===\n"
2561         "\n"
2562         "The command stands for Fr_GetVersionInfo function from the Autosar\n"
2563         "specification.\n"
2564         "It reads and prints the information about vendor, module and version of\n"
2565         "the FlexRay driver\n"
2566         "\n"
2567         "=== Example ===\n"
2568         "\n"
2569         "   --> frbtversion\n"
2570         "   vendorID: 0xAAAA\n"
2571         "   moduleID: 0xBBBB\n"
2572         "   sw_major_version: 0x1\n"
2573         "   sw_minor_version: 0x2\n"
2574         "   sw_patch_version: 0x4\n",
2575         CMD_HANDLER(cmd_do_fr_getversioninfo), (void *)&cmd_list_fr_basic_test
2576 };
2577
2578 /** Command descriptor for FlexRay get controller configuration command */
2579 cmd_des_t const cmd_des_fr_readcconfig={
2580         0, 0,
2581         "frbtccconfig*","Print value of a FlexRay cluster and node configuration parameter",
2582         "=== Command syntax ===\n"
2583         "\n"
2584         "   frbtccconfig<INDEX>\n"
2585         "\n"
2586         "where <INDEX> is an identifier of the parameter.\n"
2587         "\n"
2588         "=== Description ===\n"
2589         "\n"
2590         "The command stands for Fr_ReadCCConfig function from the Autosar\n"
2591         "specification. The driver stores the configuration parameters as an\n"
2592         "array. Each parameter can be indexed and returned by this command. See\n"
2593         "Autosar specification of the FlexRay driver\n"
2594         "(http://www.autosar.org/download/R4.1/AUTOSAR_SWS_FlexRayDriver.pdf),\n"
2595         "section 8.2.1 for parameter indexes.\n"
2596         "\n"
2597         "=== Example ===\n"
2598         "\n"
2599         "   --> frbtccconfig1\n"
2600         "   Value = 0x1\n",
2601         CMD_HANDLER(cmd_do_fr_readcconfig), (void *)&cmd_list_fr_basic_test
2602 };
2603
2604 /** List of commands for flexRay, defined as external */
2605 cmd_des_t const *cmd_list_fr_basic_test[]={
2606   &cmd_des_fr_user_config,
2607   &cmd_des_fr_config_buffer,
2608   &cmd_des_fr_config_fifo,
2609   &cmd_des_fr_init,
2610   &cmd_des_fr_start,
2611   &cmd_des_fr_allslots,
2612   &cmd_des_fr_halt,
2613   &cmd_des_fr_abort,
2614   &cmd_des_fr_sendwup,
2615   &cmd_des_fr_setwuchannel,
2616   &cmd_des_fr_getpocstatus,
2617   &cmd_des_fr_transmittxlpdu,
2618   &cmd_des_fr_canceltxlpdu,
2619   &cmd_des_fr_receiverxlpdu,
2620   &cmd_des_fr_checktxlpdustatus,
2621   &cmd_des_fr_disablelpdu,
2622   &cmd_des_fr_getglobaltime,
2623   &cmd_des_fr_getnmvector,
2624   &cmd_des_fr_nmwatch,
2625   &cmd_des_fr_getchannelstatus,
2626   &cmd_des_fr_getclockcorrection,
2627   &cmd_des_fr_getsyncframelist,
2628   &cmd_des_fr_getwakeuprxstatus,
2629   &cmd_des_fr_settimer,
2630   &cmd_des_fr_canceltimer,
2631   &cmd_des_fr_timerirq,
2632   &cmd_des_fr_getversioninfo,
2633   &cmd_des_fr_readcconfig,
2634   NULL
2635 };