Files
esp32s3_canlogger_mcp2515/aa.ino
2025-12-03 04:07:50 +00:00

58 lines
1.8 KiB
C++

// PSRAM에 Queue 버퍼 할당
uint8_t *canQueueStorage = nullptr;
uint8_t *serialQueueStorage = nullptr;
StaticQueue_t canQueueBuffer;
StaticQueue_t serialQueueBuffer;
bool allocateQueueBuffers() {
// CAN Queue 버퍼 (PSRAM)
size_t canQueueSize = CAN_QUEUE_SIZE * sizeof(CANMessage);
canQueueStorage = (uint8_t*)heap_caps_malloc(canQueueSize,
MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
if (canQueueStorage == nullptr) {
Serial.println("✗ CAN Queue 버퍼 할당 실패!");
return false;
}
// Serial Queue 버퍼 (PSRAM)
size_t serialQueueSize = SERIAL_QUEUE_SIZE * sizeof(SerialMessage);
serialQueueStorage = (uint8_t*)heap_caps_malloc(serialQueueSize,
MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
if (serialQueueStorage == nullptr) {
Serial.println("✗ Serial Queue 버퍼 할당 실패!");
heap_caps_free(canQueueStorage);
return false;
}
Serial.printf("✓ CAN Queue 버퍼: %.1f KB (PSRAM)\n", canQueueSize / 1024.0);
Serial.printf("✓ Serial Queue 버퍼: %.1f KB (PSRAM)\n", serialQueueSize / 1024.0);
return true;
}
// Queue 생성 (PSRAM 버퍼 사용)
void createQueues() {
canQueue = xQueueCreateStatic(
CAN_QUEUE_SIZE, // Queue 길이
sizeof(CANMessage), // 아이템 크기
canQueueStorage, // PSRAM 버퍼
&canQueueBuffer // 정적 Queue 구조체
);
serialQueue = xQueueCreateStatic(
SERIAL_QUEUE_SIZE,
sizeof(SerialMessage),
serialQueueStorage,
&serialQueueBuffer
);
if (canQueue == NULL || serialQueue == NULL) {
Serial.println("✗ Queue 생성 실패!");
while (1) delay(1000);
}
Serial.println("✓ Queue 생성 완료 (PSRAM)");
}