![]() |
Midnight Sun Firmware
|
Firmware Over the Air (FOTA) Update system. More...
Classes | |
struct | FotaCanTiming |
Selection for the supported CAN Bitrates. More... | |
struct | FotaCanSettings |
CAN Settings. More... | |
struct | FotaCanMessage |
CAN message structure. More... | |
struct | FotaDatagramHeaderPacketPayload |
Structure representing the datagram header (In the payload) More... | |
struct | FotaDatagram |
Structure representing datagram. More... | |
struct | FotaDatagramPayload_FirmwareMetadata |
struct | FotaDatagramPayload_FirmwareChunk |
struct | FotaDatagramPayload_JumpToApp |
struct | FotaDatagramPayload_Acknowledgement |
struct | FotaDFUContext |
DFU Context for writing firmware to flash. More... | |
struct | FotaPacket |
FOTA Packet structure. More... | |
struct | GpioAddress |
Port and pin data. More... | |
struct | UartSettings |
UART Settings. More... | |
struct | NetworkBuffer |
struct containing details of circular buffer More... | |
struct | PacketManager |
Packet manager context structure. More... | |
Macros | |
#define | CAN_HW_BASE CAN1 |
#define | FOTA_MAX_DATAGRAM_SIZE (16U * FOTA_PACKET_PAYLOAD_SIZE) |
Maximum supported datagram size (2KB) | |
#define | FOTA_MAX_PACKETS_PER_DATAGRAM ((FOTA_MAX_DATAGRAM_SIZE / FOTA_PACKET_PAYLOAD_SIZE) + 1U) |
Maximum number of packets that can make up a datagram (8 data + 1 Header) | |
#define | FOTA_DATAGRAM_HEADER_PAYLOAD_SIZE 10U |
FOTA Datagram header payload size of 10-bytes. | |
#define | FOTA_ERROR_MSG_LENGTH 256U |
Error message length in bytes. | |
#define | FOTA_FIRMWARE_ID_LENGTH 256U |
Firmware ID length in bytes. | |
#define | fota_error_ok_or_return(code) |
Use to forward failures or continue on success. More... | |
#define | NUM_FLASH_PAGES 128U |
256KB of memory / 2KB per page | |
#define | FOTA_PAGE_BYTES ((uint32_t)0x800U) |
2KB per flash page as per datasheet | |
#define | FOTA_PING_BYTES ((uint32_t)0x1000U) |
4KB max per ping | |
#define | FOTA_ADDR_TO_PAGE(addr) (((uintptr_t)(addr) - (uintptr_t)APP_ACTIVE_START_ADDRESS) / FOTA_PAGE_BYTES) |
Convert memory address to page number. More... | |
#define | FOTA_PAGE_TO_ADDR(page) ((uintptr_t)(page) * (uintptr_t)FOTA_PAGE_BYTES + (uintptr_t)APP_ACTIVE_START_ADDRESS) |
Convert page number to memory address. More... | |
#define | LOG_FOTA_DEBUG(fmt, ...) printf("[FOTA DEBUG] %s:%u: " fmt, __FILE__, __LINE__, ##__VA_ARGS__) |
Debug log. | |
#define | LOG_FOTA_WARNING(fmt, ...) printf("[FOTA WARNING] %s:%u: " fmt, __FILE__, __LINE__, ##__VA_ARGS__) |
Warning log. | |
#define | LOG_FOTA_ERROR(fmt, ...) printf("[FOTA ERROR] %s:%u: " fmt, __FILE__, __LINE__, ##__VA_ARGS__) |
Error log. | |
#define | FLASH_START_ADDRESS_LINKERSCRIPT ((uint32_t) & _flash_start) |
Flash start address as defined in the linkerscripts. | |
#define | FLASH_SIZE_LINKERSCRIPT ((size_t) & _flash_size) |
Flash size as defined in the linkerscripts. | |
#define | FLASH_PAGE_SIZE_LINKERSCRIPT ((size_t) & _flash_page_size) |
Flash page size as defined in the linkerscripts. | |
#define | APP_ACTIVE_START_ADDRESS ((uint32_t) & _app_active_start) |
Application Active start address as defined in the linkerscripts. | |
#define | APP_ACTIVE_SIZE ((size_t) & _app_active_size) |
Application Active size as defined in the linkerscripts. | |
#define | APP_STAGING_START_ADDRESS ((uint32_t) & _app_staging_start) |
Application Staging start address as defined in the linkerscripts. | |
#define | APP_STAGING_SIZE ((size_t) & _app_staging_size) |
Application Staging size as defined in the linkerscripts. | |
#define | BOOTLOADER_START_ADDRESS ((uint32_t) & _bootloader_start) |
Bootloader start address as defined in the linkerscripts. | |
#define | BOOTLOADER_SIZE ((size_t) & _bootloader_size) |
Bootloader size as defined in the linkerscripts. | |
#define | BOOTSTRAP_START_ADDRESS ((uint32_t) & _bootstrap_start) |
Bootstrap start address as defined in the linkerscripts. | |
#define | BOOTSTRAP_SIZE ((size_t) & _bootstrap_size) |
Bootstrap size as defined in the linkerscripts. | |
#define | FS_STORAGE_START_ADDRESS ((uint32_t) & _fs_storage_start) |
File System Storage start address as defined in the linkerscripts. | |
#define | FS_STORAGE_SIZE ((size_t) & _fs_storage_size) |
File System Storage size as defined in the linkerscripts. | |
#define | SRAM_START_ADDRESS ((uint32_t) & _sram_start) |
SRAM start address as defined in the linkerscripts. | |
#define | SRAM_SIZE ((size_t) & _sram_size) |
SRAM size as defined in the linkerscripts. | |
#define | FOTA_PACKET_SOF 0xAAU |
#define | FOTA_PACKET_EOF 0xBBU |
#define | FOTA_PACKET_PAYLOAD_SIZE 128U |
#define | FOTA_PACKET_HEADER_SIZE (1U + 1U + 4U + 1U + 2U) |
#define | FOTA_PACKET_SERIALIZED_SIZE (FOTA_PACKET_HEADER_SIZE + FOTA_PACKET_PAYLOAD_SIZE + 4U + 1U) |
#define | FOTA_PACKET_MINIMUM_SIZE FOTA_PACKET_SERIALIZED_SIZE |
#define | HSE_LSE_TIMEOUT_MS 5000U |
#define | USE_INTERNAL_OSCILLATOR 1U |
#define | FOTA_TIMEOUT_MS 15000U |
#define | FOTA_UART_MAX_BUFFER_LEN 256U |
Maximum size permitted for a UART transaction. | |
#define | FOTA_UART_TIMEOUT_MS 10U |
Maximum time permitted for a FOTA UART transaction. | |
#define | NETWORK_BUFFER_SIZE 1024U |
#define | FOTA_MAX_ACTIVE_DATAGRAMS 2U |
Maximum number of datagrams that can be processed simultaneously. | |
Typedefs | |
typedef struct FotaCanSettings | FotaCanSettings |
CAN Settings. More... | |
typedef enum FotaDatagramType | FotaDatagramType |
Datagram types corresponding to different FOTA operations. | |
typedef enum FotaError | FotaError |
FOTA Error code definitions. | |
typedef void(* | FotaDatagramCompleteCb) (FotaDatagram *datagram) |
Enumerations | |
enum | FotaCanBitrate { FOTA_CAN_BITRATE_125KBPS , FOTA_CAN_BITRATE_250KBPS , FOTA_CAN_BITRATE_500KBPS , FOTA_CAN_BITRATE_1000KBPS , NUM_FOTA_CAN_BITRATES } |
enum | Boot_CanMode { CAN_CONTINUOUS = 0 , CAN_ONE_SHOT_MODE , NUM_CAN_MODES , CAN_CONTINUOUS = 0 , CAN_ONE_SHOT_MODE , NUM_CAN_MODES } |
enum | FotaDatagramType { FOTA_DATAGRAM_TYPE_FIRMWARE_METADATA , FOTA_DATAGRAM_TYPE_FIRMWARE_CHUNK , FOTA_DATAGRAM_TYPE_JUMP_TO_APP , FOTA_DATAGRAM_TYPE_ACKNOWLEDGEMENT , FOTA_DATAGRAM_TYPE_ERROR } |
Datagram types corresponding to different FOTA operations. More... | |
enum | FotaDFUState { FOTA_DFU_UNINITIALIZED , FOTA_DFU_IDLE , FOTA_DFU_RECEIVING , FOTA_DFU_COMPLETE , FOTA_DFU_JUMP } |
DFU internal states. More... | |
enum | FotaError { FOTA_ERROR_SUCCESS , FOTA_ERROR_RESOURCE_EXHAUSTED , FOTA_ERROR_INVALID_ARGS , FOTA_ERROR_INTERNAL_ERROR , FOTA_ERROR_TIMEOUT , FOTA_ERROR_CRC32_MISMATCH , FOTA_ERROR_CRC32_DATA_NOT_ALIGNED , FOTA_ERROR_FLASH_WRITE_FAILED , FOTA_ERROR_FLASH_WRITE_OUT_OF_BOUNDS , FOTA_ERROR_FLASH_WRITE_NOT_ALIGNED , FOTA_ERROR_FLASH_READ_FAILED , FOTA_ERROR_FLASH_ERASE , FOTA_ERROR_FLASH_VERIFICATION_FAILED , FOTA_ERROR_INVALID_PACKET , FOTA_ERROR_BOOTLOADER_SUCCESS , FOTA_ERROR_BOOTLOADER_INVALID_STATE , FOTA_ERROR_BOOTLOADER_UNINITIALIZED , FOTA_ERROR_BOOTLOADER_INVALID_DATAGRAM , FOTA_ERROR_BOOTLOADER_WRITE_IN_PROGRESS , FOTA_ERROR_BOOTLOADER_FAILURE , FOTA_ERROR_BOOTLOADER_SEQUENCE_OUT_OF_ORDER , FOTA_ERROR_BOOTLOADER_BINARY_OVERSIZED , FOTA_CAN_INIT_ERR , FOTA_CAN_TRANSMISSION_ERROR , FOTA_CAN_RECEIVE_ERROR , FOTA_ERROR_NO_MEMORY , FOTA_ERROR_NO_DATAGRAM_FOUND , FOTA_ERROR_JUMP_FAILED } |
FOTA Error code definitions. More... | |
enum | FotaJumpRequest { FOTA_JUMP_APPLICATION , FOTA_JUMP_BOOTLOADER , FOTA_JUMP_MIDSUN_BOOTSTRAP } |
enum | FotaPacketType { FOTA_PACKET_TYPE_DATA = 0 , FOTA_PACKET_TYPE_HEADER , FOTA_PACKET_TYPE_ACK , FOTA_PACKET_TYPE_NACK , FOTA_PACKET_TYPE_ERROR } |
FOTA Packet Type. More... | |
enum | UartPort { UART_PORT_1 = 0 , UART_PORT_2 , NUM_UART_PORTS , UART_PORT_1 = 0 , UART_PORT_2 , NUM_UART_PORTS } |
UART Port selection. | |
enum | UartFlowControl { UART_FLOW_CONTROL_NONE , UART_FLOW_CONTROL_RTS , UART_FLOW_CONTROL_CTS , UART_FLOW_CONTROL_RTS_CTS , UART_FLOW_CONTROL_NONE , UART_FLOW_CONTROL_RTS , UART_FLOW_CONTROL_CTS , UART_FLOW_CONTROL_RTS_CTS } |
UART Flow control selection. More... | |
enum | GpioPort { GPIO_PORT_A = 0 , GPIO_PORT_B , NUM_GPIO_PORTS , GPIO_PORT_A = 0 , GPIO_PORT_B , GPIO_PORT_C , GPIO_PORT_D , GPIO_PORT_E , GPIO_PORT_H , NUM_GPIO_PORTS } |
UART Settings. More... | |
enum | PacketReceiverState { PKT_STATE_WAITING_SOF , PKT_STATE_READING_PACKET } |
State machine states for packet receiving. More... | |
Functions | |
FotaError | fota_init () |
void | fota_process (void) |
FotaError | fota_dfu_init (PacketManager *packet_manager, uintptr_t staging_base, uintptr_t app_start_addr) |
Initialize DFU context. More... | |
FotaError | fota_can_init (const FotaCanSettings *settings) |
Initialize the CAN interface for FOTA. More... | |
FotaError | fota_can_transmit (uint32_t id, bool extended, const uint8_t *data, size_t len) |
Transmit a CAN message in FOTA. More... | |
FotaError | fota_can_receive (FotaCanMessage *const msg) |
Receive a CAN message in FOTA. More... | |
FotaError | fota_datagram_init (FotaDatagram *datagram, FotaDatagramType type, uint32_t datagram_id, uint8_t *data, uint32_t length) |
Initialize a datagram structure. More... | |
FotaError | fota_datagram_to_packets (FotaDatagram *datagram, FotaPacket *packets, uint16_t *num_packets, uint16_t max_packets) |
Fragment a datagram into packets for transmission. More... | |
FotaError | fota_datagram_process_data_packet (FotaDatagram *datagram, FotaPacket *packet) |
Process a received packet and incorporate it into a datagram. More... | |
FotaError | fota_datagram_process_header_packet (FotaDatagram *datagram, FotaPacket *packet) |
Process a received header packet and incorporate it into a datagram. More... | |
bool | fota_datagram_is_complete (FotaDatagram *datagram) |
Check if a datagram has been completely received. More... | |
FotaError | fota_datagram_verify (FotaDatagram *datagram) |
Verify the integrity of a complete datagram. More... | |
FotaError | fota_dfu_process (FotaDatagram *datagram) |
Process an incoming datagram and write to flash. More... | |
FotaError | fota_encryption_init () |
Initialize the encryption unit. More... | |
uint32_t | fota_calculate_crc32 (uint8_t *data, uint32_t length_words) |
Calculate the CRC32 for a given buffer of 4-byte aligned data. More... | |
uint32_t | fota_calculate_crc32_on_flash_memory (uintptr_t flash_base_addr, uint32_t flash_size) |
Verify a region of flash memory. More... | |
FotaError | fota_verify_packet_encryption (FotaPacket *packet) |
Verify a FOTA packets encryption. More... | |
FotaError | fota_verify_datagram_encryption (FotaDatagram *datagram) |
Verify a FOTA datagrams encryption. More... | |
FotaError | fota_flash_write (uint32_t address, uint8_t *buffer, size_t buffer_len) |
Write to flash memory. More... | |
FotaError | fota_flash_erase (uint32_t start_page, uint8_t num_pages) |
Erase some number of flash pages. More... | |
FotaError | fota_flash_read (uint32_t address, uint8_t *buffer, size_t buffer_len) |
Read from flash memory. More... | |
FotaError | fota_verify_flash_memory (uintptr_t start_addr, size_t size_bytes) |
Verify that the flash memory is not erased. More... | |
FotaError | fota_jump (FotaJumpRequest jump_request) |
FotaError | fota_packet_init (FotaPacket *packet, FotaPacketType type, uint8_t sequence, uint16_t length) |
Initialize a FOTA packet. More... | |
FotaError | fota_packet_set_crc (FotaPacket *packet) |
Compute and set CRC32 of payload. More... | |
FotaError | fota_packet_serialize (FotaPacket *packet, uint8_t *buffer, uint32_t buf_size, uint32_t *bytes_written) |
Serialize FOTA packet into buffer. More... | |
FotaError | fota_packet_deserialize (FotaPacket *packet, uint8_t *buffer, uint32_t buf_size) |
Deserialize buffer into FOTA packet. More... | |
FotaError | fota_startup (void) |
Initialize MCU system clock and HAL. More... | |
bool | fota_is_timed_out (void) |
Checks if FOTA has timed out, meaning no requests have been received. More... | |
FotaError | network_init (UartPort uart, UartSettings *settings, NetworkBuffer *network_buffer) |
Initialize UART instance, assuming standard 8 bits 1 stop bit. More... | |
FotaError | network_read (UartPort uart, uint8_t *data, size_t len) |
Read data from the network buffer. More... | |
FotaError | network_tx (UartPort uart, uint8_t *data, size_t len) |
Transmit data from the UART port. More... | |
bool | is_network_timeout (bool is_tx) |
Checks if tx or rx command has timed out. More... | |
FotaError | network_buffer_init (NetworkBuffer *network_buffer) |
Initalizes circular buffer for use, by initalizing assocated structs. More... | |
uint16_t | network_buffer_num_items (NetworkBuffer *network_buffer) |
Fetches the number of items in the network buffer. More... | |
uint16_t | network_buffer_num_empty_slots (NetworkBuffer *network_buffer) |
Fetches the number of empty slots in the network buffer. More... | |
bool | network_buffer_empty (NetworkBuffer *network_buffer) |
Checks if the network buffer is empty. More... | |
bool | network_buffer_full (NetworkBuffer *network_buffer) |
Checks if the network buffer is full. More... | |
FotaError | network_buffer_write (NetworkBuffer *network_buffer, uint8_t *data) |
Write data bytes. More... | |
FotaError | network_buffer_read (NetworkBuffer *network_buffer, uint8_t *data) |
Read data bytes. More... | |
FotaError | packet_manager_init (PacketManager *manager, UartPort uart, UartSettings *uart_settings, FotaDatagramCompleteCb callback) |
Initialize the packet manager. More... | |
FotaError | packet_manager_process (PacketManager *manager) |
Process received data from the network buffer. More... | |
FotaError | packet_manager_send_datagram (PacketManager *manager, FotaDatagram *datagram, FotaError(*send_func)(int8_t *data, uint32_t length)) |
Send a datagram by fragmenting it into packets. More... | |
FotaError | packet_manager_create_datagram (PacketManager *manager, FotaDatagramType type, uint8_t *data, uint32_t length, FotaDatagram **datagram) |
Create a new datagram for sending. More... | |
FotaError | packet_manager_get_datagram (PacketManager *manager, uint32_t datagram_id, FotaDatagram **datagram) |
Get a pointer to a completed datagram. More... | |
FotaError | packet_manager_free_datagram (PacketManager *manager, uint32_t datagram_id) |
Free a datagram slot. More... | |
Firmware Over the Air (FOTA) Update system.
#define FOTA_ADDR_TO_PAGE | ( | addr | ) | (((uintptr_t)(addr) - (uintptr_t)APP_ACTIVE_START_ADDRESS) / FOTA_PAGE_BYTES) |
Convert memory address to page number.
addr | Address to be converted to page number |
#define fota_error_ok_or_return | ( | code | ) |
Use to forward failures or continue on success.
#define FOTA_PACKET_SOF 0xAAU |
FotaPacket Serialized Format:
+---------—+-------------—+-----------------------—+ | Field | Size (bytes) | Description | +---------—+-------------—+-----------------------—+ | sof | 1 | Start of Frame (0xAA) | | packet_type| 1 | Packet Type Enum | | datagram_id| 4 | Datagram identifier | | sequence_num| 1 | Packet index in datagram | | payload_len| 2 | Actual data in payload | | payload | 128 | Fixed-size payload | | crc32 | 4 | CRC32 of full payload | | eof | 1 | End of Frame (0xBB) | +---------—+-------------—+-----------------------—+
Total Serialized Size: 142 bytes
#define FOTA_PAGE_TO_ADDR | ( | page | ) | ((uintptr_t)(page) * (uintptr_t)FOTA_PAGE_BYTES + (uintptr_t)APP_ACTIVE_START_ADDRESS) |
Convert page number to memory address.
page | Page number |
typedef struct FotaCanSettings FotaCanSettings |
CAN Settings.
TX Pin will transmit data. RX pin will receive data. The bitrate is the number of bits sent per second. The device ID is the CAN ID of the STM32 node. Loopback will internally connect the transmit and receive CAN lines for testing. Silent mode is used for only listening to the bus.
enum FotaCanBitrate |
enum FotaDatagramType |
Datagram types corresponding to different FOTA operations.
enum FotaDFUState |
enum FotaError |
FOTA Error code definitions.
enum FotaJumpRequest |
enum FotaPacketType |
enum GpioPort |
UART Settings.
TX Pin will transmit data. RX pin will receive data. The baudrate is the number of symbols sent per second. Both devices must agree on the baudrate with a tolerance of +-3%. Flow control is of type UartFlowControl.
enum PacketReceiverState |
enum UartFlowControl |
UART Flow control selection.
Flow control is a method of synchronizing UART communication between 2 devices. For most applications, this can be set to UART_FLOW_CONTROL_NONE.
uint32_t fota_calculate_crc32 | ( | uint8_t * | data, |
uint32_t | length_words | ||
) |
Calculate the CRC32 for a given buffer of 4-byte aligned data.
data_start | Pointer to the start of the data |
length_words | Size of the data in words |
uint32_t fota_calculate_crc32_on_flash_memory | ( | uintptr_t | flash_base_addr, |
uint32_t | flash_size | ||
) |
Verify a region of flash memory.
flash_base_addr | Base address to begin verification from |
flash_size | Size of flash memory to verify in bytes |
FotaError fota_can_init | ( | const FotaCanSettings * | settings | ) |
Initialize the CAN interface for FOTA.
FotaError fota_can_receive | ( | FotaCanMessage *const | msg | ) |
Receive a CAN message in FOTA.
msg | Pointer to the message that will be updated with incoming data |
FotaError fota_can_transmit | ( | uint32_t | id, |
bool | extended, | ||
const uint8_t * | data, | ||
size_t | len | ||
) |
Transmit a CAN message in FOTA.
id | CAN Message arbitration Id |
extended | Boolean flag to select 11-bit vs 29-bit CAN transmission |
data | Pointer to the data buffer to transmit |
len | Length of the data buffer |
FotaError fota_datagram_init | ( | FotaDatagram * | datagram, |
FotaDatagramType | type, | ||
uint32_t | datagram_id, | ||
uint8_t * | data, | ||
uint32_t | length | ||
) |
Initialize a datagram structure.
datagram | Pointer to datagram to initialize |
type | Type of datagram |
datagram_id | Unique ID for this datagram |
data | Data to include in datagram (can be NULL if building incrementally) |
length | Length of data |
bool fota_datagram_is_complete | ( | FotaDatagram * | datagram | ) |
Check if a datagram has been completely received.
datagram | Datagram to check |
FotaError fota_datagram_process_data_packet | ( | FotaDatagram * | datagram, |
FotaPacket * | packet | ||
) |
Process a received packet and incorporate it into a datagram.
datagram | Datagram being reconstructed |
packet | Received packet |
FotaError fota_datagram_process_header_packet | ( | FotaDatagram * | datagram, |
FotaPacket * | packet | ||
) |
Process a received header packet and incorporate it into a datagram.
datagram | Datagram being reconstructed |
packet | Received header packet |
FotaError fota_datagram_to_packets | ( | FotaDatagram * | datagram, |
FotaPacket * | packets, | ||
uint16_t * | num_packets, | ||
uint16_t | max_packets | ||
) |
Fragment a datagram into packets for transmission.
datagram | Datagram to fragment |
packets | Array to store generated packets |
num_packets | Pointer to store number of packets generated (Including the header packet) |
max_packets | Maximum number of packets that can be stored in the array |
FotaError fota_datagram_verify | ( | FotaDatagram * | datagram | ) |
Verify the integrity of a complete datagram.
datagram | Datagram to verify |
FotaError fota_dfu_init | ( | PacketManager * | packet_manager, |
uintptr_t | staging_base, | ||
uintptr_t | app_start_addr | ||
) |
Initialize DFU context.
packet_manager | Pointer to packet manager instance |
staging_base | Flash base address where firmware will be staged |
app_start_addr | Address to jump to after flashing |
FotaError fota_dfu_process | ( | FotaDatagram * | datagram | ) |
Process an incoming datagram and write to flash.
datagram | Pointer to fully received, verified datagram |
FotaError fota_encryption_init | ( | ) |
Initialize the encryption unit.
FotaError fota_flash_erase | ( | uint32_t | start_page, |
uint8_t | num_pages | ||
) |
Erase some number of flash pages.
start_page | Initial page number to erase |
num_pages | Number of pages to erase |
FotaError fota_flash_read | ( | uint32_t | address, |
uint8_t * | buffer, | ||
size_t | buffer_len | ||
) |
Read from flash memory.
address | Base memory address to read from |
buffer | Pointer to the data buffer |
buffer_len | Length of the data buffer |
FotaError fota_flash_write | ( | uint32_t | address, |
uint8_t * | buffer, | ||
size_t | buffer_len | ||
) |
Write to flash memory.
address | Base memory address to write to |
buffer | Pointer to the data buffer |
buffer_len | Length of the data buffer |
bool fota_is_timed_out | ( | void | ) |
Checks if FOTA has timed out, meaning no requests have been received.
FotaError fota_packet_deserialize | ( | FotaPacket * | packet, |
uint8_t * | buffer, | ||
uint32_t | buf_size | ||
) |
Deserialize buffer into FOTA packet.
packet | Output FotaPacket struct |
buffer | Input buffer |
buf_size | Size of input buffer |
FotaError fota_packet_init | ( | FotaPacket * | packet, |
FotaPacketType | type, | ||
uint8_t | sequence, | ||
uint16_t | length | ||
) |
Initialize a FOTA packet.
packet | Pointer to packet |
type | Packet type |
sequence | Sequence number |
length | Length of actual data (≤ FOTA_PACKET_PAYLOAD_SIZE, multiple of 4) |
FotaError fota_packet_serialize | ( | FotaPacket * | packet, |
uint8_t * | buffer, | ||
uint32_t | buf_size, | ||
uint32_t * | bytes_written | ||
) |
Serialize FOTA packet into buffer.
packet | Packet to serialize |
buffer | Output buffer |
buf_size | Size of output buffer |
bytes_written | Number of bytes written |
FotaError fota_packet_set_crc | ( | FotaPacket * | packet | ) |
Compute and set CRC32 of payload.
packet | Pointer to packet |
FotaError fota_startup | ( | void | ) |
Initialize MCU system clock and HAL.
Call this function once at the start of your application
FotaError fota_verify_datagram_encryption | ( | FotaDatagram * | datagram | ) |
Verify a FOTA datagrams encryption.
datagram | Pointer to the encrypted datagram |
FotaError fota_verify_flash_memory | ( | uintptr_t | start_addr, |
size_t | size_bytes | ||
) |
Verify that the flash memory is not erased.
This checks the entire application flash memory to ensure it is not entirely erased
start_addr | Start address to begin verifying flash memory |
size_bytes | Size of flash memory to verify in bytes |
FotaError fota_verify_packet_encryption | ( | FotaPacket * | packet | ) |
Verify a FOTA packets encryption.
packet | Pointer to the encrypted packet |
bool is_network_timeout | ( | bool | is_tx | ) |
Checks if tx or rx command has timed out.
Subtracts the difference of current clock time and clock time when command started
is_tx | if it is checking timeout for a tx or an rx command |
bool network_buffer_empty | ( | NetworkBuffer * | network_buffer | ) |
Checks if the network buffer is empty.
network_buffer | Pointer to the network buffer |
bool network_buffer_full | ( | NetworkBuffer * | network_buffer | ) |
Checks if the network buffer is full.
network_buffer | Pointer to the network buffer |
FotaError network_buffer_init | ( | NetworkBuffer * | network_buffer | ) |
Initalizes circular buffer for use, by initalizing assocated structs.
network_buffer | Pointer to the network buffer |
uint16_t network_buffer_num_empty_slots | ( | NetworkBuffer * | network_buffer | ) |
Fetches the number of empty slots in the network buffer.
network_buffer | Pointer to the network buffer |
uint16_t network_buffer_num_items | ( | NetworkBuffer * | network_buffer | ) |
Fetches the number of items in the network buffer.
network_buffer | Pointer to the network buffer |
FotaError network_buffer_read | ( | NetworkBuffer * | network_buffer, |
uint8_t * | data | ||
) |
Read data bytes.
network_buffer | Pointer to the network buffer |
data | Reads packet from circular buffer into a provided location |
FotaError network_buffer_write | ( | NetworkBuffer * | network_buffer, |
uint8_t * | data | ||
) |
Write data bytes.
network_buffer | Pointer to the network buffer |
data | Pointer to data byte to write |
FotaError network_init | ( | UartPort | uart, |
UartSettings * | settings, | ||
NetworkBuffer * | network_buffer | ||
) |
Initialize UART instance, assuming standard 8 bits 1 stop bit.
uart | Specifies which UART port to initialize |
settings | Pointer to UART initialization settings |
network_buffer | Pointer to the network buffer for storing recieved data |
Read data from the network buffer.
Receives len bytes of data from the network buffer. Receives up to NETWORK_BUFFER_SIZE.
uart | Specifies which UART port the data is coming from |
data | Pointer to the read data buffer |
len | Length of data to receive |
Transmit data from the UART port.
Sends length bytes of data from UART TX queue to specified UART port. Sends up to UART_MAX_BUFFER_LEN. Updates start time of tx command and sets transmitting status to true, check timeout status in main loop.
uart | Specifies which UART port to send from |
data | Pointer to the tx data buffer |
len | Length of data to send |
FotaError packet_manager_create_datagram | ( | PacketManager * | manager, |
FotaDatagramType | type, | ||
uint8_t * | data, | ||
uint32_t | length, | ||
FotaDatagram ** | datagram | ||
) |
Create a new datagram for sending.
manager | Pointer to packet manager structure |
type | Type of datagram to create |
data | Data to include in datagram |
length | Length of data |
datagram | Pointer to store the created datagram |
FotaError packet_manager_free_datagram | ( | PacketManager * | manager, |
uint32_t | datagram_id | ||
) |
Free a datagram slot.
manager | Pointer to packet manager structure |
datagram_id | ID of the datagram to free |
FotaError packet_manager_get_datagram | ( | PacketManager * | manager, |
uint32_t | datagram_id, | ||
FotaDatagram ** | datagram | ||
) |
Get a pointer to a completed datagram.
manager | Pointer to packet manager structure |
datagram_id | ID of the datagram to retrieve |
datagram | Pointer to store pointer to datagram |
FotaError packet_manager_init | ( | PacketManager * | manager, |
UartPort | uart, | ||
UartSettings * | uart_settings, | ||
FotaDatagramCompleteCb | callback | ||
) |
Initialize the packet manager.
manager | Pointer to packet manager structure |
uart | UART port number |
uart_settings | Pointer to the UART settings needed for the network buffer |
callback | Callback function for completed datagrams (can be NULL) |
FotaError packet_manager_process | ( | PacketManager * | manager | ) |
Process received data from the network buffer.
This function shall be called periodically to process any data in the network buffer It will extract bytes from the buffer, assemble them into packets, and then assemble packets into datagrams.
manager | Pointer to packet manager structure |
FotaError packet_manager_send_datagram | ( | PacketManager * | manager, |
FotaDatagram * | datagram, | ||
FotaError(*)(int8_t *data, uint32_t length) | send_func | ||
) |
Send a datagram by fragmenting it into packets.
manager | Pointer to packet manager structure |
datagram | Datagram to send |
send_func | Function to call to send each packet |