forked from rtlabs-com/p-net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpnet_api.h
2096 lines (1951 loc) · 74.4 KB
/
pnet_api.h
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
/*********************************************************************
* _ _ _
* _ __ | |_ _ | | __ _ | |__ ___
* | '__|| __|(_)| | / _` || '_ \ / __|
* | | | |_ _ | || (_| || |_) |\__ \
* |_| \__|(_)|_| \__,_||_.__/ |___/
*
* www.rt-labs.com
* Copyright 2018 rt-labs AB, Sweden.
*
* This software is dual-licensed under GPLv3 and a commercial
* license. See the file LICENSE.md distributed with this software for
* full license information.
********************************************************************/
/**
* @file
* @brief Public API for Profinet stack.
*
* # HW- and OS-specifics
*
* The Profinet stack depends on some OS and device-specific functions, which
* must be implemented by the application.
*
* The API for these functions is defined in osal.h.
*/
#ifndef PNET_API_H
#define PNET_API_H
#ifdef __cplusplus
extern "C" {
#endif
#include <pnet_export.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#define PNET_PRODUCT_NAME_MAX_LEN 25 /* Not including termination */
#define PNET_ORDER_ID_MAX_LEN 20 /* Not including termination */
#define PNET_SERIAL_NUMBER_MAX_LEN 16 /* Not including termination */
/* Including termination. Standard says 22 (without termination) */
#define PNET_LOCATION_MAX_SIZE 23
/** Including separator and one termination */
#define PNET_MAX_FILE_FULLPATH_SIZE \
(PNET_MAX_DIRECTORYPATH_SIZE + PNET_MAX_FILENAME_SIZE)
/** Including termination. Based on Linux IFNAMSIZ */
#define PNET_INTERFACE_NAME_MAX_SIZE 16
/** Supported block version by this implementation */
#define PNET_BLOCK_VERSION_HIGH 1
#define PNET_BLOCK_VERSION_LOW 0
/** Some blocks (e.g. logbook) uses the following lower version number. */
#define PNET_BLOCK_VERSION_LOW_1 1
/*
* Module and submodule ident number for the DAP module.
* The DAP module and submodules must be plugged by the application after the
* call to pnet_init.
*/
#define PNET_SLOT_DAP_IDENT 0x00000000
#define PNET_SUBSLOT_DAP_WHOLE_MODULE 0x00000000
#define PNET_SUBSLOT_DAP_IDENT 0x00000001
#define PNET_SUBSLOT_DAP_INTERFACE_1_IDENT 0x00008000
#define PNET_SUBSLOT_DAP_INTERFACE_1_PORT_1_IDENT 0x00008001
#define PNET_SUBSLOT_DAP_INTERFACE_1_PORT_2_IDENT 0x00008002
#define PNET_SUBSLOT_DAP_INTERFACE_1_PORT_3_IDENT 0x00008003
#define PNET_SUBSLOT_DAP_INTERFACE_1_PORT_4_IDENT 0x00008004
#define PNET_MOD_DAP_IDENT 0x00000001 /* For use in PNET_SLOT_DAP_IDENT */
#define PNET_SUBMOD_DAP_IDENT 0x00000001
#define PNET_SUBMOD_DAP_INTERFACE_1_IDENT 0x00008000
#define PNET_SUBMOD_DAP_INTERFACE_1_PORT_1_IDENT 0x00008001
#define PNET_SUBMOD_DAP_INTERFACE_1_PORT_2_IDENT 0x00008002
#define PNET_SUBMOD_DAP_INTERFACE_1_PORT_3_IDENT 0x00008003
#define PNET_SUBMOD_DAP_INTERFACE_1_PORT_4_IDENT 0x00008004
#define PNET_API_NO_APPLICATION_PROFILE 0
#define PNET_PORT_1 1
#define PNET_PORT_2 2
#define PNET_PORT_3 3
#define PNET_PORT_4 4
/**
* # Error Codes
*
* The Profinet error code consists of 4 values. The data structure for this is
* defined in the typedef pnet_pnio_status_t.
*
* The values here do not constitute an exhaustive list.
*/
/**
* # Values used in error_code
*
* Reserved 0x00 (No error)
* Reserved 0x01-0x1F
* Manufacturer specific 0x20-0x3F (LogBookData) Reserved 0x40-0x80
*/
#define PNET_ERROR_CODE_PNIO 0x81 /** All other errors */
/** Reserved 0x82-0xDE */
#define PNET_ERROR_CODE_RTA_ERROR 0xCF /** In ERR-RTA-PDU and ERR-UDP-PDU */
/** Reserved 0xD0-0xD9 */
#define PNET_ERROR_CODE_ALARM_ACK 0xDA /** In DATA-RTA-PDU and DATA-UDP-PDU */
#define PNET_ERROR_CODE_CONNECT 0xDB /** CL-RPC-PDU */
#define PNET_ERROR_CODE_RELEASE 0xDC /** CL-RPC-PDU */
#define PNET_ERROR_CODE_CONTROL 0xDD /** CL-RPC-PDU */
#define PNET_ERROR_CODE_READ 0xDE /** Only with PNIORW */
#define PNET_ERROR_CODE_WRITE 0xDF /** Only with PNIORW */
/** Reserved 0xE0-0xFF */
/**
* # Values used in error_decode.
*
* Reserved 0x00 (No error)
*
* Reserved 0x01-0x7F
*/
#define PNET_ERROR_DECODE_PNIORW 0x80 /** Only Read/Write */
#define PNET_ERROR_DECODE_PNIO 0x81
#define PNET_ERROR_DECODE_MANUFACTURER_SPECIFIC 0x82
/** Reserved 0x83-0xFF */
/**
* # List of error_code_1 values, bits 4..7, for PNET_ERROR_DECODE_PNIORW
*/
#define PNET_ERROR_CODE_1_PNIORW_APP 0xa0
#define PNET_ERROR_CODE_1_PNIORW_ACC 0xb0
#define PNET_ERROR_CODE_1_PNIORW_RES 0xc0
/**
* # List of error_code_1 values, for PNET_ERROR_DECODE_PNIORW
*
* APP = application
* ACC = access
* RES = resource
*/
#define PNET_ERROR_CODE_1_APP_READ_ERROR (0x00 + PNET_ERROR_CODE_1_PNIORW_APP)
#define PNET_ERROR_CODE_1_APP_WRITE_ERROR (0x01 + PNET_ERROR_CODE_1_PNIORW_APP)
#define PNET_ERROR_CODE_1_APP_MODULE_FAILURE \
(0x02 + PNET_ERROR_CODE_1_PNIORW_APP)
#define PNET_ERROR_CODE_1_APP_BUSY (0x07 + PNET_ERROR_CODE_1_PNIORW_APP)
#define PNET_ERROR_CODE_1_APP_VERSION_CONFLICT \
(0x08 + PNET_ERROR_CODE_1_PNIORW_APP)
#define PNET_ERROR_CODE_1_APP_NOT_SUPPORTED \
(0x09 + PNET_ERROR_CODE_1_PNIORW_APP)
#define PNET_ERROR_CODE_1_ACC_INVALID_INDEX \
(0x00 + PNET_ERROR_CODE_1_PNIORW_ACC)
#define PNET_ERROR_CODE_1_ACC_WRITE_LENGTH_ERROR \
(0x01 + PNET_ERROR_CODE_1_PNIORW_ACC)
#define PNET_ERROR_CODE_1_ACC_INVALID_SLOT_SUBSLOT \
(0x02 + PNET_ERROR_CODE_1_PNIORW_ACC)
#define PNET_ERROR_CODE_1_ACC_TYPE_CONFLICT \
(0x03 + PNET_ERROR_CODE_1_PNIORW_ACC)
#define PNET_ERROR_CODE_1_ACC_INVALID_AREA_API \
(0x04 + PNET_ERROR_CODE_1_PNIORW_ACC)
#define PNET_ERROR_CODE_1_ACC_STATE_CONFLICT \
(0x05 + PNET_ERROR_CODE_1_PNIORW_ACC)
#define PNET_ERROR_CODE_1_ACC_ACCESS_DENIED \
(0x06 + PNET_ERROR_CODE_1_PNIORW_ACC)
#define PNET_ERROR_CODE_1_ACC_INVALID_RANGE \
(0x07 + PNET_ERROR_CODE_1_PNIORW_ACC)
#define PNET_ERROR_CODE_1_ACC_INVALID_PARAMETER \
(0x08 + PNET_ERROR_CODE_1_PNIORW_ACC)
#define PNET_ERROR_CODE_1_ACC_INVALID_TYPE (0x09 + PNET_ERROR_CODE_1_PNIORW_ACC)
#define PNET_ERROR_CODE_1_ACC_BACKUP (0x0a + PNET_ERROR_CODE_1_PNIORW_ACC)
#define PNET_ERROR_CODE_1_RES_READ_CONFLICT \
(0x00 + PNET_ERROR_CODE_1_PNIORW_RES)
#define PNET_ERROR_CODE_1_RES_WRITE_CONFLICT \
(0x01 + PNET_ERROR_CODE_1_PNIORW_RES)
#define PNET_ERROR_CODE_1_RES_RESOURCE_BUSY \
(0x02 + PNET_ERROR_CODE_1_PNIORW_RES)
#define PNET_ERROR_CODE_1_RES_RESOURCE_UNAVAILABLE \
(0x03 + PNET_ERROR_CODE_1_PNIORW_RES)
/**
* # List of error_code_1 values, for PNET_ERROR_DECODE_PNIO
*/
#define PNET_ERROR_CODE_1_CONN_FAULTY_AR_BLOCK_REQ 0x01
#define PNET_ERROR_CODE_1_CONN_FAULTY_IOCR_BLOCK_REQ 0x02
#define PNET_ERROR_CODE_1_CONN_FAULTY_EXP_BLOCK_REQ 0x03
#define PNET_ERROR_CODE_1_CONN_FAULTY_ALARM_BLOCK_REQ 0x04
#define PNET_ERROR_CODE_1_CONN_FAULTY_PRM_SERVER_BLOCK_REQ 0x05
#define PNET_ERROR_CODE_1_CONN_FAULTY_MCR_BLOCK_REQ 0x06
#define PNET_ERROR_CODE_1_CONN_FAULTY_AR_RPC_BLOCK_REQ 0x07
#define PNET_ERROR_CODE_1_CONN_FAULTY_FAULTY_RECORD 0x08
#define PNET_ERROR_CODE_1_CONN_FAULTY_IR_INFO 0x09
#define PNET_ERROR_CODE_1_CONN_FAULTY_SR_INFO 0x0A
#define PNET_ERROR_CODE_1_CONN_FAULTY_AR_FSU 0x0B
#define PNET_ERROR_CODE_1_CONN_FAULTY_VENDOR 0x0C
#define PNET_ERROR_CODE_1_CONN_FAULTY_RSINFO 0x0D
/** Reserved 0x0E-0x13 */
#define PNET_ERROR_CODE_1_DCTRL_FAULTY_CONNECT 0x14
#define PNET_ERROR_CODE_1_DCTRL_FAULTY_CONNECT_PLUG 0x15
#define PNET_ERROR_CODE_1_XCTRL_FAULTY_CONNECT 0x16
#define PNET_ERROR_CODE_1_XCTRL_FAULTY_CONNECT_PLUG 0x17
#define PNET_ERROR_CODE_1_DCTRL_FAULTY_CONNECT_PRMBEG 0x18
#define PNET_ERROR_CODE_1_DCTRL_FAULTY_CONNECT_SUBMODLIST 0x19
/** Reserved 0x1A-0x27 */
#define PNET_ERROR_CODE_1_RELS_FAULTY_BLOCK 0x28
/** Reserved 0x29-0x31 */
/** Reserved 0x39-0x3B */
#define PNET_ERROR_CODE_1_ALARM_ACK 0x3C
#define PNET_ERROR_CODE_1_CMDEV 0x3D
#define PNET_ERROR_CODE_1_CMCTL 0x3E
#define PNET_ERROR_CODE_1_CTLDINA 0x3F
#define PNET_ERROR_CODE_1_CMRPC 0x40
#define PNET_ERROR_CODE_1_ALPMI 0x41
#define PNET_ERROR_CODE_1_ALPMR 0x42
#define PNET_ERROR_CODE_1_LMPM 0x43
#define PNET_ERROR_CODE_1_MAC 0x44
#define PNET_ERROR_CODE_1_RPC 0x45
#define PNET_ERROR_CODE_1_APMR 0x46
#define PNET_ERROR_CODE_1_APMS 0x47
#define PNET_ERROR_CODE_1_CPM 0x48
#define PNET_ERROR_CODE_1_PPM 0x49
#define PNET_ERROR_CODE_1_DCPUCS 0x4A
#define PNET_ERROR_CODE_1_DCPUCR 0x4B
#define PNET_ERROR_CODE_1_DCPMCS 0x4C
#define PNET_ERROR_CODE_1_DCPMCR 0x4D
#define PNET_ERROR_CODE_1_FSPM 0x4E
/** Reserved 0x4F-0x63 */
/** CTRLxxx 0x64-0xC7 */
#define PNET_ERROR_CODE_1_CMSM 0xC8
#define PNET_ERROR_CODE_1_CMRDR 0xCA
#define PNET_ERROR_CODE_1_CMWRR 0xCC
#define PNET_ERROR_CODE_1_CMIO 0xCD
#define PNET_ERROR_CODE_1_CMSU 0xCE
#define PNET_ERROR_CODE_1_CMINA 0xD0
#define PNET_ERROR_CODE_1_CMPBE 0xD1
#define PNET_ERROR_CODE_1_CMSRL 0xD2
#define PNET_ERROR_CODE_1_CMDMC 0xD3
/** CTRLxxx 0xD4-0xFC */
#define PNET_ERROR_CODE_1_RTA_ERR_CLS_PROTOCOL 0xFD
/** Reserved 0xFE */
#define PNET_ERROR_CODE_1_USER_SPECIFIC 0xFF
/**
* # List of error_code_2 values (not exhaustive)
*/
#define PNET_ERROR_CODE_2_CMDEV_STATE_CONFLICT 0x00
#define PNET_ERROR_CODE_2_CMDEV_RESOURCE 0x01
#define PNET_ERROR_CODE_2_CMRPC_ARGSLENGTH_INVALID 0x00
#define PNET_ERROR_CODE_2_CMRPC_UNKNOWN_BLOCKS 0x01
#define PNET_ERROR_CODE_2_CMRPC_IOCR_MISSING 0x02
#define PNET_ERROR_CODE_2_CMRPC_WRONG_BLOCK_COUNT 0x03
#define PNET_ERROR_CODE_2_CMRPC_NO_AR_RESOURCES 0x04
#define PNET_ERROR_CODE_2_CMRPC_AR_UUID_UNKNOWN 0x05
#define PNET_ERROR_CODE_2_CMRPC_STATE_CONFLICT 0x06
#define PNET_ERROR_CODE_2_CMRPC_OUT_OF_PCA_RESOURCES \
0x07 /** PCA = Provider, Consumer or Alarm */
#define PNET_ERROR_CODE_2_CMRPC_OUT_OF_MEMORY 0x08
#define PNET_ERROR_CODE_2_CMRPC_PDEV_ALREADY_OWNED 0x09
#define PNET_ERROR_CODE_2_CMRPC_ARSET_STATE_CONFLICT 0x0A
#define PNET_ERROR_CODE_2_CMRPC_ARSET_PARAM_CONFLICT 0x0B
#define PNET_ERROR_CODE_2_CMRPC_PDEV_PORTS_WO_INTERFACE 0x0C
#define PNET_ERROR_CODE_2_CMSM_INVALID_STATE 0x00
#define PNET_ERROR_CODE_2_CMSM_SIGNALED_ERROR 0x01
#define PNET_ERROR_CODE_2_CMRDR_INVALID_STATE 0x00
#define PNET_ERROR_CODE_2_CMRDR_SIGNALED_ERROR 0x01
#define PNET_ERROR_CODE_2_CMWRR_INVALID_STATE 0x00
#define PNET_ERROR_CODE_2_CMWRR_AR_STATE_NOT_PRIMARY 0x01
#define PNET_ERROR_CODE_2_CMWRR_SIGNALED_ERROR 0x02
#define PNET_ERROR_CODE_2_CMIO_INVALID_STATE 0x00
#define PNET_ERROR_CODE_2_CMIO_SIGNALED_ERROR 0x01
#define PNET_ERROR_CODE_2_CMSU_INVALID_STATE 0x00
#define PNET_ERROR_CODE_2_CMSU_AR_ADD_PROV_CONS_FAILED 0x01
#define PNET_ERROR_CODE_2_CMSU_AR_ALARM_OPEN_FAILED 0x02
#define PNET_ERROR_CODE_2_CMSU_AR_ALARM_SEND 0x03
#define PNET_ERROR_CODE_2_CMSU_AR_ALARM_ACK_SEND 0x04
#define PNET_ERROR_CODE_2_CMSU_AR_ALARM_IND 0x05
#define PNET_ERROR_CODE_2_CMINA_INVALID_STATE 0x00
#define PNET_ERROR_CODE_2_CMINA_SIGNALED_ERROR 0x01
#define PNET_ERROR_CODE_2_CMPBE_INVALID_STATE 0x00
#define PNET_ERROR_CODE_2_CMPBE_SIGNALED_ERROR 0x01
#define PNET_ERROR_CODE_2_CMSRL_INVALID_STATE 0x00
#define PNET_ERROR_CODE_2_CMSRL_SIGNALED_ERROR 0x01
#define PNET_ERROR_CODE_2_CMDMC_INVALID_STATE 0x00
#define PNET_ERROR_CODE_2_CMDMC_SIGNALED_ERROR 0x01
#define PNET_ERROR_CODE_2_CPM_INVALID_STATE 0x00
#define PNET_ERROR_CODE_2_CPM_INVALID 0x01
#define PNET_ERROR_CODE_2_PPM_INVALID_STATE 0x00
#define PNET_ERROR_CODE_2_PPM_INVALID 0x01
#define PNET_ERROR_CODE_2_APMS_INVALID_STATE 0x00
#define PNET_ERROR_CODE_2_APMS_LMPM_ERROR 0x01
#define PNET_ERROR_CODE_2_APMS_TIMEOUT 0x02
/* Reserved 0x03..0xff */
#define PNET_ERROR_CODE_2_APMR_INVALID_STATE 0x00
#define PNET_ERROR_CODE_2_APMR_LMPM_ERROR 0x01
/* Reserved 0x02..0xff */
#define PNET_ERROR_CODE_2_ALPMI_INVALID_STATE 0x00
#define PNET_ERROR_CODE_2_ALPMI_WRONG_ACK_PDU 0x01
#define PNET_ERROR_CODE_2_ALPMI_INVALID 0x02
#define PNET_ERROR_CODE_2_ALPMI_WRONG_STATE 0x03
/* Reserved 0x04..0xff */
#define PNET_ERROR_CODE_2_ALPMR_INVALID_STATE 0x00
#define PNET_ERROR_CODE_2_ALPMR_WRONG_ALARM_PDU 0x01
#define PNET_ERROR_CODE_2_ALPMR_INVALID 0x02
#define PNET_ERROR_CODE_2_ALPMR_WRONG_STATE 0x03
/* Reserved 0x04..0xff */
#define PNET_ERROR_CODE_2_INVALID_BLOCK_LEN 0x01
#define PNET_ERROR_CODE_2_INVALID_BLOCK_VERSION_HIGH 0x02
#define PNET_ERROR_CODE_2_INVALID_BLOCK_VERSION_LOW 0x03
/**
* # List of error_code_2 values, for
* PNET_ERROR_CODE_1_RTA_ERR_CLS_PROTOCOL (not exhaustive).
*/
#define PNET_ERROR_CODE_2_ABORT_CODE_SEQ 0x01
#define PNET_ERROR_CODE_2_ABORT_INSTANCE_CLOSED 0x02
#define PNET_ERROR_CODE_2_ABORT_AR_OUT_OF_MEMORY 0x03
#define PNET_ERROR_CODE_2_ABORT_AR_ADD_CPM_PPM_FAILED 0x04
#define PNET_ERROR_CODE_2_ABORT_AR_CONSUMER_DHT_EXPIRED 0x05
#define PNET_ERROR_CODE_2_ABORT_AR_CMI_TIMEOUT 0x06
#define PNET_ERROR_CODE_2_ABORT_AR_ALARM_OPEN_FAILED 0x07
#define PNET_ERROR_CODE_2_ABORT_AR_ALARM_SEND_CNF_NEG 0x08
#define PNET_ERROR_CODE_2_ABORT_AR_ALARM_ACK_SEND_CNF_NEG 0x09
#define PNET_ERROR_CODE_2_ABORT_AR_ALARM_DATA_TOO_LONG 0x0a
#define PNET_ERROR_CODE_2_ABORT_AR_ALARM_IND_ERROR 0x0b
#define PNET_ERROR_CODE_2_ABORT_AR_RPC_CLIENT_CALL_CNF_NEG 0x0c
#define PNET_ERROR_CODE_2_ABORT_AR_ABORT_REQ 0x0d
#define PNET_ERROR_CODE_2_ABORT_AR_RE_RUN_ABORTS_EXISTING 0x0e
#define PNET_ERROR_CODE_2_ABORT_AR_RELEASE_IND_RECEIVED 0x0f
#define PNET_ERROR_CODE_2_ABORT_AR_DEVICE_DEACTIVATED 0x10
#define PNET_ERROR_CODE_2_ABORT_AR_REMOVED 0x11
#define PNET_ERROR_CODE_2_ABORT_AR_PROTOCOL_VIOLATION 0x12
#define PNET_ERROR_CODE_2_ABORT_AR_NAME_RESOLUTION_ERROR 0x13
#define PNET_ERROR_CODE_2_ABORT_AR_RPC_BIND_ERROR 0x14
#define PNET_ERROR_CODE_2_ABORT_AR_RPC_CONNECT_ERROR 0x15
#define PNET_ERROR_CODE_2_ABORT_AR_RPC_READ_ERROR 0x16
#define PNET_ERROR_CODE_2_ABORT_AR_RPC_WRITE_ERROR 0x17
#define PNET_ERROR_CODE_2_ABORT_AR_RPC_CONTROL_ERROR 0x18
#define PNET_ERROR_CODE_2_ABORT_AR_FORBIDDEN_PULL_OR_PLUG 0x19
#define PNET_ERROR_CODE_2_ABORT_AR_AP_REMOVED 0x1a
#define PNET_ERROR_CODE_2_ABORT_AR_LINK_DOWN 0x1b
#define PNET_ERROR_CODE_2_ABORT_AR_MC_REGISTER_FAILED 0x1c
#define PNET_ERROR_CODE_2_ABORT_NOT_SYNCHRONIZED 0x1d
#define PNET_ERROR_CODE_2_ABORT_WRONG_TOPOLOGY 0x1e
#define PNET_ERROR_CODE_2_ABORT_DCP_STATION_NAME_CHANGED 0x1f
#define PNET_ERROR_CODE_2_ABORT_DCP_RESET_TO_FACTORY 0x20
#define PNET_ERROR_CODE_2_ABORT_PDEV_CHECK_FAILED 0x24
/**
* # List of error_code_2 values, for
* PNET_ERROR_CODE_1_DCTRL_FAULTY_CONNECT (not exhaustive).
*/
#define PNET_ERROR_CODE_2_DCTRL_FAULTY_CONNECT_CONTROLCOMMAND 0x08
/**
* The events are sent from CMDEV to the application using the
* \a pnet_state_ind() call-back function.
*/
typedef enum pnet_event_values
{
PNET_EVENT_ABORT, /**< The AR has been closed. */
PNET_EVENT_STARTUP, /**< A connection has been initiated. */
PNET_EVENT_PRMEND, /**< Controller has sent all write records. */
PNET_EVENT_APPLRDY, /**< Controller has acknowledged the APPL_RDY message */
PNET_EVENT_DATA
} pnet_event_values_t;
/**
* Values used for IOCS and IOPS.
*/
typedef enum pnet_ioxs_values
{
/* Values are important */
PNET_IOXS_BAD = 0x00,
PNET_IOXS_GOOD = 0x80
} pnet_ioxs_values_t;
/**
* Values used when plugging a sub-module using \a pnet_plug_submodule().
*/
typedef enum pnet_submodule_dir
{
/* Values are important */
PNET_DIR_NO_IO = 0x00,
PNET_DIR_INPUT = 0x01,
PNET_DIR_OUTPUT = 0x02,
PNET_DIR_IO = 0x03
} pnet_submodule_dir_t;
/*
* Data configuration
* Used when indicating an expected submodule.
*/
typedef struct pnet_data_cfg
{
pnet_submodule_dir_t data_dir;
uint16_t insize;
uint16_t outsize;
} pnet_data_cfg_t;
/**
* CControl command codes used in the \a pnet_dcontrol_ind() call-back function.
*/
typedef enum pnet_control_command
{
PNET_CONTROL_COMMAND_PRM_BEGIN,
PNET_CONTROL_COMMAND_PRM_END,
PNET_CONTROL_COMMAND_APP_RDY,
PNET_CONTROL_COMMAND_RELEASE,
/* ToDo: These are not currently implemented */
PNET_CONTROL_COMMAND_RDY_FOR_COMPANION,
PNET_CONTROL_COMMAND_RDY_FOR_RTC3,
} pnet_control_command_t;
/**
* Data status bits used in the \a pnet_new_data_status_ind() call-back
* function.
*/
typedef enum pnet_data_status_bits
{
PNET_DATA_STATUS_BIT_STATE = 0, /** 0 => BACKUP, 1 => PRIMARY */
PNET_DATA_STATUS_BIT_REDUNDANCY, /** Meaning depends on STATE bit */
PNET_DATA_STATUS_BIT_DATA_VALID, /** 0 => INVALID, 1 => VALID */
PNET_DATA_STATUS_BIT_RESERVED_1,
PNET_DATA_STATUS_BIT_PROVIDER_STATE, /** 0 => STOP, 1 => RUN */
PNET_DATA_STATUS_BIT_STATION_PROBLEM_INDICATOR, /** 0 => Problem detected, 1
=> Normal operation */
PNET_DATA_STATUS_BIT_RESERVED_2,
PNET_DATA_STATUS_BIT_IGNORE /** 0 => Evaluate data status, 1 => Ignore the
data status (typically used on a frame with
subframes) */
} pnet_data_status_bits_t;
/** Network handle */
typedef struct pnet pnet_t;
/**
* Profinet stack detailed error information.
*/
typedef struct pnet_pnio_status
{
uint8_t error_code;
uint8_t error_decode;
uint8_t error_code_1;
uint8_t error_code_2;
} pnet_pnio_status_t;
/*
* Alarm and Diagnosis
*
*/
/** Summary of all diagnosis items, sent in an alarm.
Only valid for alarms attached to the Diagnosis ASE
See Profinet 2.4 Services, section 7.3.1.6.5.1 Alarm Notification */
typedef struct pnet_alarm_spec
{
/** Diagnosis in standard format (any severity, appear)
* on this subslot */
bool channel_diagnosis;
/** Diagnosis in USI format (which always is FAULT) on this subslot,
* (USI format does not have appears/disappears) */
bool manufacturer_diagnosis;
/** Fault or Qual27-Qual31 (standard or USI format, appear) on
* this subslot */
bool submodule_diagnosis;
/** Fault or Qual27-Qual31 (standard or USI format, appear) on this AR */
bool ar_diagnosis;
} pnet_alarm_spec_t;
typedef struct pnet_alarm_argument
{
uint32_t api_id;
uint16_t slot_nbr;
uint16_t subslot_nbr;
uint16_t alarm_type;
uint16_t sequence_number;
pnet_alarm_spec_t alarm_specifier;
} pnet_alarm_argument_t;
/**
* Sent to controller on negative result.
*/
typedef struct pnet_result
{
pnet_pnio_status_t pnio_status; /**< Profinet-specific error information. */
uint16_t add_data_1; /**< Application-specific error information. */
uint16_t add_data_2; /**< Application-specific error information. */
} pnet_result_t;
/*
* Application call-back functions
*
* The application should define call-back functions which are called by
* the stack when specific events occurs within the stack.
*
* Note that most of these functions are mandatory in the sense that they must
* exist and return 0 (zero) for a functioning stack. Some functions are
* required to perform specific functionality.
*
* The call-back functions should return 0 (zero) for a successful call and
* -1 for an unsuccessful call.
*/
/**
* Indication to the application that a Connect request was received from the
* controller.
*
* This application call-back function is called by the Profinet stack on every
* Connect request from the Profinet controller.
*
* The connection will be opened if this function returns 0 (zero) and the stack
* is otherwise able to establish a connection.
*
* If this function returns something other than 0 (zero) then the Connect
* request is refused by the device. In case of error the application should
* provide error information in \a p_result.
*
* It is optional to implement this callback (assumes success if not
* implemented).
*
* @param net InOut: The p-net stack instance
* @param arg InOut: User-defined data (not used by p-net)
* @param arep In: The AREP.
* @param p_result Out: Detailed error information.
* @return 0 on success.
* -1 if an error occurred.
*/
typedef int (*pnet_connect_ind) (
pnet_t * net,
void * arg,
uint32_t arep,
pnet_result_t * p_result);
/**
* Indication to the application that a Release request was received from the
* controller.
*
* This application call-back function is called by the Profinet stack on every
* Release request from the Profinet controller.
*
* The connection will be closed regardless of the return value from this
* function. In case of error the application should provide error information
* in \a p_result.
*
* It is optional to implement this callback (assumes success if not
* implemented).
*
* @param net InOut: The p-net stack instance
* @param arg InOut: User-defined data (not used by p-net)
* @param arep In: The AREP.
* @param p_result Out: Detailed error information.
* @return 0 on success.
* -1 if an error occurred.
*/
typedef int (*pnet_release_ind) (
pnet_t * net,
void * arg,
uint32_t arep,
pnet_result_t * p_result);
/**
* Indication to the application that a DControl request was received from the
* controller.
*
* This application call-back function is called by the Profinet stack on every
* DControl request from the Profinet controller.
*
* The application is not required to take any action but the function must
* return 0 (zero) for proper function of the stack. If this function returns
* something other than 0 (zero) then the DControl request is refused by the
* device. In case of error the application should provide error information in
* \a p_result.
*
* It is optional to implement this callback (assumes success if not
* implemented).
*
* @param net InOut: The p-net stack instance
* @param arg InOut: User-defined data (not used by p-net)
* @param arep In: The AREP.
* @param control_command In: The DControl command code.
* @param p_result Out: Detailed error information.
* @return 0 on success.
* -1 if an error occurred.
*/
typedef int (*pnet_dcontrol_ind) (
pnet_t * net,
void * arg,
uint32_t arep,
pnet_control_command_t control_command,
pnet_result_t * p_result);
/**
* Indication to the application that a CControl confirmation was received from
* the controller.
*
* This application call-back function is called by the Profinet stack on every
* CControl confirmation from the Profinet controller.
*
* The application is not required to take any action.
* The return value from this call-back function is ignored by the Profinet
* stack. In case of error the application should provide error information in
* \a p_result.
*
* It is optional to implement this callback (assumes success?).
*
* @param net InOut: The p-net stack instance
* @param arg InOut: User-defined data (not used by p-net)
* @param arep In: The AREP.
* @param p_result Out: Detailed error information.
* @return 0 on success. Other values are ignored.
*/
typedef int (*pnet_ccontrol_cnf) (
pnet_t * net,
void * arg,
uint32_t arep,
pnet_result_t * p_result);
/**
* Indication to the application that a state transition has occurred within the
* Profinet stack.
*
* This application call-back function is called by the Profinet stack on
* specific state transitions within the Profinet stack.
*
* At the very least the application must react to the PNET_EVENT_PRMEND state
* transition. After this event the application must call \a
* pnet_application_ready(), when it has finished its setup and it is ready to
* exchange data.
*
* The return value from this call-back function is ignored by the Profinet
* stack.
*
* It is optional to implement this callback (but then it would be difficult
* to know when to call the \a pnet_application_ready() function).
*
* @param net InOut: The p-net stack instance
* @param arg InOut: User-defined data (not used by p-net)
* @param arep In: The AREP.
* @param state In: The state transition event. See
* pnet_event_values_t.
* @return 0 on success. Other values are ignored.
*/
typedef int (*pnet_state_ind) (
pnet_t * net,
void * arg,
uint32_t arep,
pnet_event_values_t state);
/**
* Indication to the application that an IODRead request was received from the
* controller.
*
* This application call-back function is called by the Profinet stack on every
* IODRead request from the Profinet controller which specify an
* application-specific value of \a idx (0x0000 - 0x7fff). All other values of
* \a idx are handled internally by the Profinet stack.
*
* The application must verify the value of \a idx, and that \a p_read_length is
* large enough. Further, the application must provide a
* pointer to the binary value in \a pp_read_data and the size, in bytes, of the
* binary value in \a p_read_length.
*
* The Profinet stack does not perform any endianness conversion on the binary
* value.
*
* In case of error the application should provide error information in \a
* p_result.
*
* @param net InOut: The p-net stack instance
* @param arg InOut: User-defined data (not used by p-net)
* @param arep In: The AREP.
* @param api In: The AP identifier.
* @param slot In: The slot number.
* @param subslot In: The sub-slot number.
* @param idx In: The data record index.
* @param sequence_number In: The sequence number.
* @param pp_read_data Out: A pointer to the binary value.
* @param p_read_length InOut: The maximum (in) and actual (out) length in
* bytes of the binary value.
* @param p_result Out: Detailed error information.
* @return 0 on success.
* -1 if an error occurred.
*/
typedef int (*pnet_read_ind) (
pnet_t * net,
void * arg,
uint32_t arep,
uint32_t api,
uint16_t slot,
uint16_t subslot,
uint16_t idx,
uint16_t sequence_number,
uint8_t ** pp_read_data, /**< Out: A pointer to the data */
uint16_t * p_read_length, /**< Out: Size of data */
pnet_result_t * p_result); /**< Error status if returning != 0 */
/**
* Indication to the application that an IODWrite request was received from the
* controller.
*
* This application call-back function is called by the Profinet stack on every
* IODWrite request from the Profinet controller which specify an
* application-specific value of \a idx (0x0000 - 0x7fff). All other values of
* \a idx are handled internally by the Profinet stack.
*
* The application must verify the values of \a idx and \a write_length and save
* (copy) the binary value in \a p_write_data. A future IODRead must return the
* latest written value.
*
* The Profinet stack does not perform any endianness conversion on the binary
* value.
*
* In case of error the application should provide error information in \a
* p_result.
*
* @param net InOut: The p-net stack instance
* @param arg InOut: User-defined data (not used by p-net)
* @param arep In: The AREP.
* @param api In: The API identifier.
* @param slot In: The slot number.
* @param subslot In: The sub-slot number.
* @param idx In: The data record index.
* @param sequence_number In: The sequence number.
* @param write_length In: The length in bytes of the binary value.
* @param p_write_data In: A pointer to the binary value.
* @param p_result Out: Detailed error information.
* @return 0 on success.
* -1 if an error occurred.
*/
typedef int (*pnet_write_ind) (
pnet_t * net,
void * arg,
uint32_t arep,
uint32_t api,
uint16_t slot,
uint16_t subslot,
uint16_t idx,
uint16_t sequence_number,
uint16_t write_length,
const uint8_t * p_write_data,
pnet_result_t * p_result);
/**
* Indication to the application that a module is requested by the controller in
* a specific slot.
*
* This application call-back function is called by the Profinet stack to
* indicate that the controller has requested the presence of a specific module,
* ident number \a module_ident, in the slot number \a slot.
*
* The application must react to this by configuring itself accordingly (if
* possible) and call function pnet_plug_module() to configure the stack for
* this module.
*
* If the wrong module ident number is plugged then the stack will accept this,
* but signal to the controller that a substitute module is fitted.
*
* This function should return 0 (zero) if a valid module was plugged. Or return
* -1 if the application cannot handle this request.
*
* @param net InOut: The p-net stack instance
* @param arg InOut: User-defined data (not used by p-net)
* @param api In: The AP identifier.
* @param slot In: The slot number.
* @param module_ident In: The module ident number.
* @return 0 on success.
* -1 if an error occurred.
*/
typedef int (*pnet_exp_module_ind) (
pnet_t * net,
void * arg,
uint32_t api,
uint16_t slot,
uint32_t module_ident);
/**
* Indication to the application that a sub-module is requested by the
* controller in a specific sub-slot.
*
* This application call-back function is called by the Profinet stack to
* indicate that the controller has requested the presence of a specific
* sub-module, ident number \a submodule_ident, in the sub-slot number \a
* subslot, with module ident number \a module_ident in slot \a slot.
*
* If a module has not been plugged in the slot \a slot then an automatic plug
* request is issued internally by the stack.
*
* The application must react to this by configuring itself accordingly (if
* possible) and call function pnet_plug_submodule() to configure the stack with
* the correct input/output data sizes.
*
* If the wrong sub-module ident number is plugged then the stack will accept
* this, but signal to the controller that a substitute sub-module is fitted.
*
* This function should return 0 (zero) if a valid sub-module was plugged. Or
* return -1 if the application cannot handle this request.
*
* @param net InOut: The p-net stack instance
* @param arg InOut: User-defined data (not used by p-net)
* @param api In: The AP identifier.
* @param slot In: The slot number.
* @param subslot In: The sub-slot number.
* @param module_ident In: The module ident number.
* @param submodule_ident In: The sub-module ident number.
* @param p_exp_data In: The expected data configuration
* @return 0 on success.
* -1 if an error occurred.
*/
typedef int (*pnet_exp_submodule_ind) (
pnet_t * net,
void * arg,
uint32_t api,
uint16_t slot,
uint16_t subslot,
uint32_t module_ident,
uint32_t submodule_ident,
const pnet_data_cfg_t * p_exp_data);
/**
* Indication to the application that the data status received from the
* controller has changed.
*
* This application call-back function is called by the Profinet stack to
* indicate that the received data status has changed.
*
* The application is not required by the Profinet stack to take any action. It
* may use this information as it wishes. The return value from this call-back
* function is ignored by the Profinet stack.
*
* @param net InOut: The p-net stack instance
* @param arg InOut: User-defined data (not used by p-net)
* @param arep In: The AREP.
* @param crep In: The CREP.
* @param changes In: The changed bits in the received data status.
* See pnet_data_status_bits_t
* @param data_status In: Current received data status (after changes).
* See pnet_data_status_bits_t
* @return 0 on success. Other values are ignored.
*/
typedef int (*pnet_new_data_status_ind) (
pnet_t * net,
void * arg,
uint32_t arep,
uint32_t crep,
uint8_t changes, /**< Only modified bits from pnet_data_status_bits_t */
uint8_t data_status);
/**
* The IO-controller has sent an alarm to the device.
*
* This functionality is used for alarms triggered by the IO-controller.
*
* When receiving this indication, the application shall
* respond with \a pnet_alarm_send_ack().
* pnet_alarm_send_ack may be called in the context of this
* callback.
*
* @param net InOut: The p-net stack instance
* @param arg InOut: User-defined data (not used by p-net)
* @param arep In: The AREP.
* @param p_alarm_argument In: The alarm argument (with slot, subslot,
* alarm_type etc)
* @param data_len In: Data length
* @param data_usi In: Alarm USI
* @param p_data In: Alarm data
* @return 0 on success.
* Other values are ignored.
*/
typedef int (*pnet_alarm_ind) (
pnet_t * net,
void * arg,
uint32_t arep,
const pnet_alarm_argument_t * p_alarm_argument,
uint16_t data_len,
uint16_t data_usi,
const uint8_t * p_data);
/**
* The controller acknowledges the alarm sent previously.
* It is now possible to send another alarm.
*
* This functionality is used for alarms triggered by the IO-device.
*
* It is optional to implement this callback.
* The return value from this call-back function is ignored by the Profinet
* stack.
*
* @param net InOut: The p-net stack instance
* @param arg InOut: User-defined data (not used by p-net)
* @param arep In: The AREP.
* @param p_pnio_status In: Detailed ACK information.
* @return 0 on success. Other values are ignored.
*/
typedef int (*pnet_alarm_cnf) (
pnet_t * net,
void * arg,
uint32_t arep,
const pnet_pnio_status_t * p_pnio_status);
/**
* The controller acknowledges the alarm ACK sent previously.
*
* This functionality is used for alarms triggered by the IO-controller.
*
* It is optional to implement this callback.
* The return value from this call-back function is ignored by the Profinet
* stack.
*
* @param net InOut: The p-net stack instance
* @param arg InOut: User-defined data (not used by p-net)
* @param arep In: The AREP.
* @param res In: 0 if ACK was received by the remote side.
* This is cnf(+).
* -1 if ACK was not received by the remote
* side. This is cnf(-).
* @return 0 on success. Other values are ignored.
*/
typedef int (
*pnet_alarm_ack_cnf) (pnet_t * net, void * arg, uint32_t arep, int res);
/**
* Indication to the application that a reset request was received from the
* IO-controller.
*
* The IO-controller can ask for communication parameters or application
* data to be reset, or to do a factory reset.
*
* This application call-back function is called by the Profinet stack on every
* reset request (via the DCP "Set" command) from the Profinet controller.
*
* The application should reset the application data if
* \a should_reset_application is true. For other cases this callback is
* triggered for diagnostic reasons.
*
* The return value from this call-back function is ignored by the Profinet
* stack.
*
* It is optional to implement this callback (if you do not have any application
* data that could be reset).
*
* Reset modes:
* * 0: (Power-on reset, not from IO-controller. Will not trigger this.)
* * 1: Reset application data
* * 2: Reset communication parameters (done by the stack)
* * 99: Reset all (factory reset).
*
* The reset modes 1-9 (out of which 1 and 2 are supported here) are defined
* by the Profinet standard. Value 99 is used here to indicate that the
* IO-controller has requested a factory reset via another mechanism.
*
* In order to remain responsive to DCP communication and Ethernet switching,
* the device should not do a hard or soft reset for reset mode 1 or 2. It is
* allowed for the factory reset case (but not mandatory).
*
* No \a arep information is available, as this callback typically is triggered
* when there is no active connection.
*
* @param net InOut: The p-net stack instance
* @param arg InOut: User-defined data (not used by p-net)
* @param should_reset_application In: True if the user should reset the
* application data.
* @param reset_mode In: Detailed reset information.
* @return 0 on success. Other values are ignored.
*/
typedef int (*pnet_reset_ind) (
pnet_t * net,
void * arg,
bool should_reset_application,
uint16_t reset_mode);
/**
* Indication to the application that the Profinet signal LED should change
* state.
*
* Use this callback to implement control of the LED.
*