mothercup/mcm-ddc-ble/inc/app_ble_proto.h
evan.liu f4faf68ed8 boot V1.01.00: UART download mode (CLI + OTA frame upgrade in bootloader)
- boot_usart: bare-metal USART1 460800, polled TX, 3KB DMA ring RX, SysTick millis
- boot_cli: polled line editor + mini printf + command subset; wire-compatible
  with the app UART CLI (prompt/devinfo cur bank/ota marker) so
  ble_ota_update.py --uart works unchanged against the bootloader
- share app_ota.c/app_bootset.c into the Boot build via BOOT_FIRMWARE ifdef
  (single OTA engine source); frame constants moved to shared Boot/src/ota_wire.h
- entry: 2s Enter window after the boot banner, or forced when no jumpable
  image (invalid bootsetting + APP1 vector sanity fail) - brick recovery path
- OTA target in boot = inactive bank per bootsetting (APP1 when invalid)
- merge_image.py: hard-fail when boot bin exceeds the 16KB region
- APP V1.00.28 (shared-source touch only, behavior unchanged)
- tested: normal boot / download CLI / OTA APP1<->APP2 round trip / bricked
  recovery (bootsetting+APP1 sector erased -> forced download -> OTA restore)
- docs: dev log sec.52, ble_protocol sec.6.8, AGENTS.md
2026-09-05 17:25:53 +08:00

81 lines
2.5 KiB
C

/**
* @file app_ble_proto.h
* @brief BLE frame protocol frontend (over the rdtss write/notify
* characteristics): frame reassembly, CLI request/response transport,
* device info query and OTA frame dispatch (see docs/ble_protocol.md).
*
* Frame format (little endian):
* [0] SOF = 0xCA
* [1] TYPE
* [2] SEQ
* [3:4] LEN (payload length, LE)
* [5..] PAYLOAD
* [end-2..end] CRC16-CCITT (init 0xFFFF, poly 0x1021), LE, over TYPE..PAYLOAD
*
* All functions run in the BLE schedule task context only.
*/
#ifndef __APP_BLE_PROTO_H__
#define __APP_BLE_PROTO_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
/* Frame type / OTA status constants moved to the shared wire header
* (Boot/src/ota_wire.h, also compiled into the bootloader download mode) */
#include "ota_wire.h"
/**
* @brief Reset the protocol state machine.
*/
void app_ble_proto_init(void);
/**
* @brief Build one frame and push it into the ble_up uplink ring.
* Used by the CLI frontend and by the OTA/INFO handlers to answer.
* @return 0 on success, -1 when the frame exceeds the max frame size.
*/
int app_ble_proto_send_frame(uint8_t type, uint8_t seq, const uint8_t* payload, uint16_t len);
/**
* @brief Feed a received BLE write chunk into the frame reassembler.
* Called from the rdtss write indication handler (BLE task context).
*/
void app_ble_proto_rx_bytes(const uint8_t* data, uint16_t len);
/**
* @brief BLE disconnect hook: drop half-received frame and uplink buffer.
*/
void app_ble_proto_on_disconnect(void);
/**
* @brief BLE traffic log switch (default off). When on, every complete
* RX/TX frame is hex-dumped to the UART via printf, and BLE
* connect/disconnect events are printed too.
*/
void app_ble_proto_log_set(uint8_t on);
uint8_t app_ble_proto_log_get(void);
/**
* @brief Execute one raw CLI command line written to the CLI read/write
* characteristic (no frame, no notify). The command output text is
* captured into an internal buffer for app_ble_proto_cli_rsp().
* Called from the rdtss write indication handler (BLE task context).
*/
void app_ble_proto_cli_exec(const uint8_t* cmd, uint16_t len);
/**
* @brief Serve the next chunk of the last app_ble_proto_cli_exec() output
* (one call per ATT read of the CLI read/write characteristic).
* Chunks are <= att_mtu-2; a 0-length return marks end of response.
*/
const uint8_t* app_ble_proto_cli_rsp(uint16_t* out_len);
#ifdef __cplusplus
}
#endif
#endif /* __APP_BLE_PROTO_H__ */