powerpods/main/ota_uart.h

79 lines
2.3 KiB
C

#ifndef OTA_UART_H
#define OTA_UART_H
#include "esp_err.h"
#include "esp_partition.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#define OTA_UART_HOST_CHUNK_SIZE 200u
#define OTA_UART_FLASH_BLOCK_SIZE 4096u
/** OtaStatusPayload.status values (device → host). */
typedef enum {
OTA_UART_ST_PREPARING = 1,
OTA_UART_ST_READY = 2,
OTA_UART_ST_BLOCK_ACK = 3,
OTA_UART_ST_SUCCESS = 4,
OTA_UART_ST_FAILED = 5,
/** ESP-NOW slave distribution in progress (see OTA_DIST_* in cmd/cmd_ota.c). */
OTA_UART_ST_DISTRIBUTING = 6,
} ota_uart_status_t;
/** OtaStatusPayload.error when status == OTA_UART_ST_DISTRIBUTING. */
#define OTA_DIST_AGGREGATE 0u
#define OTA_DIST_PER_SLAVE 1u
typedef enum {
OTA_FEED_OK = 0,
OTA_FEED_BLOCK_WRITTEN,
OTA_FEED_SEQ_DUP,
OTA_FEED_SEQ_GAP,
OTA_FEED_ERROR,
} ota_feed_result_t;
bool ota_uart_is_active(void);
/** 0/1 while session active, else -1. */
int ota_uart_target_slot(void);
/** Begin OTA on the inactive app partition (esp_ota_begin). Returns target slot 0/1. */
int ota_uart_prepare(uint32_t total_size);
void ota_uart_abort(void);
/**
* Append up to 200 bytes with strict seq checking (0, 1, 2, …).
* Duplicates (seq < expected) return OTA_FEED_SEQ_DUP; gaps return OTA_FEED_SEQ_GAP.
*/
ota_feed_result_t ota_uart_feed_chunk(uint32_t seq, const uint8_t *data, size_t len);
/** True when a full 4 KiB block is in flash (used to re-ACK host block retries). */
bool ota_uart_block_ready_for_reack(void);
uint32_t ota_uart_bytes_written(void);
/** Bytes accepted in the current session (includes buffered block). */
uint32_t ota_uart_bytes_received(void);
/** Image size from OTA_START / ESP-NOW OTA_START; 0 if inactive. */
uint32_t ota_uart_total_size(void);
/**
* Flush remainder and esp_ota_end. When set_boot is false, the staged image
* remains readable via ota_uart_get_staged_image() until ota_uart_apply_boot().
*/
esp_err_t ota_uart_finish(bool set_boot, bool *success_out);
/** Staged partition after ota_uart_finish(false, …); valid until apply_boot or abort. */
bool ota_uart_get_staged_image(const esp_partition_t **partition_out,
uint32_t *size_out);
/** Set boot partition to the last staged image (after slave distribution). */
esp_err_t ota_uart_apply_boot(void);
void ota_uart_clear_staged(void);
#endif