f53x_linsnooper_lin.h
来自「8051试验程序 基础教材」· C头文件 代码 · 共 405 行 · 第 1/2 页
H
405 行
//-----------------------------------------------------------------------------
// F53x_LINSnooper_LIN.h
//-----------------------------------------------------------------------------
// Copyright 2006 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// File Description:
//
// This file contains all LIN-related definitions used to set the F53x LIN
// interface in either Slave or Master Mode.
//
// FID:
// Target: C8051F53x
// Tool chain: KEIL C51 7.20
// Command Line: None
// Project Name: LIN Snooper
//
// Release 1.0
// -Initial Revision
// -01 NOV 2006
//
//
//-----------------------------------------------------------------------------
// Header File Preprocessor Directive
//-----------------------------------------------------------------------------
#ifndef __LIN_H__
#define __LIN_H__
//-----------------------------------------------------------------------------
// Constant Definitions
//-----------------------------------------------------------------------------
#define LINMASTER 0x40
#define LINSLAVE 0x00
#define LIN_INTERRUPT_PRIORITY 12 // LIN interrupt vector
#define NSLP 0x08
#define NWAKE 0x10
#define LIN_AVAILABLE 1 // Define if the interface is being
#define LIN_BUSY 0 // used or is busy
// Define types of messages // All types of possible messages
#define TX_UNCONDITIONAL 0x81
#define TX_EVENT 0x82
#define TX_SPORADIC 0x83
#define TX_DIAGNOSTIC 0x84
#define TX_USER 0x85
#define RX_UNCONDITIONAL 0x06
#define RX_EVENT 0x07
#define RX_SPORADIC 0x08
#define RX_DIAGNOSTIC 0x09
#define RX_USER 0x0A
// Define the type of operation
#define LIN_MASTER_WRITE 0x80
#define LIN_MASTER_READ 0x08
#define LIN_SLAVE_WRITE 0x81
#define LIN_SLAVE_READ 0x01
// ------ Message Status ------
#define LIN_MSG_CLEAR 3 // Msg. not yet processed
#define LIN_MSG_PROCESSING 4 // Msg. being processed by LIN
#define LIN_MSG_PROCESSED 5 // Msg. transference completed
// ------ Message registers ------
#define LINDT1 0x00 // Address of Data register
#define LINDT2 0x01
#define LINDT3 0x02
#define LINDT4 0x03
#define LINDT5 0x04
#define LINDT6 0x05
#define LINDT7 0x06
#define LINDT8 0x07
//------ Control register ------
#define LINCTRL 0x08 // LIN Control Register and its bits
#define STREQ 0x01 // LIN Master Start transmission request
#define WUPREQ 0x02 // Wake-Up request
#define RSTERR 0x04 // Error reset request
#define RSTINT 0x08 // Interrupt reset request
#define DTACK 0x10 // Slave Data ACK
#define TXRX 0x20 // Master selection of TX or RX mode
#define SLEEP 0x40 // Slave flag set by master to inform
// the peripheral that either a sleep
// mode frame or bus idle timeout
// was reached
#define STOP 0x80 // Slave flag, to be set by the
// application so no processing is to be
// done until next SYNCH BREAK
//------ Status Register ------
#define LINST 0x09 // LIN Status Register and its bits
#define DONE 0x01 // Msg. processing completed
#define WAKEUP 0x02 // Wake-Up signal
#define ERROR 0x04 // Error detected
#define LININTREQ 0x08 // Interrupt request
#define DTREQ 0x10 // ID detected
#define ABORT 0x20 // Abort requested
#define IDLTOUT 0x40 // Time-out detected
#define ACTIVE 0x80 // Interface active (communicating)
//------ Error/STATUS Register ------
#define LINERR 0x0A // LIN Error Register and its bits
#define BITERROR 0x01 // Bit error detected
#define CHKERROR 0x02 // Checksum Error
#define TIMEOUTERROR 0x04 // Timeout detected in communication
#define PARITYERROR 0x08 // Parity error in the ID detected
#define SYNCERROR 0x10 // Error in synch-break detected
#define SLEEPMODE 0x20 // Part went to sleep mode
#define AWAKEN 0x40 // Part has been awaken
#define PROCESSING 0x80 // Message being processed
#define ID_RECEIVED 0x90 // Message ID received
#define NO_MESSAGE 0xA0 // No Message received
#define LIN_MSG_TRANSMITTED_OK 0xB0 // Message transmitted OK
#define LIN_MSG_RECEIVED_OK 0xC0 // Message received OK
// LIN Size (LINSIZE[3:0]) and Checksum (LINSIZE[7]) selection register
#define LINSIZE 0x0B // LIN size address and bits
#define ENHANCEDCHK 0x80 // Enhanced checksum
#define CLASSICCHK 0x00 // Classic checksum
// Divider Register (LINDIV[7:0]) lower 8 bits
#define LINDIV 0x0C
// MSB of the divider [LINMUL:0], Five bits multiplier [LINMUL5:1] ,and
// Two bits of Prescaler {LINMUL7:6]
#define LINMUL 0x0D
#define LINID 0x0E // Six bits [LINID5:0]
// LINCF related bits
#define _ENABLE 0x80 // Enable the LIN interface
#define _MASTERMODE 0x40 // Selects as master
#define _SLAVEMODE 0x00 // Selects as slave
#define _AUTOBAUD 0x20 // Slave autobaud selection
#define _MANUALBAUD 0x00 // Slave using manual baud
// MACRO Definitions
//-----------------------------------------------------------------------------
// MACRO: mLIN_WaitUntilInactive
// Parameters: NONE
// definition: Macro that waits until there is no communication in the bus
// Obs: This is a blocking ChangeRe and must be used with caution.
//-----------------------------------------------------------------------------
#define mLIN_WaitUntilInactive() LINADDR = LINST; while(LINDATA&ACTIVE)
//-----------------------------------------------------------------------------
// MACRO: mLIN_PointDataRegister
// Parameters: n, the message byte, n=[1...8]
// definition: Select one data byte of message
// Obs:
//-----------------------------------------------------------------------------
#define mLIN_PointDataRegister(n) LINADDR=(LINDT1+n-1)
//-----------------------------------------------------------------------------
// MACRO: mLIN_PointControl
// Parameters: NONE
// definition: Select the control register of the LIN interface
// Obs:
//-----------------------------------------------------------------------------
#define mLIN_PointControl() LINADDR=LINCTRL
//-----------------------------------------------------------------------------
// MACRO: mLIN_PointStatus
// Parameters: NONE
// definition: Select the status register of the LIN interface
// Obs:
//-----------------------------------------------------------------------------
#define mLIN_PointStatus() LINADDR=LINST
//-----------------------------------------------------------------------------
// MACRO: mLIN_PointError
// Parameters: NONE
// definition: Select the error register of the LIN interface
// Obs:
//-----------------------------------------------------------------------------
#define mLIN_PointError() LINADDR=LINERR // Select LIN error address
//-----------------------------------------------------------------------------
// MACRO: mLIN_PointSize
// Parameters: NONE
// definition: Select the Size and checksum mode register of the interface
// Obs:
//-----------------------------------------------------------------------------
#define mLIN_PointSize() LINADDR=LINSIZE // Select LIN size address
//-----------------------------------------------------------------------------
// MACRO: mLIN_PointDiv
// Parameters: NONE
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?