⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 j1939.h

📁 基于ucosSAEj1939的汽车组合仪表,硬件是MC9S12H128
💻 H
字号:
#ifndef _J1939_H_
#define _J1939_H_

#include "J1939_includes.h"
#define	J1939STACK_VERSION               130 //版本协议栈,包含传输协议功能     

#define  REQUEST_PGN                       0xEA00 
#define  REQUEST_PGN_NUM                   15	 //请求队列数

//允许堆栈中节点地址分配的个数,这个特点可以被用来支持多重应用如果未来需求要求改变的话
//默认是两个本节点地址和广播地址


#define  WAIT_FOR_MESSAGE                 0//State Zero: Waiting for a BAM or RTS data packet to arrive
#define  INIT_REASSEMBLE_STRUCTURE        1//State One: Message reassemble structure and message timer are initialized.
#define  CHECK_PACKET                     2//State Two: The incoming message is for this node.
#define  SEND_ABORT                       3//State Three:  No more buffers to reassemble incoming message, Abort is sent.
#define  SEND_CTS_WITH_COUNT              4//State Four: Buffers are available to reassemble incoming message, send CTS back to sender to indicate number of packets between next CTS (TRANSPORT_PACKET_COUNT). 
#define	 WAIT_FOR_DATA                    5//State Five: Waiting for DATA type packet from source.
#define	 CHECK_TIMER                      6//State Six:  Message timer is checked for expiration.
#define	 RESET_REASSEMBLY_STRUCTURE       7//State Seven: Message reassemble structure is reset.
#define	 CHECK_DATA_PACKET                8//State Eight: A DATA type packet has arrived and checked.
#define	 SAVE_DATA                        9//State Nine: The data is saved in the message reassemble buffer
#define	 SEND_EOM                         10//State Ten:  EOM message is sent.
#define	 SEND_CTS                         11//State Eleven: CTS is sent to trigger more data from the sender. 
#define	 FILL_USER_MESSAGE                12//State Twelve: The J1939_RX_MESSAGE_T data structure is filled for user application.

#define  TP_CM                0xEC00       
#define  TP_CM_RTS            16
#define  TP_CM_CTS            17         
#define  TP_CM_ENDOFMSGACK    19
#define  TP_CM_ABORT          255
#define  TP_CM_BAM            32
#define  TP_DT                0xEB00
#define  TP_NONE		      0 

#define  REQUADDR			  59904			
#define  CLIMADDR			  60928
#define  COMMADDR			  65240

#define  PRIMED               1
#define  NOTPRIMED            0 

#ifndef NULL
#define  NULL                 0
#endif

#ifndef TRUE
#define  TRUE				  1
#endif

#ifndef FALSE				  
#define  FALSE			      0
#endif

typedef struct
{
  PGN_T PGN;
  VU08  data[NUMBER_TRANS_TX_BUFFERS];
  VU16  byte_count;
  VU08  priority;  //优先级
  VU08  dest_addr; //目的地址
  VS08  status;
}J1939_TX_MESSAGE_T;

typedef struct
{
	PGN_T PGN;
	VU08  data[NUMBER_TRANS_RX_BUFFERS];
	VU16  byte_count;
	VU08  source_addr;//源地址
	VU08  dest_addr;//目的地址
}J1939_RX_MESSAGE_T;

typedef struct
{
	PGN_T PGN;
	VU08  data[NUMBER_PDU_BUFFERS];
	VU16  byte_count;
	VU08  source_addr;//源地址
	VU08  dest_addr;//目的地址		
}J1939_PDU_T;

typedef struct
{
	PGN_T PGN;
	VU08  status;
	VU08  packet_number;//当前包编号
	VU08  total_packet_number;//总包数量
	VU16  byte_count;
	VU16  timer_counter;
	VU08  source_addr;//源地址
	VU08  dest_addr;//目的地址
	VU08  TP;		//连接种类
}RECEIVE_STATU_MACHINE_T;   // J1939接收状态机*/

typedef struct
{
   VU32 	identifier;
   VU08 	data[CAN_MAX_BYTE_COUNT];
   VU08 	byte_count;
}CAN_PACKET_T;

typedef struct
{
   CAN_PACKET_T *buffer;
   VU16 head;    //Unsigned short value of the head index.
   VU16 tail;    //Unsigned short value of the tail index.
   VU08 buffer_size;
}RING_T;


//========================================================================================
//protocol stack Interface Functions
//========================================================================================
void J1939_stk_init(void);//协议栈初始化函数
void J1939_stk_periodic(void);//协议栈周期处理函数

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -