📄 can.h
字号:
#ifndef _CAN_H_
#define _CAN_H_
/*================================================================================
Header Name: can.h
General Description: This file contains all prototypes and macros exported for the
CAN communication API.
==================================================================================
Honeywell Confidential Proprietary
ACS - Security (Asia Pacific) R&D Software Operations
(c) Copyright Honeywell 2005, All Rights Reserved
Revision History:
Modification Tracking
Author Date Ver Number Description of Changes
---------------- ------------ ---------- -------------------------
Tim Luo 02/22/2006 ver0.0.1 Initial draft
Lake Hu 03/17/2006 ver0.0.2 Revise to use CAN interrupt
==================================================================================
INCLUDE FILES
================================================================================*/
#include "../canprotocol/canprotocol.h"
/*================================================================================
CONSTANTS
================================================================================*/
/* baud rate and bit timing parameters */
#define BRP_500k 0x00
#define SJW_500k 0x00
#define PRS_500k 0x02
#define PHS1_500k 0x03
#define PHS2_500k 0x03
#define BRP_50k 0x09
#define SJW_50k 0x00
#define PRS_50k 0x02
#define PHS1_50k 0x03
#define PHS2_50k 0x03
#define BRP_10k 0x31
#define SJW_10k 0x00
#define PRS_10k 0x02
#define PHS1_10k 0x03
#define PHS2_10k 0x03
#define BRP_20k 0x13
#define SJW_20k 0x00
#define PRS_20k 0x04
#define PHS1_20k 0x04
#define PHS2_20k 0x03
#define BRP_30k 0x09
#define SJW_30k 0x00
#define PRS_30k 0x06
#define PHS1_30k 0x04
#define PHS2_30k 0x06
#define BRP_40k 0x09
#define SJW_40k 0x00
#define PRS_40k 0x06
#define PHS1_40k 0x01
#define PHS2_40k 0x04
#define CS0 0x0000
#define CS1 0x0080
#define CS2 0x0040
#define CS3 0x00c0
#define CS4 0x0020
#define CS5 0x00A0
#define CS6 0x0060
#define CS7 0x00E0
#define NB_CHANNEL 15
/*---- Index for table can_ident_t */
#define STD_ID_10_4 0
#define STD_ID_3_0 1
#define EXT_ID_28_21 0
#define EXT_ID_20_13 1
#define EXT_ID_12_5 2
#define EXT_ID_4_0 3
#define MSK_CTRL_RTR 0x80
#define MSK_CTRL_IDE 0x10
#define MSK_CTRL_DLC 0x0F
/* constant for configuration of conf_rx and conf_tx */
#define CONF_IDE 0x10
#define CONF_NOIDE 0
#define CONF_RTR 0x20
#define CONF_NORTR 0
#define CONF_BUFFER 0x01
#define CONF_NOBUFFER 0
#define CONF_MSK_IDE 0x80
#define CONF_NOMSK_IDE 0
#define CONF_MSK_RTR 0x4
#define CONF_NOMSK_RTR 0
/* constant for next configuration in ReadCanMsg function. */
#define CHANNEL_DISABLE 0x01
#define CHANNEL_RX_ENABLE 0x02
#define CHANNEL_RXB_ENABLE 0x04
/*================================================================================
GLOBAL MACROS DECLARATION
================================================================================*/
#define Sfr(x, y) sfr x = y
#define Sbit(x, y, z) sbit x = y^z
#define Sfr16(x,y)sfr16 x = y
#define MSK_ADCON_PSIDLE 0x40
#define MSK_ADCON_ADEN 0x20
#define MSK_ADCON_ADEOC 0x10
#define MSK_ADCON_ADSST 0x08
#define MSK_ADCON_SCH 0x07
#define MSK_ADDL_UTILS 0x03
#define MSK_FCON_FBUSY 0x01
#define MSK_FCON_FMOD 0x06
#define MSK_FCON_FPS 0x08
#define MSK_FCON_FPL 0xF0
#define MSK_EECON_EEBUSY 0x01
#define MSK_EECON_EEE 0x02
#define MSK_EECON_EEPL 0xF0
#define MSK_AUXR_M0 0x20
#define MSK_AUXR1_ENBOOT 0x20
#define MSK_CANGIT_CANIT0x80
#define MSK_CANGIT_OVRTIM 0x20
#define MSK_CANGIT_OVRBUF0x10
#define MSK_CANGIT_SERG0x08
#define MSK_CANGIT_CERG0x04
#define MSK_CANGIT_FERG0x02
#define MSK_CANGIT_AERG0x01
#define MSK_CANGSTA_OVFG0x40
#define MSK_CANGSTA_TBSY0x10
#define MSK_CANGSTA_RBSY0x08
#define MSK_CANGSTA_ENFG0x04
#define MSK_CANGSTA_BOFF0x02
#define MSK_CANGSTA_ERRP0x01
#define MSK_CANGCON_ABRQ 0x80
#define MSK_CANGCON_OVRQ 0x40
#define MSK_CANGCON_TTC 0x20
#define MSK_CANGCON_SYNCTTC 0x10
#define TTC_EOF 0x10
#define TTC_SOF 0x00
#define MSK_CANGCON_AUTBAUD 0x08
#define MSK_CANGCON_ENA 0x02
#define MSK_CANGCON_GRES 0x01
#define MSK_CANSTCH_DLCW 0x80
#define MSK_CANSTCH_TxOk 0x40
#define MSK_CANSTCH_RxOk 0x20
#define MSK_CANSTCH_BERR 0x10
#define MSK_CANSTCH_SERR 0x08
#define MSK_CANSTCH_CERR 0x04
#define MSK_CANSTCH_FERR 0x02
#define MSK_CANSTCH_AERR 0x01
#define MSK_CANCONCH_IDE 0x10
#define MSK_CANCONCH_DLC 0x0F
#define MSK_CANCONCH_CONF 0xC0
#define DLC_MAX 8
#define CH_DISABLE 0x00
#define CH_RxENA 0x80
#define CH_TxENA 0x40
#define CH_RxBENA 0xC0
#define CAN_PRESCALER_MIN 0
#define CAN_PRESCALER_MAX 63
#define MSK_CANBT2_SJW 0x60
#define MSK_CANBT2_PRS 0x0E
#define CAN_SJW_MIN 0
#define CAN_SJW_MAX 3
#define CAN_PRS_MIN 0
#define CAN_PRS_MAX 7
#define MSK_CANBT3_PHS2 0x70
#define MSK_CANBT3_PHS1 0x0E
#define CAN_PHS2_MIN 0
#define CAN_PHS2_MAX 7
#define CAN_PHS1_MIN 0
#define CAN_PHS1_MAX 7
#define MSK_CANIDT4_RTRTAG 0x04
#define MSK_CANGIE_ENRX 0x20
#define MSK_CANGIE_ENTX 0x10
#define MSK_CANGIE_ENERCH 0x08
#define MSK_CANGIE_ENBUF 0x04
#define MSK_CANGIE_ENERG 0x02
#define MSK_CANIDM4_RTRMSK 0x04
#define MSK_CANIDM4_IDEMSK 0x01
#define MSK_CANIE_ERROR 0x0E
/*================================================================================
STRUCTURES AND OTHER TYPEDEFS
================================================================================*/
typedef unsigned char UINT8;
typedef unsigned int UINT16;
typedef int INT16;
typedef float Float16;
typedef unsigned long int UINT32;
typedef long int INT32;
typedef unsigned char INT8;
/*
typedef unsigned char can_data_t [NB_DATA_MAX];
/*typedef union{
UINT32 can_id_32;
UINT8 can_id[4];
} can_id_t;
*/
/**typedef struct{
can_id_t id;
unsigned char can_data[8];
unsigned char conf; // CANCONCH
} can_msg_t;
*/
/*================================================================================
ENUMS
================================================================================*/
typedef enum{
CHANNEL_0, CHANNEL_1, CHANNEL_2, CHANNEL_3 ,
CHANNEL_4, CHANNEL_5 ,CHANNEL_6 , CHANNEL_7 ,
CHANNEL_8, CHANNEL_9 , CHANNEL_10, CHANNEL_11,
CHANNEL_12, CHANNEL_13, CHANNEL_14, NO_CHANNEL
} channel_t;
typedef enum {
CONF_DLC_0, CONF_DLC_1, CONF_DLC_2, CONF_DLC_3,
CONF_DLC_4, CONF_DLC_5, CONF_DLC_6, CONF_DLC_7, CONF_DLC_8
} dlc_t;
/*================================================================================
UNION DECLARATION
================================================================================*/
/*================================================================================
GLOBAL VARIABLE DECLARATIONS
================================================================================*/
extern bit can_tx_busy;
extern bit can_tx_ok;
extern unsigned short data can_rx_pending;
extern unsigned char data local_can_add;
extern can_msg_t idata can_tx_buf; /* CAN message Tx buffer */
extern can_msg_t xdata can_rx_buf; /* received CAN message */
extern unsigned char idata can_tx_fail_counter; /* CAN tx fail counter */
/*================================================================================
GLOBAL FUNCTION PROTOTYPES
================================================================================*/
#define NO_CHANNEL 0xFF
#define MAX_CHANNEL_NUM CHANNEL_14
#define TX_CHANNEL_NUM CHANNEL_0
#define RX_CHANNEL_FIRST CHANNEL_1
#define RX_CHANNEL_LAST CHANNEL_14
extern void init_can();
extern void send_can_msg();
extern unsigned char FindFirstChIt (void);
extern void ReadCanMsg ();
extern void can_rx();
/*==============================================================================*/
#endif /* _CAN_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -