CANopen FD Master Library
Making your systems precise, reliable and high-quality - 5.10.01
Functions
J1939 Support

Functions

ComStatus_tv ComJ1939_PgnConfig (uint8_t ubNetV, uint16_t uwPgnIdxV, uint8_t ubPgnDirV, uint32_t ulPgnV, uint8_t ubPriorityV, uint8_t ubAddrV, uint16_t uwTimeV)
 
ComStatus_tv ComJ1939_PgnEnable (uint8_t ubNetV, uint16_t uwPgnIdxV, uint8_t ubPgnDirV, uint8_t ubEnableV)
 
ComStatus_tv ComJ1939_PgnGetCounter (uint8_t ubNetV, uint16_t uwPgnIdxV, uint8_t ubPgnDirV, uint32_t *pulCounterV)
 
ComStatus_tv ComJ1939_PgnGetData (uint8_t ubNetV, uint16_t uwPgnIdxV, uint8_t ubPgnDirV, uint8_t *pubSrcAddrV, uint8_t *pubDataV, uint16_t *puwSizeV)
 
uint8_t ComJ1939_PgnGetDestination (uint32_t ulIdentifierV)
 
ComStatus_tv ComJ1939_PgnGetSize (uint8_t ubNetV, uint16_t uwPgnIdxV, uint16_t *puwSizeV)
 
uint8_t ComJ1939_PgnGetSource (uint32_t ulIdentifierV)
 
ComStatus_tv ComJ1939_PgnIsEnabled (uint8_t ubNetV, uint16_t uwPgnIdxV, uint8_t ubPgnDirV)
 
ComStatus_tv ComJ1939_PgnRequest (uint8_t ubNetV, uint32_t ulPgnV, uint8_t ubDestAddrV)
 
ComStatus_tv ComJ1939_PgnSendAsync (uint8_t ubNetV, uint16_t uwPgnIdxV)
 
ComStatus_tv ComJ1939_PgnSetData (uint8_t ubNetV, uint16_t uwPgnIdxV, uint8_t ubPgnDirV, uint8_t *pubDataV, uint16_t uwSizeV)
 
ComStatus_tv ComJ1939_PgnSetTimer (uint8_t ubNetV, uint16_t uwPgnIdxV, uint8_t ubPgnDirV, uint16_t uwTimeV)
 

Detailed Description

The SAE J1939 module is an optional function for the CANopen Master protocol stack. The J1939 support is enabled by setting the value eCOM_MODE_J1939 for parameter ulModeV inside the function ComMgrInit().

The following example depicts the initialisation:

void MyJ1939Init(void)
{
//------------------------------------------------------
// Initialise J1939 stack with address 1
// Bitrate = 500kBit/s
//
//------------------------------------------------------
// start the CANopen master stack
//
//------------------------------------------------------
// now the CANopen Master Stack is initialised and
// has to be triggered by calling ComMgrTimerEvent()
}

Function Documentation

◆ ComJ1939_PgnConfig()

ComStatus_tv ComJ1939_PgnConfig ( uint8_t  ubNetV,
uint16_t  uwPgnIdxV,
uint8_t  ubPgnDirV,
uint32_t  ulPgnV,
uint8_t  ubPriorityV,
uint8_t  ubAddrV,
uint16_t  uwTimeV 
)

Add a PGN.

Parameters
ubNetV- Network channel
uwPgnIdxV- PGN index
ubPgnDirV- PGN direction
ulPgnV- PGN value
ubPriorityV- PGN priority
ubAddrV- address information
uwTimeV- PGN timer
Returns
eCOM_ERR_NONE on success, negative ComErr_e value on failure

This function adds a new PGN to the CANopen Master. The PGN type is defined by setting the definition ePGN_DIR_RCV for Receive-PGNs and ePGN_DIR_TRM for Transmit-PGNs to the parameter ubPgnDirV. The PGN index uwPgnIdxV starts at 0.

The parameter ubAddrV is evaluated for Receive-PGNs: only PDUs from ECUs with address ubAddrV are evaluated. In order to receive messages from all ECUs in the network on the defined index uwPgnIdxV the address parameter must be set to J1939_ADDR_BROADCAST.

Example

void MyPgnSetup(void)
{
//---------------------------------------------------
// add first receive PDU, PGN = 61184, Priority = 3
// receive from every ECU in network
//
ComJ1939_PgnConfig(eCOM_NET_1, ePGN_DIR_RCV, 0, 61184, 3, J1939_ADDR_BROADCAST, 0);
//---------------------------------------------------
// add transmit PDU, PGN = 61444
//
ComJ1939_PgnAdd(eCOM_NET_1, 0, ePGN_DIR_TRM, 61444, 6, 0, 0);
//---------------------------------------------------
// add transmit PDU, PGN = 65260
//
ComJ1939_PgnAdd(eCOM_NET_1, 1, ePGN_DIR_TRM, 65260, 6, 0, 0);
}

◆ ComJ1939_PgnEnable()

ComStatus_tv ComJ1939_PgnEnable ( uint8_t  ubNetV,
uint16_t  uwPgnIdxV,
uint8_t  ubPgnDirV,
uint8_t  ubEnableV 
)

Enable PGN.

Parameters
ubNetV- Network channel
uwPgnIdxV- PGN index
ubPgnDirV- PGN direction
ubEnableV- Enable/Disable PGN
Returns
eCOM_ERR_NONE on success, negative ComErr_e value on failure

This function enables (ubEnableV = 1) or disables (ubEnableV = 0) the PGN with index uwPgnIdxV. A PGN is disabled by default upon creation (see ComJ1939_PgnConfig()).

◆ ComJ1939_PgnGetCounter()

ComStatus_tv ComJ1939_PgnGetCounter ( uint8_t  ubNetV,
uint16_t  uwPgnIdxV,
uint8_t  ubPgnDirV,
uint32_t *  pulCounterV 
)

Get PGN counter.

Parameters
ubNetV- Network channel
uwPgnIdxV- PGN index
ubPgnDirV- PGN direction
pulCounterV- Pointer to counter variable
Returns
eCOM_ERR_NONE on success, negative ComErr_e value on failure

The function returns the number of PGNs that have been sent (for Transmit-PGNs) or received (for Receive-PGNs) by the CANopen Master.

◆ ComJ1939_PgnGetData()

ComStatus_tv ComJ1939_PgnGetData ( uint8_t  ubNetV,
uint16_t  uwPgnIdxV,
uint8_t  ubPgnDirV,
uint8_t *  pubSrcAddrV,
uint8_t *  pubDataV,
uint16_t *  puwSizeV 
)

Get PGN data.

Parameters
ubNetV- Network channel
uwPgnIdxV- PGN index
ubPgnDirV- PGN direction
pubSrcAddrV- Pointer to ECU source address
pubDataV- Pointer to data buffer
puwSizeV- Pointer to size variable
Returns
eCOM_ERR_NONE on success, negative ComErr_e value on failure

The function reads data from the PGN defined by the parameter uwPgnIdxV. The application must guarantee that pubDataV points to a buffer with sufficient size (maximum 1785 bytes).

◆ ComJ1939_PgnGetDestination()

uint8_t ComJ1939_PgnGetDestination ( uint32_t  ulIdentifierV)

Get destination address of a PDU identifier.

Parameters
ulIdentifierV- identifier value
Returns
Destination address

The function calculates the destination address of the PDU identifier given by parameter ulIdentifierV. For a PDU2 type message the function will return the broadcast address (J1939_ADDR_BROADCAST).

◆ ComJ1939_PgnGetSize()

ComStatus_tv ComJ1939_PgnGetSize ( uint8_t  ubNetV,
uint16_t  uwPgnIdxV,
uint16_t *  puwSizeV 
)

Get size of a PGN.

Parameters
ubNetV- Network channel
uwPgnIdxV- PGN index
puwSizeV- Pointer to buffer for size
Returns
eCOM_ERR_NONE on success, negative ComErr_e value on failure

The function reads the size of a PGN.

◆ ComJ1939_PgnGetSource()

uint8_t ComJ1939_PgnGetSource ( uint32_t  ulIdentifierV)

Get source address of a PDU identifier.

Parameters
ulIdentifierV- identifier value
Returns
Source address

The function calculates the source address of the PDU identifier given by parameter ulIdentifierV.

◆ ComJ1939_PgnIsEnabled()

ComStatus_tv ComJ1939_PgnIsEnabled ( uint8_t  ubNetV,
uint16_t  uwPgnIdxV,
uint8_t  ubPgnDirV 
)

Check PGN.

Parameters
ubNetV- Network channel
uwPgnIdxV- PGN index
ubPgnDirV- PGN direction
Returns
eCOM_ERR_NONE on success, negative ComErr_e value on failure

◆ ComJ1939_PgnRequest()

ComStatus_tv ComJ1939_PgnRequest ( uint8_t  ubNetV,
uint32_t  ulPgnV,
uint8_t  ubDestAddrV 
)

Request PGN.

Parameters
ubNetV- Network channel
ulPgnV- PGN value
ubDestAddrV- ECU destination address
Returns
eCOM_ERR_NONE on success, negative ComErr_e value on failure

This function sends a PGN request message to an ECU with address ubDestAddrV. The value for ubDestAddrV can be set to #J1939_ADDR_BROADCAST in order to sent the request to all ECUs present in the network.

◆ ComJ1939_PgnSendAsync()

ComStatus_tv ComJ1939_PgnSendAsync ( uint8_t  ubNetV,
uint16_t  uwPgnIdxV 
)

Send a PGN.

Parameters
ubNetV- Network channel
uwPgnIdxV- PDO index
Returns
eCOM_ERR_NONE on success, negative ComErr_e value on failure

This function sends a PGN defined by the index uwPgnIdxV asynchronous.

◆ ComJ1939_PgnSetData()

ComStatus_tv ComJ1939_PgnSetData ( uint8_t  ubNetV,
uint16_t  uwPgnIdxV,
uint8_t  ubPgnDirV,
uint8_t *  pubDataV,
uint16_t  uwSizeV 
)

Set PGN Data.

Parameters
ubNetV- Network channel
uwPgnIdxV- PGN index
ubPgnDirV- PGN direction
pubDataV- Pointer to data
uwSizeV- Number of bytes
Returns
eCOM_ERR_NONE on success, negative ComErr_e value on failure

◆ ComJ1939_PgnSetTimer()

ComStatus_tv ComJ1939_PgnSetTimer ( uint8_t  ubNetV,
uint16_t  uwPgnIdxV,
uint8_t  ubPgnDirV,
uint16_t  uwTimeV 
)

Set PGN timer.

Parameters
ubNetV- Network channel
uwPgnIdxV- PGN index
ubPgnDirV- PGN direction
uwTimeV- Time value
Returns
eCOM_ERR_NONE on success, negative ComErr_e value on failure