You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This document describes the CAN for libhal 5.0.0 which is not available yet.
5
5
6
-
Welcome to the libhal controller area network (CAN) tutorial. CAN BUS is used as a reliable broadcast communication
7
-
8
-
are used to sample analog voltage
9
-
signals and convert them into a number that can be used by controllers to sense
10
-
the world .
6
+
Welcome to the libhal controller area network (CAN) tutorial. CAN BUS is used
7
+
as a reliable broadcast communication.
11
8
12
9
## Learning about CAN BUS
13
10
14
11
To learn more about CAN BUS we recommend these online resources:
15
12
16
13
-[🎥 CAN Bus: Serial Communication - How It Works?](https://www.youtube.com/watch?v=JZSCzRT9TTo)
17
-
11m 24s video going over the basics of CAN BUS. It does not go over message ID arbitration which is quite important to understand with CAN BUS, but not necessary to use CAN APIs.
14
+
11m 24s video going over the basics of CAN BUS. It does not go over message
15
+
ID arbitration which is quite important to understand with CAN BUS, but not necessary to use CAN APIs.
18
16
-[📄 Introduction to the Controller Area Network (CAN) by Texas Instruments](https://www.ti.com/lit/an/sloa101b/sloa101b.pdf):
19
17
A fully featured document going over most of the important aspects of CAN
20
18
bus. You'll learn everything you need to know about CAN with this document.
@@ -47,45 +45,21 @@ various capabilities of hardware. For example, the number of filters of each
47
45
type can vary wildly between different devices, but the predominately fit in
48
46
these three categories.
49
47
50
-
### Using `hal::can_transceiver`
51
-
52
-
For now, lets set aside how we acquire a `hal::can_transceiver` and consider
53
-
what you can do once you have one.
54
-
55
-
```C++
56
-
u32baud_rate() = 0;
57
-
```
58
-
59
-
This function returns the baud rate in hertz of the CAN BUS. The baud rate represents the communication rate. Common baud rates for CAN BUS are:
48
+
### The `hal::can_message`
60
49
61
-
- 100 kHz or Kbit/s
62
-
- 125 kHz or Kbit/s
63
-
- 250 kHz or Kbit/s
64
-
- 500 kHz or Kbit/s
65
-
- 800 kHz or Kbit/s
66
-
- 1 MHz or Mbit/s
67
-
68
-
This function exists to ensure that drivers that share a `hal::can_transceiver`
69
-
can detect if the baud rate doesn't match a fixed baud rate required by another
70
-
device on the bus. CAN BUS driver may provide an out-of-interface function for
71
-
setting the baud rate, but this interface does not allow such control.
50
+
The `hal::can_message` struct contains all of the information stored within a
51
+
typical message. The object `hal::can_message` represents a standard CAN
52
+
message in libhal. It provides all of the information you'd need in a typical
53
+
CAN message. It is used for sending and receiving messages on the can bus. Note
54
+
that the remote request and extended fields utilize bits 29th and 30th,
55
+
respectively, within the of the 32-bit `id_flags` field. The 31st bit is
56
+
reserved for now and must remain 0.
72
57
73
-
When a can driver is constructed it is passed a baud rate it should set itself
74
-
to. If the baud rate cannot be achieved the constructor will throw
75
-
`hal::argument_out_of_domain`. Note when setting up a CAN BUS network that
76
-
every device on the bus must have the same baud rate. The baud rate is not
`hal::can_transceiver` are mandated to hold a buffer can messages received over the bus. The user is allowed, at object construction to provide buffer memory for the driver. That buffer is then exposed by the `receive_buffer()` API to allow applications and drivers to scan it and to find messages meant for them. The buffer returned from `receive_buffer()` updated as a circular buffer where the `receive_cursor()` API indicates where the driver's write cursor position is located. Any value returned from `receive_cursor()` will always work like so:
175
+
`hal::can_transceiver` are mandated to hold a buffer can messages received over
176
+
the bus. The user is allowed, at object construction to provide buffer memory
177
+
for the driver. That buffer is then exposed by the `receive_buffer()` API to
178
+
allow applications and drivers to scan it and to find messages meant for them.
179
+
The buffer returned from `receive_buffer()` updated as a circular buffer where
180
+
the `receive_cursor()` API indicates where the driver's write cursor position
181
+
is located. Any value returned from `receive_cursor()` will always work like so:
178
182
179
183
```C++
180
184
// `can.receive_cursor()` always returns a value between 0 and
0 commit comments