speeduino/speeduino/comms_sd.h

37 lines
1.2 KiB
C
Raw Permalink Normal View History

Refactor comms: save 130+ bytes RAM (#906) * Remove serialCRC - only used within parseSerial() Also hoist the CRC read into a function. * Minimize global variable visibility * Encapsulate write of multi-byte primitives * Factor out sendBufferAndCrc() * Push safety test into TS_CommandButtonsHandler() * Extract writePage() * Simpler parsing * Remove some functions from public interface * Store constant arrays in progmem * Centralize high speed logger start/stop code * Factor out loadO2Calibration() * Factor out temperature calibration table update functions * Remove dead code * Fix sendToothLog() * Fix sendCompositeLog() * Replace tooth log send booleans with an enum Saves a byte * Remove sendBufferAndCrcProgMem() Use serialPayload to send * Whitespace clean up * Optimize comms.cpp for size * Replace global unsigned long with bool Saves 2 bytes * Replace 2 global bools with an enum Saves a byte, reads better. * Remove global FastCRC instance * Make sendSerialReturnCode blocking. It was using non-blocking functions but was never re-entered. Rename to make blocking & non-blocking calls more obvious. * Use one uint16_t to track RX/TX byte count * Simplify new comms log tx API * Extract loadPageToBuffer function * All endianess changes use the same code * Doxygen comments and code organization * Remove serialWriteUpdateCrc() & updateTmpCalibration() * Combine SerialStatus & logSendStatus enums. Makes sense since we can only be doing one thing at a time. * Remove global inProgressCompositeTime Only used when sending composite log * Replace 3 global bools with expanded SerialStatus enum * Remove unused global tsCanId * Limit scope of some comms globals. * Remove isMap global - replace witth function * Reduce the serial API to only 2 calls transmit & receive * Tidy up #define visibility * Fix Black* build errors * Workaround Teensy code race condition availableForWrite() is not reliable. * Prevent race condition Was pematurely setting the serialStatusFlag to SERIAL_INACTIVE before final CRC ws read from serial. * Use post write buffer availability checks Remove buffer size check prior to writing. * Write multi-byte values as single bytes. (attempt to fix Teensy 3.5 issue) * Only use Serial.available() as a boolean test (Teensy fix) * writeNonBlocking checks Serial.write() return value * Non-blocking CRC write In sendBufferAndCrcNonBlocking(). * Fix compile warning * Set serial status flag prior to transmitting! * Reliable blocking byte writes. * Fix timeout code: not firing under some conditions * MISRA fixes
2023-02-20 17:55:54 -08:00
#pragma once
//Hardcoded TunerStudio addresses/commands for various SD/RTC commands
#define SD_READWRITE_PAGE 0x11
#define SD_READFILE_PAGE 0x14
#define SD_RTC_PAGE 0x07
#define SD_READ_STAT_ARG1 0x0000
#define SD_READ_STAT_ARG2 0x0010
#define SD_READ_DIR_ARG1 0x0000
#define SD_READ_DIR_ARG2 0x0202
#define SD_READ_SEC_ARG1 0x0002
#define SD_READ_SEC_ARG2 0x0004
#define SD_READ_STRM_ARG1 0x0004
#define SD_READ_STRM_ARG2 0x0001
#define SD_READ_COMP_ARG1 0x0000 //Not used for anything
#define SD_READ_COMP_ARG2 0x0800
#define SD_RTC_READ_ARG1 0x024D
#define SD_RTC_READ_ARG2 0x0008
#define SD_WRITE_DO_ARG1 0x0000
#define SD_WRITE_DO_ARG2 0x0001
#define SD_WRITE_DIR_ARG1 0x0001
#define SD_WRITE_DIR_ARG2 0x0002
#define SD_WRITE_READ_SEC_ARG1 0x0002
#define SD_WRITE_READ_SEC_ARG2 0x0004
#define SD_WRITE_WRITE_SEC_ARG1 0x0003
#define SD_WRITE_WRITE_SEC_ARG2 0x0204
Refactor comms: save 130+ bytes RAM (#906) * Remove serialCRC - only used within parseSerial() Also hoist the CRC read into a function. * Minimize global variable visibility * Encapsulate write of multi-byte primitives * Factor out sendBufferAndCrc() * Push safety test into TS_CommandButtonsHandler() * Extract writePage() * Simpler parsing * Remove some functions from public interface * Store constant arrays in progmem * Centralize high speed logger start/stop code * Factor out loadO2Calibration() * Factor out temperature calibration table update functions * Remove dead code * Fix sendToothLog() * Fix sendCompositeLog() * Replace tooth log send booleans with an enum Saves a byte * Remove sendBufferAndCrcProgMem() Use serialPayload to send * Whitespace clean up * Optimize comms.cpp for size * Replace global unsigned long with bool Saves 2 bytes * Replace 2 global bools with an enum Saves a byte, reads better. * Remove global FastCRC instance * Make sendSerialReturnCode blocking. It was using non-blocking functions but was never re-entered. Rename to make blocking & non-blocking calls more obvious. * Use one uint16_t to track RX/TX byte count * Simplify new comms log tx API * Extract loadPageToBuffer function * All endianess changes use the same code * Doxygen comments and code organization * Remove serialWriteUpdateCrc() & updateTmpCalibration() * Combine SerialStatus & logSendStatus enums. Makes sense since we can only be doing one thing at a time. * Remove global inProgressCompositeTime Only used when sending composite log * Replace 3 global bools with expanded SerialStatus enum * Remove unused global tsCanId * Limit scope of some comms globals. * Remove isMap global - replace witth function * Reduce the serial API to only 2 calls transmit & receive * Tidy up #define visibility * Fix Black* build errors * Workaround Teensy code race condition availableForWrite() is not reliable. * Prevent race condition Was pematurely setting the serialStatusFlag to SERIAL_INACTIVE before final CRC ws read from serial. * Use post write buffer availability checks Remove buffer size check prior to writing. * Write multi-byte values as single bytes. (attempt to fix Teensy 3.5 issue) * Only use Serial.available() as a boolean test (Teensy fix) * writeNonBlocking checks Serial.write() return value * Non-blocking CRC write In sendBufferAndCrcNonBlocking(). * Fix compile warning * Set serial status flag prior to transmitting! * Reliable blocking byte writes. * Fix timeout code: not firing under some conditions * MISRA fixes
2023-02-20 17:55:54 -08:00
#define SD_WRITE_COMP_ARG1 0x0005
#define SD_WRITE_COMP_ARG2 0x0008
#define SD_ERASEFILE_ARG1 0x0006
#define SD_ERASEFILE_ARG2 0x0006
#define SD_SPD_TEST_ARG1 0x0007
#define SD_SPD_TEST_ARG2 0x0004
#define SD_RTC_WRITE_ARG1 0x027E
#define SD_RTC_WRITE_ARG2 0x0009