Robobo
can.h
Go to the documentation of this file.
1 
44 #ifndef CAN_H_INCLUDED
45 #define CAN_H_INCLUDED
46 
47 #include "../chip.h"
48 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
58 #define GLOBAL_MAILBOX_MASK 0x000000ff
59 
61 #define CAN_DISABLE_ALL_INTERRUPT_MASK 0xffffffff
62 
64 #define CAN_BPS_1000K 1000
65 #define CAN_BPS_800K 800
66 #define CAN_BPS_500K 500
67 #define CAN_BPS_250K 250
68 #define CAN_BPS_125K 125
69 #define CAN_BPS_50K 50
70 #define CAN_BPS_25K 25
71 #define CAN_BPS_10K 10
72 #define CAN_BPS_5K 5
73 
75 #define CAN_MB_DISABLE_MODE 0
76 #define CAN_MB_RX_MODE 1
77 #define CAN_MB_RX_OVER_WR_MODE 2
78 #define CAN_MB_TX_MODE 3
79 #define CAN_MB_CONSUMER_MODE 4
80 #define CAN_MB_PRODUCER_MODE 5
81 
83 #define CAN_MAILBOX_TRANSFER_OK 0
84 #define CAN_MAILBOX_NOT_READY 0x01
85 #define CAN_MAILBOX_RX_OVER 0x02
86 #define CAN_MAILBOX_RX_NEED_RD_AGAIN 0x04
87 
88 
89 typedef struct {
90  uint32_t ul_mb_idx;
91  uint8_t uc_obj_type;
92  uint8_t uc_id_ver;
93  uint8_t uc_length;
94  uint8_t uc_tx_prio;
95  uint32_t ul_status;
96  uint32_t ul_id_msk;
97  uint32_t ul_id;
98  uint32_t ul_fid;
99  uint32_t ul_datal;
100  uint32_t ul_datah;
101 } can_mb_conf_t;
102 
118 uint32_t can_init(Can *p_can, uint32_t ul_mck, uint32_t ul_baudrate);
119 
120 void can_enable(Can *p_can);
121 void can_disable(Can *p_can);
122 
123 void can_disable_low_power_mode(Can *p_can);
124 void can_enable_low_power_mode(Can *p_can);
125 
126 void can_disable_autobaud_listen_mode(Can *p_can);
127 void can_enable_autobaud_listen_mode(Can *p_can);
128 
129 void can_disable_overload_frame(Can *p_can);
130 void can_enable_overload_frame(Can *p_can);
131 
132 void can_set_timestamp_capture_point(Can *p_can, uint32_t ul_flag);
133 
134 void can_disable_time_triggered_mode(Can *p_can);
135 void can_enable_time_triggered_mode(Can *p_can);
136 
137 void can_disable_timer_freeze(Can *p_can);
138 void can_enable_timer_freeze(Can *p_can);
139 
140 void can_disable_tx_repeat(Can *p_can);
141 void can_enable_tx_repeat(Can *p_can);
142 
143 void can_set_rx_sync_stage(Can *p_can, uint32_t ul_stage);
144 
145 void can_enable_interrupt(Can *p_can, uint32_t dw_mask);
146 void can_disable_interrupt(Can *p_can, uint32_t dw_mask);
147 
148 uint32_t can_get_interrupt_mask(Can *p_can);
149 
150 uint32_t can_get_status(Can *p_can);
151 
152 uint32_t can_get_internal_timer_value(Can *p_can);
153 
154 uint32_t can_get_timestamp_value(Can *p_can);
155 
156 uint8_t can_get_tx_error_cnt(Can *p_can);
157 uint8_t can_get_rx_error_cnt(Can *p_can);
158 
159 void can_reset_internal_timer(Can *p_can);
160 
161 void can_global_send_transfer_cmd(Can *p_can, uint8_t uc_mask);
162 void can_global_send_abort_cmd(Can *p_can, uint8_t uc_mask);
163 
164 /*
165  * Mailbox functions
166  */
167 void can_mailbox_set_timemark(Can *p_can, uint8_t uc_index, uint16_t us_cnt);
168 uint32_t can_mailbox_get_status(Can *p_can, uint8_t uc_index);
169 void can_mailbox_send_transfer_cmd(Can *p_can, uint8_t uc_index);
170 void can_mailbox_send_abort_cmd(Can *p_can, uint8_t uc_index);
171 void can_mailbox_init(Can *p_can, can_mb_conf_t *p_mailbox);
172 uint32_t can_mailbox_read(Can *p_can, can_mb_conf_t *p_mailbox);
173 uint32_t can_mailbox_write(Can *p_can, can_mb_conf_t *p_mailbox);
174 uint32_t can_mailbox_tx_remote_frame(Can *p_can, can_mb_conf_t *p_mailbox);
175 void can_reset_all_mailbox(Can *p_can);
176 
177 // from wilfredo
178 uint32_t can_reset_mailbox_data(can_mb_conf_t *p_mailbox);
179 
184 #ifdef __cplusplus
185 }
186 #endif
187 
492 #endif /* CAN_H_INCLUDED */
Definition: can.h:89
uint8_t uc_tx_prio
Received data length or transmitted data length.
Definition: can.h:94
uint8_t uc_id_ver
Mailbox object type, one of the six different objects.
Definition: can.h:92
uint32_t ul_datal
Family ID.
Definition: can.h:99
Definition: component_can.h:53
uint8_t uc_length
0 stands for standard frame, 1 stands for extended frame.
Definition: can.h:93
uint32_t ul_fid
Received frame ID or the frame ID to be transmitted.
Definition: can.h:98
uint32_t ul_id
No effect in transmit mode.
Definition: can.h:97
uint32_t ul_id_msk
Mailbox status register value.
Definition: can.h:96
uint32_t ul_status
Mailbox priority, no effect in receive mode.
Definition: can.h:95