<commit_before># MultiDrop Bootloader for AVR

A bootloader for AVR devices on a multidrop bus, like RS485, where all devices can be programmed at once.


## How it works

Somehow the master node will inform the slaves that it is time to be programed.
(most likely by sending a special message on the bus -- this is implementation specific)
The slave nodes will then set the EEPROM value `RUN_APP` to `0` and reset themselves.

Upon reset, the bootloader checks the `RUN_APP` value, and if it is 0, will go
into programming mode.

Master sends a `START` message, to inform the slave nodes that program data is 
about to be sent. Then sends the data, one page at a time. 

Each page will end with a 16 bit CRC to verify the data was received without 
corruption. If the CRC does not match, the slave node will enable the signal
line to inform master of the error.

Master will continue to send all the pages down to the nodes. 

When complete, if the signal line is enabled, it sends the data down again; starting
at the page prior to the signal line becoming enabled.

When all pages have been sent successfully (or max tries has been reached), master
will send a message telling the nodes to run their programs. Now the bootloaders
will set the EEPROM value `RUN_APP` to `1` and reset themselves.

### The Signal Line 

Since we can assume there will be multiple devices listening on the same
communication lines, we cannot have effective 2-way communication between
master and the nodes to be programmed (slave nodes). Instead, the communication
bus needs an additional shared line, called signal, that any slave node can
enable (enable low) to inform the master device of errors.

![Bus Layout](./diagrams/bus.png)

## Commands

Each message follows this format:

|  0     |  1     |  2       |  3              |  4         |  5...n   | n + 1   | n + 2  | 
|--------|--------|----------|-----------------|------------|----------|---------|--------|
| `0xFF` | `0xFF` | `<type>` | `<memory addr>` | `<length>` | `<data>` | `<crc>` | `<crc>`|

The CRC value is calculated with every byte after the second starting `0xFF`.

`0xFF 0xFF 0xF1 0 0 0 0xFF 0xFF`

`0xFF 0xFF 0xF2 <mem addr> <len> <data> <crc>`

`0xFF 0xFF 0xF3 0 0 0`

### Start commands

Informs the bootloader that the first page of data is about to be sent.<commit_msg>Remove dummy data<commit_after># MultiDrop Bootloader for AVR

A bootloader for AVR devices on a multidrop bus, like RS485, where all devices can be programmed at once.


## How it works

Somehow the master node will inform the slaves that it is time to be programed.
(most likely by sending a special message on the bus -- this is implementation specific)
The slave nodes will then set the EEPROM value `RUN_APP` to `0` and reset themselves.

Upon reset, the bootloader checks the `RUN_APP` value, and if it is 0, will go
into programming mode.

Master sends a `START` message, to inform the slave nodes that program data is 
about to be sent. Then sends the data, one page at a time. 

Each page will end with a 16 bit CRC to verify the data was received without 
corruption. If the CRC does not match, the slave node will enable the signal
line to inform master of the error.

Master will continue to send all the pages down to the nodes. 

When complete, if the signal line is enabled, it sends the data down again; starting
at the page prior to the signal line becoming enabled.

When all pages have been sent successfully (or max tries has been reached), master
will send a message telling the nodes to run their programs. Now the bootloaders
will set the EEPROM value `RUN_APP` to `1` and reset themselves.

### The Signal Line 

Since we can assume there will be multiple devices listening on the same
communication lines, we cannot have effective 2-way communication between
master and the nodes to be programmed (slave nodes). Instead, the communication
bus needs an additional shared line, called signal, that any slave node can
enable (enable low) to inform the master device of errors.

![Bus Layout](./diagrams/bus.png)

## Commands

Each message follows this format:

|  0     |  1     |  2       |  3              |  4         |  5...n   | n + 1   | n + 2  | 
|--------|--------|----------|-----------------|------------|----------|---------|--------|
| `0xFF` | `0xFF` | `<type>` | `<memory addr>` | `<length>` | `<data>` | `<crc>` | `<crc>`|

The CRC value is calculated with every byte after the second starting `0xFF`.

### Start commands

Informs the bootloader that the first page of data is about to be sent.
{'fraction_non_alphanumeric': 0.10078878177037687, 'fraction_numerical': 0.013146362839614373, 'mean_word_length': 3.061387900355872, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2415784', 'n_tokens_mistral': 1293, 'n_tokens_neox': 1209, 'n_words': 715}