esp32_shock/components/twai_ota/twai_ota.h
2024-04-29 17:35:50 +08:00

48 lines
1.2 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef __TWAI_OTA_H
#define __TWAI_OTA_H
#include <stdint.h>
#include "esp_partition.h"
#include "esp_ota_ops.h"
#define CONFIG_EXAMPLE_GPIO_DIAGNOSTIC (3)
#define OTA_BUFFSIZE (1024)
#define HASH_LEN 32 /* SHA-256 digest length */
#define OTA_ERR_OFFSET 0xAA00
typedef enum
{
OTA_OK = 0,
OTA_PARAM_ERROR = OTA_ERR_OFFSET | 1,
OTA_GET_PARTITION_ERROR,
OTA_HEADER_CHECK_ERROR,
OTA_BEGIN_FUN_ERROR,
OTA_WRITE_FUN_ERROR,
OTA_END_FUN_ERROR,
OTA_SET_BOOT_PARTITION_ERROR,
} ota_err_t;
typedef struct
{
esp_ota_handle_t update_handle;
esp_partition_t *update_partition;
bool image_header_was_checked;
int img_header_size;
int img_header_app_desc_offset;
int buf_len;
uint8_t buf[OTA_BUFFSIZE]; // buf的主要用途是twai每次8个字节在开始时因为需要进行校验所以不能把读入的直接写入分区应先存着进行校验
long long binary_file_length;
} ota_ctrl_t;
void ota_init(void);
ota_err_t ota_enter_command(void);
ota_err_t ota_image_header_check_and_start(void);
ota_err_t ota_download_data_in(uint8_t *data, int len);
ota_err_t ota_download_finish_command(void);
char *ota_read_versions(void);
#endif