- Define g_twai_bus_off in vesc_can.c, declare in vesc_can.h (was referenced in main.c but never defined — build would fail) - Add TWAI bus-off detection in vesc_can_rx_task - main.c already has armed=true bypass and 1Hz gate diagnostics (added by another agent) — now compiles cleanly Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
38 lines
1.4 KiB
C
38 lines
1.4 KiB
C
#pragma once
|
||
/* vesc_can.h — VESC CAN TWAI driver for ESP32-S3 BALANCE (bd-66hx)
|
||
*
|
||
* VESC extended CAN ID: (packet_type << 8) | vesc_node_id
|
||
* Physical layer: TWAI peripheral → SN65HVD230 → 500 kbps shared bus
|
||
*/
|
||
|
||
#include <stdint.h>
|
||
#include <stdbool.h>
|
||
#include "freertos/FreeRTOS.h"
|
||
#include "freertos/queue.h"
|
||
|
||
/* ── VESC packet types ── */
|
||
#define VESC_PKT_SET_RPM 3u
|
||
#define VESC_PKT_STATUS 9u /* int32 erpm, int16 I×10, int16 duty×1000 */
|
||
#define VESC_PKT_STATUS_4 16u /* int16 T_fet×10, T_mot×10, I_in×10 */
|
||
#define VESC_PKT_STATUS_5 27u /* int32 tacho, int16 V_in×10 */
|
||
|
||
/* ── VESC telemetry snapshot ── */
|
||
typedef struct {
|
||
int32_t erpm; /* electrical RPM (STATUS) */
|
||
int16_t current_x10; /* phase current A×10 (STATUS) */
|
||
int16_t voltage_x10; /* bus voltage V×10 (STATUS_5) */
|
||
int16_t temp_mot_x10; /* motor temp °C×10 (STATUS_4) */
|
||
uint32_t last_rx_ms; /* esp_timer ms of last STATUS frame */
|
||
} vesc_state_t;
|
||
|
||
/* ── Globals (two VESC nodes: index 0 = VESC_ID_A=56, 1 = VESC_ID_B=68) ── */
|
||
extern vesc_state_t g_vesc[2];
|
||
extern volatile bool g_twai_bus_off;
|
||
|
||
/* ── API ── */
|
||
void vesc_can_init(void);
|
||
void vesc_can_send_rpm(uint8_t vesc_id, int32_t erpm);
|
||
|
||
/* RX task — pass tx_queue as arg; forwards STATUS frames to Orin over serial */
|
||
void vesc_can_rx_task(void *arg); /* arg = QueueHandle_t orin_tx_queue */
|