📄 pcancont.h
字号:
/***********************************************************************
* *
* H E A D E R - F I L E *
* *
* B A S I C / P E L I C A N - C A N C O N T R O L L E R *
* *
************************************************************************/
/* Definition der einzelnen Bits */
/* des BASIC CAN-Mode Registers */
typedef union {
struct {
byte RR : 1; /* 0 */
byte RIE : 1; /* 1 */
byte TIE : 1; /* 2 */
byte EIE : 1; /* 3 */
byte OIE : 1; /* 4 */
byte res : 1; /* 5 */
byte S : 1; /* 6 */
byte TM : 1; /* 7 */
} bits;
byte bytes;
} can_control_type;
typedef union {
struct {
byte TR : 1;
byte AT : 1;
byte RRB : 1;
byte COS : 1;
byte GTS : 1;
byte res : 3;
} bits;
byte bytes;
} can_command_type;
typedef union {
struct {
byte RBS : 1;
byte DO : 1;
byte TBS : 1;
byte TCS : 1;
byte RS : 1;
byte TS : 1;
byte ES : 1;
byte BS : 1;
} bits;
byte bytes;
} can_status_type;
typedef union {
struct {
byte RI : 1;
byte TI : 1;
byte EI : 1;
byte DOI : 1;
byte WUI : 1;
byte res : 3;
} bits;
byte bytes;
} can_interrupt_type;
typedef struct {
byte ID1;
} can_ID1_type;
typedef struct {
byte DLC : 4;
byte RTR : 1;
byte ID2 : 3;
} can_ID2_type;
typedef union{
struct {
byte CD : 3;
byte not_used : 3;
byte CBP : 1;
byte CAN_Mode : 1;
}bits;
byte bytes;
} can_clock_devider_type;
/* Definition der einzelnen Bits */
/* des PeliCAN-Mode Registers */
typedef union {
struct {
byte RM : 1;
byte LOM : 1;
byte STM : 1; /* write access in reset mode */
byte AFM : 1; /* write access in reset mode */
byte SM : 1; /* write access in reset mode */
byte res : 3; /* = 0 when read */
} bits;
byte bytes;
} pcan_mode_type; /* RW */
typedef union {
struct {
byte TR : 1;
byte AT : 1;
byte RRB : 1;
byte CDO : 1;
byte SRR : 1;
byte res : 3;
} bits;
byte bytes;
} pcan_command_type; /* RO */
typedef union {
struct {
byte RBS : 1;
byte DOS : 1;
byte TBS : 1;
byte TCS : 1;
byte RS : 1;
byte TS : 1;
byte ES : 1;
byte BS : 1;
} bits;
byte bytes;
} pcan_status_type; /* RO */
typedef union {
struct {
byte RI : 1;
byte TI : 1; /* =0 after read */
byte EIS : 1; /* =0 after read */
byte DOI : 1; /* =0 after read */
byte WUI : 1; /* =0 after read */
byte EPI : 1; /* =0 after read */
byte ALI : 1; /* =0 after read */
byte BEI : 1; /* =0 after read */
} bits;
byte bytes;
} pcan_interrupt_type; /* RO */
typedef union {
struct {
byte RIE : 1;
byte TIE : 1;
byte EIE : 1;
byte DOIE : 1;
byte WUIE : 1;
byte EPIE : 1;
byte ALIE : 1;
byte BEIE : 1;
} bits;
byte bytes;
} pcan_interrupt_en_type; /* RW */
typedef union {
struct {
byte BRP0 : 1;
byte BRP1 : 1;
byte BRP2 : 1;
byte BRP3 : 1;
byte BRP4 : 1;
byte BRP5 : 1;
byte SJW0 : 1;
byte SJW1 : 1;
} bits;
byte bytes;
} pcan_bus_timing0_type;
typedef union {
struct {
byte TSEG10:1;
byte TSEG11:1;
byte TSEG12:1;
byte TSEG13:1;
byte TSEG20:1;
byte TSEG21:1;
byte TSEG22:1;
byte SAM1 : 1;
} bits;
byte bytes;
} pcan_bus_timing1_type;
typedef union {
struct {
byte OCMODE0:1;
byte OCMODE1:1;
byte OCPOL0 :1;
byte OCTN0 :1;
byte OCTP0 :1;
byte OCPOL1 :1;
byte OCTN1 :1;
byte OCTP1 : 1;
} bits;
byte bytes;
} pcan_output_control_type;
typedef union {
struct {
byte BITNO0 :1;
byte BITNO1 :1;
byte BITNO2 :1;
byte BITNO3 :1;
byte BITNO4 :1;
byte res :3; /* always = 0 */
} bits;
byte bytes;
} pcan_arbitr_lost_capture_type; /* RO */
typedef union {
struct {
byte SEG0 :1;
byte SEG1 :1;
byte SEG2 :1;
byte SEG3 :1;
byte SEG4 :1;
byte DIR :1;
byte ERRC0 :1;
byte ERRC1 :1;
} bits;
byte bytes;
} pcan_error_code_capture_type; /* RO */
typedef union {
struct {
byte EWL0 :1;
byte EWL1 :1;
byte EWL2 :1;
byte EWL3 :1;
byte EWL4 :1;
byte EWL5 :1;
byte EWL6 :1;
byte EWL7 :1;
} bits;
byte bytes;
} pcan_error_warning_limit_type; /* RW in reset mode, RO in operating mode */
typedef union {
struct {
byte RXERR0 :1;
byte RXERR1 :1;
byte RXERR2 :1;
byte RXERR3 :1;
byte RXERR4 :1;
byte RXERR5 :1;
byte RXERR6 :1;
byte RXERR7 :1;
} bits;
byte bytes;
} pcan_rx_error_counter_type; /* W in reset mode, RO in operating mode */
typedef union {
struct {
byte TXERR0 :1;
byte TXERR1 :1;
byte TXERR2 :1;
byte TXERR3 :1;
byte TXERR4 :1;
byte TXERR5 :1;
byte TXERR6 :1;
byte TXERR7 :1;
} bits;
byte bytes;
} pcan_tx_error_counter_type; /* W in reset mode, RO in operating mode */
typedef struct {
byte DLC : 4;
byte byte0: 2;
byte RTR : 1;
byte FF : 1;
} frame_info_type;
typedef union {
struct {
frame_info_type frame_info;
byte ident1;
byte ident2;
byte datas[8];
byte FIFO_RAM1;
byte FIFO_RAM2;
} frameSFF; /* operating mode (mode reg RM = 0 ) */
struct {
frame_info_type frame_info;
byte ident1;
byte ident2;
byte ident3;
byte ident4;
byte datas[8];
} frameEFF; /* operating mode (mode reg RM = 0 ) */
struct {
byte acc_code0;
byte acc_code1;
byte acc_code2;
byte acc_code3;
byte acc_mask0;
byte acc_mask1;
byte acc_mask2;
byte acc_mask3;
} acc_mask; /* to write reset mode (mode reg RM = 1 ) */
} pcan_rxtx_frame_acc_mask_type;
typedef union{
struct {
byte CD : 3;
byte not_used : 3;
byte CBP : 1;
byte CAN_Mode : 1;
}bits;
byte bytes;
} pcan_clock_devider_type;
typedef union { /* definieren von BasicCAN und PeliCAN Registers*/
struct
{
can_control_type control;
can_command_type command; /* write only: keine bit operationen sondern direkt schreiben */
can_status_type status;
can_interrupt_type intr;
byte acc_code;
byte acc_mask;
byte bus_tim_0;
byte bus_tim_1;
byte out_contr;
byte test;
can_ID1_type t_ID1;
can_ID2_type t_ID2;
byte trans_buf[8];
can_ID1_type r_ID1;
can_ID2_type r_ID2;
byte rec_buf[8];
byte not_used;
can_clock_devider_type clock_devider;
}bcan_reg;
struct
{
pcan_mode_type pcan_mode;
pcan_command_type pcan_command;
pcan_status_type pcan_status;
pcan_interrupt_type pcan_interrupt;
pcan_interrupt_en_type pcan_interrupt_en;
byte reserved0;
pcan_bus_timing0_type pcan_bus_timing0;
pcan_bus_timing1_type pcan_bus_timing1;
pcan_output_control_type pcan_output_control;
byte test;
byte reserved1;
pcan_arbitr_lost_capture_type pcan_arbitr_lost_capture;
pcan_error_code_capture_type pcan_error_code_capture;
pcan_error_warning_limit_type pcan_error_warning_limit;
pcan_rx_error_counter_type pcan_rx_error_counter;
pcan_tx_error_counter_type pcan_tx_error_counter;
pcan_rxtx_frame_acc_mask_type pcan_rxtx_frame_acc_mask;
byte reserved2;
byte rx_buf_start_adr;
pcan_clock_devider_type clock_devider;
byte internal_ram_adr_fifo[79];
byte not_used[15];
}pcan_reg;
byte all[128];
}reg_type;
enum can_bus_stat_t {error_active, error_passive, bus_off};
void c_first_init (void);
byte c_hw_init (byte bus_t0_reg,
byte bus_t1_reg,
byte out_c_reg,
byte clock_devider);
void c_init_cont_reg (byte cont_reg);
void c_init_accept_reg (byte acc_code,
byte acc_mask);
void c_start (void);
void c_stop (void);
unsigned long c_get_rec_id (void);
byte c_rec_remote (void);
byte c_get_rec_len (void);
void c_read_rec_data (byte xdata *arr);
void c_rel_rec_reg (void);
byte c_send_obj (unsigned long identifier,
byte remote,
byte length,
byte xdata *arr);
void c_clr_overrun (void);
byte c_get_int_reg (void);
enum can_bus_stat_t c_get_status (void);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -