J1939 Documentation
Version 4.16.00
Loading...
Searching...
No Matches
j1939_defs.h File Reference

Detailed Description

The file j1939_defs.h holds global definitions, constants and structures for the J1939 stack.

+ Include dependency graph for j1939_defs.h:

Data Structures

struct  J1939_PGN_Entry_s
 

Macros

#define J1939_VERSION_MAJOR   4
 
#define J1939_VERSION_MINOR   16
 
#define J1939_VERSION_BUILD   0
 
#define J1939_PRIORITY_LEVEL_0   ((uint16_t) 0x0000)
 
#define J1939_PRIORITY_LEVEL_1   ((uint16_t) 0x0001)
 
#define J1939_PRIORITY_LEVEL_2   ((uint16_t) 0x0002)
 
#define J1939_PRIORITY_LEVEL_3   ((uint16_t) 0x0003)
 
#define J1939_PRIORITY_LEVEL_4   ((uint16_t) 0x0004)
 
#define J1939_PRIORITY_LEVEL_5   ((uint16_t) 0x0005)
 
#define J1939_PRIORITY_LEVEL_6   ((uint16_t) 0x0006)
 
#define J1939_PRIORITY_LEVEL_7   ((uint16_t) 0x0007)
 
#define J1939_PRIORITY_CTRL   ((uint16_t) 0x0003)
 
#define J1939_PRIORITY_INFO   ((uint16_t) 0x0006)
 
#define J1939_MSG_RCV   ((uint16_t) 0x0040)
 
#define J1939_MSG_TRM   ((uint16_t) 0x0080)
 
#define J1939_MSG_FP   ((uint16_t) 0x0100)
 
#define J1939_MSG_NO_RQST   ((uint16_t) 0x0200)
 
#define J1939_ADDR_NULL   ((uint8_t) 0xFE)
 
#define J1939_ADDR_BROADCAST   ((uint8_t) 0xFF)
 
#define J1939_PGN_HANDLER_WRITE   ((uint16_t) 0x8000)
 
#define J1939_PGN_HANDLER_FP_SEL   ((uint16_t) 0x4000)
 
#define J1939_PGN_HANDLER_TP   ((uint16_t) 0x2000)
 
#define J1939_PGN_HANDLER_SIZE_MASK   ((uint16_t) 0x07FF)
 
#define J1939_TP_SIZE_MAX   ((uint16_t) 1785)
 

Typedefs

typedef int32_t J1939_Status_tv
 
typedef int16_t(* PgnHandler_fn) (uint8_t *pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV)
 

Enumerations

enum  J1939_Err_e {
  eJ1939_ERR_NONE = 0 ,
  eJ1939_ERR_CAN_INIT = -1 ,
  eJ1939_ERR_CAN_BUFFER = -2 ,
  eJ1939_ERR_CAN_FUNCTION = -3 ,
  eJ1939_ERR_RESET = -10 ,
  eJ1939_ERR_NET = -20 ,
  eJ1939_ERR_NET_VALUE = -21 ,
  eJ1939_ERR_SERVICE = -30 ,
  eJ1939_ERR_SERVICE_MODE = -31 ,
  eJ1939_ERR_SERVICE_PARAM = -32 ,
  eJ1939_ERR_PGN = -40 ,
  eJ1939_ERR_PGN_VALUE = -41
}
 
enum  J1939_Buf_e {
  eJ1939_BUF_RCV = eCP_BUFFER_1 ,
  eJ1939_BUF_ADDR ,
  eJ1939_BUF_PGN_REQ ,
  eJ1939_BUF_TP_ACK ,
  eJ1939_BUF_TP_BAM ,
  eJ1939_BUF_PDU_TRM
}
 
enum  J1939_Handler_Result_e {
  eJ1939_HANDLER_RESULT_OK = 0 ,
  eJ1939_HANDLER_RESULT_ACK = -1 ,
  eJ1939_HANDLER_RESULT_NACK = -2 ,
  eJ1939_HANDLER_RESULT_DENIED = -3 ,
  eJ1939_HANDLER_RESULT_RESPONSE = -4
}
 

Macro Definition Documentation

◆ J1939_ADDR_BROADCAST

#define J1939_ADDR_BROADCAST   ((uint8_t) 0xFF)

J1939 broadcast address

◆ J1939_ADDR_NULL

#define J1939_ADDR_NULL   ((uint8_t) 0xFE)

J1939 NULL address

◆ J1939_PGN_HANDLER_FP_SEL

#define J1939_PGN_HANDLER_FP_SEL   ((uint16_t) 0x4000)

Used in PGN callback handler (parameter uwSizeV): denotes special behaviour for Fast-packet message handling.

◆ J1939_PGN_HANDLER_SIZE_MASK

#define J1939_PGN_HANDLER_SIZE_MASK   ((uint16_t) 0x07FF)

Used in PGN callback handler (parameter uwSizeV): mask for number of bytes to copy

◆ J1939_PGN_HANDLER_TP

#define J1939_PGN_HANDLER_TP   ((uint16_t) 0x2000)

Used in PGN callback handler (parameter uwSizeV): denotes that data was transferred using the TP.CON handling instead of TP.BAM.

◆ J1939_PGN_HANDLER_WRITE

#define J1939_PGN_HANDLER_WRITE   ((uint16_t) 0x8000)

Used in PGN callback handler (parameter uwSizeV): denotes the data access direction

◆ J1939_TP_SIZE_MAX

#define J1939_TP_SIZE_MAX   ((uint16_t) 1785)

Maximum number of bytes for a transport protocol.

◆ J1939_VERSION_BUILD

#define J1939_VERSION_BUILD   0

Build version number of J1939 stack. The version number of the J1939 protocol stack is reflected by PGN 65242.

◆ J1939_VERSION_MAJOR

#define J1939_VERSION_MAJOR   4

Major version number of J1939 stack. The version number of the J1939 protocol stack is reflected by PGN 65242.

◆ J1939_VERSION_MINOR

#define J1939_VERSION_MINOR   16

Minor version number of J1939 stack. The version number of the J1939 protocol stack is reflected by PGN 65242.

Typedef Documentation

◆ J1939_Status_tv

typedef int32_t J1939_Status_tv

Function return value.

Functions of the J1939 Protocol Stack have a generic return value, which is defined as int32_t by default. A negative value of J1939_Status_tv denotes an error, defined by the enumeration J1939_Err_e.

◆ PgnHandler_fn

typedef int16_t(* PgnHandler_fn) (uint8_t *pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV)
Parameters
[in,out]pubDataVPointer to message data
[in]uwSizeVSize of data
[in]ubSrcAddrVSource address of PDU
[in]ubNetVJ1939 Network channel
Returns
Defined by J1939_Handler_Result_e

The handler is called by the stack if a PGN is available in the CA. The lower 11 bits of the parameter uwSizeV denote the size of the data to be transmitted. Within the handler the mask J1939_PGN_HANDLER_SIZE_MASK can be used to retrieve this data size. The highest bit of the parameter uwSizeV defines the data direction (see definition J1939_PGN_HANDLER_WRITE). Possible return values are defined by J1939_Handler_Result_e.

Enumeration Type Documentation

◆ J1939_Buf_e

Message buffer allocation.

Each J1939 PGN (i.e. identifier) is assigned to a specific message buffer in the CAN controller.

Enumerator
eJ1939_BUF_RCV 

Buffer 1 : Global Receive
Identifier: 00000000h (masked)
Direction : Receive

eJ1939_BUF_ADDR 

Buffer 2 : Address Claiming
Identifier: 18EEFF00h + address (variable)
Direction : Transmit

eJ1939_BUF_PGN_REQ 

Buffer 3 : PGN Request, xx = Destination address
Identifier: 18EAxx00 + address (variable)
Direction : Transmit

eJ1939_BUF_TP_ACK 

Buffer 4 : TP ACK,
Identifier: 18E8FF00h + address (variable)
Direction : Transmit

eJ1939_BUF_TP_BAM 

Buffer 5 : BAM , xx = Destination address
Identifier: 1CECxx00h + address (variable)
Direction : Transmit

eJ1939_BUF_PDU_TRM 

Buffer 6 : PDU buffer
Identifier: (variable)
Direction : Transmit

◆ J1939_Err_e

Error Codes of protocol stack.

All error codes of the J1939 protocol stack have the prefix 'eJ1939_Err_'.

Enumerator
eJ1939_ERR_NONE 

No error

eJ1939_ERR_CAN_INIT 

CAN bus initialisation error

eJ1939_ERR_CAN_BUFFER 

CAN buffer error

eJ1939_ERR_CAN_FUNCTION 

CAN function error

eJ1939_ERR_RESET 

Reset condition

eJ1939_ERR_NET 

Generic Network error

eJ1939_ERR_NET_VALUE 

Network index out of range, not valid

eJ1939_ERR_SERVICE 

Generic service error

eJ1939_ERR_SERVICE_MODE 

Service mode error The service is in a mode that does not allow this operation

eJ1939_ERR_SERVICE_PARAM 

Service parameter error The service does not accept this parameter

eJ1939_ERR_PGN 

Generic PGN error

eJ1939_ERR_PGN_VALUE 

PGN value out of range

◆ J1939_Handler_Result_e

PGN handler result.

This enumeration lists possible return values for the PGN handler function PgnHandler_fn

Enumerator
eJ1939_HANDLER_RESULT_OK 

Handler executed, no further action required

eJ1939_HANDLER_RESULT_ACK 

Send an ACK message as response

eJ1939_HANDLER_RESULT_NACK 

Send an NACK message as response

eJ1939_HANDLER_RESULT_DENIED 

Send an Access Denied message as response

eJ1939_HANDLER_RESULT_RESPONSE 

Send an Cannot Respond message as response

◆ J1939_Net_e

Network channel definition.

Enumerator
eJ1939_NET_1 

J1939 network #1

eJ1939_NET_2 

J1939 network #2

eJ1939_NET_3 

J1939 network #3

eJ1939_NET_4 

J1939 network #4