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 #ifndef CAN_CONFIG_LOADED
62 #ifdef HAS_CAN_CONFIG_H
63 /* try to load can_config.h */
64 #include "can_config.h"
65 #else
66 /* try to load config.h - compatibility */
67 #include "config.h"
68 #endif
69 #endif
70 
71 // ----------------------------------------------------------------------------
76 #define ONLY_NON_RTR 2
77 #define ONLY_RTR 3
78 
79 
83 typedef enum {
84  BITRATE_10_KBPS = 0, // ungetestet
85  BITRATE_20_KBPS = 1, // ungetestet
86  BITRATE_50_KBPS = 2, // ungetestet
87  BITRATE_100_KBPS = 3, // ungetestet
89  BITRATE_250_KBPS = 5, // ungetestet
90  BITRATE_500_KBPS = 6, // ungetestet
91  BITRATE_1_MBPS = 7, // ungetestet
93 
98 #define CAN_ALL_FILTER 0xff
99 
104 #ifndef SUPPORT_EXTENDED_CANID
105  #define SUPPORT_EXTENDED_CANID 1
106 #endif
107 
113 #ifndef SUPPORT_TIMESTAMPS
114  #define SUPPORT_TIMESTAMPS 0
115 #endif
116 
149 #if defined(__DOXYGEN__)
150 
151  #define MCP2515_FILTER_EXTENDED(id)
152  #define MCP2515_FILTER(id)
153 
154 #else
155 
156  #if SUPPORT_EXTENDED_CANID
157  #define MCP2515_FILTER_EXTENDED(id) \
158  (uint8_t) ((uint32_t) (id) >> 21), \
159  (uint8_t)((((uint32_t) (id) >> 13) & 0xe0) | (1<<3) | \
160  (((uint32_t) (id) >> 16) & 0x3)), \
161  (uint8_t) ((uint32_t) (id) >> 8), \
162  (uint8_t) ((uint32_t) (id))
163  #endif
164 
165  #define MCP2515_FILTER(id) \
166  (uint8_t)((uint32_t) id >> 3), \
167  (uint8_t)((uint32_t) id << 5), \
168  0, \
169  0
170 #endif
171 
172 // ----------------------------------------------------------------------------
177 typedef struct
178 {
179  #if SUPPORT_EXTENDED_CANID
181  struct {
182  int rtr : 1;
183  int extended : 1;
184  } flags;
185  #else
186  uint16_t id;
187  struct {
188  int rtr : 1;
189  } flags;
190  #endif
191 
193  uint8_t data[8];
194 
195  #if SUPPORT_TIMESTAMPS
196  uint16_t timestamp;
197  #endif
198 } can_t;
199 
200 
201 
202 // ----------------------------------------------------------------------------
233 typedef struct
234 {
235  #if SUPPORT_EXTENDED_CANID
238  struct {
239  uint8_t rtr : 2;
241  } flags;
242  #else
243  uint16_t id;
244  uint16_t mask;
245  struct {
246  uint8_t rtr : 2;
247  } flags;
248  #endif
249 } can_filter_t;
250 
251 
252 // ----------------------------------------------------------------------------
257 typedef struct {
261 
262 // ----------------------------------------------------------------------------
267 typedef enum {
271  SLEEP_MODE // sleep mode
272 } can_mode_t;
273 
274 // ----------------------------------------------------------------------------
284 extern bool
285 can_init(can_bitrate_t bitrate);
286 
287 // ----------------------------------------------------------------------------
331 extern void
332 can_sleep(void);
333 
334 extern void
335 can_wakeup(void);
336 
337 // ----------------------------------------------------------------------------
349 extern bool
350 can_set_filter(uint8_t number, const can_filter_t *filter);
351 
352 // ----------------------------------------------------------------------------
363 extern bool
365 
366 // ----------------------------------------------------------------------------
399 extern void
400 can_static_filter(const uint8_t *filter_array);
401 
402 // ----------------------------------------------------------------------------
428 extern uint8_t
429 can_get_filter(uint8_t number, can_filter_t *filter);
430 
431 // ----------------------------------------------------------------------------
438 extern bool
439 can_check_message(void);
440 
441 // ----------------------------------------------------------------------------
448 extern bool
450 
451 // ----------------------------------------------------------------------------
460 extern uint8_t
461 can_send_message(const can_t *msg);
462 
463 // ----------------------------------------------------------------------------
472 extern uint8_t
473 can_get_message(can_t *msg);
474 
475 // ----------------------------------------------------------------------------
487 
488 // ----------------------------------------------------------------------------
499 extern bool
500 can_check_bus_off(void);
501 
502 // ----------------------------------------------------------------------------
512 extern void
513 can_reset_bus_off(void);
514 
515 // ----------------------------------------------------------------------------
522 extern void
524 
525 #if defined (__cplusplus)
526 }
527 #endif
528 
529 #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: can.h:269
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: can.h:86
can_t::length
uint8_t length
Anzahl der Datenbytes.
Definition: can.h:192
uavcan::uint32_t
std::uint32_t uint32_t
Definition: std.hpp:26
can_mode_t
can_mode_t
Modus des CAN Interfaces.
Definition: can.h:267
can_filter_t::mask
uint32_t mask
Maske.
Definition: can.h:237
can_t::rtr
int rtr
Remote-Transmit-Request-Frame?
Definition: can.h:182
SLEEP_MODE
@ SLEEP_MODE
Definition: can.h:271
can_t
Datenstruktur zum Aufnehmen von CAN Nachrichten.
Definition: can.h:177
can_filter_t::extended
uint8_t extended
extended ID
Definition: can.h:240
can_bitrate_t
can_bitrate_t
Bitraten fuer den CAN-Bus.
Definition: can.h:83
can_filter_t::id
uint32_t id
ID der Nachricht (11 oder 29 Bit)
Definition: can.h:236
can_config.h
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: can.h:90
can_filter_t
Datenstruktur zur Aufnahme von CAN-Filtern.
Definition: can.h:233
NORMAL_MODE
@ NORMAL_MODE
normaler Modus, CAN Controller ist aktiv
Definition: can.h:270
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: can.h:268
can_reset_bus_off
void can_reset_bus_off(void)
BITRATE_100_KBPS
@ BITRATE_100_KBPS
Definition: can.h:87
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: can.h:89
BITRATE_125_KBPS
@ BITRATE_125_KBPS
Definition: can.h:88
can_error_register_t::tx
uint8_t tx
Sende-Register.
Definition: can.h:259
can_t::extended
int extended
extended ID?
Definition: can.h:183
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: can.h:91
can_get_filter
uint8_t can_get_filter(uint8_t number, can_filter_t *filter)
can_filter_t::rtr
uint8_t rtr
Remote Request Frame.
Definition: can.h:239
BITRATE_10_KBPS
@ BITRATE_10_KBPS
Definition: can.h:84
can_wakeup
void can_wakeup(void)
can_init
bool can_init(can_bitrate_t bitrate)
Initialisierung des CAN Interfaces.
can_t::id
uint32_t id
ID der Nachricht (11 oder 29 Bit)
Definition: can.h:180
BITRATE_20_KBPS
@ BITRATE_20_KBPS
Definition: can.h:85
can_error_register_t::rx
uint8_t rx
Empfangs-Register.
Definition: can.h:258
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