118 lines
5.2 KiB
C
118 lines
5.2 KiB
C
// config.h - Pin definitions and constants for ESP32-S3 CAN FD Logger
|
|
// Hardware: ESP32-S3-WROOM-1-N16R8 (16MB Flash, 8MB OPI PSRAM)
|
|
// Board Settings:
|
|
// - Board: ESP32S3 Dev Module
|
|
// - USB CDC On Boot: Enabled
|
|
// - Partition Scheme: 16M Flash (3MB APP/9.9MB FAT)
|
|
// - PSRAM: OPI PSRAM
|
|
|
|
#ifndef CONFIG_H
|
|
#define CONFIG_H
|
|
|
|
#include <Arduino.h>
|
|
|
|
// =============================================================================
|
|
// HSPI Pins (CAN FD MCP2518FD)
|
|
// =============================================================================
|
|
#define HSPI_MISO_PIN 13
|
|
#define HSPI_MOSI_PIN 11
|
|
#define HSPI_SCLK_PIN 12
|
|
#define HSPI_CS_PIN 10
|
|
#define CAN_INT_PIN 3 // NOTE: GPIO3 conflicts with USB D- if USB used
|
|
|
|
// =============================================================================
|
|
// SDIO 4-bit Pins (SD Card)
|
|
// =============================================================================
|
|
#define SDIO_CLK_PIN 39
|
|
#define SDIO_CMD_PIN 38
|
|
#define SDIO_D0_PIN 40
|
|
#define SDIO_D1_PIN 41
|
|
#define SDIO_D2_PIN 42
|
|
#define SDIO_D3_PIN 21 // WARNING: Strapping pin (boot mode)
|
|
|
|
// =============================================================================
|
|
// I2C Pins (DS3231 RTC)
|
|
// =============================================================================
|
|
#define RTC_SDA_PIN 8
|
|
#define RTC_SCL_PIN 9
|
|
#define DS3231_ADDRESS 0x68
|
|
|
|
// =============================================================================
|
|
// CAN FD Settings
|
|
// =============================================================================
|
|
#define CAN_DEFAULT_ARBITRATION_BAUDRATE 500000 // 500 kbps
|
|
#define CAN_DEFAULT_DATA_BAUDRATE 2000000 // 2 Mbps (CAN FD)
|
|
#define CAN_MAX_DATA_BAUDRATE 8000000 // 8 Mbps (max)
|
|
#define CAN_OSCILLATOR_FREQ 40000000 // 40 MHz crystal
|
|
|
|
// =============================================================================
|
|
// SD Card Settings
|
|
// =============================================================================
|
|
#define SD_MOUNT_POINT "/sdcard"
|
|
#define LOGS_DIR "/logs"
|
|
#define CONFIG_DIR "/config"
|
|
#define FILE_SPLIT_SIZE (100 * 1024 * 1024) // 100 MB
|
|
#define PCAP_MAGIC_NUMBER 0xa1b2c3d4
|
|
#define PCAP_LINK_TYPE 227 // LINKTYPE_CAN_SOCKETCAN
|
|
|
|
// =============================================================================
|
|
// FreeRTOS Task Settings
|
|
// =============================================================================
|
|
#define TASK_PRIORITY_CAN_RX 5
|
|
#define TASK_PRIORITY_SD_WRITE 4
|
|
#define TASK_PRIORITY_CAN_TX 3
|
|
#define TASK_PRIORITY_WS_TX 3
|
|
#define TASK_PRIORITY_WEB_SERVER 2
|
|
#define TASK_PRIORITY_TIME_SYNC 1
|
|
|
|
#define TASK_STACK_CAN_RX 8192
|
|
#define TASK_STACK_SD_WRITE 8192
|
|
#define TASK_STACK_CAN_TX 4096
|
|
#define TASK_STACK_WS_TX 8192
|
|
#define TASK_STACK_WEB_SERVER 16384
|
|
#define TASK_STACK_TIME_SYNC 4096
|
|
|
|
// =============================================================================
|
|
// Queue Sizes (Increased for CAN FD high-speed operation)
|
|
// =============================================================================
|
|
#define QUEUE_SIZE_CAN_RX 5000 // Increased from 1000 for CAN FD burst handling
|
|
#define QUEUE_SIZE_CAN_TX 200 // Increased from 100
|
|
#define QUEUE_SIZE_GRAPH 500
|
|
|
|
// =============================================================================
|
|
// Buffer Settings
|
|
// =============================================================================
|
|
#define PSRAM_BUFFER_SIZE (256 * 1024) // 256 KB for CAN frame buffer (increased)
|
|
#define MAX_CAN_FRAMES 3200 // 256KB / ~80 bytes per frame
|
|
#define SD_WRITE_BUFFER_SIZE (8 * 1024) // 8 KB batch write buffer for SD card
|
|
|
|
// =============================================================================
|
|
// MCP2518FD FIFO Settings (Critical for zero frame loss)
|
|
// =============================================================================
|
|
#define MCP2518FD_RX_FIFO_SIZE 32 // MCP2518FD internal RX FIFO
|
|
#define MCP2518FD_TX_FIFO_SIZE 16 // MCP2518FD internal TX FIFO
|
|
|
|
// =============================================================================
|
|
// Performance Tuning
|
|
// =============================================================================
|
|
#define SD_FLUSH_INTERVAL_MS 1000 // Flush SD every 1 second (not every frame)
|
|
#define CAN_RX_BATCH_SIZE 32 // Process up to 32 frames per interrupt
|
|
#define TIMESTAMP_FROM_RTC true // Use DS3231 for drift correction
|
|
|
|
// =============================================================================
|
|
// Web Server Settings
|
|
// =============================================================================
|
|
#define WEB_SERVER_PORT 80
|
|
#define WIFI_AP_SSID "ESP32-CANLogger"
|
|
#define WIFI_AP_PASSWORD "" // Open AP (no password)
|
|
#define WIFI_AP_CHANNEL 1
|
|
#define WIFI_AP_MAX_CLIENTS 4
|
|
|
|
// =============================================================================
|
|
// Time Settings
|
|
// =============================================================================
|
|
#define NTP_SYNC_INTERVAL_MS (24 * 60 * 60 * 1000) // 24 hours
|
|
#define TIMEZONE_OFFSET_HOURS 9 // KST (Korea Standard Time)
|
|
|
|
#endif // CONFIG_H
|