Skip to content

Commit 36ecb92

Browse files
committed
Organize firmware by subsystem
1 parent b2b57a6 commit 36ecb92

73 files changed

Lines changed: 774 additions & 639 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.dockerignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ pi/dist/
77
stm32/.deps/
88
stm32/app/build/
99
stm32/tests/test_build_info
10-
stm32/tests/test_can_control
1110
stm32/tests/test_can_protocol
12-
stm32/tests/test_can_queue
11+
stm32/tests/test_can_rx_queue
1312
stm32/tests/test_can_tx_queue
1413
stm32/tests/test_diagnostics
15-
stm32/tests/test_protocol
1614
stm32/tests/test_protocol_vectors
15+
stm32/tests/test_rf_commands
16+
stm32/tests/test_rf_plan
1717
**/__pycache__/
1818
**/.pytest_cache/
1919
*.pyc

AGENTS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,10 @@
1313

1414
- Use only repositories, branches, or implementations named by the user.
1515
- Do not inspect unrelated rewrites as design references unless the user explicitly asks.
16+
17+
## Firmware layout
18+
19+
- Keep production firmware under `stm32/app/src/{can,rf,platform}` with matching headers under `stm32/app/include/`.
20+
- Keep board GPIO and alternate-function assignments in `platform/board.h`.
21+
- Keep bench experiments and captured media under `stm32/bringup/`, not production source directories.
22+
- Name modules by responsibility: CAN transport/codec, RF planning/execution, or platform support.

docs/rf-control.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CAN carries logical values; STM32 builds device serial words.
44

55
## PE44820
66

7-
Each phase value is a `0..255` lookup index. Firmware maps it to a calibrated 2.4 GHz `optimizedPhaseState_e` value from `PhaseStateEnum.h`:
7+
Each phase value is a `0..255` lookup index. Firmware maps it to a calibrated 2.4 GHz `optimizedPhaseState_e` value from `rf/phase_states_2_4ghz.h`:
88

99
```text
1010
bit 8 OPT

stm32/.gitignore

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
app/build/
22
app/generated.*.ld
3-
tests/test_protocol
3+
tests/test_rf_commands
4+
tests/test_rf_plan
45
tests/test_diagnostics
56
tests/test_can_protocol
6-
tests/test_can_queue
7-
tests/test_can_control
8-
tests/test_can_filter
7+
tests/test_can_rx_queue
8+
tests/test_can_tx_queue
99
tests/test_build_info
10+
tests/test_protocol_vectors
1011
__pycache__/
1112
*.pyc
1213
*.o

stm32/README.md

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,47 @@ Both RF buses are transmit-only. ACK means the STM32 completed the transfer, not
4343

4444
## Source map
4545

46+
```mermaid
47+
flowchart LR
48+
main["main.c<br/>startup + service loop"]
49+
50+
subgraph can["can/"]
51+
bus["bus + queues"]
52+
protocol["protocol codec"]
53+
runtime["runtime + replay"]
54+
end
55+
56+
subgraph rf["rf/"]
57+
commands["serial commands"]
58+
plan["safe planner"]
59+
execute["plan executor"]
60+
drivers["PE44820 + F0480 drivers"]
61+
end
62+
63+
subgraph platform["platform/"]
64+
board["board pins"]
65+
support["clock, time, watchdog, faults, diagnostics"]
66+
end
67+
68+
main --> runtime
69+
main --> plan --> execute --> drivers
70+
bus --> runtime --> protocol
71+
runtime --> plan
72+
runtime --> execute
73+
plan --> commands
74+
drivers --> board
75+
main --> support
76+
runtime --> support
77+
```
78+
4679
```text
47-
app/src/main.c startup/main loop
48-
app/src/can_runtime.c execution/responses/replay
49-
app/src/can_protocol.c CAN codec
50-
app/src/can_bus.c bxCAN transport/ISR
51-
app/src/can_control.c safe operation planner
52-
app/src/phaseShifter.c PE44820 driver
53-
app/src/vga.c F0480 driver
54-
app/src/diagnostics.c retained diagnostics
55-
app/src/faults.c fault reset handlers
56-
tests/ native tests
80+
app/src/main.c startup and service loop
81+
app/src/can/ CAN hardware, codec, queues, runtime
82+
app/src/rf/ RF encoding, planning, execution, drivers
83+
app/src/platform/ board map, clock, time, faults, diagnostics
84+
app/include/ matching public headers
85+
bringup/ archived bench code and evidence; not compiled
86+
tests/ native unit and contract tests
5787
```
5888

5989
See [RF encoding](../docs/rf-control.md) and [hardware validation](docs/HARDWARE_VALIDATION.md).

stm32/app/Makefile

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,25 @@ OPENCM3_DEFS := -DSTM32F0
77

88
CFILES := \
99
src/main.c \
10-
src/beamforming_protocol.c \
11-
src/build_info.c \
12-
src/can_bus.c \
13-
src/can_tx_queue.c \
14-
src/can_control.c \
15-
src/can_filter.c \
16-
src/can_protocol.c \
17-
src/can_queue.c \
18-
src/can_runtime.c \
19-
src/clock_control.c \
20-
src/diagnostic_record.c \
21-
src/diagnostics.c \
22-
src/faults.c \
23-
src/phaseShifter.c \
24-
src/spi_guard.c \
25-
src/timebase.c \
26-
src/vga.c \
27-
src/watchdog.c
10+
src/can/bus.c \
11+
src/can/filter.c \
12+
src/can/protocol.c \
13+
src/can/runtime.c \
14+
src/can/rx_queue.c \
15+
src/can/tx_queue.c \
16+
src/rf/commands.c \
17+
src/rf/execute.c \
18+
src/rf/phase_shifter.c \
19+
src/rf/plan.c \
20+
src/rf/vga.c \
21+
src/platform/build_info.c \
22+
src/platform/clock.c \
23+
src/platform/diagnostic_record.c \
24+
src/platform/diagnostics.c \
25+
src/platform/faults.c \
26+
src/platform/spi_guard.c \
27+
src/platform/timebase.c \
28+
src/platform/watchdog.c
2829

2930
INCLUDES += -Iinclude
3031
CSTD := -std=c2x

stm32/app/include/PhaseShifter.h

Lines changed: 0 additions & 25 deletions
This file was deleted.

stm32/app/include/Vga.h

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
#ifndef CAN_BUS_H
22
#define CAN_BUS_H
33

4-
#include "can_protocol.h"
4+
#include "can/protocol.h"
5+
#include "can/tx_queue.h"
56

67
#include <stdbool.h>
78
#include <stdint.h>
89

9-
/* Software TX-queue priority. Lower numeric value = higher priority. */
10-
typedef enum can_tx_priority {
11-
CAN_TX_PRIORITY_ERROR = 0,
12-
CAN_TX_PRIORITY_ACK = 1,
13-
CAN_TX_PRIORITY_REQUESTED_STATUS = 2,
14-
CAN_TX_PRIORITY_TELEMETRY = 3,
15-
CAN_TX_PRIORITY_COUNT = 4
16-
} can_tx_priority_t;
17-
1810
bool can_bus_setup(uint8_t self_node);
1911
bool can_bus_receive(can_frame_t *frame);
2012

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef CAN_PROTOCOL_H
22
#define CAN_PROTOCOL_H
33

4+
#include "rf/limits.h"
5+
46
#include <stdbool.h>
57
#include <stdint.h>
68

@@ -25,20 +27,6 @@
2527
#define CAN_ID_NODE_MASK 0x1fu
2628
#define CAN_ID_SEQUENCE_MASK 0xffffu
2729

28-
/*
29-
* BeamControl has four physical RF channels.
30-
*
31-
* CAN payload arrays use channel indexes 0..3. The PE44820 unit addresses used
32-
* on the receiver board are 1..4, matching the CANDev implementation.
33-
*/
34-
#define CAN_RF_CHANNEL_MIN 0u
35-
#define CAN_RF_CHANNEL_MAX 3u
36-
#define CAN_RF_CHANNEL_COUNT 4u
37-
#define CAN_PHASE_ADDRESS_MIN 1u
38-
#define CAN_PHASE_ADDRESS_MAX 4u
39-
40-
#define CAN_VGA_ATTENUATION_MAX_DB 23u
41-
4230
#define CAN_ENTER_SAFE_LENGTH 1u
4331
#define CAN_SET_PHASE_INDIVIDUAL_LENGTH 2u
4432
#define CAN_SET_PHASE_BULK_LENGTH 4u
@@ -111,8 +99,8 @@ typedef struct can_command {
11199
uint16_t sequence;
112100

113101
/* Fixed order: array index 0..3 maps to RF channel / PE44820 address 1..4. */
114-
uint8_t phase_states[CAN_RF_CHANNEL_COUNT];
115-
uint8_t attenuation_db[CAN_RF_CHANNEL_COUNT];
102+
uint8_t phase_states[RF_CHANNEL_COUNT];
103+
uint8_t attenuation_db[RF_CHANNEL_COUNT];
116104

117105
/* Individual RF commands and ENTER_SAFE use this zero-based channel. */
118106
uint8_t channel;

0 commit comments

Comments
 (0)