pnet_api.h 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328
  1. /*********************************************************************
  2. * _ _ _
  3. * _ __ | |_ _ | | __ _ | |__ ___
  4. * | '__|| __|(_)| | / _` || '_ \ / __|
  5. * | | | |_ _ | || (_| || |_) |\__ \
  6. * |_| \__|(_)|_| \__,_||_.__/ |___/
  7. *
  8. * www.rt-labs.com
  9. * Copyright 2018 rt-labs AB, Sweden.
  10. *
  11. * This software is dual-licensed under GPLv3 and a commercial
  12. * license. See the file LICENSE.md distributed with this software for
  13. * full license information.
  14. ********************************************************************/
  15. /**
  16. * @file
  17. * @brief Public API for Profinet stack.
  18. *
  19. * # HW- and OS-specifics
  20. *
  21. * The Profinet stack depends on some OS and device-specific functions, which
  22. * must be implemented by the application.
  23. *
  24. * The API for these functions is defined in osal.h.
  25. */
  26. #ifndef PNET_API_H
  27. #define PNET_API_H
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. #include "pnet_export.h"
  32. #include "pnet_options.h"
  33. #include "pnet_version.h"
  34. #include "pnal_config.h"
  35. #if PNET_OPTION_DRIVER_ENABLE
  36. #include "driver_config.h" /* Configuration options for enabled driver */
  37. #endif
  38. #include <stdbool.h>
  39. #include <stddef.h>
  40. #include <stdint.h>
  41. #include <sys/time.h>
  42. #define PNET_PRODUCT_NAME_MAX_LEN 25 /* Not including termination */
  43. #define PNET_ORDER_ID_MAX_LEN 20 /* Not including termination */
  44. #define PNET_SERIAL_NUMBER_MAX_LEN 16 /* Not including termination */
  45. /* Including termination. Standard says 22 (without termination) */
  46. #define PNET_LOCATION_MAX_SIZE 23
  47. /** Including separator and one termination */
  48. #define PNET_MAX_FILE_FULLPATH_SIZE \
  49. (PNET_MAX_DIRECTORYPATH_SIZE + PNET_MAX_FILENAME_SIZE)
  50. /** Including termination. Based on Linux IFNAMSIZ */
  51. #define PNET_INTERFACE_NAME_MAX_SIZE 16
  52. /** Supported block version by this implementation */
  53. #define PNET_BLOCK_VERSION_HIGH 1
  54. #define PNET_BLOCK_VERSION_LOW 0
  55. /** Some blocks (e.g. logbook) uses the following lower version number. */
  56. #define PNET_BLOCK_VERSION_LOW_1 1
  57. /*
  58. * Module and submodule ident number for the DAP module.
  59. * The DAP module and submodules must be plugged by the application after the
  60. * call to pnet_init.
  61. */
  62. #define PNET_SLOT_DAP_IDENT 0x00000000
  63. #define PNET_SUBSLOT_DAP_WHOLE_MODULE 0x00000000
  64. #define PNET_SUBSLOT_DAP_IDENT 0x00000001
  65. #define PNET_SUBSLOT_DAP_INTERFACE_1_IDENT 0x00008000
  66. #define PNET_SUBSLOT_DAP_INTERFACE_1_PORT_1_IDENT 0x00008001
  67. #define PNET_SUBSLOT_DAP_INTERFACE_1_PORT_2_IDENT 0x00008002
  68. #define PNET_SUBSLOT_DAP_INTERFACE_1_PORT_3_IDENT 0x00008003
  69. #define PNET_SUBSLOT_DAP_INTERFACE_1_PORT_4_IDENT 0x00008004
  70. #define PNET_MOD_DAP_IDENT 0x00000001 /* For use in PNET_SLOT_DAP_IDENT */
  71. #define PNET_SUBMOD_DAP_IDENT 0x00000001
  72. #define PNET_SUBMOD_DAP_INTERFACE_1_IDENT 0x00008000
  73. #define PNET_SUBMOD_DAP_INTERFACE_1_PORT_1_IDENT 0x00008001
  74. #define PNET_SUBMOD_DAP_INTERFACE_1_PORT_2_IDENT 0x00008002
  75. #define PNET_SUBMOD_DAP_INTERFACE_1_PORT_3_IDENT 0x00008003
  76. #define PNET_SUBMOD_DAP_INTERFACE_1_PORT_4_IDENT 0x00008004
  77. #define PNET_API_NO_APPLICATION_PROFILE 0
  78. #define PNET_PORT_1 1
  79. #define PNET_PORT_2 2
  80. #define PNET_PORT_3 3
  81. #define PNET_PORT_4 4
  82. /**************************** Error codes ***********************************/
  83. /**
  84. * Error Codes
  85. *
  86. * The Profinet error code consists of 4 values. The data structure for this is
  87. * defined in the typedef pnet_pnio_status_t.
  88. *
  89. * The values here do not constitute an exhaustive list.
  90. */
  91. /**
  92. * # Values used in error_code
  93. *
  94. * Reserved 0x00 (No error)
  95. * Reserved 0x01-0x1F
  96. * Manufacturer specific 0x20-0x3F (LogBookData) Reserved 0x40-0x80
  97. */
  98. #define PNET_ERROR_CODE_NOERROR 0x00
  99. #define PNET_ERROR_CODE_PNIO 0x81 /** All other errors */
  100. /** Reserved 0x82-0xDE */
  101. #define PNET_ERROR_CODE_RTA_ERROR 0xCF /** In ERR-RTA-PDU and ERR-UDP-PDU */
  102. /** Reserved 0xD0-0xD9 */
  103. #define PNET_ERROR_CODE_ALARM_ACK 0xDA /** In DATA-RTA-PDU and DATA-UDP-PDU */
  104. #define PNET_ERROR_CODE_CONNECT 0xDB /** CL-RPC-PDU */
  105. #define PNET_ERROR_CODE_RELEASE 0xDC /** CL-RPC-PDU */
  106. #define PNET_ERROR_CODE_CONTROL 0xDD /** CL-RPC-PDU */
  107. #define PNET_ERROR_CODE_READ 0xDE /** Only with PNIORW */
  108. #define PNET_ERROR_CODE_WRITE 0xDF /** Only with PNIORW */
  109. /** Reserved 0xE0-0xFF */
  110. /**
  111. * # Values used in error_decode.
  112. *
  113. * Reserved 0x00 (No error)
  114. *
  115. * Reserved 0x01-0x7F
  116. */
  117. #define PNET_ERROR_DECODE_NOERROR 0x00
  118. #define PNET_ERROR_DECODE_PNIORW 0x80 /** Only Read/Write */
  119. #define PNET_ERROR_DECODE_PNIO 0x81
  120. #define PNET_ERROR_DECODE_MANUFACTURER_SPECIFIC 0x82
  121. /** Reserved 0x83-0xFF */
  122. /**
  123. * # List of error_code_1 values, for PNET_ERROR_DECODE_PNIORW
  124. *
  125. * APP = application
  126. * ACC = access
  127. * RES = resource
  128. */
  129. #define PNET_ERROR_CODE_1_APP_READ_ERROR 0xA0
  130. #define PNET_ERROR_CODE_1_APP_WRITE_ERROR 0xA1
  131. #define PNET_ERROR_CODE_1_APP_MODULE_FAILURE 0xA2
  132. #define PNET_ERROR_CODE_1_APP_BUSY 0xA7
  133. #define PNET_ERROR_CODE_1_APP_VERSION_CONFLICT 0xA8
  134. #define PNET_ERROR_CODE_1_APP_NOT_SUPPORTED 0xA9
  135. #define PNET_ERROR_CODE_1_ACC_INVALID_INDEX 0xB0
  136. #define PNET_ERROR_CODE_1_ACC_WRITE_LENGTH_ERROR 0xB1
  137. #define PNET_ERROR_CODE_1_ACC_INVALID_SLOT_SUBSLOT 0xB2
  138. #define PNET_ERROR_CODE_1_ACC_TYPE_CONFLICT 0xB3
  139. #define PNET_ERROR_CODE_1_ACC_INVALID_AREA_API 0xB4
  140. #define PNET_ERROR_CODE_1_ACC_STATE_CONFLICT 0xB5
  141. #define PNET_ERROR_CODE_1_ACC_ACCESS_DENIED 0xB6
  142. #define PNET_ERROR_CODE_1_ACC_INVALID_RANGE 0xB7
  143. #define PNET_ERROR_CODE_1_ACC_INVALID_PARAMETER 0xB8
  144. #define PNET_ERROR_CODE_1_ACC_INVALID_TYPE 0xB9
  145. #define PNET_ERROR_CODE_1_ACC_BACKUP 0xBA
  146. #define PNET_ERROR_CODE_1_RES_READ_CONFLICT 0xC0
  147. #define PNET_ERROR_CODE_1_RES_WRITE_CONFLICT 0xC1
  148. #define PNET_ERROR_CODE_1_RES_RESOURCE_BUSY 0xC2
  149. #define PNET_ERROR_CODE_1_RES_RESOURCE_UNAVAILABLE 0xC3
  150. /**
  151. * # List of error_code_1 values, for PNET_ERROR_DECODE_PNIO
  152. */
  153. #define PNET_ERROR_CODE_1_CONN_FAULTY_AR_BLOCK_REQ 0x01
  154. #define PNET_ERROR_CODE_1_CONN_FAULTY_IOCR_BLOCK_REQ 0x02
  155. #define PNET_ERROR_CODE_1_CONN_FAULTY_EXP_BLOCK_REQ 0x03
  156. #define PNET_ERROR_CODE_1_CONN_FAULTY_ALARM_BLOCK_REQ 0x04
  157. #define PNET_ERROR_CODE_1_CONN_FAULTY_PRM_SERVER_BLOCK_REQ 0x05
  158. #define PNET_ERROR_CODE_1_CONN_FAULTY_MCR_BLOCK_REQ 0x06
  159. #define PNET_ERROR_CODE_1_CONN_FAULTY_AR_RPC_BLOCK_REQ 0x07
  160. #define PNET_ERROR_CODE_1_CONN_FAULTY_FAULTY_RECORD 0x08
  161. #define PNET_ERROR_CODE_1_CONN_FAULTY_IR_INFO 0x09
  162. #define PNET_ERROR_CODE_1_CONN_FAULTY_SR_INFO 0x0A
  163. #define PNET_ERROR_CODE_1_CONN_FAULTY_AR_FSU 0x0B
  164. #define PNET_ERROR_CODE_1_CONN_FAULTY_VENDOR 0x0C
  165. #define PNET_ERROR_CODE_1_CONN_FAULTY_RSINFO 0x0D
  166. /** Reserved 0x0E-0x13 */
  167. #define PNET_ERROR_CODE_1_DCTRL_FAULTY_CONNECT 0x14
  168. #define PNET_ERROR_CODE_1_DCTRL_FAULTY_CONNECT_PLUG 0x15
  169. #define PNET_ERROR_CODE_1_XCTRL_FAULTY_CONNECT 0x16
  170. #define PNET_ERROR_CODE_1_XCTRL_FAULTY_CONNECT_PLUG 0x17
  171. #define PNET_ERROR_CODE_1_DCTRL_FAULTY_CONNECT_PRMBEG 0x18
  172. #define PNET_ERROR_CODE_1_DCTRL_FAULTY_CONNECT_SUBMODLIST 0x19
  173. /** Reserved 0x1A-0x27 */
  174. #define PNET_ERROR_CODE_1_RELS_FAULTY_BLOCK 0x28
  175. /** Reserved 0x29-0x31 */
  176. /** Reserved 0x39-0x3B */
  177. #define PNET_ERROR_CODE_1_ALARM_ACK 0x3C
  178. #define PNET_ERROR_CODE_1_CMDEV 0x3D
  179. #define PNET_ERROR_CODE_1_CMCTL 0x3E
  180. #define PNET_ERROR_CODE_1_CTLDINA 0x3F
  181. #define PNET_ERROR_CODE_1_CMRPC 0x40
  182. #define PNET_ERROR_CODE_1_ALPMI 0x41
  183. #define PNET_ERROR_CODE_1_ALPMR 0x42
  184. #define PNET_ERROR_CODE_1_LMPM 0x43
  185. #define PNET_ERROR_CODE_1_MAC 0x44
  186. #define PNET_ERROR_CODE_1_RPC 0x45
  187. #define PNET_ERROR_CODE_1_APMR 0x46
  188. #define PNET_ERROR_CODE_1_APMS 0x47
  189. #define PNET_ERROR_CODE_1_CPM 0x48
  190. #define PNET_ERROR_CODE_1_PPM 0x49
  191. #define PNET_ERROR_CODE_1_DCPUCS 0x4A
  192. #define PNET_ERROR_CODE_1_DCPUCR 0x4B
  193. #define PNET_ERROR_CODE_1_DCPMCS 0x4C
  194. #define PNET_ERROR_CODE_1_DCPMCR 0x4D
  195. #define PNET_ERROR_CODE_1_FSPM 0x4E
  196. /** Reserved 0x4F-0x63 */
  197. /** CTRLxxx 0x64-0xC7 */
  198. #define PNET_ERROR_CODE_1_CMSM 0xC8
  199. #define PNET_ERROR_CODE_1_CMRDR 0xCA
  200. #define PNET_ERROR_CODE_1_CMWRR 0xCC
  201. #define PNET_ERROR_CODE_1_CMIO 0xCD
  202. #define PNET_ERROR_CODE_1_CMSU 0xCE
  203. #define PNET_ERROR_CODE_1_CMINA 0xD0
  204. #define PNET_ERROR_CODE_1_CMPBE 0xD1
  205. #define PNET_ERROR_CODE_1_CMSRL 0xD2
  206. #define PNET_ERROR_CODE_1_CMDMC 0xD3
  207. /** CTRLxxx 0xD4-0xFC */
  208. #define PNET_ERROR_CODE_1_RTA_ERR_CLS_PROTOCOL 0xFD
  209. /** Reserved 0xFE */
  210. #define PNET_ERROR_CODE_1_USER_SPECIFIC 0xFF
  211. /**
  212. * # List of error_code_2 values (not exhaustive)
  213. */
  214. #define PNET_ERROR_CODE_2_CMDEV_STATE_CONFLICT 0x00
  215. #define PNET_ERROR_CODE_2_CMDEV_RESOURCE 0x01
  216. #define PNET_ERROR_CODE_2_CMRPC_ARGSLENGTH_INVALID 0x00
  217. #define PNET_ERROR_CODE_2_CMRPC_UNKNOWN_BLOCKS 0x01
  218. #define PNET_ERROR_CODE_2_CMRPC_IOCR_MISSING 0x02
  219. #define PNET_ERROR_CODE_2_CMRPC_WRONG_BLOCK_COUNT 0x03
  220. #define PNET_ERROR_CODE_2_CMRPC_NO_AR_RESOURCES 0x04
  221. #define PNET_ERROR_CODE_2_CMRPC_AR_UUID_UNKNOWN 0x05
  222. #define PNET_ERROR_CODE_2_CMRPC_STATE_CONFLICT 0x06
  223. #define PNET_ERROR_CODE_2_CMRPC_OUT_OF_PCA_RESOURCES \
  224. 0x07 /** PCA = Provider, Consumer or Alarm */
  225. #define PNET_ERROR_CODE_2_CMRPC_OUT_OF_MEMORY 0x08
  226. #define PNET_ERROR_CODE_2_CMRPC_PDEV_ALREADY_OWNED 0x09
  227. #define PNET_ERROR_CODE_2_CMRPC_ARSET_STATE_CONFLICT 0x0A
  228. #define PNET_ERROR_CODE_2_CMRPC_ARSET_PARAM_CONFLICT 0x0B
  229. #define PNET_ERROR_CODE_2_CMRPC_PDEV_PORTS_WO_INTERFACE 0x0C
  230. #define PNET_ERROR_CODE_2_CTLDINA_ARP_MULTIPLE_IP_ADDRESSES 0x07
  231. #define PNET_ERROR_CODE_2_CMSM_INVALID_STATE 0x00
  232. #define PNET_ERROR_CODE_2_CMSM_SIGNALED_ERROR 0x01
  233. #define PNET_ERROR_CODE_2_CMRDR_INVALID_STATE 0x00
  234. #define PNET_ERROR_CODE_2_CMRDR_SIGNALED_ERROR 0x01
  235. #define PNET_ERROR_CODE_2_CMWRR_INVALID_STATE 0x00
  236. #define PNET_ERROR_CODE_2_CMWRR_AR_STATE_NOT_PRIMARY 0x01
  237. #define PNET_ERROR_CODE_2_CMWRR_SIGNALED_ERROR 0x02
  238. #define PNET_ERROR_CODE_2_CMIO_INVALID_STATE 0x00
  239. #define PNET_ERROR_CODE_2_CMIO_SIGNALED_ERROR 0x01
  240. #define PNET_ERROR_CODE_2_CMSU_INVALID_STATE 0x00
  241. #define PNET_ERROR_CODE_2_CMSU_AR_ADD_PROV_CONS_FAILED 0x01
  242. #define PNET_ERROR_CODE_2_CMSU_AR_ALARM_OPEN_FAILED 0x02
  243. #define PNET_ERROR_CODE_2_CMSU_AR_ALARM_SEND 0x03
  244. #define PNET_ERROR_CODE_2_CMSU_AR_ALARM_ACK_SEND 0x04
  245. #define PNET_ERROR_CODE_2_CMSU_AR_ALARM_IND 0x05
  246. #define PNET_ERROR_CODE_2_CMINA_INVALID_STATE 0x00
  247. #define PNET_ERROR_CODE_2_CMINA_SIGNALED_ERROR 0x01
  248. #define PNET_ERROR_CODE_2_CMPBE_INVALID_STATE 0x00
  249. #define PNET_ERROR_CODE_2_CMPBE_SIGNALED_ERROR 0x01
  250. #define PNET_ERROR_CODE_2_CMSRL_INVALID_STATE 0x00
  251. #define PNET_ERROR_CODE_2_CMSRL_SIGNALED_ERROR 0x01
  252. #define PNET_ERROR_CODE_2_CMDMC_INVALID_STATE 0x00
  253. #define PNET_ERROR_CODE_2_CMDMC_SIGNALED_ERROR 0x01
  254. #define PNET_ERROR_CODE_2_CPM_INVALID_STATE 0x00
  255. #define PNET_ERROR_CODE_2_CPM_INVALID 0x01
  256. #define PNET_ERROR_CODE_2_PPM_INVALID_STATE 0x00
  257. #define PNET_ERROR_CODE_2_PPM_INVALID 0x01
  258. #define PNET_ERROR_CODE_2_APMS_INVALID_STATE 0x00
  259. #define PNET_ERROR_CODE_2_APMS_LMPM_ERROR 0x01
  260. #define PNET_ERROR_CODE_2_APMS_TIMEOUT 0x02
  261. /* Reserved 0x03..0xff */
  262. #define PNET_ERROR_CODE_2_APMR_INVALID_STATE 0x00
  263. #define PNET_ERROR_CODE_2_APMR_LMPM_ERROR 0x01
  264. /* Reserved 0x02..0xff */
  265. #define PNET_ERROR_CODE_2_ALPMI_INVALID_STATE 0x00
  266. #define PNET_ERROR_CODE_2_ALPMI_WRONG_ACK_PDU 0x01
  267. #define PNET_ERROR_CODE_2_ALPMI_INVALID 0x02
  268. #define PNET_ERROR_CODE_2_ALPMI_WRONG_STATE 0x03
  269. /* Reserved 0x04..0xff */
  270. #define PNET_ERROR_CODE_2_ALPMR_INVALID_STATE 0x00
  271. #define PNET_ERROR_CODE_2_ALPMR_WRONG_ALARM_PDU 0x01
  272. #define PNET_ERROR_CODE_2_ALPMR_INVALID 0x02
  273. #define PNET_ERROR_CODE_2_ALPMR_WRONG_STATE 0x03
  274. /* Reserved 0x04..0xff */
  275. #define PNET_ERROR_CODE_2_INVALID_BLOCK_LEN 0x01
  276. #define PNET_ERROR_CODE_2_INVALID_BLOCK_VERSION_HIGH 0x02
  277. #define PNET_ERROR_CODE_2_INVALID_BLOCK_VERSION_LOW 0x03
  278. /**
  279. * # List of error_code_2 values, for
  280. * PNET_ERROR_CODE_1_RTA_ERR_CLS_PROTOCOL (not exhaustive).
  281. */
  282. #define PNET_ERROR_CODE_2_ABORT_CODE_SEQ 0x01
  283. #define PNET_ERROR_CODE_2_ABORT_INSTANCE_CLOSED 0x02
  284. #define PNET_ERROR_CODE_2_ABORT_AR_OUT_OF_MEMORY 0x03
  285. #define PNET_ERROR_CODE_2_ABORT_AR_ADD_CPM_PPM_FAILED 0x04
  286. #define PNET_ERROR_CODE_2_ABORT_AR_CONSUMER_DHT_EXPIRED 0x05
  287. #define PNET_ERROR_CODE_2_ABORT_AR_CMI_TIMEOUT 0x06
  288. #define PNET_ERROR_CODE_2_ABORT_AR_ALARM_OPEN_FAILED 0x07
  289. #define PNET_ERROR_CODE_2_ABORT_AR_ALARM_SEND_CNF_NEG 0x08
  290. #define PNET_ERROR_CODE_2_ABORT_AR_ALARM_ACK_SEND_CNF_NEG 0x09
  291. #define PNET_ERROR_CODE_2_ABORT_AR_ALARM_DATA_TOO_LONG 0x0a
  292. #define PNET_ERROR_CODE_2_ABORT_AR_ALARM_IND_ERROR 0x0b
  293. #define PNET_ERROR_CODE_2_ABORT_AR_RPC_CLIENT_CALL_CNF_NEG 0x0c
  294. #define PNET_ERROR_CODE_2_ABORT_AR_ABORT_REQ 0x0d
  295. #define PNET_ERROR_CODE_2_ABORT_AR_RE_RUN_ABORTS_EXISTING 0x0e
  296. #define PNET_ERROR_CODE_2_ABORT_AR_RELEASE_IND_RECEIVED 0x0f
  297. #define PNET_ERROR_CODE_2_ABORT_AR_DEVICE_DEACTIVATED 0x10
  298. #define PNET_ERROR_CODE_2_ABORT_AR_REMOVED 0x11
  299. #define PNET_ERROR_CODE_2_ABORT_AR_PROTOCOL_VIOLATION 0x12
  300. #define PNET_ERROR_CODE_2_ABORT_AR_NAME_RESOLUTION_ERROR 0x13
  301. #define PNET_ERROR_CODE_2_ABORT_AR_RPC_BIND_ERROR 0x14
  302. #define PNET_ERROR_CODE_2_ABORT_AR_RPC_CONNECT_ERROR 0x15
  303. #define PNET_ERROR_CODE_2_ABORT_AR_RPC_READ_ERROR 0x16
  304. #define PNET_ERROR_CODE_2_ABORT_AR_RPC_WRITE_ERROR 0x17
  305. #define PNET_ERROR_CODE_2_ABORT_AR_RPC_CONTROL_ERROR 0x18
  306. #define PNET_ERROR_CODE_2_ABORT_AR_FORBIDDEN_PULL_OR_PLUG 0x19
  307. #define PNET_ERROR_CODE_2_ABORT_AR_AP_REMOVED 0x1a
  308. #define PNET_ERROR_CODE_2_ABORT_AR_LINK_DOWN 0x1b
  309. #define PNET_ERROR_CODE_2_ABORT_AR_MC_REGISTER_FAILED 0x1c
  310. #define PNET_ERROR_CODE_2_ABORT_NOT_SYNCHRONIZED 0x1d
  311. #define PNET_ERROR_CODE_2_ABORT_WRONG_TOPOLOGY 0x1e
  312. #define PNET_ERROR_CODE_2_ABORT_DCP_STATION_NAME_CHANGED 0x1f
  313. #define PNET_ERROR_CODE_2_ABORT_DCP_RESET_TO_FACTORY 0x20
  314. #define PNET_ERROR_CODE_2_ABORT_PDEV_CHECK_FAILED 0x24
  315. /**
  316. * # List of error_code_2 values, for
  317. * PNET_ERROR_CODE_1_DCTRL_FAULTY_CONNECT (not exhaustive).
  318. */
  319. #define PNET_ERROR_CODE_2_DCTRL_FAULTY_CONNECT_CONTROLCOMMAND 0x08
  320. /******************************** Events ******************************/
  321. /**
  322. * The events are sent from CMDEV to the application using the
  323. * \a pnet_state_ind() call-back function.
  324. */
  325. typedef enum pnet_event_values
  326. {
  327. /** The AR has been closed. */
  328. PNET_EVENT_ABORT,
  329. /** A connection has been initiated. */
  330. PNET_EVENT_STARTUP,
  331. /** Controller has sent all write records. */
  332. PNET_EVENT_PRMEND,
  333. /** Controller has acknowledged the APPL_RDY message */
  334. PNET_EVENT_APPLRDY,
  335. /** The cyclic data transmission is now properly set up */
  336. PNET_EVENT_DATA
  337. } pnet_event_values_t;
  338. /**
  339. * Values used for IOCS and IOPS. The actual values are important, as they are
  340. * sent on the wire.
  341. */
  342. typedef enum pnet_ioxs_values
  343. {
  344. PNET_IOXS_BAD = 0x00,
  345. PNET_IOXS_GOOD = 0x80
  346. } pnet_ioxs_values_t;
  347. /**
  348. * Values used when plugging a sub-module using \a pnet_plug_submodule().
  349. * The actual values are important, as they are sent on the wire.
  350. */
  351. typedef enum pnet_submodule_dir
  352. {
  353. PNET_DIR_NO_IO = 0x00,
  354. PNET_DIR_INPUT = 0x01,
  355. PNET_DIR_OUTPUT = 0x02,
  356. PNET_DIR_IO = 0x03
  357. } pnet_submodule_dir_t;
  358. /*
  359. * Data configuration for one submodule.
  360. *
  361. * Used when indicating an expected submodule.
  362. */
  363. typedef struct pnet_data_cfg
  364. {
  365. pnet_submodule_dir_t data_dir;
  366. uint16_t insize;
  367. uint16_t outsize;
  368. } pnet_data_cfg_t;
  369. /**
  370. * CControl command codes used in the \a pnet_dcontrol_ind() call-back function.
  371. */
  372. typedef enum pnet_control_command
  373. {
  374. PNET_CONTROL_COMMAND_PRM_BEGIN,
  375. PNET_CONTROL_COMMAND_PRM_END,
  376. PNET_CONTROL_COMMAND_APP_RDY,
  377. PNET_CONTROL_COMMAND_RELEASE,
  378. /** Not yet implemented */
  379. PNET_CONTROL_COMMAND_RDY_FOR_COMPANION,
  380. /** Not yet implemented */
  381. PNET_CONTROL_COMMAND_RDY_FOR_RTC3,
  382. } pnet_control_command_t;
  383. /**
  384. * Data status bits used in the \a pnet_new_data_status_ind() call-back
  385. * function.
  386. */
  387. typedef enum pnet_data_status_bits
  388. {
  389. /** 0 => BACKUP, 1 => PRIMARY */
  390. PNET_DATA_STATUS_BIT_STATE = 0,
  391. /** Meaning depends on STATE bit */
  392. PNET_DATA_STATUS_BIT_REDUNDANCY,
  393. /** 0 => INVALID, 1 => VALID */
  394. PNET_DATA_STATUS_BIT_DATA_VALID,
  395. PNET_DATA_STATUS_BIT_RESERVED_1,
  396. /** 0 => STOP, 1 => RUN */
  397. PNET_DATA_STATUS_BIT_PROVIDER_STATE,
  398. /** 0 => Problem detected, 1 => Normal operation */
  399. PNET_DATA_STATUS_BIT_STATION_PROBLEM_INDICATOR,
  400. PNET_DATA_STATUS_BIT_RESERVED_2,
  401. /** 0 => Evaluate data status,
  402. * 1 => Ignore the data status (typically used on a frame with subframes) */
  403. PNET_DATA_STATUS_BIT_IGNORE
  404. } pnet_data_status_bits_t;
  405. /** Network handle */
  406. typedef struct pnet pnet_t;
  407. /**
  408. * Profinet stack detailed error information.
  409. */
  410. typedef struct pnet_pnio_status
  411. {
  412. uint8_t error_code;
  413. uint8_t error_decode;
  414. uint8_t error_code_1;
  415. uint8_t error_code_2;
  416. } pnet_pnio_status_t;
  417. /************************ Alarm and Diagnosis ********************************/
  418. /** Summary of all diagnosis items, sent in an alarm.
  419. Only valid for alarms attached to the Diagnosis ASE
  420. See Profinet 2.4 Services, section 7.3.1.6.5.1 Alarm Notification */
  421. typedef struct pnet_alarm_spec
  422. {
  423. /** Diagnosis in standard format (any severity, appear)
  424. * on this subslot */
  425. bool channel_diagnosis;
  426. /** Diagnosis in USI format (which always is FAULT) on this subslot,
  427. * (USI format does not have appears/disappears) */
  428. bool manufacturer_diagnosis;
  429. /** Fault or Qual27-Qual31 (standard or USI format, appear) on
  430. * this subslot */
  431. bool submodule_diagnosis;
  432. /** Fault or Qual27-Qual31 (standard or USI format, appear) on this AR */
  433. bool ar_diagnosis;
  434. } pnet_alarm_spec_t;
  435. /**
  436. * Shows location and summary of diagnosis items in an alarm
  437. */
  438. typedef struct pnet_alarm_argument
  439. {
  440. uint32_t api_id;
  441. uint16_t slot_nbr;
  442. uint16_t subslot_nbr;
  443. uint16_t alarm_type;
  444. uint16_t sequence_number;
  445. pnet_alarm_spec_t alarm_specifier;
  446. } pnet_alarm_argument_t;
  447. /**
  448. * Sent to controller on negative result.
  449. */
  450. typedef struct pnet_result
  451. {
  452. /** Profinet-specific error information. */
  453. pnet_pnio_status_t pnio_status;
  454. /** Application-specific error information. */
  455. uint16_t add_data_1;
  456. /** Application-specific error information. */
  457. uint16_t add_data_2;
  458. } pnet_result_t;
  459. /******************************* Callbacks ************************************/
  460. /*
  461. * Application call-back functions
  462. *
  463. * The application should define call-back functions which are called by
  464. * the stack when specific events occurs within the stack.
  465. *
  466. * Note that most of these functions are mandatory in the sense that they must
  467. * exist and return 0 (zero) for a functioning stack. Some functions are
  468. * required to perform specific functionality.
  469. *
  470. * The call-back functions should return 0 (zero) for a successful call and
  471. * -1 for an unsuccessful call.
  472. */
  473. /**
  474. * Indication to the application that a Connect request was received from the
  475. * controller.
  476. *
  477. * This application call-back function is called by the Profinet stack on every
  478. * Connect request from the Profinet controller.
  479. *
  480. * The connection will be opened if this function returns 0 (zero) and the stack
  481. * is otherwise able to establish a connection.
  482. *
  483. * If this function returns something other than 0 (zero) then the Connect
  484. * request is refused by the device. In case of error the application should
  485. * provide error information in \a p_result.
  486. *
  487. * It is optional to implement this callback (assumes success if not
  488. * implemented).
  489. *
  490. * @param net InOut: The p-net stack instance
  491. * @param arg InOut: User-defined data (not used by p-net)
  492. * @param arep In: The AREP.
  493. * @param p_result Out: Detailed error information if return != 0.
  494. * @return 0 on success.
  495. * -1 if an error occurred.
  496. */
  497. typedef int (*pnet_connect_ind) (
  498. pnet_t * net,
  499. void * arg,
  500. uint32_t arep,
  501. pnet_result_t * p_result);
  502. /**
  503. * Indication to the application that a Release request was received from the
  504. * controller.
  505. *
  506. * This application call-back function is called by the Profinet stack on every
  507. * Release request from the Profinet controller.
  508. *
  509. * The connection will be closed regardless of the return value from this
  510. * function. In case of error the application should provide error information
  511. * in \a p_result.
  512. *
  513. * It is optional to implement this callback (assumes success if not
  514. * implemented).
  515. *
  516. * @param net InOut: The p-net stack instance
  517. * @param arg InOut: User-defined data (not used by p-net)
  518. * @param arep In: The AREP.
  519. * @param p_result Out: Detailed error information if return != 0.
  520. * @return 0 on success.
  521. * -1 if an error occurred.
  522. */
  523. typedef int (*pnet_release_ind) (
  524. pnet_t * net,
  525. void * arg,
  526. uint32_t arep,
  527. pnet_result_t * p_result);
  528. /**
  529. * Indication to the application that a DControl request was received from the
  530. * controller. Typically this means that the controller is done writing
  531. * parameters.
  532. *
  533. * This application call-back function is called by the Profinet stack on every
  534. * DControl request from the Profinet controller.
  535. *
  536. * The application is not required to take any action but the function must
  537. * return 0 (zero) for proper function of the stack. If this function returns
  538. * something other than 0 (zero) then the DControl request is refused by the
  539. * device. In case of error the application should provide error information in
  540. * \a p_result.
  541. *
  542. * It is optional to implement this callback (assumes success if not
  543. * implemented).
  544. *
  545. * @param net InOut: The p-net stack instance
  546. * @param arg InOut: User-defined data (not used by p-net)
  547. * @param arep In: The AREP.
  548. * @param control_command In: The DControl command code.
  549. * @param p_result Out: Detailed error information if return != 0.
  550. * @return 0 on success.
  551. * -1 if an error occurred.
  552. */
  553. typedef int (*pnet_dcontrol_ind) (
  554. pnet_t * net,
  555. void * arg,
  556. uint32_t arep,
  557. pnet_control_command_t control_command,
  558. pnet_result_t * p_result);
  559. /**
  560. * Indication to the application that a submodule has been released, and is
  561. * now owned by a new AR.
  562. *
  563. * After receiving this, the application is required to set new values for the
  564. * following, as applicable for the subslot in question:
  565. *
  566. * - input data
  567. * - input IOPS
  568. * - output IOCS
  569. *
  570. * After setting the values, the application must call
  571. * \a pnet_sm_released_cnf(), for the stack to function properly.
  572. *
  573. * This callback is mandatory to implement if p-net has been configured to
  574. * accept more than one AR (PNET_MAX_AR > 1), in which case shared device is
  575. * supported. If only one AR is allowed, this callback is never called.
  576. *
  577. * @param net InOut: The p-net stack instance
  578. * @param arg InOut: User-defined data (not used by p-net)
  579. * @param arep In: The AREP.
  580. * @param api In: The API containing the submodule.
  581. * @param slot_number In: The slot containing the submodule.
  582. * @param subslot_number In: The subslot containing the submodule.
  583. * @param p_result Out: Detailed error information if return != 0.
  584. * @return 0 on success.
  585. * -1 if an error occurred.
  586. */
  587. typedef int (*pnet_sm_released_ind) (
  588. pnet_t * net,
  589. void * arg,
  590. uint32_t arep,
  591. uint32_t api,
  592. uint16_t slot_number,
  593. uint16_t subslot_number,
  594. pnet_result_t * p_result);
  595. /**
  596. * Indication to the application that a CControl confirmation was received from
  597. * the controller. Typically this means that the controller has received our
  598. * "Application ready" message.
  599. *
  600. * This application call-back function is called by the Profinet stack on every
  601. * CControl confirmation from the Profinet controller.
  602. *
  603. * The application is not required to take any action.
  604. * The return value from this call-back function is ignored by the Profinet
  605. * stack. In case of error the application should provide error information in
  606. * \a p_result.
  607. *
  608. * It is optional to implement this callback (assumes success?).
  609. *
  610. * @param net InOut: The p-net stack instance
  611. * @param arg InOut: User-defined data (not used by p-net)
  612. * @param arep In: The AREP.
  613. * @param p_result Out: Detailed error information.
  614. * @return 0 on success. Other values are ignored.
  615. */
  616. typedef int (*pnet_ccontrol_cnf) (
  617. pnet_t * net,
  618. void * arg,
  619. uint32_t arep,
  620. pnet_result_t * p_result);
  621. /**
  622. * Indication to the application that a state transition has occurred within the
  623. * Profinet stack.
  624. *
  625. * This application call-back function is called by the Profinet stack on
  626. * specific state transitions within the Profinet stack.
  627. *
  628. * At the very least the application must react to the PNET_EVENT_PRMEND state
  629. * transition. After this event the application must call \a
  630. * pnet_application_ready(), when it has finished its setup and it is ready to
  631. * exchange data.
  632. *
  633. * The return value from this call-back function is ignored by the Profinet
  634. * stack.
  635. *
  636. * It is optional to implement this callback (but then it would be difficult
  637. * to know when to call the \a pnet_application_ready() function).
  638. *
  639. * @param net InOut: The p-net stack instance
  640. * @param arg InOut: User-defined data (not used by p-net)
  641. * @param arep In: The AREP.
  642. * @param state In: The state transition event. See
  643. * pnet_event_values_t.
  644. * @return 0 on success. Other values are ignored.
  645. */
  646. typedef int (*pnet_state_ind) (
  647. pnet_t * net,
  648. void * arg,
  649. uint32_t arep,
  650. pnet_event_values_t state);
  651. /**
  652. * Indication to the application that an IODRead request was received from the
  653. * controller.
  654. *
  655. * This application call-back function is called by the Profinet stack on every
  656. * IODRead request from the Profinet controller which specify an
  657. * application-specific value of \a idx (0x0000 - 0x7fff). All other values of
  658. * \a idx are handled internally by the Profinet stack.
  659. *
  660. * The application must verify the value of \a idx, and that \a p_read_length is
  661. * large enough. Further, the application must provide a
  662. * pointer to the binary value in \a pp_read_data and the size, in bytes, of the
  663. * binary value in \a p_read_length.
  664. *
  665. * The Profinet stack does not perform any endianness conversion on the binary
  666. * value.
  667. *
  668. * In case of error the application should provide error information in \a
  669. * p_result.
  670. *
  671. * Note that the read request from the PLC does not contain any information on
  672. * the number of bytes it expects to receive, just the maximum number of
  673. * bytes it is able to handle.
  674. *
  675. * @param net InOut: The p-net stack instance
  676. * @param arg InOut: User-defined data (not used by p-net)
  677. * @param arep In: The AREP.
  678. * @param api In: The AP identifier.
  679. * @param slot In: The slot number.
  680. * @param subslot In: The sub-slot number.
  681. * @param idx In: The data record index.
  682. * @param sequence_number In: The sequence number.
  683. * @param pp_read_data Out: A pointer to the binary value.
  684. * @param p_read_length InOut: The maximum (in) and actual (out) length in
  685. * bytes of the binary value.
  686. * @param p_result Out: Detailed error information if returning != 0
  687. * @return 0 on success.
  688. * -1 if an error occurred.
  689. */
  690. typedef int (*pnet_read_ind) (
  691. pnet_t * net,
  692. void * arg,
  693. uint32_t arep,
  694. uint32_t api,
  695. uint16_t slot,
  696. uint16_t subslot,
  697. uint16_t idx,
  698. uint16_t sequence_number,
  699. uint8_t ** pp_read_data,
  700. uint16_t * p_read_length,
  701. pnet_result_t * p_result);
  702. /**
  703. * Indication to the application that an IODWrite request was received from the
  704. * controller.
  705. *
  706. * This application call-back function is called by the Profinet stack on every
  707. * IODWrite request from the Profinet controller which specify an
  708. * application-specific value of \a idx (0x0000 - 0x7fff). All other values of
  709. * \a idx are handled internally by the Profinet stack.
  710. *
  711. * The application must verify the values of \a idx and \a write_length and save
  712. * (copy) the binary value in \a p_write_data. A future IODRead must return the
  713. * latest written value.
  714. *
  715. * The Profinet stack does not perform any endianness conversion on the binary
  716. * value.
  717. *
  718. * In case of error the application should provide error information in \a
  719. * p_result.
  720. *
  721. * @param net InOut: The p-net stack instance
  722. * @param arg InOut: User-defined data (not used by p-net)
  723. * @param arep In: The AREP.
  724. * @param api In: The API identifier.
  725. * @param slot In: The slot number.
  726. * @param subslot In: The sub-slot number.
  727. * @param idx In: The data record index.
  728. * @param sequence_number In: The sequence number.
  729. * @param write_length In: The length in bytes of the binary value.
  730. * @param p_write_data In: A pointer to the binary value.
  731. * @param p_result Out: Detailed error information if returning != 0
  732. * @return 0 on success.
  733. * -1 if an error occurred.
  734. */
  735. typedef int (*pnet_write_ind) (
  736. pnet_t * net,
  737. void * arg,
  738. uint32_t arep,
  739. uint32_t api,
  740. uint16_t slot,
  741. uint16_t subslot,
  742. uint16_t idx,
  743. uint16_t sequence_number,
  744. uint16_t write_length,
  745. const uint8_t * p_write_data,
  746. pnet_result_t * p_result);
  747. /**
  748. * Indication to the application that a module is requested by the controller in
  749. * a specific slot.
  750. *
  751. * This application call-back function is called by the Profinet stack to
  752. * indicate that the controller has requested the presence of a specific module,
  753. * ident number \a module_ident, in the slot number \a slot.
  754. *
  755. * The application must react to this by configuring itself accordingly (if
  756. * possible) and call function pnet_plug_module() to configure the stack for
  757. * this module.
  758. *
  759. * If the wrong module ident number is plugged then the stack will accept this,
  760. * but signal to the controller that a substitute module is fitted.
  761. *
  762. * This function should return 0 (zero) if a valid module was plugged. Or return
  763. * -1 if the application cannot handle this request.
  764. *
  765. * @param net InOut: The p-net stack instance
  766. * @param arg InOut: User-defined data (not used by p-net)
  767. * @param api In: The AP identifier.
  768. * @param slot In: The slot number.
  769. * @param module_ident In: The module ident number.
  770. * @return 0 on success.
  771. * -1 if an error occurred.
  772. */
  773. typedef int (*pnet_exp_module_ind) (
  774. pnet_t * net,
  775. void * arg,
  776. uint32_t api,
  777. uint16_t slot,
  778. uint32_t module_ident);
  779. /**
  780. * Indication to the application that a sub-module is requested by the
  781. * controller in a specific sub-slot.
  782. *
  783. * This application call-back function is called by the Profinet stack to
  784. * indicate that the controller has requested the presence of a specific
  785. * sub-module with ident number \a submodule_ident, in the sub-slot number
  786. * \a subslot, with module ident number \a module_ident in slot \a slot.
  787. *
  788. * If a module has not been plugged in the slot \a slot then an automatic plug
  789. * request is issued internally by the stack.
  790. *
  791. * The application must react to this by configuring itself accordingly (if
  792. * possible) and call function \a pnet_plug_submodule() to configure the stack
  793. * with the correct input/output data sizes.
  794. *
  795. * If the wrong sub-module ident number is plugged then the stack will accept
  796. * this, but signal to the controller that a substitute sub-module is fitted.
  797. *
  798. * This function should return 0 (zero) if a valid sub-module was plugged,
  799. * or return -1 if the application cannot handle this request.
  800. *
  801. * @param net InOut: The p-net stack instance
  802. * @param arg InOut: User-defined data (not used by p-net)
  803. * @param api In: The AP identifier.
  804. * @param slot In: The slot number.
  805. * @param subslot In: The sub-slot number.
  806. * @param module_ident In: The module ident number.
  807. * @param submodule_ident In: The sub-module ident number.
  808. * @param p_exp_data In: The expected data configuration (sizes and
  809. * direction)
  810. * @return 0 on success.
  811. * -1 if an error occurred.
  812. */
  813. typedef int (*pnet_exp_submodule_ind) (
  814. pnet_t * net,
  815. void * arg,
  816. uint32_t api,
  817. uint16_t slot,
  818. uint16_t subslot,
  819. uint32_t module_ident,
  820. uint32_t submodule_ident,
  821. const pnet_data_cfg_t * p_exp_data);
  822. /**
  823. * Indication to the application that the data status received from the
  824. * controller has changed.
  825. *
  826. * This application call-back function is called by the Profinet stack to
  827. * indicate that the received data status has changed.
  828. *
  829. * The application is not required by the Profinet stack to take any action. It
  830. * may use this information as it wishes. The return value from this call-back
  831. * function is ignored by the Profinet stack.
  832. *
  833. * @param net InOut: The p-net stack instance
  834. * @param arg InOut: User-defined data (not used by p-net)
  835. * @param arep In: The AREP.
  836. * @param crep In: The CREP.
  837. * @param changes In: The changed bits in the received data status.
  838. * See pnet_data_status_bits_t
  839. * @param data_status In: Current received data status (after changes).
  840. * See pnet_data_status_bits_t
  841. * @return 0 on success. Other values are ignored.
  842. */
  843. typedef int (*pnet_new_data_status_ind) (
  844. pnet_t * net,
  845. void * arg,
  846. uint32_t arep,
  847. uint32_t crep,
  848. uint8_t changes,
  849. uint8_t data_status);
  850. /**
  851. * The IO-controller has sent an alarm to the device.
  852. *
  853. * This functionality is used for alarms triggered by the IO-controller.
  854. *
  855. * When receiving this indication, the application shall
  856. * respond with \a pnet_alarm_send_ack(), which
  857. * may be called in the context of this callback.
  858. *
  859. * @param net InOut: The p-net stack instance
  860. * @param arg InOut: User-defined data (not used by p-net)
  861. * @param arep In: The AREP.
  862. * @param p_alarm_argument In: The alarm argument (with slot, subslot,
  863. * alarm_type etc)
  864. * @param data_len In: Data length
  865. * @param data_usi In: Alarm USI
  866. * @param p_data In: Alarm data
  867. * @return 0 on success.
  868. * Other values are ignored.
  869. */
  870. typedef int (*pnet_alarm_ind) (
  871. pnet_t * net,
  872. void * arg,
  873. uint32_t arep,
  874. const pnet_alarm_argument_t * p_alarm_argument,
  875. uint16_t data_len,
  876. uint16_t data_usi,
  877. const uint8_t * p_data);
  878. /**
  879. * The controller acknowledges the alarm sent previously.
  880. * It is now possible to send another alarm.
  881. *
  882. * This functionality is used for alarms triggered by the IO-device.
  883. *
  884. * It is optional to implement this callback.
  885. * The return value from this call-back function is ignored by the Profinet
  886. * stack.
  887. *
  888. * @param net InOut: The p-net stack instance
  889. * @param arg InOut: User-defined data (not used by p-net)
  890. * @param arep In: The AREP.
  891. * @param p_pnio_status In: Detailed ACK information.
  892. * @return 0 on success. Other values are ignored.
  893. */
  894. typedef int (*pnet_alarm_cnf) (
  895. pnet_t * net,
  896. void * arg,
  897. uint32_t arep,
  898. const pnet_pnio_status_t * p_pnio_status);
  899. /**
  900. * The controller acknowledges the alarm ACK sent previously.
  901. *
  902. * This functionality is used for alarms triggered by the IO-controller.
  903. *
  904. * It is optional to implement this callback.
  905. * The return value from this call-back function is ignored by the Profinet
  906. * stack.
  907. *
  908. * @param net InOut: The p-net stack instance
  909. * @param arg InOut: User-defined data (not used by p-net)
  910. * @param arep In: The AREP.
  911. * @param res In: 0 if ACK was received by the remote side.
  912. * This is cnf(+).
  913. * -1 if ACK was not received by the remote
  914. * side. This is cnf(-).
  915. * @return 0 on success. Other values are ignored.
  916. */
  917. typedef int (
  918. *pnet_alarm_ack_cnf) (pnet_t * net, void * arg, uint32_t arep, int res);
  919. /**
  920. * Indication to the application that a reset request was received from the
  921. * IO-controller.
  922. *
  923. * The IO-controller can ask for communication parameters or application
  924. * data to be reset, or to do a factory reset.
  925. *
  926. * This application call-back function is called by the Profinet stack on every
  927. * reset request (via the DCP "Set" command) from the Profinet controller.
  928. *
  929. * The application should reset the application data if
  930. * \a should_reset_application is true. For other cases this callback is
  931. * triggered for diagnostic reasons.
  932. *
  933. * The return value from this call-back function is ignored by the Profinet
  934. * stack.
  935. *
  936. * It is optional to implement this callback (if you do not have any application
  937. * data that could be reset).
  938. *
  939. * Reset modes:
  940. * * 0: (Power-on reset, not from IO-controller. Will not trigger this.)
  941. * * 1: Reset application data
  942. * * 2: Reset communication parameters (done by the stack)
  943. * * 99: Reset all (factory reset).
  944. *
  945. * The reset modes 1-9 (out of which 1 and 2 are supported here) are defined
  946. * by the Profinet standard. Value 99 is used here to indicate that the
  947. * IO-controller has requested a factory reset via another mechanism.
  948. *
  949. * In order to remain responsive to DCP communication and Ethernet switching,
  950. * the device should not do a hard or soft reset for reset mode 1 or 2. It is
  951. * allowed for the factory reset case (but not mandatory).
  952. *
  953. * No \a arep information is available, as this callback typically is triggered
  954. * when there is no active connection.
  955. *
  956. * @param net InOut: The p-net stack instance
  957. * @param arg InOut: User-defined data (not used by p-net)
  958. * @param should_reset_application In: True if the user should reset the
  959. * application data.
  960. * @param reset_mode In: Detailed reset information.
  961. * @return 0 on success. Other values are ignored.
  962. */
  963. typedef int (*pnet_reset_ind) (
  964. pnet_t * net,
  965. void * arg,
  966. bool should_reset_application,
  967. uint16_t reset_mode);
  968. /**
  969. * Indication to the application that the Profinet signal LED should change
  970. * state.
  971. *
  972. * Use this callback to implement control of the LED.
  973. *
  974. * It is optional to implement this callback (but a compliant Profinet device
  975. * must have a signal LED)
  976. *
  977. * No \a arep information is available, as this callback typically is triggered
  978. * when there is no active connection.
  979. *
  980. * @param net InOut: The p-net stack instance
  981. * @param arg InOut: User-defined data (not used by p-net)
  982. * @param led_state In: True if the signal LED should be on.
  983. * @return 0 on success.
  984. * -1 if an error occurred. Will trigger a log message.
  985. */
  986. typedef int (*pnet_signal_led_ind) (pnet_t * net, void * arg, bool led_state);
  987. /*
  988. * Network and device configuration.
  989. *
  990. * Configuration of the stack is performed by transferring a structure
  991. * in the call to pnet_init().
  992. *
  993. * Along with the configuration the initial (default) values of the
  994. * I&M data records are conveyed as well as the values used for
  995. * sending LLDP frames.
  996. *
  997. * Configuration values are taken as is. No validation is performed.
  998. */
  999. /**
  1000. * Describe which I&M values are supported.
  1001. *
  1002. * I&M0 is always supported.
  1003. *
  1004. */
  1005. typedef enum pnet_im_supported_values
  1006. {
  1007. PNET_SUPPORTED_IM1 = 0x0002,
  1008. PNET_SUPPORTED_IM2 = 0x0004,
  1009. PNET_SUPPORTED_IM3 = 0x0008,
  1010. /** Should only be used together with functional safety */
  1011. PNET_SUPPORTED_IM4 = 0x0010,
  1012. } pnet_im_supported_values_t;
  1013. /**
  1014. * The I&M0 data record is read-only by the controller.
  1015. *
  1016. * This data record is mandatory.
  1017. */
  1018. typedef struct pnet_im_0
  1019. {
  1020. uint8_t im_vendor_id_hi;
  1021. uint8_t im_vendor_id_lo;
  1022. /** Terminated string */
  1023. char im_order_id[PNET_ORDER_ID_MAX_LEN + 1];
  1024. /** Terminated string */
  1025. char im_serial_number[PNET_SERIAL_NUMBER_MAX_LEN + 1];
  1026. uint16_t im_hardware_revision;
  1027. char im_sw_revision_prefix;
  1028. uint8_t im_sw_revision_functional_enhancement;
  1029. uint8_t im_sw_revision_bug_fix;
  1030. uint8_t im_sw_revision_internal_change;
  1031. uint16_t im_revision_counter;
  1032. uint16_t im_profile_id;
  1033. uint16_t im_profile_specific_type;
  1034. /** Always 1 */
  1035. uint8_t im_version_major;
  1036. /** Always 1 */
  1037. uint8_t im_version_minor;
  1038. /** One bit for each supported I&M1..15. I&M0 is always supported.
  1039. Use pnet_im_supported_values_t. */
  1040. uint16_t im_supported;
  1041. } pnet_im_0_t;
  1042. /**
  1043. * The I&M1 data record is read-write by the controller.
  1044. *
  1045. * This data record is optional. If this data record is supported
  1046. * by the application then bit 1 in the im_supported member of I&M0 shall be
  1047. * set.
  1048. */
  1049. typedef struct pnet_im_1
  1050. {
  1051. /** Terminated string */
  1052. char im_tag_function[32 + 1];
  1053. /** Terminated string */
  1054. char im_tag_location[PNET_LOCATION_MAX_SIZE];
  1055. } pnet_im_1_t;
  1056. /**
  1057. * The I&M2 data record is read-write by the controller.
  1058. *
  1059. * This data record is optional. If this data record is supported
  1060. * by the application then bit 2 in the im_supported member of I&M0 shall be
  1061. * set.
  1062. */
  1063. typedef struct pnet_im_2
  1064. {
  1065. /** Terminated string in the format "YYYY-MM-DD HH:MM" */
  1066. char im_date[16 + 1];
  1067. } pnet_im_2_t;
  1068. /**
  1069. * The I&M3 data record is read-write by the controller.
  1070. *
  1071. * This data record is optional. If this data record is supported
  1072. * by the application then bit 3 in the im_supported member of I&M0 shall be
  1073. * set.
  1074. */
  1075. typedef struct pnet_im_3
  1076. {
  1077. /** Terminated string padded with spaces */
  1078. char im_descriptor[54 + 1];
  1079. } pnet_im_3_t;
  1080. /**
  1081. * The I&M4 data record is read-write by the controller.
  1082. *
  1083. * Used for functional safety.
  1084. *
  1085. * This data record is optional. If this data record is supported
  1086. * by the application then bit 4 in the im_supported member of I&M0 shall be
  1087. * set.
  1088. */
  1089. typedef struct pnet_im_4
  1090. {
  1091. /** Non-terminated binary string, padded with zeroes */
  1092. char im_signature[54];
  1093. } pnet_im_4_t;
  1094. /**
  1095. * The device-specific vendor and device identities.
  1096. *
  1097. * The vendor id is obtained from Profibus International.
  1098. *
  1099. * The device id is assigned by the vendor.
  1100. */
  1101. typedef struct pnet_cfg_device_id
  1102. {
  1103. uint8_t vendor_id_hi;
  1104. uint8_t vendor_id_lo;
  1105. uint8_t device_id_hi;
  1106. uint8_t device_id_lo;
  1107. } pnet_cfg_device_id_t;
  1108. /**
  1109. * Used for assigning a static IPv4 address to the device.
  1110. *
  1111. * The Profinet stack also supports assigning an IP address, mask and gateway
  1112. * address via DCP Set commands based on the Ethernet MAC address.
  1113. *
  1114. * An IP address of 0.0.0.1 has the member d=1, and the rest of the members
  1115. * set to 0.
  1116. *
  1117. */
  1118. typedef struct pnet_ip_addr_t
  1119. {
  1120. uint8_t a;
  1121. uint8_t b;
  1122. uint8_t c;
  1123. uint8_t d;
  1124. } pnet_cfg_ip_addr_t;
  1125. /**
  1126. * The Ethernet MAC address.
  1127. */
  1128. typedef struct pnet_ethaddr
  1129. {
  1130. uint8_t addr[6];
  1131. } pnet_ethaddr_t;
  1132. /* Including termination. Standard says 240 (without termination) */
  1133. #define PNET_CHASSIS_ID_MAX_SIZE (241)
  1134. /* Including termination. Standard says 240 (without termination) */
  1135. #define PNET_STATION_NAME_MAX_SIZE (241)
  1136. /* Including termination. Standard says 14 (without termination) */
  1137. #define PNET_PORT_NAME_MAX_SIZE (15)
  1138. /** Including termination */
  1139. #define PNET_LLDP_CHASSIS_ID_MAX_SIZE (PNET_CHASSIS_ID_MAX_SIZE)
  1140. /** Including termination */
  1141. #define PNET_LLDP_PORT_ID_MAX_SIZE \
  1142. (PNET_STATION_NAME_MAX_SIZE + PNET_PORT_NAME_MAX_SIZE)
  1143. /**
  1144. * Physical Port Configuration
  1145. */
  1146. typedef struct pnet_port_cfg
  1147. {
  1148. const char * netif_name;
  1149. /** Ethernet MAU type to use when it not can be read from hardware.
  1150. * For example
  1151. * 0x0010 = Copper 100 Mbit/s Full duplex.
  1152. * 0x001E = Copper 1000 Mbit/s Full duplex.
  1153. * See \a pnal_eth_mau_t for more examples. */
  1154. uint16_t default_mau_type;
  1155. } pnet_port_cfg_t;
  1156. /**
  1157. * IP Configuration
  1158. */
  1159. typedef struct pnet_ip_cfg
  1160. {
  1161. /** Not yet supported by stack. */
  1162. bool dhcp_enable;
  1163. pnet_cfg_ip_addr_t ip_addr;
  1164. pnet_cfg_ip_addr_t ip_mask;
  1165. pnet_cfg_ip_addr_t ip_gateway;
  1166. } pnet_ip_cfg_t;
  1167. /**
  1168. * Interface Configuration
  1169. *
  1170. * Configuration of network interfaces used by the stack.
  1171. * The \a main_netif_name defines the network interface used by a controller/PLC
  1172. * to access the device (called Management Port in Profinet).
  1173. * The \a physical_ports array defines the physical ports connected to the
  1174. * main_port.
  1175. *
  1176. * In the case one network interface is used, \a main_netif_name and
  1177. * \a physical_ports[0].netif_name will refer to the same network interface.
  1178. */
  1179. typedef struct pnet_if_cfg
  1180. {
  1181. /** Main (DAP) network interface */
  1182. const char * main_netif_name;
  1183. /** IP Settings for main network interface */
  1184. pnet_ip_cfg_t ip_cfg;
  1185. pnet_port_cfg_t physical_ports[PNET_MAX_PHYSICAL_PORTS];
  1186. } pnet_if_cfg_t;
  1187. /**
  1188. * This is all the configuration needed to use the Profinet stack.
  1189. *
  1190. * The application must supply the values in the call to
  1191. * function \a pnet_init().
  1192. */
  1193. typedef struct pnet_cfg
  1194. {
  1195. /** Tick interval in us.
  1196. * Specifies the time between calls to \a pnet_handle_periodic().
  1197. */
  1198. uint32_t tick_us;
  1199. pnet_state_ind state_cb;
  1200. pnet_connect_ind connect_cb;
  1201. pnet_release_ind release_cb;
  1202. pnet_dcontrol_ind dcontrol_cb;
  1203. pnet_ccontrol_cnf ccontrol_cb;
  1204. pnet_write_ind write_cb;
  1205. pnet_read_ind read_cb;
  1206. pnet_exp_module_ind exp_module_cb;
  1207. pnet_exp_submodule_ind exp_submodule_cb;
  1208. pnet_new_data_status_ind new_data_status_cb;
  1209. pnet_alarm_ind alarm_ind_cb;
  1210. pnet_alarm_cnf alarm_cnf_cb;
  1211. pnet_alarm_ack_cnf alarm_ack_cnf_cb;
  1212. pnet_reset_ind reset_cb;
  1213. pnet_signal_led_ind signal_led_cb;
  1214. pnet_sm_released_ind sm_released_cb;
  1215. /** User data passed to callbacks, not used by stack */
  1216. void * cb_arg;
  1217. pnet_im_0_t im_0_data;
  1218. pnet_im_1_t im_1_data;
  1219. pnet_im_2_t im_2_data;
  1220. pnet_im_3_t im_3_data;
  1221. pnet_im_4_t im_4_data;
  1222. pnet_cfg_device_id_t device_id;
  1223. pnet_cfg_device_id_t oem_device_id;
  1224. /** Default station name. Terminated string */
  1225. char station_name[PNET_STATION_NAME_MAX_SIZE];
  1226. /**
  1227. * Product name
  1228. *
  1229. * This is known as DeviceVendorValue and DeviceType in the Profinet
  1230. * specification. It constitutes the first part of SystemIdentification
  1231. * (sysDescr in SNMP). It may also be used to construct the Chassis ID.
  1232. * See IEC CDV 61158-6-10 ch. 4.10.3.3.1.
  1233. *
  1234. * Terminated string.
  1235. */
  1236. char product_name[PNET_PRODUCT_NAME_MAX_LEN + 1];
  1237. /** Smallest allowed data exchange interval, in units of 31.25 us.
  1238. * Used for triggering error messages to the PLC. Should match GSDML file.
  1239. * Typically 32, which corresponds to 1 ms. Max 0x1000 (128 ms) */
  1240. uint16_t min_device_interval;
  1241. /** Operating system dependent settings */
  1242. pnal_cfg_t pnal_cfg;
  1243. /** Send DCP HELLO message on startup if true. */
  1244. bool send_hello;
  1245. /** Number of physical ports. Should respect PNET_MAX_PHYSICAL_PORTS.
  1246. This parameter is useful when shipping a single compiled version of the
  1247. library, but there are several applications with different number of
  1248. ports. */
  1249. uint8_t num_physical_ports; // TODO int or uint16_t ?
  1250. /** Send diagnosis in the qualified format (otherwise extended format) */
  1251. bool use_qualified_diagnosis;
  1252. pnet_if_cfg_t if_cfg;
  1253. #if PNET_OPTION_DRIVER_ENABLE
  1254. bool driver_enable;
  1255. pnet_driver_config_t driver_config;
  1256. #endif
  1257. /** Storage between runs
  1258. * Terminated string with absolute path.
  1259. * Use NULL or empty string for current directory. */
  1260. char file_directory[PNET_MAX_DIRECTORYPATH_SIZE];
  1261. } pnet_cfg_t;
  1262. /*
  1263. * API function return values
  1264. *
  1265. * All functions return either (zero) 0 for a successful call or
  1266. * -1 for an unsuccessful call.
  1267. */
  1268. /**
  1269. * Initialize the Profinet stack.
  1270. *
  1271. * This function must be called to initialize the Profinet stack.
  1272. * @param p_cfg In: Profinet configuration. These values are used
  1273. * at first startup and at factory reset.
  1274. * @return a handle to the stack instance, or NULL if an error occurred.
  1275. */
  1276. PNET_EXPORT pnet_t * pnet_init (const pnet_cfg_t * p_cfg);
  1277. /**
  1278. * Execute all periodic functions within the ProfiNet stack.
  1279. *
  1280. * This function shall be called periodically by the application.
  1281. * The period is specified by the tick_us parameter, part of pnet_cfg_t
  1282. * configuration.
  1283. * The period should match the expected I/O data rate to and from the device.
  1284. * @param net InOut: The p-net stack instance
  1285. */
  1286. PNET_EXPORT void pnet_handle_periodic (pnet_t * net);
  1287. /**
  1288. * Application signals ready to exchange data.
  1289. *
  1290. * Sends a CControl request to the IO-controller.
  1291. *
  1292. * This function must be called _after_ the application has received
  1293. * the \a pnet_state_ind() user callback with PNET_EVENT_PRMEND,
  1294. * in order for a connection to be established.
  1295. *
  1296. * If this CControl request ("Application ready") is sent (to the PLC) before
  1297. * the DControl response ("Param end") is sent (to the PLC) there will
  1298. * be problems at startup.
  1299. *
  1300. * If this function does not see all PPM data and IOPS areas are set (by the
  1301. * app) then it returns error and the application must try again - otherwise the
  1302. * startup will hang.
  1303. *
  1304. * Triggers the \a pnet_state_ind() user callback with PNET_EVENT_APPLRDY.
  1305. *
  1306. * @param net InOut: The p-net stack instance
  1307. * @param arep In: The AREP
  1308. * @return 0 if the operation succeeded.
  1309. * -1 if an error occurred.
  1310. */
  1311. PNET_EXPORT int pnet_application_ready (pnet_t * net, uint32_t arep);
  1312. /**
  1313. * Application signals that it is ready to exchange data for a submodule that
  1314. * has changed owner.
  1315. *
  1316. * This should only be called after the application has set subslot data
  1317. * following a \a pnet_sm_released_ind() callback. It must not be called in any
  1318. * other situation.
  1319. *
  1320. * @param net InOut: The p-net stack instance
  1321. * @param arep In: The AREP
  1322. */
  1323. PNET_EXPORT void pnet_sm_released_cnf (pnet_t * net, uint32_t arep);
  1324. /**
  1325. * Plug a module into a slot.
  1326. *
  1327. * This function is used to plug a specific module into a specific slot.
  1328. *
  1329. * This function may be called from the \a pnet_exp_module_ind() call-back
  1330. * function of the application.
  1331. *
  1332. * @param net InOut: The p-net stack instance
  1333. * @param api In: The API identifier.
  1334. * @param slot In: The slot number.
  1335. * @param module_ident In: The module ident number.
  1336. * @return 0 if a module could be plugged into the slot.
  1337. * -1 if an error occurred (for example module already plugged)
  1338. */
  1339. PNET_EXPORT int pnet_plug_module (
  1340. pnet_t * net,
  1341. uint32_t api,
  1342. uint16_t slot,
  1343. uint32_t module_ident);
  1344. /**
  1345. * Plug a sub-module into a sub-slot.
  1346. *
  1347. * This function is used to plug a specific sub-module into a specific sub-slot.
  1348. *
  1349. * This function may be called from the \a pnet_exp_submodule_ind call-back
  1350. * function of the application.
  1351. *
  1352. * If a module has not been plugged into the designated slot then it will be
  1353. * plugged automatically by this function.
  1354. *
  1355. * @param net InOut: The p-net stack instance
  1356. * @param api In: The API identifier.
  1357. * @param slot In: The slot number.
  1358. * @param subslot In: The sub-slot number.
  1359. * @param module_ident In: The module ident number.
  1360. * @param submodule_ident In: The sub-module ident number.
  1361. * @param direction In: The direction of data.
  1362. * @param length_input In: The size in bytes of the input data.
  1363. * @param length_output In: The size in bytes of the output data.
  1364. * @return 0 if the sub-module could be plugged into the sub-slot.
  1365. * -1 if an error occurred (for example submodule already plugged)
  1366. */
  1367. PNET_EXPORT int pnet_plug_submodule (
  1368. pnet_t * net,
  1369. uint32_t api,
  1370. uint16_t slot,
  1371. uint16_t subslot,
  1372. uint32_t module_ident,
  1373. uint32_t submodule_ident,
  1374. pnet_submodule_dir_t direction,
  1375. uint16_t length_input,
  1376. uint16_t length_output);
  1377. /**
  1378. * Pull a module from a slot.
  1379. *
  1380. * This function may be used to unplug a module from a specific slot.
  1381. *
  1382. * This function internally calls pnet_pull_submodule() on any plugged
  1383. * sub-modules before pulling the module itself.
  1384. *
  1385. * @param net InOut: The p-net stack instance
  1386. * @param api In: The API identifier.
  1387. * @param slot In: The slot number.
  1388. * @return 0 if a module could be pulled from the slot.
  1389. * -1 if an error occurred (for example module not plugged)
  1390. */
  1391. PNET_EXPORT int pnet_pull_module (pnet_t * net, uint32_t api, uint16_t slot);
  1392. /**
  1393. * Pull a sub-module from a sub-slot.
  1394. *
  1395. * This function may be used to unplug a sub-module from a specific sub-slot.
  1396. *
  1397. * @param net InOut: The p-net stack instance
  1398. * @param api In: The API identifier.
  1399. * @param slot In: The slot number.
  1400. * @param subslot In: The sub-slot number.
  1401. * @return 0 if the sub-module could be pulled from the sub-slot.
  1402. * -1 if an error occurred (for example submodule not plugged)
  1403. */
  1404. PNET_EXPORT int pnet_pull_submodule (
  1405. pnet_t * net,
  1406. uint32_t api,
  1407. uint16_t slot,
  1408. uint16_t subslot);
  1409. /**
  1410. * Updates the IOPS and data of one sub-slot to send to the controller.
  1411. *
  1412. * This function may be called to set new data and IOPS values of a sub-slot to
  1413. * send to the controller.
  1414. *
  1415. * You need to call this function on all subslots having input data to the PLC,
  1416. * before calling \a pnet_application_ready(). This includes all subslots in the
  1417. * DAP slot (slot 0).
  1418. *
  1419. * This function will copy the user data to the frame buffer, for sending to the PLC.
  1420. *
  1421. * Note that setting the IOPS to BAD will trigger an
  1422. * "Error: User data failure of hardware component" in the PLC, and it
  1423. * typically needs to be cleared manually.
  1424. *
  1425. * @param net InOut: The p-net stack instance
  1426. * @param api In: The API.
  1427. * @param slot In: The slot.
  1428. * @param subslot In: The sub-slot.
  1429. * @param p_data In: User buffer with data to be sent. If NULL the data
  1430. * will not be updated.
  1431. * @param data_len In: Bytes in data buffer.
  1432. * @param iops In: The device provider status (GOOD or BAD).
  1433. * See pnet_ioxs_values_t
  1434. * @return 0 if a sub-module data and IOPS was set.
  1435. * -1 if an error occurred.
  1436. */
  1437. PNET_EXPORT int pnet_input_set_data_and_iops (
  1438. pnet_t * net,
  1439. uint32_t api,
  1440. uint16_t slot,
  1441. uint16_t subslot,
  1442. const uint8_t * p_data,
  1443. uint16_t data_len,
  1444. uint8_t iops);
  1445. /**
  1446. * Fetch the controller consumer status of one sub-slot.
  1447. *
  1448. * This function is used to retrieve the consumer status (IOCS) value of
  1449. * an input sub-slot (data sent to the controller) back from the controller.
  1450. *
  1451. * Note that this function will reset the \a p_new_flag flag that is available
  1452. * in the \a pnet_output_get_data_and_iops() function. See that documentation
  1453. * entry for details.
  1454. *
  1455. * @param net InOut: The p-net stack instance
  1456. * @param api In: The API.
  1457. * @param slot In: The slot.
  1458. * @param subslot In: The sub-slot.
  1459. * @param p_iocs Out: The controller consumer status (GOOD or BAD).
  1460. * See pnet_ioxs_values_t
  1461. * @return 0 if a sub-module IOCS was set.
  1462. * -1 if an error occurred.
  1463. */
  1464. PNET_EXPORT int pnet_input_get_iocs (
  1465. pnet_t * net,
  1466. uint32_t api,
  1467. uint16_t slot,
  1468. uint16_t subslot,
  1469. uint8_t * p_iocs);
  1470. /**
  1471. * Retrieve latest sub-slot data and IOPS received from the controller.
  1472. *
  1473. * This function may be called to retrieve the latest data and IOPS values
  1474. * of a sub-slot sent from the controller.
  1475. *
  1476. * Note that this function retrieves output data from the controller. The
  1477. * function \a pnet_input_set_data_and_iops() sends input data to the
  1478. * controller. Those are different data streams, so you can not expect to read
  1479. * back data that has been set by \a pnet_input_set_data_and_iops() using this
  1480. * function.
  1481. *
  1482. * This function will copy the data from the frame buffer (which has data from the PLC)
  1483. * to the user buffer.
  1484. *
  1485. * If a valid new data (and IOPS) frame has arrived from the IO-controller since
  1486. * your last call to this function (regardless of the slot/subslot arguments)
  1487. * then the flag \a p_new_flag is set to true, else it is set to false.
  1488. * Note that this does not check whether the data content has changed from
  1489. * any previous frame. This flag will be reset also by using
  1490. * \a pnet_input_get_iocs(), so it is recommended to execute
  1491. * \a pnet_output_get_data_and_iops() first if you are to execute both
  1492. * (and the value of the flag is important to your application).
  1493. *
  1494. * Note that the latest data and IOPS values are copied to the application
  1495. * buffers regardless of the value of \a p_new_flag.
  1496. *
  1497. * @param net InOut: The p-net stack instance
  1498. * @param api In: The API.
  1499. * @param slot In: The slot.
  1500. * @param subslot In: The sub-slot.
  1501. * @param p_new_flag Out: true if new data.
  1502. * @param p_data Out: User buffer for the received data.
  1503. * @param p_data_len In: Size of receive buffer.
  1504. * Out: Received number of data bytes.
  1505. * @param p_iops Out: The controller provider status (IOPS).
  1506. * See pnet_ioxs_values_t
  1507. * @return 0 if a sub-module data and IOPS is retrieved.
  1508. * -1 if an error occurred.
  1509. */
  1510. PNET_EXPORT int pnet_output_get_data_and_iops (
  1511. pnet_t * net,
  1512. uint32_t api,
  1513. uint16_t slot,
  1514. uint16_t subslot,
  1515. bool * p_new_flag,
  1516. uint8_t * p_data,
  1517. uint16_t * p_data_len,
  1518. uint8_t * p_iops);
  1519. /**
  1520. * Set the device consumer status for one sub-slot.
  1521. *
  1522. * This function is used to set the device consumer status (IOCS)
  1523. * of a specific sub-slot. It is used for output sub-slots (data from the
  1524. * controller) to send consumer status back to the controller.
  1525. *
  1526. * You need to call this function on all subslots having output data
  1527. * to the PLC, before calling \a pnet_application_ready().
  1528. *
  1529. * @param net InOut: The p-net stack instance
  1530. * @param api In: The API.
  1531. * @param slot In: The slot.
  1532. * @param subslot In: The sub-slot.
  1533. * @param iocs In: The device consumer status (GOOD or BAD).
  1534. * See pnet_ioxs_values_t
  1535. * @return 0 if a sub-module IOCS was set.
  1536. * -1 if an error occurred.
  1537. */
  1538. PNET_EXPORT int pnet_output_set_iocs (
  1539. pnet_t * net,
  1540. uint32_t api,
  1541. uint16_t slot,
  1542. uint16_t subslot,
  1543. uint8_t iocs);
  1544. /**
  1545. * Set the state to "Primary" or "Backup" in the cyclic data sent to the
  1546. * IO-Controller.
  1547. *
  1548. * Implements the "Local Set State" primitive.
  1549. *
  1550. * By default the cyclic communication is "Primary".
  1551. *
  1552. * @param net InOut: The p-net stack instance
  1553. * @param primary In: true to set state to "Primary".
  1554. * @return 0 if the operation succeeded.
  1555. * -1 if an error occurred.
  1556. */
  1557. PNET_EXPORT int pnet_set_primary_state (pnet_t * net, bool primary);
  1558. /**
  1559. * Set the state to redundant in the cyclic data sent to the IO-Controller.
  1560. *
  1561. * Implements the "Local Set Redundancy State" primitive.
  1562. *
  1563. * By default the cyclic communication is not in redundant state.
  1564. *
  1565. * @param net InOut: The p-net stack instance
  1566. * @param redundant In: true to set state to "redundant".
  1567. * @return 0 if the operation succeeded.
  1568. * -1 if an error occurred.
  1569. */
  1570. PNET_EXPORT int pnet_set_redundancy_state (pnet_t * net, bool redundant);
  1571. /**
  1572. * Implements the "Local set Provider State" primitive.
  1573. *
  1574. * The application should call this function at least once during startup to set
  1575. * the provider status of frames sent to the controller.
  1576. *
  1577. * The application may call this function at any time, e.g., to signal a
  1578. * temporary inability to produce new application data to the controller.
  1579. *
  1580. * Its effect is similar to setting IOPS to PNET_IOXS_BAD for all sub-slots.
  1581. *
  1582. * @param net InOut: The p-net stack instance
  1583. * @param run In: true to set state to "run".
  1584. * @return 0 if the operation succeeded.
  1585. * -1 if an error occurred.
  1586. */
  1587. PNET_EXPORT int pnet_set_provider_state (pnet_t * net, bool run);
  1588. /**
  1589. * Application requests abortion of the connection.
  1590. *
  1591. * @param net InOut: The p-net stack instance
  1592. * @param arep In: The AREP
  1593. * @return 0 if the operation succeeded.
  1594. * -1 if an error occurred.
  1595. */
  1596. PNET_EXPORT int pnet_ar_abort (pnet_t * net, uint32_t arep);
  1597. /**
  1598. * Application requests factory reset of the device.
  1599. *
  1600. * Use this for example when a local hardware switch is used to do a
  1601. * factory reset.
  1602. *
  1603. * Also closes any open connections.
  1604. *
  1605. * @param net InOut: The p-net stack instance
  1606. * @return 0 if the operation succeeded.
  1607. * -1 if an error occurred.
  1608. */
  1609. PNET_EXPORT int pnet_factory_reset (pnet_t * net);
  1610. /**
  1611. * Delete data files.
  1612. *
  1613. * Mainly intended for device development and testing.
  1614. * Applications should typically not use this function.
  1615. *
  1616. * Use \a pnet_factory_reset() instead, that uses this functionality internally.
  1617. *
  1618. * @param file_directory In: File directory
  1619. * @return 0 if the operation succeeded.
  1620. * -1 if an error occurred.
  1621. */
  1622. PNET_EXPORT int pnet_remove_data_files (const char * file_directory);
  1623. /**
  1624. * Fetch error information from the AREP.
  1625. *
  1626. * @param net InOut: The p-net stack instance
  1627. * @param arep In: The AREP.
  1628. * @param p_err_cls Out: The error class. See PNET_ERROR_CODE_1_*
  1629. * @param p_err_code Out: The error code. See PNET_ERROR_CODE_2_*
  1630. * @return 0 If the AREP is valid.
  1631. * -1 if the AREP is not valid.
  1632. */
  1633. PNET_EXPORT int pnet_get_ar_error_codes (
  1634. pnet_t * net,
  1635. uint32_t arep,
  1636. uint16_t * p_err_cls,
  1637. uint16_t * p_err_code);
  1638. /**
  1639. * Application creates an entry in the log book.
  1640. *
  1641. * This function is used to insert an entry into the Profinet log-book.
  1642. * Controllers may read the entire log-book using IODRead requests.
  1643. *
  1644. * @param net InOut: The p-net stack instance
  1645. * @param arep In: The AREP.
  1646. * @param p_pnio_status In: The PNIO status.
  1647. * @param entry_detail In: Additional application information.
  1648. * Manufacturer specific.
  1649. */
  1650. PNET_EXPORT void pnet_create_log_book_entry (
  1651. pnet_t * net,
  1652. uint32_t arep,
  1653. const pnet_pnio_status_t * p_pnio_status,
  1654. uint32_t entry_detail);
  1655. /**
  1656. * Application issues a process alarm.
  1657. *
  1658. * This function may be used by the application to issue a process alarm.
  1659. * Such alarms are sent to the controller using high-priority alarm messages.
  1660. *
  1661. * Optional payload may be attached to the alarm. If \a payload_usi is != 0
  1662. * and \a payload_len > 0 then
  1663. * the \a payload_usi and the payload at \a p_payload is attached to the alarm.
  1664. *
  1665. * After calling this function the application must wait for
  1666. * the \a pnet_alarm_cnf() callback before sending another alarm.
  1667. * This function fails if the application does not wait for the
  1668. * \a pnet_alarm_cnf() between sending two alarms.
  1669. *
  1670. * Note that the PLC can set the max alarm payload length at startup. This
  1671. * limit can be 200 to 1432 bytes.
  1672. *
  1673. * This functionality is used for alarms triggered by the IO-device.
  1674. *
  1675. * @param net InOut: The p-net stack instance
  1676. * @param arep In: The AREP.
  1677. * @param api In: The API.
  1678. * @param slot In: The slot.
  1679. * @param subslot In: The sub-slot.
  1680. * @param payload_usi In: The USI for the payload. Max 0x7fff
  1681. * @param payload_len In: Length in bytes of the payload. May be 0.
  1682. * Max PNET_MAX_ALARM_PAYLOAD_DATA_SIZE or
  1683. * value from PLC.
  1684. * @param p_payload In: The alarm payload (USI specific format).
  1685. * @return 0 if the operation succeeded.
  1686. * -1 if an error occurred (or waiting for ACK from controller: re-try
  1687. * later).
  1688. */
  1689. PNET_EXPORT int pnet_alarm_send_process_alarm (
  1690. pnet_t * net,
  1691. uint32_t arep,
  1692. uint32_t api,
  1693. uint16_t slot,
  1694. uint16_t subslot,
  1695. uint16_t payload_usi,
  1696. uint16_t payload_len,
  1697. const uint8_t * p_payload);
  1698. /**
  1699. * Application acknowledges the reception of an alarm from the controller.
  1700. *
  1701. * This function sends an ACK to the controller.
  1702. * This function must be called by the application after receiving an alarm
  1703. * in the \a pnet_alarm_ind() call-back. Failure to do so within the timeout
  1704. * specified in the connect of the controller will make the controller
  1705. * re-send the alarm.
  1706. *
  1707. * This functionality is used for alarms triggered by the IO-controller.
  1708. *
  1709. * @param net InOut: The p-net stack instance
  1710. * @param arep In: The AREP.
  1711. * @param p_alarm_argument In: The alarm argument (with slot, subslot,
  1712. * alarm_type etc)
  1713. * @param p_pnio_status In: Detailed ACK status.
  1714. * @return 0 if the operation succeeded.
  1715. * -1 if an error occurred.
  1716. */
  1717. PNET_EXPORT int pnet_alarm_send_ack (
  1718. pnet_t * net,
  1719. uint32_t arep,
  1720. const pnet_alarm_argument_t * p_alarm_argument,
  1721. const pnet_pnio_status_t * p_pnio_status);
  1722. /* ****************************** Diagnosis ****************************** */
  1723. #define PNET_CHANNEL_WHOLE_SUBMODULE 0x8000
  1724. /**
  1725. * Channel size in bits. Values 8..255 are reserved.
  1726. */
  1727. typedef enum pnet_diag_ch_prop_type_values
  1728. {
  1729. PNET_DIAG_CH_PROP_TYPE_UNSPECIFIED = 0,
  1730. PNET_DIAG_CH_PROP_TYPE_1_BIT = 1,
  1731. PNET_DIAG_CH_PROP_TYPE_2_BIT = 2,
  1732. PNET_DIAG_CH_PROP_TYPE_4_BIT = 3,
  1733. PNET_DIAG_CH_PROP_TYPE_8_BIT = 4,
  1734. PNET_DIAG_CH_PROP_TYPE_16_BIT = 5,
  1735. PNET_DIAG_CH_PROP_TYPE_32_BIT = 6,
  1736. PNET_DIAG_CH_PROP_TYPE_64_BIT = 7,
  1737. } pnet_diag_ch_prop_type_values_t;
  1738. /** Channel group or individual channel. Also known as "Accumulative" */
  1739. typedef enum pnet_diag_ch_group_values
  1740. {
  1741. PNET_DIAG_CH_INDIVIDUAL_CHANNEL = 0,
  1742. PNET_DIAG_CH_CHANNEL_GROUP = 1
  1743. } pnet_diag_ch_group_values_t;
  1744. /**
  1745. * Channel direction.
  1746. */
  1747. typedef enum pnet_diag_ch_prop_dir_values
  1748. {
  1749. PNET_DIAG_CH_PROP_DIR_MANUF_SPEC = 0,
  1750. PNET_DIAG_CH_PROP_DIR_INPUT = 1,
  1751. PNET_DIAG_CH_PROP_DIR_OUTPUT = 2,
  1752. PNET_DIAG_CH_PROP_DIR_INOUT = 3,
  1753. } pnet_diag_ch_prop_dir_values_t;
  1754. /**
  1755. * Diagnosis severity.
  1756. */
  1757. typedef enum pnet_diag_ch_prop_maint_values
  1758. {
  1759. PNET_DIAG_CH_PROP_MAINT_FAULT = 0,
  1760. PNET_DIAG_CH_PROP_MAINT_REQUIRED = 1,
  1761. PNET_DIAG_CH_PROP_MAINT_DEMANDED = 2,
  1762. PNET_DIAG_CH_PROP_MAINT_QUALIFIED = 3,
  1763. } pnet_diag_ch_prop_maint_values_t;
  1764. /**
  1765. * Diagnosis source.
  1766. */
  1767. typedef struct pnet_diag_source
  1768. {
  1769. uint32_t api;
  1770. uint16_t slot;
  1771. uint16_t subslot;
  1772. /** 0 - 0x7FFF manufacturer specific, 0x8000 whole submodule */
  1773. uint16_t ch;
  1774. pnet_diag_ch_group_values_t ch_grouping;
  1775. pnet_diag_ch_prop_dir_values_t ch_direction;
  1776. } pnet_diag_source_t;
  1777. /**
  1778. * Add a diagnosis entry, in the standard format.
  1779. *
  1780. * The channel error types and the extended channel error types are
  1781. * defined in Profinet 2.4 Services Annex F.
  1782. *
  1783. * This sends a diagnosis alarm.
  1784. *
  1785. * Uses the "Qualified channel diagnosis" format on the wire if the
  1786. * configuration parameter use_qualified_diagnosis is true, otherwise
  1787. * "Extended channel diagnosis".
  1788. *
  1789. * @param net InOut: The p-net stack instance.
  1790. * @param p_diag_source In: Slot, subslot, channel, direction etc.
  1791. * @param ch_bits In: Number of bits in the channel.
  1792. * @param severity In: Diagnosis severity.
  1793. * @param ch_error_type In: The channel error type.
  1794. * @param ext_ch_error_type In: The extended channel error type
  1795. * (more details on the channel error type).
  1796. * Use 0 if not given.
  1797. * @param ext_ch_add_value In: The extended channel error additional
  1798. * value. Typically a measurement value (for
  1799. * example number of dropped packets) related
  1800. * to the error.
  1801. * @param qual_ch_qualifier In: More detailed severity information. Used
  1802. * when severity =
  1803. * PNET_DIAG_CH_PROP_MAINT_QUALIFIED and the
  1804. * use_qualified_diagnosis is enabled.
  1805. * Max one bit should be set.
  1806. * Use 0 otherwise.
  1807. * @return 0 if the operation succeeded.
  1808. * -1 if an error occurred.
  1809. */
  1810. PNET_EXPORT int pnet_diag_std_add (
  1811. pnet_t * net,
  1812. const pnet_diag_source_t * p_diag_source,
  1813. pnet_diag_ch_prop_type_values_t ch_bits,
  1814. pnet_diag_ch_prop_maint_values_t severity,
  1815. uint16_t ch_error_type,
  1816. uint16_t ext_ch_error_type,
  1817. uint32_t ext_ch_add_value,
  1818. uint32_t qual_ch_qualifier);
  1819. /**
  1820. * Update the "extended channel error additional value", for a diagnosis entry
  1821. * in the standard format.
  1822. *
  1823. * The Profinet standard says that diagnosis updates should not be done at a
  1824. * higher frequency than 1 Hz.
  1825. *
  1826. * This sends a diagnosis alarm.
  1827. *
  1828. * @param net InOut: The p-net stack instance.
  1829. * @param p_diag_source In: Slot, subslot, channel, direction etc.
  1830. * @param ch_error_type In: The channel error type.
  1831. * @param ext_ch_error_type In: The extended channel error type
  1832. * (more details on the channel error type).
  1833. * Use 0 if not given.
  1834. * @param ext_ch_add_value In: New extended channel error additional value.
  1835. * Typically a measurement value (for
  1836. * example number of dropped packets) related
  1837. * to the error.
  1838. * @return 0 if the operation succeeded.
  1839. * -1 if an error occurred.
  1840. */
  1841. PNET_EXPORT int pnet_diag_std_update (
  1842. pnet_t * net,
  1843. const pnet_diag_source_t * p_diag_source,
  1844. uint16_t ch_error_type,
  1845. uint16_t ext_ch_error_type,
  1846. uint32_t ext_ch_add_value);
  1847. /**
  1848. * Remove a diagnosis entry in the standard format.
  1849. *
  1850. * An error is returned if the diagnosis doesn't exist.
  1851. *
  1852. * This sends a diagnosis alarm.
  1853. *
  1854. * @param net InOut: The p-net stack instance.
  1855. * @param p_diag_source In: Slot, subslot, channel, direction etc.
  1856. * @param ch_error_type In: The channel error type.
  1857. * @param ext_ch_error_type In: The extended channel error type
  1858. * (more details on the channel error type).
  1859. * Use 0 if not given.
  1860. * @return 0 if the operation succeeded.
  1861. * -1 if an error occurred.
  1862. */
  1863. PNET_EXPORT int pnet_diag_std_remove (
  1864. pnet_t * net,
  1865. const pnet_diag_source_t * p_diag_source,
  1866. uint16_t ch_error_type,
  1867. uint16_t ext_ch_error_type);
  1868. /**
  1869. * Add a diagnosis entry in manufacturer-specified ("USI") format.
  1870. *
  1871. * If the diagnosis already exists, it is updated.
  1872. * Use \a pnet_diag_usi_update() instead if you would like to have an error
  1873. * if the diagnosis is missing when trying to update it.
  1874. *
  1875. * A diagnosis in USI format is always assigned to the channel “whole submodule”
  1876. * (not individual channels). The severity is always “Fault”, the accumulative
  1877. * flag is false and the direction is "Manufacturer specific".
  1878. *
  1879. * It is recommended to use the standard diagnosis format in most cases.
  1880. * Use the manufacturer specific format ("USI format") only if it's not
  1881. * possible to use the standard format.
  1882. *
  1883. * Note that the PLC can set the max alarm payload length at startup, and
  1884. * that affects how large diagnosis entries can be sent via alarms.
  1885. * This payload limit can be 200 to 1432 bytes.
  1886. *
  1887. * This sends a diagnosis alarm.
  1888. *
  1889. * @param net InOut: The p-net stack instance.
  1890. * @param api In: The API.
  1891. * @param slot In: The slot.
  1892. * @param subslot In: The sub-slot.
  1893. * @param usi In: The USI. Range 0..0x7fff
  1894. * @param manuf_data_len In: Length in bytes of the
  1895. * manufacturer specific diagnosis data.
  1896. * A value 0 is allowed.
  1897. * Max PNET_MAX_DIAG_MANUF_DATA_SIZE or value
  1898. * from PLC.
  1899. * @param p_manuf_data In: The manufacturer specific diagnosis data.
  1900. * Mandatory if manuf_data_len > 0, otherwise
  1901. * NULL.
  1902. * @return 0 if the operation succeeded.
  1903. * -1 if an error occurred.
  1904. */
  1905. PNET_EXPORT int pnet_diag_usi_add (
  1906. pnet_t * net,
  1907. uint32_t api,
  1908. uint16_t slot,
  1909. uint16_t subslot,
  1910. uint16_t usi,
  1911. uint16_t manuf_data_len,
  1912. const uint8_t * p_manuf_data);
  1913. /**
  1914. * Update the manufacturer specific data, for a diagnosis entry in
  1915. * manufacturer-specified ("USI") format.
  1916. *
  1917. * An error is returned if the diagnosis doesn't exist.
  1918. * Use \a pnet_diag_usi_add() instead if you would like to create the
  1919. * missing diagnosis when trying to update it.
  1920. *
  1921. * Note that the PLC can set the max alarm payload length at startup, and
  1922. * that affects how large diagnosis entries can be sent via alarms.
  1923. * This payload limit can be 200 to 1432 bytes.
  1924. *
  1925. * The Profinet standard says that diagnosis updates should not be done at a
  1926. * higher frequency than 1 Hz.
  1927. *
  1928. * This sends a diagnosis alarm.
  1929. *
  1930. * @param net InOut: The p-net stack instance.
  1931. * @param api In: The API.
  1932. * @param slot In: The slot.
  1933. * @param subslot In: The sub-slot.
  1934. * @param usi In: The USI. Range 0..0x7fff
  1935. * @param manuf_data_len In: Length in bytes of the
  1936. * manufacturer specific diagnosis data.
  1937. * A value 0 is allowed.
  1938. * Max PNET_MAX_DIAG_MANUF_DATA_SIZE or
  1939. * value from PLC.
  1940. * @param p_manuf_data In: New manufacturer specific diagnosis data.
  1941. * Mandatory if manuf_data_len > 0, otherwise
  1942. * NULL.
  1943. * @return 0 if the operation succeeded.
  1944. * -1 if an error occurred.
  1945. */
  1946. PNET_EXPORT int pnet_diag_usi_update (
  1947. pnet_t * net,
  1948. uint32_t api,
  1949. uint16_t slot,
  1950. uint16_t subslot,
  1951. uint16_t usi,
  1952. uint16_t manuf_data_len,
  1953. const uint8_t * p_manuf_data);
  1954. /**
  1955. * Remove a diagnosis entry in manufacturer-specified ("USI") format.
  1956. *
  1957. * An error is returned if the diagnosis doesn't exist.
  1958. *
  1959. * This sends a diagnosis alarm.
  1960. *
  1961. * @param net InOut: The p-net stack instance.
  1962. * @param api In: The API.
  1963. * @param slot In: The slot.
  1964. * @param subslot In: The sub-slot.
  1965. * @param usi In: The USI. Range 0..0x7fff
  1966. * @return 0 if the operation succeeded.
  1967. * -1 if an error occurred.
  1968. */
  1969. PNET_EXPORT int pnet_diag_usi_remove (
  1970. pnet_t * net,
  1971. uint32_t api,
  1972. uint16_t slot,
  1973. uint16_t subslot,
  1974. uint16_t usi);
  1975. /**
  1976. * Add a diagnosis entry, in standard or USI format.
  1977. *
  1978. * This is a low-level function. Typically you should use one of these instead
  1979. * (which uses this function internally):
  1980. * - pnet_diag_std_add()
  1981. * - pnet_diag_usi_add()
  1982. *
  1983. * Note that the PLC can set the max alarm payload length at startup, and
  1984. * that affects how large diagnosis entries can be sent via alarms.
  1985. * This payload limit can be 200 to 1432 bytes.
  1986. *
  1987. * This sends a diagnosis alarm.
  1988. *
  1989. * @param net InOut: The p-net stack instance.
  1990. * @param p_diag_source In: Slot, subslot, channel, direction etc.
  1991. * @param ch_bits In: Number of bits in the channel.
  1992. * @param severity In: Diagnosis severity.
  1993. * @param ch_error_type In: The channel error type.
  1994. * @param ext_ch_error_type In: The extended channel error type.
  1995. * @param ext_ch_add_value In: The extended channel error additional
  1996. * value.
  1997. * @param qual_ch_qualifier In: The qualified channel qualifier.
  1998. * @param usi In: The USI.
  1999. * @param manuf_data_len In: Length in bytes of the
  2000. * manufacturer specific diagnosis data.
  2001. * Max PNET_MAX_DIAG_MANUF_DATA_SIZE or
  2002. * value from PLC.
  2003. * (Only needed if USI <= 0x7fff,
  2004. * and may still be 0).
  2005. * @param p_manuf_data In: The manufacturer specific diagnosis data.
  2006. * (Only needed if USI <= 0x7fff).
  2007. * @return 0 if the operation succeeded.
  2008. * -1 if an error occurred.
  2009. */
  2010. PNET_EXPORT int pnet_diag_add (
  2011. pnet_t * net,
  2012. const pnet_diag_source_t * p_diag_source,
  2013. pnet_diag_ch_prop_type_values_t ch_bits,
  2014. pnet_diag_ch_prop_maint_values_t severity,
  2015. uint16_t ch_error_type,
  2016. uint16_t ext_ch_error_type,
  2017. uint32_t ext_ch_add_value,
  2018. uint32_t qual_ch_qualifier,
  2019. uint16_t usi,
  2020. uint16_t manuf_data_len,
  2021. const uint8_t * p_manuf_data);
  2022. /**
  2023. * Update a diagnosis entry, in standard or USI format.
  2024. *
  2025. * This is a low-level function. Typically you should use one of these instead
  2026. * (which uses this function internally):
  2027. * - pnet_diag_std_update()
  2028. * - pnet_diag_usi_update()
  2029. *
  2030. * If the USI of the item is in the manufacturer-specified range then
  2031. * the USI is used to identify the item.
  2032. * Otherwise the other parameters are used (all must match):
  2033. * - p_diag_source (all fields)
  2034. * - Channel error type.
  2035. * - Extended error type.
  2036. *
  2037. * When the item is found either the manufacturer data is updated (for
  2038. * USI in manufacturer-specific range) or the extended channel additional
  2039. * value is updated.
  2040. *
  2041. * Note that the PLC can set the max alarm payload length at startup, and
  2042. * that affects how large diagnosis entries can be sent via alarms.
  2043. * This payload limit can be 200 to 1432 bytes.
  2044. *
  2045. * This sends a diagnosis alarm.
  2046. *
  2047. * @param net InOut: The p-net stack instance.
  2048. * @param p_diag_source In: Slot, subslot, channel, direction etc.
  2049. * @param ch_error_type In: The channel error type.
  2050. * @param ext_ch_error_type In: The extended channel error type, or 0.
  2051. * @param ext_ch_add_value In: New extended channel error additional value.
  2052. * @param usi In: The USI.
  2053. * @param manuf_data_len In: Length in bytes of the
  2054. * manufacturer specific diagnosis data.
  2055. * Max PNET_MAX_DIAG_MANUF_DATA_SIZE or
  2056. * value from PLC.
  2057. * (Only needed if USI <= 0x7fff,
  2058. * and may still be 0).
  2059. * @param p_manuf_data In: New manufacturer specific diagnosis data.
  2060. * (Only needed if USI <= 0x7fff).
  2061. * @return 0 if the operation succeeded.
  2062. * -1 if an error occurred.
  2063. */
  2064. PNET_EXPORT int pnet_diag_update (
  2065. pnet_t * net,
  2066. const pnet_diag_source_t * p_diag_source,
  2067. uint16_t ch_error_type,
  2068. uint16_t ext_ch_error_type,
  2069. uint32_t ext_ch_add_value,
  2070. uint16_t usi,
  2071. uint16_t manuf_data_len,
  2072. const uint8_t * p_manuf_data);
  2073. /**
  2074. * Remove a diagnosis entry, in standard or USI format.
  2075. *
  2076. * This is a low-level function. Typically you should use one of these instead
  2077. * (which uses this function internally):
  2078. * - pnet_diag_std_remove()
  2079. * - pnet_diag_usi_remove()
  2080. *
  2081. * If the USI of the item is in the manufacturer-specified range then
  2082. * the USI is used to identify the item.
  2083. * Otherwise the other parameters are used (all must match):
  2084. * - p_diag_source (all fields)
  2085. * - Channel error type.
  2086. * - Extended error type.
  2087. *
  2088. * This sends a diagnosis alarm.
  2089. *
  2090. * @param net InOut: The p-net stack instance.
  2091. * @param p_diag_source In: Slot, subslot, channel, direction etc.
  2092. * @param ch_error_type In: The channel error type.
  2093. * @param ext_ch_error_type In: The extended channel error type, or 0.
  2094. * @param usi In: The USI.
  2095. * @return 0 if the operation succeeded.
  2096. * -1 if an error occurred.
  2097. */
  2098. PNET_EXPORT int pnet_diag_remove (
  2099. pnet_t * net,
  2100. const pnet_diag_source_t * p_diag_source,
  2101. uint16_t ch_error_type,
  2102. uint16_t ext_ch_error_type,
  2103. uint16_t usi);
  2104. /******************** Show Profinet stack info ********************************/
  2105. /**
  2106. * Show information from the Profinet stack.
  2107. *
  2108. * @param net InOut: The p-net stack instance
  2109. * @param level In: The amount of detail to show.
  2110. *
  2111. * 0x0010 | Show compile time options
  2112. * 0x0020 | Show CMDEV
  2113. * 0x0080 | Show SNMP
  2114. * 0x0100 | Show Ports
  2115. * 0x0200 | Show diagnosis
  2116. * 0x0400 | Show logbook
  2117. * 0x0800 | Show all sessions.
  2118. * 0x1000 | Show all ARs.
  2119. * 0x1001 | include IOCR.
  2120. * 0x1002 | include data_descriptors.
  2121. * 0x1003 | include IOCR and data_descriptors.
  2122. * 0x2000 | Show config/CMINA information.
  2123. * 0x4000 | Show scheduler information.
  2124. * 0x8000 | Show I&M data.
  2125. *
  2126. * Bit in the level parameter:
  2127. * 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
  2128. * 1 I&M
  2129. * 1 Scheduler
  2130. * 1 CMINA
  2131. * 1 AR
  2132. * 1 Sessions
  2133. * 1 Logbook
  2134. * 1 Diagnosis
  2135. * 1 Ports
  2136. * 1 SNMP
  2137. * 1 CMDEV
  2138. * 1 Options
  2139. * 1 More IOCR info on AR
  2140. * 1 More IOCR info on AR
  2141. */
  2142. PNET_EXPORT void pnet_show (pnet_t * net, unsigned level);
  2143. #ifdef __cplusplus
  2144. }
  2145. #endif
  2146. #endif /* PNET_API_H */