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

📄 lin_master.h

📁 基于LPC76X的LIN开发通信源程序调试通过
💻 H
字号:
/****************************************************************/
/* 项目名称     : R8C/23 CAN/LIN Demo Board		                */
/*              : 样例程序3                                     */
/*              : LIN主机										*/
/* 硬件环境		: R0K521237C000BB								*/
/* MCU型号      : R5F21237JFP                                   */
/* C编译器		: NC30WA,版本5.30.r02及以上					*/
/* 文件名	    : lin_master.h									*/
/* 版本			: 1.0                                           */
/* 作者			: wangsy                                        */
/* 修订历史     :                                               */
/*			修订者		时间		版本	说明				*/
/*			wangsy		2006/9/11	1.0		初版发行			*/
/*																*/
/****************************************************************/
/*		Copyright, 2006 RENESAS TECHNOLOGY CORPORATION &        */
/*                      RENESAS SOLUTIONS CORPORATION			*/
/****************************************************************/

#ifndef _LIN_MASTER_H_
#define _LIN_MASTER_H_

/* lin_status */
#define lin_SLEEP	0				// 休眠态
#define lin_RESET	1				// 初始化
#define lin_RUN		2				// 运行态
#define lin_IDLE	3				// IDLE态
#define lin_ERROR	4				// 错误态

/* lin command */
#define CMD_NO_COMMAND 	0			// 无命令
#define CMD_SLEEP		1			// 休眠命令
#define CMD_RESET		2			// 初始化命令
#define CMD_RUN			3			// 运行命令
#define CMD_IDLE		4			// IDLE命令
#define CMD_ERROR		5			// 错误命令
#define CMD_WAKEUP		6			// 唤醒命令

//error_code
#define NO_ERROR				0	// 无错
#define UART_OVERRUN_ERROR		1	// UART 过载错误
#define UART_PARITY_ERROR		2	// UART 奇偶校验错误
#define UART_FRAMING_ERROR		3	// UART 传输错误
#define LINRX_CHECKSUM_ERROR 	4	// 校验和错误
#define SHORT_MESSAGE_ERROR		5 	// 消息不全错误

// sleep_status
#define SLEEP_RCV_WAKEUP	0		// sleep接收wakeup
#define SLEEP_SND_WAKEUP	1		// sleep发送wakeup

//run_status
#define RUN_IDLE 		0			// 运行期IDLE态
#define RUN_SND_BREAK 	1			// 发送break状态
#define RUN_TX_SYNC 	2			// 发送同步段状态
#define RUN_TX_PID 		3			// 发送PID状态
#define RUN_RX_DATA 	4			// 接收数据状态
#define RUN_TX_DATA		5			// 发送数据状态
#define RUN_TX_CHECKSUM	6			// 发送校验和状态

#define SYNC_TIME 		0x55		// 同步段字节

#define TOTAL_SCH		4			// schedule总数
#define SCHEDULE_0		0			// schedule0
#define SCHEDULE_1		1			// schedule1
#define SCHEDULE_2		2			// schedule2
#define SCHEDULE_3		3			// schedule3

#define TIMERRB_INT_PRIORITY	3	// timerRB中断优先级
#define INIT_UART0_BITRATE		130 // 初始uart波特率

typedef struct
{
	union
	{
		uchar8 byte;
		struct
		{
	        uchar8  cmd0:1;     
	        uchar8  cmd1:1;     
	        uchar8  cmd2:1;    
	        uchar8  cmd3:1; 
			uchar8  dummy:4;
		} bit;
	} cmd; 				// ID 
	union
	{
		uchar8 byte;
		struct
		{
			uchar8	dlc0:1;   
			uchar8	dlc1:1;
			uchar8	dummy:6;
		} bit;
	} dlc; 				// 数据段数据字节数 
	uchar8 data[8]; 	// 数据
}lin_std_frm_def;

/*--------------LIN 缓冲器--------------*/
typedef struct 
{
	union
	{
		struct
		{
	        uchar8  ID0:1;   	//cmd0    
	        uchar8  ID1:1;   	//cmd1  
	        uchar8  ID2:1;   	//cmd2 
	        uchar8  ID3:1; 		//cmd3
			uchar8	ID4:1;		//dlc0
			uchar8	ID5:1;		//dlc1
			uchar8	P0:1;		//parity0
			uchar8	P1:1;		//parity1
	    } bit;
		struct
		{
			uchar8 cmd:4;
			uchar8 dlc:2;
			uchar8 parity:2;
		} pid_str;
	    uchar8   byte;
	} pid;				// PID 
	uchar8   data[8];  	// 数据
	uchar8	 checksum;	// 校验和
} lin_slot_def;

typedef struct
{
	lin_slot_def lin_slot[3];
} lin_buffer_def;

typedef union{
	struct{
		uchar8	complete:1;		//0: 进度表正在执行中/1: 进度表结束
		uchar8	loop:1;			//0: 非循环执行/1:循环执行
		uchar8	total_sch:2;	//总进度表数 00: 1sch / 01: 2sch / 10:3sch / 11:4sch
		uchar8	cur_sch:2;		//当前正在执行的进度表 00: sch1 / 01: sch2 / 10:sch3 / 11:sch4
		uchar8	dummy:2;
	} bit;
	uchar8	byte;
}sch_flg;						// 进度表状态

typedef union{
	struct{
		uchar8	complete:1;		//0: 帧正在传输中/1: 帧传输完毕
		uchar8	total_frm:2;	//总帧数 00: 1frm / 01: 2frm / 10: 3frm /11: reserved
		uchar8 	cur_frm:2;		//当前正在执行的帧 00: frm1 / 01: frm2 / 10: frm3 /11: reserved
		uchar8	dummy:3;				
	} bit;
	uchar8	byte;
}frm_flg;						// 帧状态

/*-----------------函数声明-----------------*/
//UART0初始化
void uart_init(void);

//timerRA 初始化
void timerRA_rcv_wakeup_config(void);

//lin 状态转换函数
void lin_sts_convert(uchar8 lin_in_cur_sch, uchar8 app_event);

/*-----------------外部引用变量声明-----------------*/
extern uchar8 lin_cmd;				// lin 命令
extern uchar8 lin_sts;				// lin 状态
extern uchar8 linM[7][5];				// 命令状态转换table

#endif

⌨️ 快捷键说明

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