X-Git-Url: http://rtime.felk.cvut.cz/gitweb/lincan.git/blobdiff_plain/ad1d46af5c8562e90a3f8564cf511213ff1f1745..8c25832fed15843b3ca7cdda9c99e755f063196b:/embedded/app/usbcan/can/lpc17xx_can.h diff --git a/embedded/app/usbcan/can/lpc17xx_can.h b/embedded/app/usbcan/can/lpc17xx_can.h index 1b66997..d4683e5 100644 --- a/embedded/app/usbcan/can/lpc17xx_can.h +++ b/embedded/app/usbcan/can/lpc17xx_can.h @@ -5,6 +5,8 @@ #include "hal_machperiph.h" #include "cpu_def.h" #include "system_def.h" + +#include "can/can.h" #include "can/canmsg.h" #ifdef __cplusplus @@ -15,6 +17,7 @@ extern "C" #define CAN1_REGS_BASE 0x40044000UL #define CAN2_REGS_BASE 0x40048000UL +#define CANAF_REGS_BASE 0x4003C000UL #define CAN_MOD_o 0x0000 #define CAN_CMR_o 0x0004 @@ -41,6 +44,16 @@ extern "C" #define CAN_TDA3_o 0x0058 #define CAN_TDB3_o 0x005C + +#define CANAF_AFMR_o 0x0000 +#define CANAF_SFF_sa_o 0x0004 +#define CANAF_SFF_GRP_sa_o 0x0008 +#define CANAF_EFF_sa_o 0x000C +#define CANAF_EFF_GRP_sa_o 0x0010 +#define CANAF_ENDofTable_o 0x0014 +#define CANAF_LUTerrAd_o 0x0018 +#define CANAF_LUTerr_o 0x001C + //---------------------------------- #define CAN1MOD (*(uint32_t*)(CAN1_REGS_BASE+CAN_MOD_o)) @@ -69,6 +82,54 @@ extern "C" #define CAN1TDB3 (*(uint32_t*)(CAN1_REGS_BASE+CAN_TDB3_o)) + +#define CANAF_AFMR (*(uint32_t*)(CANAF_REGS_BASE+CANAF_AFMR_o)) +#define CANAF_SFF_sa (*(uint32_t*)(CANAF_REGS_BASE+CANAF_SFF_sa_o)) +#define CANAF_SFF_GRP_sa (*(uint32_t*)(CANAF_REGS_BASE+CANAF_SFF_GRP_sa_o)) +#define CANAF_EFF_sa (*(uint32_t*)(CANAF_REGS_BASE+CANAF_EFF_sa_o)) +#define CANAF_EFF_GRP_sa (*(uint32_t*)(CANAF_REGS_BASE+CANAF_EFF_GRP_sa_o)) +#define CANAF_ENDofTable (*(uint32_t*)(CANAF_REGS_BASE+CANAF_ENDofTable_o)) +#define CANAF_LUTerrAd (*(uint32_t*)(CANAF_REGS_BASE+CANAF_LUTerrAd_o)) +#define CANAF_LUTerr (*(uint32_t*)(CANAF_REGS_BASE+CANAF_LUTerr_o)) + +//---------------------------------- + +//CAN Global Status Register +#define CAN_GSR_BS (1<<7) + +//CAN Interrupt and Capture Register bits +#define CAN_ICR_RI (1<<0) +#define CAN_ICR_TI1 (1<<1) +#define CAN_ICR_DOI (1<<3) +#define CAN_ICR_IDI (1<<8) + +//CAN Status Register bits +#define CAN_SR_RBS (1<<0) +#define CAN_SR_DOS (1<<1) +#define CAN_SR_TBS1 (1<<2) + +//CAN Command Register bits +#define CAN_CMR_TR (1<<0) +#define CAN_CMR_AT (1<<1) +#define CAN_CMR_RRB (1<<2) +#define CAN_CMR_CDO (1<<3) +#define CAN_CMR_STB1 (1<<5) + +//CAN Transmit Frame Information register 1 bits +#define CAN_TFI1_RTR (1<<30) +#define CAN_TFI1_EXT (1<<31) + +//CAN Receive Frame Status register +#define CAN_RFS_RTR (1<<30) +#define CAN_RFS_EXT (1<<31) + +//CAN Interrupt Enable Register bits +#define CAN_IER_RIE (1<<0) +#define CAN_IER_TIE1 (1<<1) +#define CAN_IER_DOIE (1<<3) +#define CAN_IER_IDIE (1<<8) + + //---------------------------------- #define PCONP SC->PCONP @@ -93,6 +154,40 @@ extern "C" void CAN_init(uint32_t baudrate); void CAN_send(canmsg_t* msg); +void CAN_recv(canmsg_t* msg); +void CAN_IRQHandler(void); + +//---------------------------------- + +struct can_lmc1_chip_data +{ + int flags; +}; + +// board can-lmc1 specific functions: +int can_lmc1_register(struct hwspecops_t *hwspecops); +int can_lmc1_init_hw_data(struct candevice_t *candev); +int can_lmc1_init_chip_data(struct candevice_t *candev, int chipnr); +int can_lmc1_init_obj_data(struct canchip_t *chip, int objnr); +void can_lmc1_write_register(unsigned data, unsigned long address); +unsigned can_lmc1_read_register(unsigned long address); +int can_lmc1_request_io(struct candevice_t *candev); +int can_lmc1_reset(struct candevice_t *candev); + +// lpc17xx can chip specific functions: +int lpc17xx_chip_config(struct canchip_t *chip); +int lpc17xx_pre_write_config(struct canchip_t *chip, struct msgobj_t *obj, + struct canmsg_t *msg); +int lpc17xx_send_msg(struct canchip_t *chip, struct msgobj_t *obj, + struct canmsg_t *msg); +int lpc17xx_wakeup_tx(struct canchip_t *chip, struct msgobj_t *obj); +int lpc17xx_irq_handler(int irq, struct canchip_t *chip); +void lpc17xx_irq_write_handler(struct canchip_t *chip, struct msgobj_t *obj); +int lpc17xx_fill_chipspecops(struct canchip_t *chip); +int lpc17xx_register(struct chipspecops_t *chipspecops); +int lpc17xx_attach_to_chip(struct canchip_t *chip); +int lpc17xx_pre_read_config(struct canchip_t *chip, struct msgobj_t *obj); +void lpc17xx_read(struct canchip_t *chip, struct msgobj_t *obj); #ifdef __cplusplus }