?? canreg.h
字號:
/****************************************Copyright (c)**************************************************
** 廣州周立功單片機發展有限公司
** 研 究 所
** 產品一部
** http://www.zlgmcu.com
**-------------------------------------文件信息--------------------------------------------------------
** 文 件 名: CANREG.H
** 創 建 人: 滕欣欣
** 版 本: v1.0
** 日 期: 2004年2月23日
** 描 述: CAN模塊寄存器類型定義、地址定義頭文件
********************************************************************************************************/
#ifndef _CANREG_H_
#define _CANREG_H_
/*
**********************************************************************************************************************
** 驗收濾波器RAM首地址
**********************************************************************************************************************
*/
#define CANAFRAM_BADR 0xE0038000
/*
**********************************************************************************************************************
** CAN寄存器基地址定義
**********************************************************************************************************************
*/
#define CANMOD_BADR 0xE0044000 //模式寄存器
#define CANCMR_BADR 0xE0044004 //命令寄存器
#define CANGSR_BADR 0xE0044008 //全局狀態寄存器
#define CANICR_BADR 0xE004400C //中斷及捕獲寄存器
#define CANIER_BADR 0xE0044010 //中斷使能寄存器
#define CANBTR_BADR 0xE0044014 //總線時序寄存器
#define CANEWL_BADR 0xE0044018 //報警限制寄存器
#define CANSR_BADR 0xE004401C //狀態寄存器
#define CANRFS_BADR 0xE0044020 //接收幀信息寄存器
#define CANRID_BADR 0xE0044024 //接收報文ID寄存器
#define CANRDA_BADR 0xE0044028 //接收數據1~4
#define CANRDB_BADR 0xE004402C //接收數據5~8
#define CANTFI1_BADR 0xE0044030 //CAN發送緩沖區1幀信息寄存器
#define CANTID1_BADR 0xE0044034 // CAN發送緩沖區1報文ID寄存器
#define CANTDA1_BADR 0xE0044038 // CAN發送緩沖區1發送數據1~4寄存器
#define CANTDB1_BADR 0xE004403C // CAN發送緩沖區1發送數據5~8寄存器
#define CANTFI2_BADR 0xE0044040 // CAN發送緩沖區2幀信息寄存器
#define CANTID2_BADR 0xE0044044 // CAN發送緩沖區2報文ID寄存器
#define CANTDA2_BADR 0xE0044048 // CAN發送緩沖區2發送數據1~4寄存器
#define CANTDB2_BADR 0xE004404C // CAN發送緩沖區2發送數據5~8寄存器
#define CANTFI3_BADR 0xE0044050 // CAN發送緩沖區3幀信息寄存器
#define CANTID3_BADR 0xE0044054 // CAN發送緩沖區3報文ID寄存器
#define CANTDA3_BADR 0xE0044058 // CAN發送緩沖區3發送數據1~4寄存器
#define CANTDB3_BADR 0xE004405C // CAN發送緩沖區3發送數據5~8寄存器
/*
**********************************************************************************************************************
** 定義RxBUF的基地址
**********************************************************************************************************************
*/
#define RxBUF_BADR 0xE0044020
/*
**********************************************************************************************************************
** 定義TxBUF的基地址
**********************************************************************************************************************
*/
#define TxBUF1_BADR 0xE0044030 // CAN發送緩沖區1首地址
#define TxBUF2_BADR 0xE0044040 // CAN發送緩沖區2首地址
#define TxBUF3_BADR 0xE0044050 // CAN發送緩沖區3首地址
/*
**********************************************************************************************************************
** 定義全局應用的寄存器
**********************************************************************************************************************
*/
#define CANTxSR_GADR 0xE0040000 //發送狀態寄存器
#define CANRxSR_GADR 0xE0040004 //接收狀態寄存器
#define CANMSR_GADR 0xE0040008 //錯誤狀態寄存器
#define CANAFMR_GADR 0xE003C000 //驗收濾波控制
#define CANSFF_sa_GADR 0xE003C004 //標準幀表格
#define CANSFF_GRP_sa_GADR 0xE003C008 //標準幀組表格
#define CANEFF_sa_GADR 0xE003C00C //擴展幀表格
#define CANEFF_GRP_sa_GADR 0xE003C010 //擴展幀組表格
#define CANENDofTable_GADR 0xE003C014 //表格結束地址
#define CANLUTerrAd_GADR 0xE003C018 //LUT錯誤地址地址寄存器
#define CANLUTerr_GADR 0xE003C01C //LUT錯誤寄存器
/*
**********************************************************************************************************************
** CAN控制器通道定義
**********************************************************************************************************************
*/
typedef enum _cannum_
{
#if CAN_MAX_NUM == 4 //微處理器中含有4路CAN
CAN1 = 0, //CAN1模塊
CAN2, //CAN2模塊
CAN3, //CAN3模塊
CAN4 //CAN4模塊
#elif CAN_MAX_NUM == 2 //微處理器中含有2路CAN
CAN1 = 0, //CAN1模塊
CAN2 //CAN2模塊
#endif
} eCANNUM;
//#define REGAFRAM (*((volatile INT32U *) 0xE0038000)) /* lpc2119\lpc2129\lpc2292\lpc2294 only */
/*
*********************************************************************************************************************
** 定義 CANMOD 寄存器:
1.This register controls the basic operating mode of the CAN Controller.
2.Bits not listed read as 0 and should be written as 0.
*********************************************************************************************************************
*/
typedef union _canmod_
{
INT32U Word;
struct {
INT32U RM :1; //定義RM位(復位位)
INT32U LOM :1; //定義LOM位(只聽模式位)
INT32U STM :1; //定義STM位 "0"發送的信息必須被應答才被認可
// "1"自測試模式,CANCMR的SRR位一起使用,可以達到自發自收的效果
INT32U TPM :1; //定義TPM位 "0"3個發送緩沖區的優先級由各自的CAN ID決定
// "1"3個發送緩沖區的優先級由各自的Tx優先級域決定
INT32U SM :1; //定義SM位(睡眠模式位)
INT32U RPM :1; //定義RPM位 "0"如果傳輸的是顯性位,Rx和Tx腳為低電平
// "1"翻轉極性模式--如果傳輸的是顯性位,Rx腳為高電平
INT32U RSV1 :1; //保留位
INT32U TM :1; //定義TM位(測試模式)
INT32U RSV24 :24; //保留位
}Bits;
}uCANMod,*P_uCANMod;
#define CANMOD(CanNum) (*((volatile P_uCANMod)(CANMOD_BADR+CanNum* CAN_OFFSET_ADR)))
/*
**********************************************************************************************************************
** 定義 CANCMR 寄存器:
1.Writing to this write-only register initiates an action.
2.Bits not listed should be written as 0. Reading this register yields zeroes.
**********************************************************************************************************************
*/
typedef union _cancmr_
{
INT32U Word;
struct
{
INT32U TR :1; //定義TR位(發送請求)
INT32U AT :1; //定義AT位(發送中止)
INT32U RRB :1; //定義RRB位(接收緩沖區釋放)
INT32U CDO :1; //清除數據溢出位
INT32U SRR :1; //定義SRR位(自接收請求)
INT32U STB1 :1; //定義SEND TxBUF1位(選擇BUF1發送)
INT32U STB2 :1; //定義SEND TxBUF2位(選擇BUF2發送)
INT32U STB3 :1; //定義SEND TxBUF3位(選擇BUF3發送)
INT32U RSV24 :24; //保留位
}Bits;
}uCANCMR,*P_uCANCMR;
#define CANCMR(CanNum) (*((volatile P_uCANCMR)(CANCMR_BADR+CanNum* CAN_OFFSET_ADR )))
/*
************************************************************************************************************************
** 定義 CANGSR 寄存器:
1.This register is read-only, except that the Error Counters can be written when the RM bit in the CANMOD register is 1.
2.Bits not listed read as 0 and should be written as 0.
************************************************************************************************************************
*/
typedef union _cangsr_
{
INT32U Word; //字操作定義
struct
{
INT32U RBS :1; //接收緩沖區狀態位
INT32U DOS :1; //數據溢出狀態位
INT32U TBS :1; //發送緩沖區狀態鎖定位
INT32U TCS :1; //發送完成狀態位
INT32U RS :1; //正在接收狀態
INT32U TS :1; //正在發送狀態
INT32U ES :1; //錯誤狀態
INT32U BS :1; //總線關閉
INT32U RSV8 :8; //保留位
INT32U RXERR :8; //接收錯誤計數
INT32U TXERR :8; //發送錯誤計數
}Bits;
}uCANGSR,*P_uCANGSR;
#define CANGSR(CanNum) (*((volatile P_uCANGSR)( CANGSR_BADR+CanNum* CAN_OFFSET_ADR )))
/*
**********************************************************************************************************************
** 定義 CANICR 寄存器:
1.Bits in this register indicate information about events on the CAN bus. This register is read-only.
2.Bits not listed read as 0 and should be written as 0.
3.The clearing of bits 1-9 and the releasing of bits 16-23 and 24-31 all occur on any read from CANICR,
regardless of whether part or all of the register is read.This means that software should always read CANICR as a word,
and and process and deal with all bits of the register as appropriate for the application.
**********************************************************************************************************************
*/
typedef union _canicr_
{
INT32U Word; //字操作定義
struct
{
INT32U RI :1; //接收中斷位
INT32U TI1 :1; //TxBUF1發送成功中斷位
INT32U EI :1; //錯誤報警中斷位
INT32U DOI :1; //數據溢出中斷位
INT32U WUI :1; //睡眠喚醒中斷位
INT32U EPI :1; //錯誤認可中斷位
INT32U ALI :1; //仲裁錯誤中斷位
INT32U BEI :1; //總線錯誤中斷
INT32U IDI :1; //接收到CAN標識符中斷位
INT32U TI2 :1; // TxBUF2發送成功中斷位
INT32U TI3 :1; // TxBUF3發送成功中斷位
INT32U RSV5 :5; //保留位
INT32U ERRBIT :5; //錯誤代碼捕獲
INT32U ERRDIR :1; //錯誤方向
INT32U ERRC :2; //錯誤類型
INT32U ALCBIT :5; //仲裁錯誤代碼捕獲
INT32U RSV3 :3; //保留
}Bits;
}uCANICR,*P_uCANICR;
#define CANICR(CanNum) (*((volatile P_uCANICR)( CANICR_BADR+CanNum* CAN_OFFSET_ADR )))
/*
**********************************************************************************************************************
** 定義 CANIER 寄存器:
1.This read/write register controls whether various events on the CAN controller will result in an interrupt.
2.Bits 7:0 in this register correspond 1-to-1 with bits 7:0 in the CANICR register.
**********************************************************************************************************************
*/
typedef union _canier_
{
INT32U Word; //字操作定義
struct
{
INT32U RIE :1; //接收中斷使能位
INT32U TIE1 :1; //TxBUF1發送完成中斷使能位
INT32U EIE :1; //錯誤報警中斷使能位
INT32U DOIE :1; //數據溢出中斷使能位
INT32U WUIE :1; //睡眠模式喚醒中斷使能位
INT32U EPIE :1; //錯誤認可中斷使能位
INT32U ALIE :1; //仲裁丟失中斷使能位
INT32U BEIE :1; //總線錯誤中斷使能位
INT32U IDIE :1; //接收到CAN標識符中斷使能位
INT32U TIE2 :1; //TxBUF2發送完成中斷使能位
INT32U TIE3 :1; //TxBUF3發送完成中斷使能位
INT32U RSV21 :21;//保留位
}Bits;
}uCANIER,*P_uCANIER;
#define CANIER(CanNum) (*((volatile P_uCANIER)( CANIER_BADR+CanNum* CAN_OFFSET_ADR )))
/*
**********************************************************************************************************************
** 定義 CANBTR 寄存器:
1.This register controls how various CAN timings are derived from the VPB clock.
2.It can be read at any time, but can only be written if the RM bit in CANmod is 1.
**********************************************************************************************************************
*/
typedef union _canbtr_
{
INT32U Word; //字操作定義
struct
{
INT32U BRP :10; //預分頻位組合定義
INT32U RSV4 :4; //保留位
INT32U SJW :2; //同步跳轉寬度
INT32U TSEG1 :4; //時間段1
INT32U TSEG2 :3; //時間段2
INT32U SAM :1; //采樣模式位
INT32U RSV8 :8; //保留
}Bits;
}uCANBTR,*P_uCANBTR;
#define CANBTR(CanNum) (*((volatile P_uCANBTR)( CANBTR_BADR+CanNum* CAN_OFFSET_ADR )))
/*
**********************************************************************************************************************
** 定義 CANEWL 寄存器:
1.This register sets a limit on Tx or Rx errors at which an interrupt can occur.
2.It can be read at any time, but can only be written if the RM bit in CANmod is 1.
**********************************************************************************************************************
*/
typedef union _canewl_
{
INT32U Word; //字操作定義
struct
{
INT32U EWL :8; ///出錯警告界限值
INT32U RSV24 :24; //保留位
}Bits;
}uCANEWL,*P_uCANEWL;
#define CANEWL(CanNum) (*((volatile P_uCANEWL)( CANEWL_BADR+CanNum* CAN_OFFSET_ADR )))
/*
**********************************************************************************************************************
** 定義 CANSR 寄存器:
1.This register contains three status bytes, in which the bits not related to tranmission are identical to the
corresponding bits in the Global Status Register, while those relating to transmission reflect the status of
each of the 3 Tx Buffers.
**********************************************************************************************************************
*/
typedef union _cansr_
{
INT32U Word; //字操作定義
struct
{
INT32U RBS1 :1; //接收緩沖區有效
INT32U DOS1 :1; //數據溢出
INT32U TBS1 :1; //TxBUF1鎖定位 "0":鎖定
INT32U TCS1 :1; //TxBUF1的數據發送完成
INT32U RS1 :1; //正在接收
INT32U TS1 :1; //TxBUF1的數據正在發送 "1"正在發送
INT32U ES1 :1; //錯誤認可
INT32U BS1 :1; //總線錯誤
INT32U RBS2 :1; //
INT32U DOS2 :1; //
INT32U TBS2 :1; // TxBUF2鎖定
INT32U TCS2 :1; // TxBUF2的數據發送完成
INT32U RS2 :1; //
INT32U TS2 :1; // TxBUF2的數據正在發送
INT32U ES2 :1; //
INT32U BS2 :1; //
INT32U RBS3 :1; //
INT32U DOS3 :1; //
INT32U TBS3 :1; // TxBUF3鎖定
INT32U TCS3 :1; // TxBUF3的數據發送完成
INT32U RS3 :1; //
INT32U TS3 :1; // TxBUF3的數據正在發送
INT32U ES3 :1; //
INT32U BS3 :1; //
INT32U RSV8 :8; //
}Bits;
}uCANSR,*P_uCANSR;
#define CANSR(CanNum) (*((volatile P_uCANSR)( CANSR_BADR+CanNum* CAN_OFFSET_ADR )))
/*
**********************************************************************************************************************
** 定義 CANRFS 寄存器:
1.This register defines the characteristics of the current received message.
2.It is read-only in normal operation, but can be written for testing purposes if the RM bit in CANMOD is 1.
**********************************************************************************************************************
*/
typedef union _canrfs_
{
INT32U Word; //字操作定義
struct
{
INT32U IDIN :10; //ID索引值
INT32U BP :1; //BP
INT32U RSV5 :5; //保留
INT32U DLC :4; //數據長度
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -