![]() |
Midnight Sun Firmware
|
telemetry Firmware More...
Classes | |
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 | 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 | 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 | |
void | decode_can_message (Datagram *datagram, CanMessage *msg) |
Decode CAN message and update a datagram. 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 *storage, TelemetryConfig *config) |
Initialize the telemetry interface. More... | |
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
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)
void 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 |
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 * | storage, |
TelemetryConfig * | config | ||
) |
Initialize the telemetry interface.
storage | Pointer to the telemetry storage |
config | Pointer to the telemetry config |