75 lines
2.1 KiB
C
75 lines
2.1 KiB
C
#ifndef SETP_TMS2812_BOOT_H
|
|
#define SETP_TMS2812_BOOT_H
|
|
|
|
#include "set_can.h"
|
|
#include "set_firmware.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#ifndef SETP_TMS2812_MAX_BLOCK_SIZE
|
|
#define SETP_TMS2812_MAX_BLOCK_SIZE 64U
|
|
#endif
|
|
|
|
#define SETP_TMS2812_RESPONSE_PAYLOAD_SIZE \
|
|
(2U + SETP_DEVICE_INFO_FIXED_SIZE + SETP_DEVICE_MODEL_MAX)
|
|
|
|
typedef struct {
|
|
uint8_t node_id;
|
|
uint16_t device_class;
|
|
uint32_t hardware_version;
|
|
uint32_t firmware_version;
|
|
uint32_t dictionary_version;
|
|
uint64_t serial_number;
|
|
const uint8_t *model;
|
|
uint8_t model_length;
|
|
uint32_t app_base_address;
|
|
uint32_t max_image_size;
|
|
uint16_t max_block_size;
|
|
uint8_t active_slot;
|
|
uint8_t require_signature;
|
|
} setp_tms2812_boot_config_t;
|
|
|
|
typedef struct {
|
|
setp_can_send_fn send_can;
|
|
bool (*erase_image)(void *user, uint32_t image_size);
|
|
bool (*write_image)(void *user, uint32_t offset,
|
|
const uint8_t *data, uint16_t length);
|
|
bool (*read_image)(void *user, uint32_t offset,
|
|
uint8_t *data, uint16_t length);
|
|
bool (*authorize)(void *user, const setp_fw_begin_t *manifest);
|
|
void (*reboot)(void *user);
|
|
} setp_tms2812_boot_port_t;
|
|
|
|
typedef struct {
|
|
setp_tms2812_boot_config_t config;
|
|
setp_tms2812_boot_port_t port;
|
|
void *port_user;
|
|
setp_can_rx_t rx;
|
|
setp_fw_begin_t manifest;
|
|
uint32_t next_offset;
|
|
uint16_t last_error;
|
|
uint8_t state;
|
|
uint8_t response_payload[SETP_TMS2812_RESPONSE_PAYLOAD_SIZE];
|
|
uint8_t response_packet[SETP_FRAME_MAX];
|
|
} setp_tms2812_boot_t;
|
|
|
|
bool setp_tms2812_boot_init(setp_tms2812_boot_t *boot,
|
|
const setp_tms2812_boot_config_t *config,
|
|
const setp_tms2812_boot_port_t *port,
|
|
void *port_user);
|
|
|
|
/** Process one classic-CAN frame in task context, never from an ISR. */
|
|
bool setp_tms2812_boot_process(setp_tms2812_boot_t *boot,
|
|
const setp_can_frame_t *frame,
|
|
uint32_t now_ms);
|
|
|
|
void setp_tms2812_boot_abort(setp_tms2812_boot_t *boot);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* SETP_TMS2812_BOOT_H */
|