| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- #ifndef YMODEM_H
- #define YMODEM_H
- #include <stdint.h>
- #include "stm32h7xx_hal.h"
- /* 接收结果码 */
- typedef enum {
- YM_ERR_NONE = 0, /* 会话正常完成 */
- YM_ERR_NO_START, /* 探测窗口内无任何 YMODEM 起始(放行跳 APP 判定) */
- YM_ERR_TIMEOUT, /* 半途超时 */
- YM_ERR_ABORT, /* 对端 CAN 取消 */
- YM_ERR_RETRIES, /* 重传次数耗尽 */
- YM_ERR_OVERSIZE, /* 超出暂存区容量 */
- YM_ERR_WRITE, /* 写存储回调失败 */
- YM_ERR_TOOLARGE, /* 文件名块 size 字段超限 */
- } ym_err_t;
- typedef struct {
- uint8_t blk;
- uint8_t blk_inv;
- uint16_t size; /* 128/1024 */
- uint16_t crc;
- uint8_t data[1024];
- } ym_frame_t;
- typedef struct {
- ym_err_t result;
- uint32_t image_size; /* 文件名块声明的大小, 0=未解析到 */
- uint8_t size_known;
- uint32_t recv_bytes; /* 实际落盘字节(含末块填充) */
- uint32_t blocks_done; /* 已接受的数据块数(绝对序号); 失败时=死在哪一块 */
- } ym_result_t;
- void ymodem_init(UART_HandleTypeDef *huart);
- void ymodem_flush(void);
- /*
- * 阻塞接收一个 YMODEM 文件流。
- * idle_ms: 无进展超时(ms)——自上一帧到达起计时, 持续传输不会触发。
- * 探测阶段传短值(如 2000ms 无人发起→NO_START); 升级会话传 30000。
- * on_start_cb: 收到合法文件名块后回调一次(可为 0), 供上层置 DOWNLOADING 状态。
- * write_cb: 把解出的数据块写到偏移 off 处, 返回 0=OK。
- */
- ym_result_t ymodem_receive(uint32_t idle_ms,
- void (*on_start_cb)(void),
- uint8_t (*write_cb)(uint32_t off, const uint8_t *d, uint32_t n));
- #endif /* YMODEM_H */
|