Supported platforms: CODESYS 3.5, CODESYS 3.5 SAFETY
This function calculates safety configuration signature of one SRDO from given input parameters.
This function is intended to be used in device that configures safety unit. E.g. a display unit. |
SRDO signature is calculated by MultiTool Creator when configuring the unit with it. |
Unlike all other CRCs, safety configuration signature is specified to be calculated little-endian. |
This function is endianness-aware. Separate big-endian format conversions shall NOT be used. |
Signature calculation is described in CANopen safety standard EN50325-5. |
The function calculates CRC sequentially over SRDO communication and mapping parameters. As mentioned in safety parameter checksum calculation, each member of SRDO communication parameter STRUCT, and each mapping parameter has to be calculated individually. At start the i_Seed input parameter value for used Calculate16bitCRC is 0. Each following seed value is the result of preceding checksum calculation. All checksum calculations use i_Polynomial parameter value 1021h.
Order |
Index |
Sub-index |
Name |
Size |
1 |
1301h SRDO Communication parameter |
1 |
Information direction |
1 byte |
2 |
2 |
Safeguard Cycle Time / Refresh Time |
2 bytes |
|
3 |
3 |
SR Validation Time |
1 byte |
|
4 |
5 |
COB-ID 1 |
4 bytes |
|
5 |
6 |
COB-ID 2 |
4 bytes |
|
6 |
1381h SRDO mapping parameter |
0 |
Number of SRDO mapping parameters |
1 byte |
7 |
1 |
Sub-index number |
1 byte |
|
8 |
1 |
SRDO 1 plain variable 1 mapping |
4 bytes |
|
9 |
2 |
Sub-index number |
1 byte |
|
10 |
2 |
SRDO 1 inverted variable 1 mapping |
4 bytes |
|
… |
… |
… |
… |
|
259 |
127 |
Sub-index number |
1 byte |
|
260 |
127 |
SRDO 1 plain variable 64 mapping |
4 bytes |
|
261 |
128 |
Sub-index number |
1 byte |
|
262 |
128 |
SRDO 1 inverted variable 64 mapping |
4 bytes |
Input variable name |
Data type |
Unit |
Range |
Description |
i_InfoDirection |
BYTE |
- |
0 - 2 |
0 = not valid 1 = SRDO producer 2 = SRDO consumer |
i_SCTime |
UINT |
ms |
- |
Safety Cycle Time / Refresh Time of SRDO |
i_SRVTime |
USINT |
ms |
- |
Safety-Related Validation Time of SRDO |
i_COBID1 |
DWORD |
- |
101h - 17Fh, odd values only |
Plain SRDO message COB-ID |
i_COBID2 |
DWORD |
- |
102h – 180h, even values only |
Inverted SRDO message COB-ID |
i_Mappings |
USINT |
- |
> 0 |
Number of variable mappings of one SRDO message |
i_pMapping |
POINTER TO BYTE |
- |
≠ 0 |
Pointer to variable mapping table of one SRDO message |
Output variable name |
Data type |
Range |
Description |
o_OutputValid |
BOOL |
TRUE/FALSE |
Calculated value is valid. |
o_ParameterError |
BOOL |
TRUE/FALSE |
Error in input parameters. |
Data type |
Description |
WORD |
Calculated SRDO signature. |
Conditions |
Return value |
o_OutputValid |
o_ParameterError |
i_pMapping = 0 OR i_Mappings = 0 OR i_COBID1 out of range OR i_COBID2 out of range |
0 |
FALSE |
TRUE |
Parameters ok |
Calculated result |
TRUE |
FALSE |
Definitions at global variable list G_CAN1_TSRDO: |
|
(*NOTE! This object is created by Epec MultiTool Creator*)
/// Plain SRDO variables tdw1 AT %MD0: DWORD := DWORD#16#0; tdw2 AT %MD1: DWORD := DWORD#16#0;
/// Inverted SRDO variables tdw1_i AT %MD2: DWORD := DWORD#16#0; tdw2_i AT %MD3: DWORD := DWORD#16#0;
/// Plain SRDO variable timestamps tdw1_TIME: UDINT := UDINT#0; tdw2_TIME: UDINT := UDINT#0;
/// Inverted SRDO variable timestamps tdw1_i_TIME: UDINT := UDINT#0; tdw2_i_TIME: UDINT := UDINT#0;
|
Definitions at global variable list G_CANopen_CAN1: |
|
(*NOTE! This object is created by Epec MultiTool Creator*)
/// SRDO SRDO: EPEC_CANopen.SRDOData; (* Protocol data *) SRDOS: ARRAY[1..2] OF EPEC_CANopen.CANopenSRDO; (* SRDO instances *) SRDO_Handler: EPEC_CANopen.CANopenSRDOHandler; (* Protocol handler *) SRDO_Error: EPEC_CANopen.Errors := EPEC_CANopen.Errors.NotInitialized; SRDO_Triggers: ARRAY[1..2] OF BOOL; SRDO_Signatures: ARRAY[1..2] OF WORD; SRDO_EventCodes: ARRAY[1..2] OF EPEC_DITF.EventCode;
|
Definitions at global variable list G_CANopen_CAN1_Mappings: |
|
(*NOTE! This object is created by Epec MultiTool Creator*)
/// SRDO variable mappings SRDO1Mappings: ARRAY [1..G_CANOPEN_NUMBER_OF_LAST_SRDO_MAP*2] OF DWORD := [ DWORD#16#5FD60120, (* G_CAN1_TSRDO.tdw1 *) DWORD#16#5FD50120, (* G_CAN1_TSRDO.tdw1_i *) DWORD#16#5FD60220, (* G_CAN1_TSRDO.tdw2 *) DWORD#16#5FD50220, (* G_CAN1_TSRDO.tdw2_i *) 12(DWORD#16#0)]; (* 16 - 4 = 12 *)
|
SRDO protocol initialization at non-safe Init_CANopen_CAN1 (PRG): |
|
(*NOTE! This object is created by Epec MultiTool Creator*)
(*Define SRDO protocol*) G_CANopen_CAN1.Protocols[6].Protocol:=EPEC_CANopen.ProtocolType.SRDO; G_CANopen_CAN1.Protocols[6].pData:=ADR(G_CANopen_CAN1.SRDO); G_CANopen_CAN1.Protocols[6].itfProtocol:=G_CANopen_CAN1.SRDO_Handler; G_CANopen_CAN1.Protocols[6].pError:=ADR(G_CANopen_CAN1.SRDO_Error); G_CANopen_CAN1.ProtocolAdded[6] := CANopenDeviceAddProtocol( (* Add to protocol stack *) i_pDevice:=ADR(G_CANopen_CAN1.Device), i_pProtocol:=ADR(G_CANopen_CAN1.Protocols[6]) ); IF G_CANopen_CAN1.ProtocolAdded[6] THEN G_CANopen_CAN1.SRDO_Handler.Init( i_pDevice := ADR(G_CANopen_CAN1.Device) ); ELSE G_CANopen_CAN1.SRDO_Error := EPEC_CANopen.Errors.ProtocolDataMissing; END_IF
SRDO initialization at non-safe Init_CANopen_CAN1 (PRG):
(* Init SRDOs *) G_CANopen_CAN1.SRDOS[1].i_pTimings[1]:= ADR(G_CAN1_TSRDO.tdw1_TIME); (*tdw1 *) G_CANopen_CAN1.SRDOS[1].i_pTimings[2]:= ADR(G_CAN1_TSRDO.tdw1_i_TIME); (*tdw1_i *) G_CANopen_CAN1.SRDOS[1].i_pTimings[3]:= ADR(G_CAN1_TSRDO.tdw2_TIME); (*tdw2 *) G_CANopen_CAN1.SRDOS[1].i_pTimings[4]:= ADR(G_CAN1_TSRDO.tdw2_i_TIME); (*tdw2_i *) G_CANopen_CAN1.SRDOS[1].Init( i_pDevice := ADR(G_CANopen_CAN1.Device), i_SRDONumber := 1, i_SRDOType := EPEC_CANopen.SRDOType.TransmitSRDO, i_SCTime := UINT#25, (* TSRDO Refresh Time (ms) *) i_SRVTime := USINT#0, (* Validation time (rx) (ms) *) i_COB_ID1 := DWORD#16#101, (* Plain message COB-ID *) i_COB_ID2 := DWORD#16#102, (* Inverted message COB-ID *) i_Mapping := G_CANopen_CAN1_Mappings.SRDO1Mappings, (* Plain + Inverted data mappings *) i_Mappings := 4, (* Plain + Inverted data mappings *) o_Error => G_CANopen_CAN1.SRDO_Error );
|
Definitions: |
srdoerror: BOOL; srdovalid: BOOL;
SignatureValid: BOOL := FALSE; SignatureError: BOOL := FALSE;
|
Code: |
SignatureValid := TRUE;
FOR i := UINT#1 TO SIZEOF(G_CANopen_CAN1.SRDOS)/SIZEOF(G_CANopen_CAN1.SRDOS[1]) DO
G_CANopen_CAN1.SRDO_Signatures[i] := EPEC_SDV.CalculateSRDOSignature ( i_InfoDirection := G_CANopen_CAN1.SRDOS[i].i_SRDOType, i_SCTime := G_CANopen_CAN1.SRDOS[i].i_SCTime, i_SRVTime := G_CANopen_CAN1.SRDOS[i].i_SRVTime, i_COBID1 := G_CANopen_CAN1.SRDOS[i].i_COB_ID1, i_COBID2 := G_CANopen_CAN1.SRDOS[i].i_COB_ID2, i_Mappings := G_CANopen_CAN1.SRDOS[i].i_Mappings, i_pMappingParameter := ADR(G_CANopen_CAN1.SRDOS[i].i_Mapping), o_ParameterError => srdoerror, o_OutputValid => srdovalid );
SignatureValid := SignatureValid AND srdovalid; SignatureError := SignatureError OR srdoerror;
END_FOR
|
S_ValidateSRDOSignature (FUN)
Source file topic100388.htm
Last updated 19-Dec-2024