demo/can.h
Go to the documentation of this file.
1 // coding: utf-8
2 // ----------------------------------------------------------------------------
3 /*
4  * Copyright (c) 2007 Fabian Greif, Roboterclub Aachen e.V.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
34 
35 #ifndef CAN_H
36 #define CAN_H
37 
38 #if defined (__cplusplus)
39  extern "C" {
40 #endif
41 
42 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
56 
57 #include <avr/pgmspace.h>
58 #include <stdint.h>
59 #include <stdbool.h>
60 
61 #include "config.h"
62 
63 // ----------------------------------------------------------------------------
68 #define ONLY_NON_RTR 2
69 #define ONLY_RTR 3
70 
71 
75 typedef enum {
76  BITRATE_10_KBPS = 0, // ungetestet
77  BITRATE_20_KBPS = 1, // ungetestet
78  BITRATE_50_KBPS = 2, // ungetestet
79  BITRATE_100_KBPS = 3, // ungetestet
81  BITRATE_250_KBPS = 5, // ungetestet
82  BITRATE_500_KBPS = 6, // ungetestet
83  BITRATE_1_MBPS = 7, // ungetestet
85 
90 #define CAN_ALL_FILTER 0xff
91 
96 #ifndef SUPPORT_EXTENDED_CANID
97  #define SUPPORT_EXTENDED_CANID 1
98 #endif
99 
105 #ifndef SUPPORT_TIMESTAMPS
106  #define SUPPORT_TIMESTAMPS 0
107 #endif
108 
141 #if defined(__DOXYGEN__)
142 
143  #define MCP2515_FILTER_EXTENDED(id)
144  #define MCP2515_FILTER(id)
145 
146 #else
147 
148  #if SUPPORT_EXTENDED_CANID
149  #define MCP2515_FILTER_EXTENDED(id) \
150  (uint8_t) ((uint32_t) (id) >> 21), \
151  (uint8_t)((((uint32_t) (id) >> 13) & 0xe0) | (1<<3) | \
152  (((uint32_t) (id) >> 16) & 0x3)), \
153  (uint8_t) ((uint32_t) (id) >> 8), \
154  (uint8_t) ((uint32_t) (id))
155  #endif
156 
157  #define MCP2515_FILTER(id) \
158  (uint8_t)((uint32_t) id >> 3), \
159  (uint8_t)((uint32_t) id << 5), \
160  0, \
161  0
162 #endif
163 
164 // ----------------------------------------------------------------------------
169 typedef struct
170 {
171  #if SUPPORT_EXTENDED_CANID
172  uint32_t id;
173  struct {
174  int rtr : 1;
175  int extended : 1;
176  } flags;
177  #else
178  uint16_t id;
179  struct {
180  int rtr : 1;
181  } flags;
182  #endif
183 
184  uint8_t length;
185  uint8_t data[8];
186 
187  #if SUPPORT_TIMESTAMPS
188  uint16_t timestamp;
189  #endif
190 } can_t;
191 
192 
193 
194 // ----------------------------------------------------------------------------
225 typedef struct
226 {
227  #if SUPPORT_EXTENDED_CANID
228  uint32_t id;
229  uint32_t mask;
230  struct {
231  uint8_t rtr : 2;
232  uint8_t extended : 2;
233  } flags;
234  #else
235  uint16_t id;
236  uint16_t mask;
237  struct {
238  uint8_t rtr : 2;
239  } flags;
240  #endif
241 } can_filter_t;
242 
243 
244 // ----------------------------------------------------------------------------
249 typedef struct {
250  uint8_t rx;
251  uint8_t tx;
253 
254 // ----------------------------------------------------------------------------
259 typedef enum {
263  SLEEP_MODE // sleep mode
264 } can_mode_t;
265 
266 // ----------------------------------------------------------------------------
276 extern bool
277 can_init(can_bitrate_t bitrate);
278 
279 // ----------------------------------------------------------------------------
323 extern void
324 can_sleep(void);
325 
326 extern void
327 can_wakeup(void);
328 
329 // ----------------------------------------------------------------------------
341 extern bool
342 can_set_filter(uint8_t number, const can_filter_t *filter);
343 
344 // ----------------------------------------------------------------------------
355 extern bool
357 
358 // ----------------------------------------------------------------------------
391 extern void
392 can_static_filter(const uint8_t *filter_array);
393 
394 // ----------------------------------------------------------------------------
420 extern uint8_t
421 can_get_filter(uint8_t number, can_filter_t *filter);
422 
423 // ----------------------------------------------------------------------------
430 extern bool
431 can_check_message(void);
432 
433 // ----------------------------------------------------------------------------
440 extern bool
442 
443 // ----------------------------------------------------------------------------
452 extern uint8_t
453 can_send_message(const can_t *msg);
454 
455 // ----------------------------------------------------------------------------
464 extern uint8_t
465 can_get_message(can_t *msg);
466 
467 // ----------------------------------------------------------------------------
479 
480 // ----------------------------------------------------------------------------
491 extern bool
492 can_check_bus_off(void);
493 
494 // ----------------------------------------------------------------------------
504 extern void
505 can_reset_bus_off(void);
506 
507 // ----------------------------------------------------------------------------
514 extern void
516 
517 #if defined (__cplusplus)
518 }
519 #endif
520 
521 #endif // CAN_H
can_check_free_buffer
bool can_check_free_buffer(void)
Ueberprueft ob ein Puffer zum Versenden einer Nachricht frei ist.
LOOPBACK_MODE
@ LOOPBACK_MODE
alle Nachrichten direkt auf die Empfangsregister umleiten ohne sie zu senden
Definition: demo/can.h:261
can_wakeup
void can_wakeup(void)
can_send_message
uint8_t can_send_message(const can_t *msg)
Verschickt eine Nachricht über den CAN Bus.
BITRATE_50_KBPS
@ BITRATE_50_KBPS
Definition: demo/can.h:78
uavcan::uint32_t
std::uint32_t uint32_t
Definition: std.hpp:26
can_mode_t
can_mode_t
Modus des CAN Interfaces.
Definition: demo/can.h:259
SLEEP_MODE
@ SLEEP_MODE
Definition: demo/can.h:263
can_t
Datenstruktur zum Aufnehmen von CAN Nachrichten.
Definition: can.h:177
can_bitrate_t
can_bitrate_t
Bitraten fuer den CAN-Bus.
Definition: demo/can.h:75
can_read_error_register
can_error_register_t can_read_error_register(void)
Reads the Contents of the CAN Error Counter.
BITRATE_500_KBPS
@ BITRATE_500_KBPS
Definition: demo/can.h:82
can_filter_t
Datenstruktur zur Aufnahme von CAN-Filtern.
Definition: can.h:233
NORMAL_MODE
@ NORMAL_MODE
normaler Modus, CAN Controller ist aktiv
Definition: demo/can.h:262
can_disable_filter
bool can_disable_filter(uint8_t number)
Filter deaktivieren.
uavcan::uint16_t
std::uint16_t uint16_t
Definition: std.hpp:25
can_set_mode
void can_set_mode(can_mode_t mode)
Setzt den Operations-Modus.
can_get_message
uint8_t can_get_message(can_t *msg)
Liest eine Nachricht aus den Empfangspuffern des CAN Controllers.
LISTEN_ONLY_MODE
@ LISTEN_ONLY_MODE
der CAN Contoller empfängt nur und verhält sich völlig passiv
Definition: demo/can.h:260
can_reset_bus_off
void can_reset_bus_off(void)
BITRATE_100_KBPS
@ BITRATE_100_KBPS
Definition: demo/can.h:79
can_sleep
void can_sleep(void)
Put CAN interface to sleep and wake up.
can_check_bus_off
bool can_check_bus_off(void)
uavcan::uint8_t
std::uint8_t uint8_t
Definition: std.hpp:24
BITRATE_250_KBPS
@ BITRATE_250_KBPS
Definition: demo/can.h:81
BITRATE_125_KBPS
@ BITRATE_125_KBPS
Definition: demo/can.h:80
can_set_filter
bool can_set_filter(uint8_t number, const can_filter_t *filter)
Setzen eines Filters.
can_check_message
bool can_check_message(void)
Ueberpruefen ob neue CAN Nachrichten vorhanden sind.
BITRATE_1_MBPS
@ BITRATE_1_MBPS
Definition: demo/can.h:83
can_get_filter
uint8_t can_get_filter(uint8_t number, can_filter_t *filter)
BITRATE_10_KBPS
@ BITRATE_10_KBPS
Definition: demo/can.h:76
config.h
can_init
bool can_init(can_bitrate_t bitrate)
Initialisierung des CAN Interfaces.
BITRATE_20_KBPS
@ BITRATE_20_KBPS
Definition: demo/can.h:77
can_static_filter
void can_static_filter(const uint8_t *filter_array)
Setzt die Werte für alle Filter.
can_error_register_t
Inhalt der Fehler-Register.
Definition: can.h:257


uavcan_communicator
Author(s):
autogenerated on Fri Dec 13 2024 03:10:02