Supported platforms: CODESYS 3.5 SP19 SAFETY
This functionblock handles both sending and receiving of SAE 1939-76 safety data group (SDG) messages. The FB co-operates with the non-safe J1939 FB.
The S_J1939 FB copies and validates SPN data between non-safe message buffers and safe SPN values.
The non-safe J1939 FB writes messages from buffer to CAN bus and vice versa.
Init method is used to initialize the necessary static calculation parameters for the function block instance.
The method shall be called at least once before the actual function block can be called, i.e. at the application initialization phase.
The method checks the validity of input parameters. However, none of the function block outputs are affected by the initialization.
Initialization also examines the system endianness for data copy byte ordering between messages and SPN variables. The library does not need separate user environment definition for the endianness.
|
A parameter error is diagnosed if:
|
Parameter |
Type |
Default value |
Description |
i_pRxSDGs | POINTER TO S_J1939_SDG | NULL | Pointer to the list of receive SDGs. |
i_NumberOfRxSDGs | UINT | 0 | Number of SDGs in the list of receive SDGs. |
i_pTxSDGs | POINTER TO S_J1939_SDG | NULL | Pointer to the list of transmit SDGs. |
i_NumberOfTxSDGs |
UINT | 0 | Number of SDGs in the list of transmit SDGs. |
i_pEventCode |
POINTER TO EPEC_DITF.EventCode | NULL | Pointer to application event code |
TRUE: Error in initialization parameter(s). |
FALSE: All initialization parameters ok. |
The value is enumeration of J1939_ReturnCodes.
Name of error |
Description |
J1939_ERR_None |
No errors |
J1939_ERR_SDGDataNULL |
Any of the PGN pointer not initialized, or number of SafeSPNs = 0, or SCT = 0, or SRVT = 0. |
J1939_ERR_NullPointer |
Message buffer pointer null, or no given message table. |
J1939_ERR_SPNUninitialized |
SPN size 0, or pointed data null. |
J1939_ERR_DataOutOfRange |
SPN size > 64 bits. |
The errors during communication do not require the application to reset the FB instance. However, the application may react to the statuses as desired. The SDGStatus of each SDG inform the application of the validity of the safe mapped SPN variables. The errors are reset after two consecutive successful SDGs, except those mentioned in SDGStatus description.
|
All J1939 variables and structures must be properly initialized before calling S_J1939 FB. All the used pointers in the structures must be initialized. The given number of SDGs and PGNs must match the size of their arrays. |
|
SPN sizes of 17..32 bits must always have 4 bytes of data buffer. This limitation comes from little/big endian conversion. |
|
J1939-76 protocol supports maximum PG data length of 8 bytes.
|
|
In addition to the accuracy information of J1939 FB, the SDG message pair send interval accuracy depends of the safe and non-safe task cycle and duty times. |
Input variable name |
Data type |
Range |
Description |
i_Enable |
BOOL |
TRUE/FALSE |
Enable FB operation |
Output variable name |
Data type |
Range |
Description |
o_Status |
Status |
|
Main FB status |
o_TxSDGCount | UINT | Amount of valid Tx SDGs | |
o_RxSDGCount |
UINT |
|
Amount of valid Rx SDGs |
See Diagnostic Interface library description of error status and event code functionality.
Conditions |
o_Status OutputValid |
o_Status error |
EventCode FunctionID |
EventCode EventID |
o_TxSDGCount / o_RxSDGCount |
i_Enable rises & Init not called | FALSE |
ParameterError |
- | - | 0 |
i_Enable = true & Init called with i_pEventCode = 0 |
FALSE |
ParameterError |
- | - | 0 |
i_Enable = true & Init called with valid i_pEventCode & parameter error |
FALSE |
ParameterError |
J1939 | PARAMETER_ ERROR | 0 |
i_Enable = true & Init ok & error in given TxSDGs |
FALSE |
ParameterError |
J1939 | PARAMETER_ ERROR | number of correct SDGs before error |
i_Enable = true & Init ok & error in given RxSDGs |
FALSE |
ParameterError |
J1939 | PARAMETER_ ERROR | number of correct SDGs before error |
i_Enable = true & Init ok & SDGs ok |
TRUE | - | NO_FUNC | NO_ERROR | number of correct SDGs |
Code example is included in Using SafeJ1939.
Data types
Source file topic10030777.htm
Last updated 21-Feb-2025