1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*!
UartCAT is a realtime memory bus protocol implemented on a UART daisy chain. Its concept are inspired from EtherCAT but with most of its complexity removed. UartCAT is a caterpillar propagating protocol using UART just like Ethercat is a caterpillar propagating protocol using Ethernet.
The main advantages of this protocol are
- fully open-source
- light weight
- no need for specific hardware for the protocol, any microcontroller has at least one UART
## differences with EtherCAT
- no more communication state machine (INIT, PREOP, SAFE-OP, OP) all features are working all the time
- no more mailbox nor canopen, just registers including user made ones
- no more EEPROM interface for slave informations, its registers too
- exchanges of data mapped to virtual (aka logical) memory are always bidirectional (no more sync manager directions)
- no distributed clock (for now, can be added in the future)
also differences due to UART instead of Ethernet:
- hotplug of devices need to be manually done, this is unspecified by UART
- no detection of whether the bus is connected or not to other devices
- much lower bandwidth
- no automatic negociation of bus frequency
### example
on your master (can be your PC):
```rust
const CUSTOM_REGISTER: SlaveRegister<u32> = Register::new(0x500);
let master = Master::new("/dev/ttyUSB1", 1_500_000).unwrap();
let custom = master.read(CUSTOM_REGISTER).await?.any()?;
master.write(CUSTOM_REGISTER, custom+1).await?.any()?;
assert_eq!(custom, 42);
```
on your slave (any microcontroller)
```rust
const CUSTOM_REGISTER: SlaveRegister<u32> = Register::new(0x500);
const BUFFER: usize = 0x504; // size of slave buffer accessible by master
let slave = Slave::<_, BUFFER>::new(
I2c(UART1, 1_500_000, GPIO1, GPIO2),
Device {...},
);
slave.lock().await.set(CUSTOM_REGISTER, 42);
slave.run().await;
```
for a complete example see [`master/examples/basic.rs`](https://github.com/jimy-byerley/uartcat/blob/master/master/examples/basic.rs) and matching [`slave/examples/basic.rs`](https://github.com/jimy-byerley/uartcat/blob/master/slave/examples/basic.rs)
*/
extern crate std;