📄 lin_initnode.h
字号:
//****************************************************************************
// @Module LIN
// @Filename LIN_InitNode.h
// @Project LIN_Protocol
//----------------------------------------------------------------------------
// @Controller Infineon C161CI, Evaluation Kit
//
// @Compiler Keil uVision2 V2.03
//
// @Version 0.1
//
// @Description Headerfile for initiate and control the LIN-node.
//
//----------------------------------------------------------------------------
// @Date 04/03/2000
//
//****************************************************************************
// USER CODE BEGIN
//----------------------------------------------------------------------------
// @Globals
// <name> <type (In/Out/InOut)> <description>
//
//----------------------------------------------------------------------------
// @Error
// <description of possible errors and error handling>
//
//----------------------------------------------------------------------------
// @AppNote
// <general description of the appnote specific user code within this module>
//
//----------------------------------------------------------------------------
// <else descriptions>
//
//----------------------------------------------------------------------------
// @Copyright (C) 2000 INFINEON TECHNOLOGIES AG. All rights reserved.
//
// Systems Engineering Automotive AI SM SEA
// Juergen Ketterer
//****************************************************************************
// USER CODE END
//****************************************************************************
// @Project Includes
//****************************************************************************
// USER CODE BEGIN
#include <INTRINS.H> // for _idle_ instruction (sleep-mode)
// USER CODE END
//****************************************************************************
// @Macros
//****************************************************************************
// USER CODE BEGIN (main,<position>)
//<User local macros definitions>
// USER CODE END
//****************************************************************************
// @Application-Defines
//****************************************************************************
// USER CODE BEGIN (<module>,<position>)
// ID Definiton
#define RMessage_1 0x20
#define RMessage_2 0x21
#define RMessage_3 0x22
#define TMessage_1 0x28
#define TMessage_2 0x29
#define TMessage_3 0x2A
// USER CODE END
//****************************************************************************
// @INTINSIC-FUNCTION Defines
//****************************************************************************
#define SET_SLEEP_MODE _idle_() // KEIL-Compiler intrinsic function to set
// controller in sleep-mode
/////////////////////////////////////////////////////////////////////////////
// LIN Node Mode
/////////////////////////////////////////////////////////////////////////////
//#define SLAVE // MASTER or SLAVE
#define MASTER // MASTER or SLAVE
/////////////////////////////////////////////////////////////////////////////
// ID Settings / allocation
//
// IMPORTANT: The ID 0 is reserved for the Sleep-ID-Field 0x80 which will be
// created by an ID Handling function. It's not allowed to define
// the ID 0 here. It will be automatically detect if the node is
// MASTER or SLAVE and the Sleep-ID-Field (0x80) will then sent
// or received by the node. The User-Application has to provide
// an Array-Element to save the Data-Bytes of the Sleep-Frame.
// EXAMPLE:
// --------
// #define MAX_LIN_ID 2 // the absolut number of all used IDs
// #define NUM_SEND 1 // number of send_IDs
// #define SEND_IDx yy // Send-ID definition: x={0...15}, yy={1...63}
// // yy=0 is Sleep-Mode
// #define SEND_ID0 51 // Send-ID definition: x=0, y=51
// // The first ID has the Value 51
//
// #define NUM_REC 1 // number of receive_IDs
// #define REC_IDx yy // Receive-ID definition: x={0...15}, yy={1...63}
// // yy=0 is Sleep-Mode
// #define REC_ID0 12 // example for the first Receive ID= 12
// #define REC_ID1 10 // example for the second Receive ID= 10
//
// Monitor IDs only for Master. This IDs will be sent by the
// Scheduling-Function.
//
// #ifdef MASTER
//
// #define MON_ID0 1 //ID of the first monitor ID
// #define MON_ID1 2 //ID of the second monitor ID
// #define MON_ID2 3 //ID of the next monitor ID
// #define MON_ID3 4 //ID of the next monitor ID
// #define MON_ID4 5 //ID of the next monitor ID
// #define MON_ID5 6 //ID of the next monitor ID
// #define MON_ID6 7 //ID of the next monitor ID
// #define MON_ID7 8 //ID of the next monitor ID
// #endif
/////////////////////////////////////////////////////////////////////////////
#ifdef MASTER
#define MAX_LIN_ID 6 // Number of maximum LIN-IDs in the
// LIN-Network.
#define NUM_SEND 3 //Number of send_IDs
#define SEND_ID0 TMessage_1
#define SEND_ID1 TMessage_2
#define SEND_ID2 TMessage_3
#define NUM_REC 3 //Number of Receive_IDs
#define REC_ID0 RMessage_1
#define REC_ID1 RMessage_2
#define REC_ID2 RMessage_3
// Monitor IDs only for Master. This IDs will be sent by the
// Scheduling-Function.
//#define MON_ID0 0x12 //ID of the first monitor ID
#endif
#ifdef SLAVE
#define MAX_LIN_ID 6 // Number of maximum LIN-IDs in the
// LIN-Network: 16=default
#define NUM_SEND 3 //Number of send_IDs
#define SEND_ID0 Message_1
#define SEND_ID1 Message_2
#define SEND_ID2 Message_3
#define NUM_REC 3 //Number of Receive_IDs
#define REC_ID0 Message_4
#define REC_ID1 Message_5
#define REC_ID2 Message_6
#endif
//****************************************************************************
// @Defines
//****************************************************************************
// USER CODE BEGIN (<module>,<position>)
/////////////////////////////////////////////////////////////////////////////
// CAPTURE COMPARE Settings
/////////////////////////////////////////////////////////////////////////////
// define the CapCom Mode Register: CCMx
#define CC_MODE_REGISTER CCM4
// define the CapCom Register: CCxx
#define CC_REGISTER CC16
// define the CapCom Interrupt Control Register: CCxxIC
#define CC_IRQ_CONTROL_REGISTER CC16IC
// define bit in the CC_IRQ_CONTROL_REGISTER
// for enable/disable capture interrupt for defined channel
#define CC_INTERRUPT_ENABLE_BIT 0x0040
// define bits in the CC_MODE_REGISTER for reset/disable the CapCom-Mode
//#define CC_MODE_DISABLE 0x3000
#define CC_MODE_DISABLE 0x0003
// define bit in the CC_MODE_REGISTER for Compare Mode 0
//#define CC_COMPARE_MODE_0 0x4000
#define CC_COMPARE_MODE_0 0x0004
/////////////////////////////////////////////////////////////////////////////
// CAPTURE COMPARE TIMER Settings
/////////////////////////////////////////////////////////////////////////////
// define the CapCom Timer Control Register: TxxCON
#define CC_TIMER_CONTROL_REGISTER T78CON
// define the CapCom Timer Register: Tx
#define CC_TIMER_REGISTER T7
// define the CapCom Timer Reload Register: TxREL
#define CC_TIMER_RELOAD_REGISTER T7REL
// define the CapCom Timer Interrupt Control Register: TxIC
#define CC_TIMER_IRQ_CONTROL_REGISTER T7IC
// define bit for enable/disable the timer interrupt in the
// CC_TIMER_IRQ_CONTROL_REGISTER
#define CC_TIMER_IRQ_ENABLE 0x0040
// define the TxR Bit in the CC_TIMER_CONTROL_REGISTER
#define CC_TIMER_RUN_BIT 0x0040
/////////////////////////////////////////////////////////////////////////////
// ASC Settings
/////////////////////////////////////////////////////////////////////////////
// define the ASC Control Register
#define ASC_CONTROL_REGISTER S0CON
// define the ASC Baudrate Register
#define ASC_BAUDRATE_REGISTER S0BG
// define the ASC Receive Interrupt Control Register
#define ASC_RECEIVE_IRQ_CONTROL_REGISTER S0RIC
// define the ASC Receive Buffer Register
#define ASC_RECEIVE_BUFFER_REGISTER S0RBUF
// define the ASC Transmit Buffer Register
#define ASC_TRANSMIT_BUFFER_REGISTER S0TBUF
// define bit for enable/disable the ASC Baudrate Generator Run Bit
// (S1R) in the ASC_CONTROL_REGISTER
#define ASC_BAUDRATE_GENERATOR_RUN_BIT 0x8000
// define bit for enable/disable the ASC interrupt in the
// ASC_RECEIVE_IRQ_REGISTER
#define ASC_RECEIVE_IRQ_ENABLE 0x0040
// define bit for enable/disable the ASC receive-function in the
// ASC_CONTROL_REGISTER
#define ASC_RECEIVE_ENABLE 0x0010
// define value for ASC Mode in the ASC_CONTROL_REGISTER
// with following settings
// 8-bit data asynchronous operation
// one stop bit
// ignore framing error
// ignore overrun error
// receiver enabled
#define ASC_MODE_VALUE 0x0011
/////////////////////////////////////////////////////////////////////////////
// Port Settings
/////////////////////////////////////////////////////////////////////////////
// LIN Port Register
#define LIN_PORT_REGISTER P3
// LIN Port Direction Register
#define LIN_PORT_DIRECTION_REGISTER DP3
// LIN TxD-Bit in LIN_PORT_REGISTER
#define LIN_TXD_BIT 0x0400
// LIN RxD-Bit in LIN_PORT_REGISTER
#define LIN_RXD_BIT 0x0800
/////////////////////////////////////////////////////////////////////////////
// Interrupt Priority Settings
/////////////////////////////////////////////////////////////////////////////
// ASC IRQ priority should be lower than the Compare IRQ priority.
// ASC Receive IRQ Priority Value
#define ASC_RECEIVE_PRIORITY_VALUE 0x0062 // ILV and GLV settings
// Capture Compare IRQ Priority Value
#define CC_PRIORITY_VALUE 0x0064 // ILV and GLV settings
/////////////////////////////////////////////////////////////////////////////
// Interrupt Settings
/////////////////////////////////////////////////////////////////////////////
// define the global Interrupt enable/disable
#define GLOBAL_INTERRUPT IEN
/////////////////////////////////////////////////////////////////////////////
// LIN Baudrate Settings
/////////////////////////////////////////////////////////////////////////////
#define BAUDRATE_LIN 19200 // set Baudrate: 19200 or 9600
// The register-values are different to the real values. Because:
// The real Bit-Time on a baudrate of 19200 bits/sec is 52,08us but
// here the best resolution is 51,2us that is a deviation of 1,0171875
// to get the right value multiply the wished value with 1,0171875 and
// you will get the right value.
#if BAUDRATE_LIN == 19200
#define BAUDRATE_ASC 0x0020 // Baudrate for LIN : 19200 Baud
#define BAUDRATE_SYN 0x002F // Baudrate for Synchbreak
#define BITTIME_LIN 0x0047 // T0: resol.= 51,2us = 0x0047
#define TIMEBASE_LIN 0x0000 // Time base = max = 3,36 sec
// == Reload-Value
#define TIME_FRAMEMAX2 0x005C // 91 bittime
#define TIME_FRAMEMAX4 0x0079 // 119 bittime
#define TIME_FRAMEMAX8 0x00B2 // 175 bittime
#define TIME_OUT 0x6355 // 25000 bittime
#define T_T0BRK 0x0082 // 128 bittime
#define T_T3BRK 0x3B99 // 15000 bittime
#else
#if BAUDRATE_LIN == 9600
#define BAUDRATE_ASC 0x0040 // Baudrate for LIN : 9600 Baud
#define BAUDRATE_SYN 0x005E // Baudrate for Synchbreak
#define BITTIME_LIN 0x0047 // T0: resol.= 51,2us = 0x0047
#define TIMEBASE_LIN 0x0000 // Time base = max = 3,36 sec
// == Reload-Value
#define TIME_FRAMEMAX2 0x00B8 // 91 bittime
#define TIME_FRAMEMAX4 0x00F2 // 119 bittime
#define TIME_FRAMEMAX8 0x0164 // 175 bittime
#define TIME_OUT 0xC6AA // 25000 bittime
#define T_T0BRK 0x0104 // 128 bittime
#define T_T3BRK 0x7732 // 15000 bittime
#endif
#endif
/////////////////////////////////////////////////////////////////////////////
// General Settings
/////////////////////////////////////////////////////////////////////////////
#define ON 1
#define OFF 0
#define ZERO 0
#define NULL 0
#define BUFFER_1 0
#define SEND_TYPE 0
#define REC_TYPE 1
#define MON_TYPE 2
#define LIN_SYNCHBREAK 0x00
#define LIN_SYNCHFIELD 0x55
#define LIN_SLEEP_CHAR 0x80
#define LIN_WAKEUP_CHAR 0x80
#define LIN_CHECKSUM_OK 0xFF
// USER CODE END
//****************************************************************************
// @Imported Global Variables
//****************************************************************************
// USER CODE BEGIN (<module>,<position>)
//<User external declarations of imported global variables>
// USER CODE END
//<User external declarations of imported functions>
// USER CODE END
//****************************************************************************
// @Global Variables
//****************************************************************************
// USER CODE BEGIN
// USER CODE END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -