#ifndef _Shark_Can0_h__ #define _Shark_Can0_h__ #include #include "os/os_types.h" #include "config.h" //CAN DLC lenght #define CAN_DLC_LENGTH 8 #define CAN_EXTENDE_FRAME 1 #ifdef CAN_EXTENDE_FRAME #define CAN_DATA_SIZE CAN_DLC_LENGTH #else #define CAN_DATA_SIZE 64 #endif typedef union { uint32_t id; struct { uint32_t dest :7; /*bit 0-6 */ uint32_t src :7; /*bit 7-13 */ uint32_t idx :5; /*bit 14-18 */ uint32_t total :5; /*bit 19-23 */ uint32_t type :2; /*bit 24-25 */ /*1:PT_REQ_NEED_RES ; 2:PT_RES 3:PT_REQ_NO_IND*/ uint32_t retry :3; /*bit 26-28 */ uint32_t length :3; /*bit 29-13 */ //0-7:1-8 }; }can_id_t; //CAN filter setting #ifdef CAN_COMMUNICATION_SPEC_V1P4 //specification 1.4 #define CAN_ID_FILTER_START_OFFSET 3 #define CAN_ID_FILTER_FLAG_OFFSET 7 #define CAN_ID_FILTER_FLAG 0x7F #else //specification 1.3 #define CAN_ID_FILTER_START_OFFSET 3 #define CAN_ID_FILTER_FLAG_OFFSET 8 #define CAN_ID_FILTER_FLAG 0xFF #endif #define CAN_FILTER_DEST_MASK 0x7F #define ptype_beat_heart 0 // can heat heart #define ptype_request 1 // can request with need response #define ptype_response 2 // can response of the request #define ptype_indicater 3 // can request with no need response #define can_packet_priority_value 0x06 #define can_packet_quick_packet_value 0x01 //used when can recv static __inline__ uint16_t decoder_can_key(const void *buf){ uint8_t *key_buf = (uint8_t *)buf; return key_buf[1]<<8 | key_buf[0]; } //used when can send static __inline__ void encoder_can_key(uint8_t *buff, uint16_t key) { buff[0] = key & 0xFF; buff[1] = (key >> 8) & 0xFF; } int shark_can0_send_message(uint32_t can_id, const void*buff, int len); void shark_can0_route_message(uint32_t can_id, const void *buff, int len); int shark_can0_send_ext_message(uint32_t can_id, const void*buff, int len); void shark_can0_init(void); void shark_can0_reset(void); void shark_can0_deinit(void); void can_rx_poll(void); #endif /* _Shark_Can0_h__ */