![]() |
Midnight Sun Firmware
|
telemetry Firmware More...
Classes | |
| struct | CanMessageCache |
| Per-message cache entry. More... | |
| struct | Datagram |
| Datagram storage class. More... | |
| struct | SdSpiSettings |
| Configuration settings for initializing an SD SPI port. More... | |
| struct | TelemetryConfig |
| Telemetry configuration data. More... | |
| struct | TelemetryStorage |
| Telemetry storage. More... | |
Macros | |
| #define | TELEMETRY_STATS_CAN_ID 2020U |
| Synthetic XBee-only ID for the telemetry bus-load stats datagram. | |
| #define | TELEMETRY_STATS_DLC 6U |
| DLC of the telemetry stats datagram (3 × uint16_t). | |
| #define | WS22_TELEMETRY_STATUS_ID 2039U |
| Synthetic XBee-only IDs for WS22 re-encoded telemetry (floats → scaled integers). 2039–2043 sit above the highest system CAN ID (AFE_temperature, 2035). More... | |
| #define | WS22_TELEMETRY_BUS_ID 2040U |
| #define | WS22_TELEMETRY_VELOCITY_ID 2041U |
| #define | WS22_TELEMETRY_TEMP_ID 2042U |
| #define | WS22_TELEMETRY_DRIVE_CMD_ID 2043U |
| #define | WS22_TELEMETRY_DLC 4U |
| #define | DATAGRAM_BUFFER_SIZE 64U |
| Datagram buffer size. | |
| #define | DATAGRAM_START_FRAME 0xAAU |
| Start of frame indicator. | |
| #define | DATAGRAM_END_FRAME 0xBBU |
| End of frame indicator. | |
| #define | DATAGRAM_METADATA_SIZE 5U |
| Datagram metadata size. More... | |
Enumerations | |
| enum | CanMsgPriority { CAN_MSG_PRIORITY_HIGH = 0 , CAN_MSG_PRIORITY_MEDIUM , CAN_MSG_PRIORITY_LOW , NUM_CAN_MSG_PRIORITIES } |
| Transmission priority tier for a cached CAN message. More... | |
| enum | SdSpiBaudrate { SD_SPI_BAUDRATE_312_5KHZ = 0 , SD_SPI_BAUDRATE_625KHZ , SD_SPI_BAUDRATE_1_25MHZ , SD_SPI_BAUDRATE_2_5MHZ , SD_SPI_BAUDRATE_5MHZ , SD_SPI_BAUDRATE_10MHZ , SD_SPI_BAUDRATE_20MHZ , SD_SPI_BAUDRATE_40MHZ , NUM_SD_SPI_BAUDRATES } |
| SD Card SPI baudrate options. More... | |
| enum | SdSpiMode { SD_SPI_MODE_0 = 0 , SD_SPI_MODE_1 , SD_SPI_MODE_2 , SD_SPI_MODE_3 , NUM_SD_SPI_MODES } |
| SPI modes (CPOL and CPHA settings) More... | |
| enum | SdSpiPort { SD_SPI_PORT_1 = 0 , SD_SPI_PORT_2 , SD_SPI_PORT_3 , NUM_SD_SPI_PORTS } |
| SD SPI port options. | |
Functions | |
| StatusCode | decode_can_message (Datagram *datagram, CanMessage *msg) |
| Decode CAN message and update a datagram. More... | |
| StatusCode | encode_datagram (Datagram *datagram, uint32_t id, uint8_t dlc, const uint8_t *data) |
| Encode id/dlc/data directly into a datagram (no CanMessage wrapper). More... | |
| void | log_decoded_message (Datagram *datagram) |
| Log the decoded datagram for debug purposes. More... | |
| StatusCode | sd_card_link_driver (SdSpiPort spi, SdSpiSettings *settings) |
| Link the SD card driver with the FATFs API and initialize it. More... | |
| StatusCode | sd_spi_init (SdSpiPort spi, const SdSpiSettings *settings) |
| Initialize SD SPI port with given settings. More... | |
| StatusCode | sd_spi_tx (SdSpiPort spi, uint8_t *tx_data, size_t tx_len) |
| Transmit data to SD card via SPI. More... | |
| StatusCode | sd_spi_rx (SdSpiPort spi, uint8_t *rx_data, size_t rx_len, uint8_t placeholder) |
| Receive data from SD card via SPI. More... | |
| StatusCode | sd_spi_exchange (SdSpiPort spi, uint8_t *tx_data, size_t tx_len, uint8_t *rx_data, size_t rx_len) |
| Exchange data over SPI. More... | |
| StatusCode | sd_spi_cs_set_state (SdSpiPort spi, GpioState state) |
| Set the CS (chip select) GPIO state. More... | |
| GpioState | sd_spi_cs_get_state (SdSpiPort spi) |
| Get the current state of the CS (chip select) pin. More... | |
| StatusCode | sd_spi_set_frequency (SdSpiPort spi, SdSpiBaudrate baudrate) |
| Change the baudrate of an initialized SPI port. More... | |
| StatusCode | telemetry_init (TelemetryStorage *telemetry_storage, TelemetryConfig *config, Bmi323Storage *bmi323_storage, CanStorage *can_storage) |
| Initialize the telemetry interface. More... | |
| StatusCode | xb_transmit_init (TelemetryStorage *storage, TelemetryConfig *config) |
| Initializes the xb_transmit component. More... | |
Variables | |
| CanMessageCache | g_can_cache_high [] |
| High-priority (fast-cycle) message cache. More... | |
| const size_t | g_can_cache_high_size |
| CanMessageCache | g_can_cache_medium [] |
| Medium-priority (medium-cycle) message cache. More... | |
| const size_t | g_can_cache_medium_size |
| CanMessageCache | g_can_cache_low [] |
| Low-priority (slow-cycle) message cache. More... | |
| const size_t | g_can_cache_low_size |
telemetry Firmware
| #define DATAGRAM_METADATA_SIZE 5U |
Datagram metadata size.
1 byte for start frame 2 bytes for ID 1 byte for DLC 1 byte for end frame
| #define WS22_TELEMETRY_BUS_ID 2040U |
bus_voltage_cV (u16) + bus_current_cA (i16)
| #define WS22_TELEMETRY_DLC 4U |
DLC for all WS22 synthetic entries (2 × uint16_t)
| #define WS22_TELEMETRY_DRIVE_CMD_ID 2043U |
drive_current×10000 (u16) + drive_velocity_rpm (i16)
| #define WS22_TELEMETRY_STATUS_ID 2039U |
Synthetic XBee-only IDs for WS22 re-encoded telemetry (floats → scaled integers). 2039–2043 sit above the highest system CAN ID (AFE_temperature, 2035).
error_flags (u16) + limit_flags (u16)
| #define WS22_TELEMETRY_TEMP_ID 2042U |
motor_temp_°C×10 (i16) + heatsink_temp_°C×10 (i16)
| #define WS22_TELEMETRY_VELOCITY_ID 2041U |
motor_velocity_rpm×10 (i16) + vehicle_kph×100 (u16)
| enum CanMsgPriority |
Transmission priority tier for a cached CAN message.
Derived from the message's cycle rate in the board YAML: fast-cycle → HIGH, medium-cycle → MEDIUM, slow-cycle → LOW
| enum SdSpiBaudrate |
SD Card SPI baudrate options.
These prescaler values map to SPI peripheral baudrate divisors. The actual baudrate is calculated as APB_Frequency / Prescaler. On STM32, prescalers must be powers of 2.
| enum SdSpiMode |
SPI modes (CPOL and CPHA settings)
| StatusCode decode_can_message | ( | Datagram * | datagram, |
| CanMessage * | msg | ||
| ) |
Decode CAN message and update a datagram.
| datagram | Pointer to the datagram to be updated |
| msg | Pointer to the new CAN data |
| StatusCode encode_datagram | ( | Datagram * | datagram, |
| uint32_t | id, | ||
| uint8_t | dlc, | ||
| const uint8_t * | data | ||
| ) |
Encode id/dlc/data directly into a datagram (no CanMessage wrapper).
| datagram | Pointer to the datagram to populate |
| id | Raw CAN ID |
| dlc | Payload length in bytes |
| data | Pointer to payload |
| void log_decoded_message | ( | Datagram * | datagram | ) |
Log the decoded datagram for debug purposes.
| datagram | Pointer to the datagram to be debugged |
| StatusCode sd_card_link_driver | ( | SdSpiPort | spi, |
| SdSpiSettings * | settings | ||
| ) |
Link the SD card driver with the FATFs API and initialize it.
| spi | which SPI port to use for the SD card |
| settings | pointer to your pre-configured SdSpiSettings |
Get the current state of the CS (chip select) pin.
| spi | SPI port |
| StatusCode sd_spi_cs_set_state | ( | SdSpiPort | spi, |
| GpioState | state | ||
| ) |
Set the CS (chip select) GPIO state.
| spi | SPI port |
| state | Desired CS state (GPIO_STATE_LOW to select) |
| StatusCode sd_spi_exchange | ( | SdSpiPort | spi, |
| uint8_t * | tx_data, | ||
| size_t | tx_len, | ||
| uint8_t * | rx_data, | ||
| size_t | rx_len | ||
| ) |
Exchange data over SPI.
Simultaneously transmit and receive data. Lengths may differ. Transmits 0xFF if no TX data
| spi | SPI port to use |
| tx_data | Pointer to data to transmit (can be NULL) |
| tx_len | Number of bytes to transmit |
| rx_data | Pointer to buffer for received data (can be NULL) |
| rx_len | Number of bytes to receive |
| StatusCode sd_spi_init | ( | SdSpiPort | spi, |
| const SdSpiSettings * | settings | ||
| ) |
Initialize SD SPI port with given settings.
Note that STM32 SPI baudrate prescalers are powers of 2, so the resulting baudrate may not match the requested value exactly. Check resulting timing if critical
| spi | SPI port to initialize |
| settings | Pointer to configuration settings |
| StatusCode sd_spi_rx | ( | SdSpiPort | spi, |
| uint8_t * | rx_data, | ||
| size_t | rx_len, | ||
| uint8_t | placeholder | ||
| ) |
Receive data from SD card via SPI.
Reads |rx_len| bytes into |rx_data|. Sends the specified |placeholder| byte while receiving (commonly 0xFF)
| spi | SPI port to use |
| rx_data | Pointer to buffer to receive data |
| rx_len | Number of bytes to receive |
| placeholder | Byte to transmit during receive |
| StatusCode sd_spi_set_frequency | ( | SdSpiPort | spi, |
| SdSpiBaudrate | baudrate | ||
| ) |
Change the baudrate of an initialized SPI port.
Reconfigures the SPI peripheral to operate at a different baudrate
| spi | SPI port |
| baudrate | Desired new baudrate |
| StatusCode sd_spi_tx | ( | SdSpiPort | spi, |
| uint8_t * | tx_data, | ||
| size_t | tx_len | ||
| ) |
Transmit data to SD card via SPI.
Sends |tx_len| bytes from |tx_data| over SPI without changing the CS line. Received bytes are discarded
| spi | SPI port to use |
| tx_data | Pointer to data to transmit |
| tx_len | Number of bytes to transmit |
| StatusCode telemetry_init | ( | TelemetryStorage * | telemetry_storage, |
| TelemetryConfig * | config, | ||
| Bmi323Storage * | bmi323_storage, | ||
| CanStorage * | can_storage | ||
| ) |
Initialize the telemetry interface.
| telemetry_storage | Pointer to the telemetry storage struct |
| config | Pointer to the telemetry config |
| bmi323_storage | pointer to bmi323_storage struct |
| can_storage | pointer to can_storage struct |
| StatusCode xb_transmit_init | ( | TelemetryStorage * | storage, |
| TelemetryConfig * | config | ||
| ) |
Initializes the xb_transmit component.
|
extern |
High-priority (fast-cycle) message cache.
Currently empty — no fast-cycle messages target telemetry.
|
extern |
Low-priority (slow-cycle) message cache.
Contains 3 front_controller power group entries plus the telemetry-internal stats datagram and 5 WS22 synthetic entries.
|
extern |
Medium-priority (medium-cycle) message cache.
Contains 23 entries from rear_controller, steering, front_controller, and IMU.