forked from CANopenNode/CANopenNode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CANopen.c
1517 lines (1362 loc) · 49.2 KB
/
CANopen.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Main CANopenNode file.
*
* @file CANopen.c
* @ingroup CO_CANopen
* @author Janez Paternoster
* @copyright 2010 - 2020 Janez Paternoster
*
* This file is part of CANopenNode, an opensource CANopen Stack.
* Project home page is <https://github.com/CANopenNode/CANopenNode>.
* For more information on CANopen see <http://www.can-cia.org/>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "CANopen.h"
/* Get values from CO_config_t or from single default OD.h ********************/
#ifdef CO_MULTIPLE_OD
#define CO_GET_CO(obj) co->obj
#define CO_GET_CNT(obj) co->config->CNT_##obj
#define OD_GET(entry, index) co->config->ENTRY_##entry
#else
#include "OD.h"
#define CO_GET_CO(obj) CO_##obj
#define CO_GET_CNT(obj) OD_CNT_##obj
#define OD_GET(entry, index) OD_ENTRY_##entry
/* Verify parameters from "OD.h" and calculate necessary values for each object:
* - verify OD_CNT_xx or set default
* - calculate number of CANrx and CYNtx messages: CO_RX_CNT_xx and CO_TX_CNT_xx
* - set optional undefined OD_ENTRY_Hxxxx to NULL.
* - calculate indexes: CO_RX_IDX_xx and CO_TX_IDX_xx
* - calculate total count of CAN message buffers: CO_CNT_ALL_RX_MSGS and
* CO_CNT_ALL_TX_MSGS. */
#if OD_CNT_NMT != 1
#error OD_CNT_NMT from OD.h not correct!
#endif
#define CO_RX_CNT_NMT_SLV OD_CNT_NMT
#if (CO_CONFIG_NMT) & CO_CONFIG_NMT_MASTER
#define CO_TX_CNT_NMT_MST 1
#else
#define CO_TX_CNT_NMT_MST 0
#endif
#if OD_CNT_HB_PROD != 1
#error OD_CNT_HB_PROD from OD.h not correct!
#endif
#define CO_TX_CNT_HB_PROD OD_CNT_HB_PROD
#if !defined OD_CNT_HB_CONS
#define OD_CNT_HB_CONS 0
#elif OD_CNT_HB_CONS < 0 || OD_CNT_HB_CONS > 1
#error OD_CNT_HB_CONS from OD.h not correct!
#endif
#if ((CO_CONFIG_HB_CONS) & CO_CONFIG_HB_CONS_ENABLE) && OD_CNT_HB_CONS == 1
#if OD_CNT_ARR_1016 < 1 || OD_CNT_ARR_1016 > 127
#error OD_CNT_ARR_1016 is not defined in Object Dictionary or value is wrong!
#endif
#define CO_RX_CNT_HB_CONS OD_CNT_ARR_1016
#else
#define CO_RX_CNT_HB_CONS 0
#endif
#if OD_CNT_EM != 1
#error OD_CNT_EM from OD.h not correct!
#endif
#ifndef OD_ENTRY_H1003
#define OD_ENTRY_H1003 NULL
#endif
#ifndef OD_CNT_ARR_1003
#define OD_CNT_ARR_1003 8
#endif
#if (CO_CONFIG_EM) & CO_CONFIG_EM_PRODUCER
#if OD_CNT_EM_PROD == 1
#define CO_TX_CNT_EM_PROD OD_CNT_EM_PROD
#else
#error wrong OD_CNT_EM_PROD
#endif
#ifndef OD_ENTRY_H1015
#define OD_ENTRY_H1015 NULL
#endif
#else
#define CO_TX_CNT_EM_PROD 0
#endif
#if (CO_CONFIG_EM) & CO_CONFIG_EM_CONSUMER
#define CO_RX_CNT_EM_CONS 1
#else
#define CO_RX_CNT_EM_CONS 0
#endif
#if !defined OD_CNT_SDO_SRV
#define OD_CNT_SDO_SRV 1
#define OD_ENTRY_H1200 NULL
#elif OD_CNT_SDO_SRV < 1 || OD_CNT_SDO_SRV > 128
#error OD_CNT_SDO_SRV from OD.h not correct!
#endif
#define CO_RX_CNT_SDO_SRV OD_CNT_SDO_SRV
#define CO_TX_CNT_SDO_SRV OD_CNT_SDO_SRV
#if (CO_CONFIG_SDO_CLI) & CO_CONFIG_SDO_CLI_ENABLE
#if !defined OD_CNT_SDO_CLI
#define OD_CNT_SDO_CLI 0
#define OD_ENTRY_H1280 NULL
#elif OD_CNT_SDO_CLI < 0 || OD_CNT_SDO_CLI > 128
#error OD_CNT_SDO_CLI from OD.h not correct!
#endif
#define CO_RX_CNT_SDO_CLI OD_CNT_SDO_CLI
#define CO_TX_CNT_SDO_CLI OD_CNT_SDO_CLI
#else
#define CO_RX_CNT_SDO_CLI 0
#define CO_TX_CNT_SDO_CLI 0
#endif
#if (CO_CONFIG_TIME) & CO_CONFIG_TIME_ENABLE
#if !defined OD_CNT_TIME
#define OD_CNT_TIME 0
#define OD_ENTRY_H1012 NULL
#elif OD_CNT_TIME < 0 || OD_CNT_TIME > 1
#error OD_CNT_TIME from OD.h not correct!
#endif
#define CO_RX_CNT_TIME OD_CNT_TIME
#if (CO_CONFIG_TIME) & CO_CONFIG_TIME_PRODUCER
#define CO_TX_CNT_TIME OD_CNT_TIME
#else
#define CO_TX_CNT_TIME 0
#endif
#else
#define CO_RX_CNT_TIME 0
#define CO_TX_CNT_TIME 0
#endif
#if (CO_CONFIG_SYNC) & CO_CONFIG_SYNC_ENABLE
#if !defined OD_CNT_SYNC
#define OD_CNT_SYNC 0
#define OD_ENTRY_H1005 NULL
#define OD_ENTRY_H1006 NULL
#elif OD_CNT_SYNC < 0 || OD_CNT_SYNC > 1
#error OD_CNT_SYNC from OD.h not correct!
#endif
#define CO_RX_CNT_SYNC OD_CNT_SYNC
#if (CO_CONFIG_SYNC) & CO_CONFIG_SYNC_PRODUCER
#define CO_TX_CNT_SYNC OD_CNT_SYNC
#else
#define CO_TX_CNT_SYNC 0
#endif
#ifndef OD_ENTRY_H1007
#define OD_ENTRY_H1007 NULL
#endif
#ifndef OD_ENTRY_H1019
#define OD_ENTRY_H1019 NULL
#endif
#else
#define CO_RX_CNT_SYNC 0
#define CO_TX_CNT_SYNC 0
#endif
#if (CO_CONFIG_PDO) & CO_CONFIG_RPDO_ENABLE
#if !defined OD_CNT_RPDO
#define OD_CNT_RPDO 0
#define OD_ENTRY_H1400 NULL
#define OD_ENTRY_H1600 NULL
#elif OD_CNT_RPDO < 0 || OD_CNT_RPDO > 0x200
#error OD_CNT_RPDO from OD.h not correct!
#endif
#define CO_RX_CNT_RPDO OD_CNT_RPDO
#else
#define CO_RX_CNT_RPDO 0
#endif
#if (CO_CONFIG_PDO) & CO_CONFIG_TPDO_ENABLE
#if !defined OD_CNT_TPDO
#define OD_CNT_TPDO 0
#define OD_ENTRY_H1800 NULL
#define OD_ENTRY_H1A00 NULL
#elif OD_CNT_TPDO < 0 || OD_CNT_TPDO > 0x200
#error OD_CNT_TPDO from OD.h not correct!
#endif
#define CO_TX_CNT_TPDO OD_CNT_TPDO
#else
#define CO_TX_CNT_TPDO 0
#endif
#if (CO_CONFIG_LEDS) & CO_CONFIG_LEDS_ENABLE
#define OD_CNT_LEDS 1
#endif
#if (CO_CONFIG_GFC) & CO_CONFIG_GFC_ENABLE
#if !defined OD_CNT_GFC
#define OD_CNT_GFC 0
#define OD_ENTRY_H1300 NULL
#elif OD_CNT_GFC < 0 || OD_CNT_GFC > 1
#error OD_CNT_GFC from OD.h not correct!
#endif
#define CO_RX_CNT_GFC OD_CNT_GFC
#define CO_TX_CNT_GFC OD_CNT_GFC
#else
#define CO_RX_CNT_GFC 0
#define CO_TX_CNT_GFC 0
#endif
#if (CO_CONFIG_SRDO) & CO_CONFIG_SRDO_ENABLE
#if !defined OD_CNT_SRDO
#define OD_CNT_SRDO 0
#define OD_ENTRY_H1301 NULL
#define OD_ENTRY_H1381 NULL
#define OD_ENTRY_H13FE NULL
#define OD_ENTRY_H13FF NULL
#elif OD_CNT_SRDO < 0 || OD_CNT_SRDO > 64
#error OD_CNT_SRDO from OD.h not correct!
#endif
#define CO_RX_CNT_SRDO OD_CNT_SRDO
#define CO_TX_CNT_SRDO OD_CNT_SRDO
#else
#define CO_RX_CNT_SRDO 0
#define CO_TX_CNT_SRDO 0
#endif
#if (CO_CONFIG_LSS) & CO_CONFIG_LSS_SLAVE
#define OD_CNT_LSS_SLV 1
#else
#define OD_CNT_LSS_SLV 0
#endif
#define CO_RX_CNT_LSS_SLV OD_CNT_LSS_SLV
#define CO_TX_CNT_LSS_SLV OD_CNT_LSS_SLV
#if (CO_CONFIG_LSS) & CO_CONFIG_LSS_MASTER
#define OD_CNT_LSS_MST 1
#else
#define OD_CNT_LSS_MST 0
#endif
#define CO_RX_CNT_LSS_MST OD_CNT_LSS_MST
#define CO_TX_CNT_LSS_MST OD_CNT_LSS_MST
#if (CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII
#define OD_CNT_GTWA 1
#endif
#if (CO_CONFIG_TRACE) & CO_CONFIG_TRACE_ENABLE
#if !defined OD_CNT_TRACE
#define OD_CNT_TRACE 0
#elif OD_CNT_TRACE < 0
#error OD_CNT_TRACE from OD.h not correct!
#endif
#endif
/* Indexes of CO_CANrx_t and CO_CANtx_t objects in CO_CANmodule_t and total
* number of them. Indexes are sorted in a way, that objects with highest
* priority of the CAN identifier are listed first. */
#define CO_RX_IDX_NMT_SLV 0
#define CO_RX_IDX_SYNC (CO_RX_IDX_NMT_SLV + CO_RX_CNT_NMT_SLV)
#define CO_RX_IDX_EM_CONS (CO_RX_IDX_SYNC + CO_RX_CNT_SYNC)
#define CO_RX_IDX_TIME (CO_RX_IDX_EM_CONS + CO_RX_CNT_EM_CONS)
#define CO_RX_IDX_GFC (CO_RX_IDX_TIME + CO_RX_CNT_TIME)
#define CO_RX_IDX_SRDO (CO_RX_IDX_GFC + CO_RX_CNT_GFC)
#define CO_RX_IDX_RPDO (CO_RX_IDX_SRDO + CO_RX_CNT_SRDO * 2)
#define CO_RX_IDX_SDO_SRV (CO_RX_IDX_RPDO + CO_RX_CNT_RPDO)
#define CO_RX_IDX_SDO_CLI (CO_RX_IDX_SDO_SRV + CO_RX_CNT_SDO_SRV)
#define CO_RX_IDX_HB_CONS (CO_RX_IDX_SDO_CLI + CO_RX_CNT_SDO_CLI)
#define CO_RX_IDX_LSS_SLV (CO_RX_IDX_HB_CONS + CO_RX_CNT_HB_CONS)
#define CO_RX_IDX_LSS_MST (CO_RX_IDX_LSS_SLV + CO_RX_CNT_LSS_SLV)
#define CO_CNT_ALL_RX_MSGS (CO_RX_IDX_LSS_MST + CO_RX_CNT_LSS_MST)
#define CO_TX_IDX_NMT_MST 0
#define CO_TX_IDX_SYNC (CO_TX_IDX_NMT_MST + CO_TX_CNT_NMT_MST)
#define CO_TX_IDX_EM_PROD (CO_TX_IDX_SYNC + CO_TX_CNT_SYNC)
#define CO_TX_IDX_TIME (CO_TX_IDX_EM_PROD + CO_TX_CNT_EM_PROD)
#define CO_TX_IDX_GFC (CO_TX_IDX_TIME + CO_TX_CNT_TIME)
#define CO_TX_IDX_SRDO (CO_TX_IDX_GFC + CO_TX_CNT_GFC)
#define CO_TX_IDX_TPDO (CO_TX_IDX_SRDO + CO_TX_CNT_SRDO * 2)
#define CO_TX_IDX_SDO_SRV (CO_TX_IDX_TPDO + CO_TX_CNT_TPDO)
#define CO_TX_IDX_SDO_CLI (CO_TX_IDX_SDO_SRV + CO_TX_CNT_SDO_SRV)
#define CO_TX_IDX_HB_PROD (CO_TX_IDX_SDO_CLI + CO_TX_CNT_SDO_CLI)
#define CO_TX_IDX_LSS_SLV (CO_TX_IDX_HB_PROD + CO_TX_CNT_HB_PROD)
#define CO_TX_IDX_LSS_MST (CO_TX_IDX_LSS_SLV + CO_TX_CNT_LSS_SLV)
#define CO_CNT_ALL_TX_MSGS (CO_TX_IDX_LSS_MST + CO_TX_CNT_LSS_MST)
#endif /* #ifdef #else CO_MULTIPLE_OD */
/* Objects from heap **********************************************************/
#ifndef CO_USE_GLOBALS
#include <stdlib.h>
/* Default allocation strategy ************************************************/
#if !defined(CO_alloc) || !defined(CO_free)
#if defined(CO_alloc)
#warning CO_alloc is defined but CO_free is not. using default values instead
#undef CO_alloc
#endif
#if defined(CO_free)
#warning CO_free is defined but CO_alloc is not. using default values instead
#undef CO_free
#endif
/*
* Allocate memory for number of elements, each of specific size
* Allocated memory must be reset to all zeros
*/
#define CO_alloc(num, size) calloc((num), (size))
#define CO_free(ptr) free((ptr))
#endif
/* Define macros for allocation */
#define CO_alloc_break_on_fail(var, num, size) if (((var) = CO_alloc((num), (size))) != NULL) { mem += (size) * (num); } else { break; }
#ifdef CO_MULTIPLE_OD
#define ON_MULTI_OD(sentence) sentence
#else
#define ON_MULTI_OD(sentence)
#endif
CO_t *CO_new(CO_config_t *config, uint32_t *heapMemoryUsed) {
CO_t *co = NULL;
/* return values */
CO_t *coFinal = NULL;
uint32_t mem = 0;
/* For each object:
* - allocate memory, verify allocation and calculate size of heap used
* - if CO_MULTIPLE_OD is defined:
* - use config structure
* - calculate number of CANrx and CYNtx messages: RX_CNT_xx and TX_CNT_xx
* - calculate indexes: RX_IDX_xx and TX_IDX_xx
* - calculate total count of CAN message buffers: CNT_ALL_RX_MSGS and
* CNT_ALL_TX_MSGS. */
do {
#ifdef CO_MULTIPLE_OD
/* verify arguments */
if (config == NULL || config->CNT_NMT > 1 || config->CNT_HB_CONS > 1
|| config->CNT_EM > 1 || config->CNT_SDO_SRV > 128
|| config->CNT_SDO_CLI > 128 || config->CNT_SYNC > 1
|| config->CNT_RPDO > 512 || config->CNT_TPDO > 512
|| config->CNT_TIME > 1 || config->CNT_LEDS > 1
|| config->CNT_GFC > 1 || config->CNT_SRDO > 64
|| config->CNT_LSS_SLV > 1 || config->CNT_LSS_MST > 1
|| config->CNT_GTWA > 1
) {
break;
}
#else
(void) config;
#endif
/* CANopen object */
CO_alloc_break_on_fail(co, 1, sizeof(*co));
#ifdef CO_MULTIPLE_OD
co->config = config;
#endif
/* NMT_Heartbeat */
ON_MULTI_OD(uint8_t RX_CNT_NMT_SLV = 0);
ON_MULTI_OD(uint8_t TX_CNT_NMT_MST = 0);
ON_MULTI_OD(uint8_t TX_CNT_HB_PROD = 0);
if (CO_GET_CNT(NMT) == 1) {
CO_alloc_break_on_fail(co->NMT, CO_GET_CNT(NMT), sizeof(*co->NMT));
ON_MULTI_OD(RX_CNT_NMT_SLV = 1);
#if (CO_CONFIG_NMT) & CO_CONFIG_NMT_MASTER
ON_MULTI_OD(TX_CNT_NMT_MST = 1);
#endif
ON_MULTI_OD(TX_CNT_HB_PROD = 1);
}
#if (CO_CONFIG_HB_CONS) & CO_CONFIG_HB_CONS_ENABLE
ON_MULTI_OD(uint8_t RX_CNT_HB_CONS = 0);
if (CO_GET_CNT(HB_CONS) == 1) {
uint8_t countOfMonitoredNodes = CO_GET_CNT(ARR_1016);
CO_alloc_break_on_fail(co->HBcons, CO_GET_CNT(HB_CONS), sizeof(*co->HBcons));
CO_alloc_break_on_fail(co->HBconsMonitoredNodes, countOfMonitoredNodes, sizeof(*co->HBconsMonitoredNodes));
ON_MULTI_OD(RX_CNT_HB_CONS = countOfMonitoredNodes);
}
#endif
/* Emergency */
ON_MULTI_OD(uint8_t RX_CNT_EM_CONS = 0);
ON_MULTI_OD(uint8_t TX_CNT_EM_PROD = 0);
if (CO_GET_CNT(EM) == 1) {
CO_alloc_break_on_fail(co->em, CO_GET_CNT(EM), sizeof(*co->em));
#if (CO_CONFIG_EM) & CO_CONFIG_EM_CONSUMER
ON_MULTI_OD(RX_CNT_EM_CONS = 1);
#endif
#if (CO_CONFIG_EM) & CO_CONFIG_EM_PRODUCER
ON_MULTI_OD(TX_CNT_EM_PROD = 1);
#endif
#if (CO_CONFIG_EM) & (CO_CONFIG_EM_PRODUCER | CO_CONFIG_EM_HISTORY)
uint8_t fifoSize = CO_GET_CNT(ARR_1003) + 1;
if (fifoSize >= 2) {
CO_alloc_break_on_fail(co->em_fifo, fifoSize, sizeof(*co->em_fifo));
}
#endif
}
/* SDOserver */
ON_MULTI_OD(uint8_t RX_CNT_SDO_SRV = 0);
ON_MULTI_OD(uint8_t TX_CNT_SDO_SRV = 0);
if (CO_GET_CNT(SDO_SRV) > 0) {
CO_alloc_break_on_fail(co->SDOserver, CO_GET_CNT(SDO_SRV), sizeof(*co->SDOserver));
ON_MULTI_OD(RX_CNT_SDO_SRV = config->CNT_SDO_SRV);
ON_MULTI_OD(TX_CNT_SDO_SRV = config->CNT_SDO_SRV);
}
#if (CO_CONFIG_SDO_CLI) & CO_CONFIG_SDO_CLI_ENABLE
ON_MULTI_OD(uint8_t RX_CNT_SDO_CLI = 0);
ON_MULTI_OD(uint8_t TX_CNT_SDO_CLI = 0);
if (CO_GET_CNT(SDO_CLI) > 0) {
CO_alloc_break_on_fail(co->SDOclient, CO_GET_CNT(SDO_CLI), sizeof(*co->SDOclient));
ON_MULTI_OD(RX_CNT_SDO_CLI = config->CNT_SDO_CLI);
ON_MULTI_OD(TX_CNT_SDO_CLI = config->CNT_SDO_CLI);
}
#endif
#if (CO_CONFIG_TIME) & CO_CONFIG_TIME_ENABLE
ON_MULTI_OD(uint8_t RX_CNT_TIME = 0);
ON_MULTI_OD(uint8_t TX_CNT_TIME = 0);
if (CO_GET_CNT(TIME) == 1) {
CO_alloc_break_on_fail(co->TIME, CO_GET_CNT(TIME), sizeof(*co->TIME));
ON_MULTI_OD(RX_CNT_TIME = 1);
#if (CO_CONFIG_TIME) & CO_CONFIG_TIME_PRODUCER
ON_MULTI_OD(TX_CNT_TIME = 1);
#endif
}
#endif
#if (CO_CONFIG_SYNC) & CO_CONFIG_SYNC_ENABLE
ON_MULTI_OD(uint8_t RX_CNT_SYNC = 0);
ON_MULTI_OD(uint8_t TX_CNT_SYNC = 0);
if (CO_GET_CNT(SYNC) == 1) {
CO_alloc_break_on_fail(co->SYNC, CO_GET_CNT(SYNC), sizeof(*co->SYNC));
ON_MULTI_OD(RX_CNT_SYNC = 1);
#if (CO_CONFIG_SYNC) & CO_CONFIG_SYNC_PRODUCER
ON_MULTI_OD(TX_CNT_SYNC = 1);
#endif
}
#endif
#if (CO_CONFIG_PDO) & CO_CONFIG_RPDO_ENABLE
ON_MULTI_OD(uint16_t RX_CNT_RPDO = 0);
if (CO_GET_CNT(RPDO) > 0) {
CO_alloc_break_on_fail(co->RPDO, CO_GET_CNT(RPDO), sizeof(*co->RPDO));
ON_MULTI_OD(RX_CNT_RPDO = config->CNT_RPDO);
}
#endif
#if (CO_CONFIG_PDO) & CO_CONFIG_TPDO_ENABLE
ON_MULTI_OD(uint16_t TX_CNT_TPDO = 0);
if (CO_GET_CNT(TPDO) > 0) {
CO_alloc_break_on_fail(co->TPDO, CO_GET_CNT(TPDO), sizeof(*co->TPDO));
ON_MULTI_OD(TX_CNT_TPDO = config->CNT_TPDO);
}
#endif
#if (CO_CONFIG_LEDS) & CO_CONFIG_LEDS_ENABLE
if (CO_GET_CNT(LEDS) == 1) {
CO_alloc_break_on_fail(co->LEDs, CO_GET_CNT(LEDS), sizeof(*co->LEDs));
}
#endif
#if (CO_CONFIG_GFC) & CO_CONFIG_GFC_ENABLE
ON_MULTI_OD(uint8_t RX_CNT_GFC = 0);
ON_MULTI_OD(uint8_t TX_CNT_GFC = 0);
if (CO_GET_CNT(GFC) == 1) {
CO_alloc_break_on_fail(co->GFC, CO_GET_CNT(GFC), sizeof(*co->GFC));
ON_MULTI_OD(RX_CNT_GFC = 1);
ON_MULTI_OD(TX_CNT_GFC = 1);
}
#endif
#if (CO_CONFIG_SRDO) & CO_CONFIG_SRDO_ENABLE
ON_MULTI_OD(uint8_t RX_CNT_SRDO = 0);
ON_MULTI_OD(uint8_t TX_CNT_SRDO = 0);
if (CO_GET_CNT(SRDO) > 0) {
CO_alloc_break_on_fail(co->SRDOGuard, 1, sizeof(*co->SRDOGuard));
CO_alloc_break_on_fail(co->SRDO, CO_GET_CNT(SRDO), sizeof(*co->SRDO));
ON_MULTI_OD(RX_CNT_SRDO = config->CNT_SRDO * 2);
ON_MULTI_OD(TX_CNT_SRDO = config->CNT_SRDO * 2);
}
#endif
#if (CO_CONFIG_LSS) & CO_CONFIG_LSS_SLAVE
ON_MULTI_OD(uint8_t RX_CNT_LSS_SLV = 0);
ON_MULTI_OD(uint8_t TX_CNT_LSS_SLV = 0);
if (CO_GET_CNT(LSS_SLV) == 1) {
CO_alloc_break_on_fail(co->LSSslave, CO_GET_CNT(LSS_SLV), sizeof(*co->LSSslave));
ON_MULTI_OD(RX_CNT_LSS_SLV = 1);
ON_MULTI_OD(TX_CNT_LSS_SLV = 1);
}
#endif
#if (CO_CONFIG_LSS) & CO_CONFIG_LSS_MASTER
ON_MULTI_OD(uint8_t RX_CNT_LSS_MST = 0);
ON_MULTI_OD(uint8_t TX_CNT_LSS_MST = 0);
if (CO_GET_CNT(LSS_MST) == 1) {
CO_alloc_break_on_fail(co->LSSmaster, CO_GET_CNT(LSS_MST), sizeof(*co->LSSmaster));
ON_MULTI_OD(RX_CNT_LSS_MST = 1);
ON_MULTI_OD(TX_CNT_LSS_MST = 1);
}
#endif
#if (CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII
if (CO_GET_CNT(GTWA) == 1) {
CO_alloc_break_on_fail(co->gtwa, CO_GET_CNT(GTWA), sizeof(*co->gtwa));
}
#endif
#if (CO_CONFIG_TRACE) & CO_CONFIG_TRACE_ENABLE
if (CO_GET_CNT(TRACE) > 0) {
CO_alloc_break_on_fail(co->trace, CO_GET_CNT(TRACE), sizeof(*co->trace));
}
#endif
#ifdef CO_MULTIPLE_OD
/* Indexes of CO_CANrx_t and CO_CANtx_t objects in CO_CANmodule_t and
* total number of them. Indexes are sorted in a way, that objects with
* highest priority of the CAN identifier are listed first. */
int16_t idxRx = 0;
co->RX_IDX_NMT_SLV = idxRx; idxRx += RX_CNT_NMT_SLV;
#if (CO_CONFIG_SYNC) & CO_CONFIG_SYNC_ENABLE
co->RX_IDX_SYNC = idxRx; idxRx += RX_CNT_SYNC;
#endif
co->RX_IDX_EM_CONS = idxRx; idxRx += RX_CNT_EM_CONS;
#if (CO_CONFIG_TIME) & CO_CONFIG_TIME_ENABLE
co->RX_IDX_TIME = idxRx; idxRx += RX_CNT_TIME;
#endif
#if (CO_CONFIG_GFC) & CO_CONFIG_GFC_ENABLE
co->RX_IDX_GFC = idxRx; idxRx += RX_CNT_GFC;
#endif
#if (CO_CONFIG_SRDO) & CO_CONFIG_SRDO_ENABLE
co->RX_IDX_SRDO = idxRx; idxRx += RX_CNT_SRDO * 2;
#endif
#if (CO_CONFIG_PDO) & CO_CONFIG_RPDO_ENABLE
co->RX_IDX_RPDO = idxRx; idxRx += RX_CNT_RPDO;
#endif
co->RX_IDX_SDO_SRV = idxRx; idxRx += RX_CNT_SDO_SRV;
#if (CO_CONFIG_SDO_CLI) & CO_CONFIG_SDO_CLI_ENABLE
co->RX_IDX_SDO_CLI = idxRx; idxRx += RX_CNT_SDO_CLI;
#endif
#if (CO_CONFIG_HB_CONS) & CO_CONFIG_HB_CONS_ENABLE
co->RX_IDX_HB_CONS = idxRx; idxRx += RX_CNT_HB_CONS;
#endif
#if (CO_CONFIG_LSS) & CO_CONFIG_LSS_SLAVE
co->RX_IDX_LSS_SLV = idxRx; idxRx += RX_CNT_LSS_SLV;
#endif
#if (CO_CONFIG_LSS) & CO_CONFIG_LSS_MASTER
co->RX_IDX_LSS_MST = idxRx; idxRx += RX_CNT_LSS_MST;
#endif
co->CNT_ALL_RX_MSGS = idxRx;
int16_t idxTx = 0;
co->TX_IDX_NMT_MST = idxTx; idxTx += TX_CNT_NMT_MST;
#if (CO_CONFIG_SYNC) & CO_CONFIG_SYNC_ENABLE
co->TX_IDX_SYNC = idxTx; idxTx += TX_CNT_SYNC;
#endif
co->TX_IDX_EM_PROD = idxTx; idxTx += TX_CNT_EM_PROD;
#if (CO_CONFIG_TIME) & CO_CONFIG_TIME_ENABLE
co->TX_IDX_TIME = idxTx; idxTx += TX_CNT_TIME;
#endif
#if (CO_CONFIG_GFC) & CO_CONFIG_GFC_ENABLE
co->TX_IDX_GFC = idxTx; idxTx += TX_CNT_GFC;
#endif
#if (CO_CONFIG_SRDO) & CO_CONFIG_SRDO_ENABLE
co->TX_IDX_SRDO = idxTx; idxTx += TX_CNT_SRDO * 2;
#endif
#if (CO_CONFIG_PDO) & CO_CONFIG_TPDO_ENABLE
co->TX_IDX_TPDO = idxTx; idxTx += TX_CNT_TPDO;
#endif
co->TX_IDX_SDO_SRV = idxTx; idxTx += TX_CNT_SDO_SRV;
#if (CO_CONFIG_SDO_CLI) & CO_CONFIG_SDO_CLI_ENABLE
co->TX_IDX_SDO_CLI = idxTx; idxTx += TX_CNT_SDO_CLI;
#endif
co->TX_IDX_HB_PROD = idxTx; idxTx += TX_CNT_HB_PROD;
#if (CO_CONFIG_LSS) & CO_CONFIG_LSS_SLAVE
co->TX_IDX_LSS_SLV = idxTx; idxTx += TX_CNT_LSS_SLV;
#endif
#if (CO_CONFIG_LSS) & CO_CONFIG_LSS_MASTER
co->TX_IDX_LSS_MST = idxTx; idxTx += TX_CNT_LSS_MST;
#endif
co->CNT_ALL_TX_MSGS = idxTx;
#endif /* #ifdef CO_MULTIPLE_OD */
/* CANmodule */
CO_alloc_break_on_fail(co->CANmodule, 1, sizeof(*co->CANmodule));
/* CAN RX blocks */
CO_alloc_break_on_fail(co->CANrx, CO_GET_CO(CNT_ALL_RX_MSGS), sizeof(*co->CANrx));
/* CAN TX blocks */
CO_alloc_break_on_fail(co->CANtx, CO_GET_CO(CNT_ALL_TX_MSGS), sizeof(*co->CANtx));
/* finish successfully, set other parameters */
co->nodeIdUnconfigured = true;
coFinal = co;
} while (false);
if (coFinal == NULL) {
CO_delete(co);
}
if (heapMemoryUsed != NULL) {
*heapMemoryUsed = mem;
}
return coFinal;
}
void CO_delete(CO_t *co) {
if (co == NULL) {
return;
}
CO_CANmodule_disable(co->CANmodule);
/* CANmodule */
CO_free(co->CANtx);
CO_free(co->CANrx);
CO_free(co->CANmodule);
#if (CO_CONFIG_TRACE) & CO_CONFIG_TRACE_ENABLE
CO_free(co->trace);
#endif
#if (CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII
CO_free(co->gtwa);
#endif
#if (CO_CONFIG_LSS) & CO_CONFIG_LSS_MASTER
CO_free(co->LSSmaster);
#endif
#if (CO_CONFIG_LSS) & CO_CONFIG_LSS_SLAVE
CO_free(co->LSSslave);
#endif
#if (CO_CONFIG_SRDO) & CO_CONFIG_SRDO_ENABLE
CO_free(co->SRDO);
CO_free(co->SRDOGuard);
#endif
#if (CO_CONFIG_GFC) & CO_CONFIG_GFC_ENABLE
CO_free(co->GFC);
#endif
#if (CO_CONFIG_LEDS) & CO_CONFIG_LEDS_ENABLE
CO_free(co->LEDs);
#endif
#if (CO_CONFIG_PDO) & CO_CONFIG_TPDO_ENABLE
CO_free(co->TPDO);
#endif
#if (CO_CONFIG_PDO) & CO_CONFIG_RPDO_ENABLE
CO_free(co->RPDO);
#endif
#if (CO_CONFIG_SYNC) & CO_CONFIG_SYNC_ENABLE
CO_free(co->SYNC);
#endif
#if (CO_CONFIG_TIME) & CO_CONFIG_TIME_ENABLE
CO_free(co->TIME);
#endif
#if (CO_CONFIG_SDO_CLI) & CO_CONFIG_SDO_CLI_ENABLE
free(co->SDOclient);
#endif
/* SDOserver */
CO_free(co->SDOserver);
/* Emergency */
CO_free(co->em);
#if (CO_CONFIG_EM) & (CO_CONFIG_EM_PRODUCER | CO_CONFIG_EM_HISTORY)
CO_free(co->em_fifo);
#endif
#if (CO_CONFIG_HB_CONS) & CO_CONFIG_HB_CONS_ENABLE
CO_free(co->HBconsMonitoredNodes);
CO_free(co->HBcons);
#endif
/* NMT_Heartbeat */
CO_free(co->NMT);
/* CANopen object */
CO_free(co);
}
#endif /* #ifndef CO_USE_GLOBALS */
/* Objects as globals *********************************************************/
#ifdef CO_USE_GLOBALS
#ifdef CO_MULTIPLE_OD
#error CO_MULTIPLE_OD can not be used with CO_USE_GLOBALS
#endif
static CO_t COO;
static CO_CANmodule_t COO_CANmodule;
static CO_CANrx_t COO_CANmodule_rxArray[CO_CNT_ALL_RX_MSGS];
static CO_CANtx_t COO_CANmodule_txArray[CO_CNT_ALL_TX_MSGS];
static CO_NMT_t COO_NMT;
#if (CO_CONFIG_HB_CONS) & CO_CONFIG_HB_CONS_ENABLE
static CO_HBconsumer_t COO_HBcons;
static CO_HBconsNode_t COO_HBconsMonitoredNodes[OD_CNT_ARR_1016];
#endif
static CO_EM_t COO_EM;
#if (CO_CONFIG_EM) & (CO_CONFIG_EM_PRODUCER | CO_CONFIG_EM_HISTORY)
static CO_EM_fifo_t COO_EM_FIFO[CO_GET_CNT(ARR_1003) + 1];
#endif
static CO_SDOserver_t COO_SDOserver[OD_CNT_SDO_SRV];
#if (CO_CONFIG_SDO_CLI) & CO_CONFIG_SDO_CLI_ENABLE
static CO_SDOclient_t COO_SDOclient[OD_CNT_SDO_CLI];
#endif
#if (CO_CONFIG_TIME) & CO_CONFIG_TIME_ENABLE
static CO_TIME_t COO_TIME;
#endif
#if (CO_CONFIG_SYNC) & CO_CONFIG_SYNC_ENABLE
static CO_SYNC_t COO_SYNC;
#endif
#if (CO_CONFIG_PDO) & CO_CONFIG_RPDO_ENABLE
static CO_RPDO_t COO_RPDO[OD_CNT_RPDO];
#endif
#if (CO_CONFIG_PDO) & CO_CONFIG_TPDO_ENABLE
static CO_TPDO_t COO_TPDO[OD_CNT_TPDO];
#endif
#if (CO_CONFIG_LEDS) & CO_CONFIG_LEDS_ENABLE
static CO_LEDs_t COO_LEDs;
#endif
#if (CO_CONFIG_GFC) & CO_CONFIG_GFC_ENABLE
static CO_GFC_t COO_GFC;
#endif
#if (CO_CONFIG_SRDO) & CO_CONFIG_SRDO_ENABLE
static CO_SRDOGuard_t COO_SRDOGuard;
static CO_SRDO_t COO_SRDO[OD_CNT_SRDO];
#endif
#if (CO_CONFIG_LSS) & CO_CONFIG_LSS_SLAVE
static CO_LSSslave_t COO_LSSslave;
#endif
#if (CO_CONFIG_LSS) & CO_CONFIG_LSS_MASTER
static CO_LSSmaster_t COO_LSSmaster;
#endif
#if (CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII
static CO_GTWA_t COO_gtwa;
#endif
#if (CO_CONFIG_TRACE) & CO_CONFIG_TRACE_ENABLE
#ifndef CO_TRACE_BUFFER_SIZE_FIXED
#define CO_TRACE_BUFFER_SIZE_FIXED 100
#endif
static CO_trace_t COO_trace[OD_CNT_TRACE];
static uint32_t COO_traceTimeBuffers[OD_CNT_TRACE][CO_TRACE_BUFFER_SIZE_FIXED];
static int32_t COO_traceValueBuffers[OD_CNT_TRACE][CO_TRACE_BUFFER_SIZE_FIXED];
#endif
CO_t *CO_new(CO_config_t *config, uint32_t *heapMemoryUsed) {
(void)config; (void)heapMemoryUsed;
CO_t *co = &COO;
co->CANmodule = &COO_CANmodule;
co->CANrx = &COO_CANmodule_rxArray[0];
co->CANtx = &COO_CANmodule_txArray[0];
co->NMT = &COO_NMT;
#if (CO_CONFIG_HB_CONS) & CO_CONFIG_HB_CONS_ENABLE
co->HBcons = &COO_HBcons;
co->HBconsMonitoredNodes = &COO_HBconsMonitoredNodes[0];
#endif
co->em = &COO_EM;
#if (CO_CONFIG_EM) & (CO_CONFIG_EM_PRODUCER | CO_CONFIG_EM_HISTORY)
co->em_fifo = &COO_EM_FIFO[0];
#endif
co->SDOserver = &COO_SDOserver[0];
#if (CO_CONFIG_SDO_CLI) & CO_CONFIG_SDO_CLI_ENABLE
co->SDOclient = &COO_SDOclient[0];
#endif
#if (CO_CONFIG_TIME) & CO_CONFIG_TIME_ENABLE
co->TIME = &COO_TIME;
#endif
#if (CO_CONFIG_SYNC) & CO_CONFIG_SYNC_ENABLE
co->SYNC = &COO_SYNC;
#endif
#if (CO_CONFIG_PDO) & CO_CONFIG_RPDO_ENABLE
co->RPDO = &COO_RPDO[0];
#endif
#if (CO_CONFIG_PDO) & CO_CONFIG_TPDO_ENABLE
co->TPDO = &COO_TPDO[0];
#endif
#if (CO_CONFIG_LEDS) & CO_CONFIG_LEDS_ENABLE
co->LEDs = &COO_LEDs;
#endif
#if (CO_CONFIG_GFC) & CO_CONFIG_GFC_ENABLE
co->GFC = &COO_GFC;
#endif
#if (CO_CONFIG_SRDO) & CO_CONFIG_SRDO_ENABLE
co->SRDOGuard = &COO_SRDOGuard;
co->SRDO = &COO_SRDO[0];
#endif
#if (CO_CONFIG_LSS) & CO_CONFIG_LSS_SLAVE
co->LSSslave = &COO_LSSslave;
#endif
#if (CO_CONFIG_LSS) & CO_CONFIG_LSS_MASTER
co->LSSmaster = &COO_LSSmaster;
#endif
#if (CO_CONFIG_GTW) & CO_CONFIG_GTW_ASCII
co->gtwa = &COO_gtwa;
#endif
#if (CO_CONFIG_TRACE) & CO_CONFIG_TRACE_ENABLE
co->trace = &COO_trace[0];
co->traceTimeBuffers = &COO_traceTimeBuffers[0][0];
co->traceValueBuffers = &COO_traceValueBuffers[0][0];
co->traceBufferSize = CO_TRACE_BUFFER_SIZE_FIXED;
#endif
return co;
}
void CO_delete(CO_t *co) {
if (co == NULL) {
return;
}
CO_CANmodule_disable(co->CANmodule);
}
#endif /* #ifdef CO_USE_GLOBALS */
/* Helper functions ***********************************************************/
bool_t CO_isLSSslaveEnabled(CO_t *co) {
(void) co; /* may be unused */
bool_t en = false;
#if (CO_CONFIG_LSS) & CO_CONFIG_LSS_SLAVE
if (CO_GET_CNT(LSS_SLV) == 1) en = true;
#endif
return en;
}
/******************************************************************************/
CO_ReturnError_t CO_CANinit(CO_t *co, void *CANptr, uint16_t bitRate) {
CO_ReturnError_t err;
if (co == NULL) return CO_ERROR_ILLEGAL_ARGUMENT;
co->CANmodule->CANnormal = false;
CO_CANsetConfigurationMode(CANptr);
/* CANmodule */
err = CO_CANmodule_init(co->CANmodule,
CANptr,
co->CANrx,
CO_GET_CO(CNT_ALL_RX_MSGS),
co->CANtx,
CO_GET_CO(CNT_ALL_TX_MSGS),
bitRate);
return err;
}
/******************************************************************************/
#if (CO_CONFIG_LSS) & CO_CONFIG_LSS_SLAVE
CO_ReturnError_t CO_LSSinit(CO_t *co,
CO_LSS_address_t *lssAddress,
uint8_t *pendingNodeID,
uint16_t *pendingBitRate)
{
CO_ReturnError_t err;
if (co == NULL || CO_GET_CNT(LSS_SLV) != 1) {
return CO_ERROR_ILLEGAL_ARGUMENT;
}
/* LSSslave */
err = CO_LSSslave_init(co->LSSslave,
lssAddress,
pendingBitRate,
pendingNodeID,
co->CANmodule,
CO_GET_CO(RX_IDX_LSS_SLV),
CO_CAN_ID_LSS_MST,
co->CANmodule,
CO_GET_CO(TX_IDX_LSS_SLV),
CO_CAN_ID_LSS_SLV);
return err;
}
#endif /* (CO_CONFIG_LSS) & CO_CONFIG_LSS_SLAVE */
/******************************************************************************/
CO_ReturnError_t CO_CANopenInit(CO_t *co,
CO_NMT_t *NMT,
CO_EM_t *em,
OD_t *od,
OD_entry_t *OD_statusBits,
CO_NMT_control_t NMTcontrol,
uint16_t firstHBTime_ms,
uint16_t SDOserverTimeoutTime_ms,
uint16_t SDOclientTimeoutTime_ms,
bool_t SDOclientBlockTransfer,
uint8_t nodeId,
uint32_t *errInfo)
{
(void)SDOclientTimeoutTime_ms; (void)SDOclientBlockTransfer;
CO_ReturnError_t err;
if (co == NULL
|| (CO_GET_CNT(NMT) == 0 && NMT == NULL)
|| (CO_GET_CNT(EM) == 0 && em == NULL)
) {
return CO_ERROR_ILLEGAL_ARGUMENT;
}
/* alternatives */
if (CO_GET_CNT(NMT) == 0) {
co->NMT = NMT;
}
if (em == NULL) {
em = co->em;
}
/* Verify CANopen Node-ID */
co->nodeIdUnconfigured = false;
#if (CO_CONFIG_LSS) & CO_CONFIG_LSS_SLAVE
if (CO_GET_CNT(LSS_SLV) == 1 && nodeId == CO_LSS_NODE_ID_ASSIGNMENT) {
co->nodeIdUnconfigured = true;
}
else
#endif
if (nodeId < 1 || nodeId > 127) {
return CO_ERROR_ILLEGAL_ARGUMENT;
}
#if (CO_CONFIG_LEDS) & CO_CONFIG_LEDS_ENABLE
if (CO_GET_CNT(LEDS) == 1) {
err = CO_LEDs_init(co->LEDs);
if (err) return err;
}
#endif
/* CANopen Node ID is unconfigured, stop initialization here */
if (co->nodeIdUnconfigured) {
return CO_ERROR_NODE_ID_UNCONFIGURED_LSS;
}
/* Emergency */
if (CO_GET_CNT(EM) == 1) {
err = CO_EM_init(co->em,
co->CANmodule,
OD_GET(H1001, OD_H1001_ERR_REG),
#if (CO_CONFIG_EM) & (CO_CONFIG_EM_PRODUCER | CO_CONFIG_EM_HISTORY)
co->em_fifo,
(CO_GET_CNT(ARR_1003) + 1),
#endif
#if (CO_CONFIG_EM) & CO_CONFIG_EM_PRODUCER
OD_GET(H1014, OD_H1014_COBID_EMERGENCY),
CO_GET_CO(TX_IDX_EM_PROD),
#if (CO_CONFIG_EM) & CO_CONFIG_EM_PROD_INHIBIT
OD_GET(H1015, OD_H1015_INHIBIT_TIME_EMCY),
#endif
#endif
#if (CO_CONFIG_EM) & CO_CONFIG_EM_HISTORY
OD_GET(H1003, OD_H1003_PREDEF_ERR_FIELD),
#endif
#if (CO_CONFIG_EM) & CO_CONFIG_EM_STATUS_BITS
OD_statusBits,
#endif
#if (CO_CONFIG_EM) & CO_CONFIG_EM_CONSUMER
co->CANmodule,
CO_GET_CO(RX_IDX_EM_CONS),
#endif
nodeId,
errInfo);
if (err) return err;
}
/* NMT_Heartbeat */
if (CO_GET_CNT(NMT) == 1) {
err = CO_NMT_init(co->NMT,
OD_GET(H1017, OD_H1017_PRODUCER_HB_TIME),
em,
nodeId,
NMTcontrol,
firstHBTime_ms,
co->CANmodule,
CO_GET_CO(RX_IDX_NMT_SLV),
CO_CAN_ID_NMT_SERVICE,
#if (CO_CONFIG_NMT) & CO_CONFIG_NMT_MASTER
co->CANmodule,
CO_GET_CO(TX_IDX_NMT_MST),
CO_CAN_ID_NMT_SERVICE,
#endif
co->CANmodule,
CO_GET_CO(TX_IDX_HB_PROD),
CO_CAN_ID_HEARTBEAT + nodeId,