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

📄 lin_driver08.h

📁 此程序为DP256的SPI实验程序,已经通过实验证明
💻 H
📖 第 1 页 / 共 2 页
字号:
/*
	LIN Driver for MC9S12DP256B
	Establish data: 2005-01-06
	Programmed by:	Wangjunpeng
	Modify date:    2005-01-06
	Current version: v0.1
*/
#ifndef __LINDRV_H__
#define __LINDRV_H__


#ifdef LINDRV_GLOBALS
	#define LINDRV_EXT
#else
	#define LINDRV_EXT	extern
#endif

/*      LINStatusType Constant Definition     */

#define LIN_OK                0x00    /* No error, service call has succeeded.                    */
/*      LIN_MSG_NODATA        0x01       The message data buffer is empty (data has not been      */
                                      /* initialized or reseived yet). Defined in "lindef.h" file.*/
#define LIN_MSG_NOCHANGE      0x02    /* The message data has not changed since last read.        */
#define LIN_MSG_OVERRUN       0x04    /* The message data has not been read and was overwritten.  */
#define LIN_REQ_PENDING       0x15    /* The message request is already pending.                  */
#define LIN_INVALID_MODE      0x16    /* The service could not be called in the current driver    */
                                      /* state.                                                   */
#define LIN_INVALID_ID        0x80    /* The message identifier is invalid, i.e. the message      */
                                      /* direction differs from the configured one.               */
#define LIN_NO_ID             0x7F    /* The message identifier is absent, i.e. there is no such  */
                                      /* identifier configured on this node.                      */

/*      LINDriverStatusType bit mask constant values */

#define LIN_STATUS_RUN        0x01    /* Driver is in run state                                   */
#define LIN_STATUS_IDLE       0x02    /* No-Bus_activity timeout is expired                       */
#if defined(MASTER)
#define LIN_STATUS_PENDING    0x04    /* LIN bus frame is pending                                 */
#endif /* defined(MASTER) */

//type defines
#define L_BOOL 		unsigned char
#define L_IOCTL_OP	unsigned char//uint
#define L_IRQMASK	unsigned char
#define L_U8		unsigned char
#define L_U16		unsigned int
#define L_Signal_Handle unsigned char
#define L_Flag_Handle	unsigned char
#define L_IFC_Handle	unsigned char
#define L_U8P		unsigned char * 
#define L_U8PC		unsigned char* const
#define L_U8CP		const unsigned char* const
#define L_VOIDP		void*

LINDRV_EXT	const	struct
{
	L_U16	LIN_IdleTimeoutClocks;
	L_U16	LIN_Baudrate;
	L_U16	LIN_BreakBaudrate;
	L_U16	LIN_TimerPrescaler;
}LIN_CfgConst;

LINDRV_EXT	unsigned int	wSysTime;
LINDRV_EXT	unsigned int	wTimerIncrement;

LINDRV_EXT	const	L_U8	LIN_MsgId[];//
LINDRV_EXT	const	L_U8	LIN_MsgLen[];//


LINDRV_EXT			L_U8	LIN_MsgStatus[];
LINDRV_EXT	const	L_U8	LIN_Msg_Index[];//

LINDRV_EXT	const	L_U16	LIN_Wakeup_Timer[];
LINDRV_EXT			L_U8	LIN_Wakeup_Phase;
LINDRV_EXT			L_U16	LIN_Timeout;

#define LIN_SLEEP_TIME_INDEX	4

#define LIN_WAKEUP_PHASE_1		150
#define LIN_WAKEUP_PHASE_2		150
#define LIN_WAKEUP_PHASE_3		150
#define LIN_WAKEUP_PHASE_4		1500
#define LIN_NO_BUS_ACTIVE_TIME	4000
/*
#define LIN_WAKEUP_PHASE_1		146
#define LIN_WAKEUP_PHASE_2		146
#define LIN_WAKEUP_PHASE_3		146
#define LIN_WAKEUP_PHASE_4		1465
#define LIN_NO_BUS_ACTIVE_TIME	3906
*/
//canstant in CONFIG2 register
#define CFG2_MSCANEN		0x08
#define CFG2_TMCLKSEL		0x04
#define CFG2_OSCENINSTOP	0x02
#define CFG2_ESCIBDSRC		0x01

//constant in CONFIG1 register
#define CFG1_COPRS 		0x80
#define CFG1_LVISTOP 	0x40
#define CFG1_LVIRSTD 	0x20
#define	CFG1_LVIPWRD 	0x10
#define CFG1_LVI5OR3 	0x08
#define CFG1_SSREC 		0x04
#define CFG1_STOP 		0x02
#define CFG1_COPD		0x01


typedef	union
{
	L_U8	LIN_Errors;
	struct
	{
		L_U8	LIN_Bits_Error			:1;//Bit0
		L_U8	LIN_ChkSum_Error		:1;//Bit1
		L_U8	LIN_PID_Error			:1;//Bit2
		L_U8	LIN_Response_Error		:1;//Bit3
		L_U8	LIN_SYNC_Error			:1;//Bit4
		L_U8	LIN_Bus_NOAct_Error		:1;//Bit5
		L_U8	LIN_Success_Transfer	:1;//Bit6
		L_U8	LIN_Error_In_Response	:1;//Bit7
	}Bits;
}LIN_ERR_Status;
/*
#define LIN_BITS_ERR				1u
#define	LIN_CHKSUM_ERR				2u
#define LIN_PID_ERR					4u
#define	LIN_RESPONSE_ERR			8u
#define LIN_SYNC_ERR				0x10u
#define LIN_BUS_NOACT_ERR			0x20u
#define LIN_SUCCESS_TRANSFER		0x40u
#define LIN_ERR_IN_RESPONSE			0x80u

#define	LIN_SYNCH_CHAR				0x55u
#define	LIN_WAKEUP_CHAR				0xf0u
#define LIN_ID_GOTO_SLEEP			0x3cu
*/
typedef union
{
	L_U16	LIN_Flags;
	struct
	{
		L_U16	LIN_Flag_NOInit			:1;//Bit0	*****
		L_U16	LIN_Flag_Disconnect		:1;//Bit1	*****	
		L_U16	LIN_Flag_Send_Break		:1;//Bit2
		L_U16	LIN_Flag_Send_SYNC		:1;//Bit3
		L_U16	LIN_Flag_Send_Header	:1;//Bit4
		L_U16	LIN_Flag_Received_Break	:1;//Bit5	*****
		L_U16	LIN_Flag_Received_SYNC	:1;//Bit6	*****
		L_U16	LIN_Flag_Adjust			:1;//Bit7
		L_U16	LIN_Flag_Receive_Header	:1;//Bit8	
		L_U16	LIN_Flag_Sleep			:1;//Bit9	*****
		L_U16	LIN_Flag_Ignore			:1;//Bit10	*****
		L_U16	LIN_Flag_Send_Data		:1;//Bit11	*****
		L_U16	LIN_Flag_Receive_Data	:1;//Bit12	*****
		L_U16	LIN_Flag_Ignore_Data	:1;//Bit13		
		L_U16	LIN_Flag_Wakeup_Timeout	:1;//Bit14	*****
		L_U16	LIN_Flag_Reserved		:1;//Bit15
	}Bits;
}LIN_Flag_Str;

typedef union
{
	L_U16	LIN_TIC_Counter;
	struct
	{
		L_U8	LIN_TIC_CounterH;
		L_U8	LIN_TIC_CounterL;
	}Bytes;
}LIN_TIC_Cntr_Str;

LINDRV_EXT	LIN_TIC_Cntr_Str	_LIN_TIC_Cntr;
#define 	LIN_TIC_Cntr		_LIN_TIC_Cntr.LIN_TIC_Counter
#define 	LIN_TIC_CntrL		_LIN_TIC_Cntr.Bytes.LIN_TIC_CounterL
#define 	LIN_TIC_CntrH		_LIN_TIC_Cntr.Bytes.LIN_TIC_CounterH

LINDRV_EXT	LIN_TIC_Cntr_Str	_LIN_TIC_Tmr;
#define 	LIN_TIC_Tmr			_LIN_TIC_Tmr.LIN_TIC_Counter
#define 	LIN_TIC_TmrL		_LIN_TIC_Tmr.Bytes.LIN_TIC_CounterL
#define 	LIN_TIC_TmrH		_LIN_TIC_Tmr.Bytes.LIN_TIC_CounterH

/*
#define LIN_FLAG_NOINIT			0x0001//
#define	LIN_FLAG_DISCONNECT		0x0002//
#define LIN_FLAG_SEND_BREAK		0x0004
#define LIN_FLAG_SEND_SYNC		0x0008
#define LIN_FLAG_SEND_HEADER	0x0010
#define LIN_FLAG_REC_BREAK		0x0020
#define LIN_FLAG_REC_SYNC		0x0040
#define	LIN_FLAG_ADJUST			0x0080
#define LIN_FLAG_REC_HEADER		0x0100
#define	LIN_FLAG_SLEEP			0x0200//
#define LIN_FLAG_IGNORE			0x0400//
#define LIN_FLAG_SEND_DATA		0x0800//
#define LIN_FLAG_RECEIVE_DATA	0x1000//
#define LIN_FLAG_IGNORE_DATA	0x2000
#define LIN_FLAG_WAKEUP_TIMEOUT	0x4000//
*/
//#define LIN_SCIBD		SCI0BD
#define OSC_FREQ		8000000L
#define SCI_CLK_USE_OSC	1


#define SCI_BPD_DIV1	0
#define SCI_BPD_DIV3	0x10
#define SCI_BPD_DIV4	0x20
#define SCI_BPD_DIV13	0x30

#define SCI_BPD_DIV 	SCI_BPD_DIV3

#define SCI_BD_DIV1 		0
#define SCI_BD_DIV2 		1
#define SCI_BD_DIV4 		2
#define SCI_BD_DIV8 		3
#define SCI_BD_DIV16 		4
#define SCI_BD_DIV32 		5
#define SCI_BD_DIV64 		6
#define SCI_BD_DIV128 		7

#define SCI_BD_DIV 			SCI_BD_DIV1

#define SCI_PD_DIV1 			0 
#define SCI_PD_DIV2 			0x20
#define SCI_PD_DIV3 			0x40
#define SCI_PD_DIV4 			0x60
#define SCI_PD_DIV5 			0x80
#define SCI_PD_DIV6 			0xa0
#define SCI_PD_DIV7 			0xc0
#define SCI_PD_DIV8 			0xe0

#define SCI_PD_DIV  			SCI_PD_DIV4

#define SCI_PDFA_DIV0 			0
#define SCI_PDFA_DIV1 			1
#define SCI_PDFA_DIV2 			2
#define SCI_PDFA_DIV3 			3
#define SCI_PDFA_DIV4 			4
#define SCI_PDFA_DIV5 			5
#define SCI_PDFA_DIV6 			6
#define SCI_PDFA_DIV7 			7
#define SCI_PDFA_DIV8 			8
#define SCI_PDFA_DIV9 			9
#define SCI_PDFA_DIV10 			10
#define SCI_PDFA_DIV11 			11
#define SCI_PDFA_DIV12 			12
#define SCI_PDFA_DIV13 			13
#define SCI_PDFA_DIV14			14
#define SCI_PDFA_DIV15			15
#define SCI_PDFA_DIV16			16
#define SCI_PDFA_DIV17			17
#define SCI_PDFA_DIV18			18
#define SCI_PDFA_DIV19			19
#define SCI_PDFA_DIV20			20
#define SCI_PDFA_DIV21			21
#define SCI_PDFA_DIV22			22
#define SCI_PDFA_DIV23			23
#define SCI_PDFA_DIV24			24
#define SCI_PDFA_DIV25			25
#define SCI_PDFA_DIV26			26
#define SCI_PDFA_DIV27			27
#define SCI_PDFA_DIV28			28
#define SCI_PDFA_DIV29			29
#define SCI_PDFA_DIV30			30
#define SCI_PDFA_DIV31			31

#define SCI_PDFA_DIV 			SCI_PDFA_DIV11


#define SCI_CLK			8000000L//8000000L/16
						//0: Divide by 1; 
						//1: Divide by 3;
						//2: Devide by 4;

⌨️ 快捷键说明

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