Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3034e1f
immediate drop
irvingywang Mar 21, 2026
7faf3b8
inline the common irq handler
irvingywang Mar 21, 2026
5bebca4
route IT1 to tx handler
irvingywang Mar 21, 2026
51e4274
draft tx interrupt config
irvingywang Mar 21, 2026
4f97f64
common TX/RX task init
irvingywang Mar 21, 2026
05b5893
poke from enqueue
irvingywang Mar 21, 2026
222c29e
draft new G4 tx task
irvingywang Mar 21, 2026
44d1962
extra picture
irvingywang Mar 24, 2026
c84edcc
move irq init into common
irvingywang Mar 24, 2026
cfa8d6d
move nvic setup into can_common
irvingywang Mar 24, 2026
aac49b8
draft f4
irvingywang Mar 25, 2026
8ea77c4
take daq off of canpiler
irvingywang Mar 25, 2026
71d00e1
enable tx interrupt in hal
irvingywang Mar 25, 2026
73876ad
cleanup
irvingywang Mar 25, 2026
5735a2d
further cleanup
irvingywang Mar 25, 2026
b143749
typos
irvingywang Mar 25, 2026
ef8ccfd
guard irq prio
irvingywang Mar 25, 2026
ac55338
rename queues
irvingywang Mar 25, 2026
6a56661
mark volatile
irvingywang Mar 25, 2026
a178ad1
reduce queue length now that jitter is nuked
irvingywang Mar 25, 2026
2197adf
doc
irvingywang Mar 25, 2026
df0d925
update doc
irvingywang Mar 25, 2026
ded6c5e
margin
irvingywang Mar 25, 2026
1a494f7
alignment
irvingywang Mar 25, 2026
3e908d3
typo
irvingywang Mar 25, 2026
9dcc502
show message source
irvingywang Mar 25, 2026
9678970
better wording
irvingywang Mar 25, 2026
bebaa78
less aesthetic, more accurate
irvingywang Mar 25, 2026
954d6a0
oops
irvingywang Mar 25, 2026
7423faf
add rx diagram
irvingywang Mar 25, 2026
42a1ad9
doc
irvingywang Mar 26, 2026
c6ddf3d
fix pop/check order
irvingywang Mar 26, 2026
8e0a7cf
reference the handle properly
irvingywang Mar 28, 2026
3945eab
cleanup
irvingywang Mar 30, 2026
6d9570d
convert daq to external
irvingywang Apr 1, 2026
4284f90
discard volatile qualifier
irvingywang Apr 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The codebase represents a real-time distributed system for an FSAE electric vehi
## Code Standards
- Codestyle is defined in `docs/code_style.md`
- Dynamic memory allocation is FORBIDDEN
- In-repo documentation should be updated in the same PR as code changes.

## Real-Time Constraints
- Code must be deterministic
Expand Down
22 changes: 17 additions & 5 deletions common/can_library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,27 @@ Standardized framework for CAN communication and system-wide fault management wi
- `faults_common.h / .c`: System-wide fault management.
- `can_library.cmake`: CMake integration and node library generation.

## Logic
The high-level logic flow of an RX is shown here:
![CAN RX Logic](can_rx_logic.drawio.png)
> [!NOTE]
> The all RX IRQs push to the same queue rather than having separate queues per peripheral.

The high-level logic flow of a TX is shown here:
![CAN TX Logic](can_tx_logic.drawio.png)
> [!NOTE]
> The actual implementation of the CAN TX task manages up to 3 seperate hardware peripherals at once, each with its own software queue.

## Usage
1. Define your CAN network and global faults in `common/can_library/configs/` using the provided JSON schemas.
1. Use FDCAN peripherals on G4 and CAN peripherals on F4/F7.
2. Add to `COMMON_LIBRARIES` of your target: `can_node_<node_name>`.
3. Define your RX interrupt handlers to call `CAN_handle_irq(CAN_TypeDef *bus, uint8_t fifo)`
3. Include the generated header for your node (e.g. `#include "common/can_library/generated/can_node_<node_name>.h"`) in your `main.c`.
3. Initialize the CAN library in your `main.c` with `CAN_init()`.
4. Setup CAN tasks in your `main.c` using `DEFINE_CAN_TASKS()` and `START_CAN_TASKS()`.

> [!NOTE]
> Weird quirk: we run the CANpiler twice.
> Once during CMake configuration time and one during build time.
> This avoids any possibility of building with stale generated files.
The most recent rx'd data is available in the `can_data` struct, which is updated by the CAN RX task.
Sending CAN messages is done via the generated `CAN_SEND_<message_name>()` functions, which enqueue messages to be sent by the CAN TX task.

## Fault System
The `faults_common` module implements the **FIDR (Fault Isolation, Detection, and Recovery)** system. It manages the lifecycle of system-wide faults using a robust Finite State Machine (FSM) to prevent flickering and ensure deterministic fault handling.
Expand All @@ -32,6 +43,7 @@ The `faults_common` module implements the **FIDR (Fault Isolation, Detection, an
- `update_fault(fault_index, value)`: Called by the owner node to feed sensor/status data into the FSM.
- `fault_library_periodic()`: Tally active faults and broadcast a `tx_fault_sync` message.
- `is_latched(fault_index)`: Check if a specific fault is active.
- `is_clear(fault_index)`: Check if a specific fault is clear.

> [!NOTE]
> Each node is assigned a specific range of faults (`MY_FAULT_START` to `MY_FAULT_END`).
Expand Down
Loading
Loading