SDK สำหรับ TESAIoT Dev Kit
คู่มืออ้างอิง API และ Tutorial (MTB & µPython)
Toggle main menu visibility
Loading...
Searching...
No Matches
bento_link.h
Go to the documentation of this file.
1
/*******************************************************************************
2
* File Name : bento_link.h
3
*
4
* Description : BENTO transport-agnostic link layer — ONE interface for
5
* the sensor/model data plane over pluggable backends:
6
* "ipc" (CM33<->CM55 pipe), "usb" (TACP serial), "ble"
7
* (NUS), "wifi" (TCP socket). v1 ships the ipc backend.
8
*
9
* Two planes:
10
* - CONTROL: u8 cmd + u32 value — DEEPCraft-compatible, so
11
* the vendored deepcraft_engine.c drives it through a
12
* ~40-line adapter (first-member vtable cast pattern,
13
* see common/deepcraft/deepcraft_interface.h).
14
* - DATA: framed byte streams (stream_id + seq), for bulk
15
* capture (mic PCM, IMU, model scores). v1: reserved.
16
*
17
* Backends self-register by name; availability follows the
18
* board persona (compile-time BSP flags), so Python-side
19
* deepcraft.links() reflects the real board automatically.
20
*
21
* Design reference : TESAIoT_PLAN/2026-7/MPY_Sensor_DEEPCraft_Integration/
22
*******************************************************************************/
23
24
#ifndef BENTO_LINK_H
25
#define BENTO_LINK_H
26
27
#include <stdint.h>
28
#include <stdbool.h>
29
30
#ifdef __cplusplus
31
extern
"C"
{
32
#endif
33
34
/* Capability flags */
35
#define BL_F_LOSSY (1u << 0)
/* frames may drop (no retransmit) */
36
#define BL_F_BULK_RING (1u << 1)
/* supports negotiated shared-memory bulk */
37
38
typedef
struct
bento_link_s
bento_link_t
;
39
40
struct
bento_link_s
{
41
/* CONTROL PLANE — u8 cmd + u32 value. Must be callable from task context;
42
* returns false if the transport is busy/unavailable. */
43
bool (*
send_ctrl
)(
bento_link_t
*self, uint8_t cmd, uint32_t value);
44
45
/* DATA PLANE — framed stream chunk (<= mtu). v1: ipc backend returns
46
* false (bulk rides the negotiated SOCMEM ring in a later phase). */
47
bool (*
send_data
)(
bento_link_t
*self, uint8_t stream_id,
48
const
void
*buf, uint16_t len);
49
50
/* Receive callbacks. Backends MUST invoke these OFF interrupt context
51
* (each backend trampolines: ISR -> queue -> delivery task). */
52
void (*
register_receive
)(
bento_link_t
*self,
53
void (*ctrl_cb)(uint8_t cmd, uint32_t value),
54
void
(*data_cb)(uint8_t stream_id,
const
void
*buf,
55
uint16_t len, uint16_t seq));
56
57
/* Capability advertisement — callers adapt, never assume. */
58
const
char
*
name
;
/* "ipc" | "usb" | "ble" | "wifi" */
59
uint16_t
mtu
;
/* max data-plane payload per frame */
60
uint32_t
bandwidth_bps
;
/* honest sustained budget for the data plane */
61
uint8_t
flags
;
/* BL_F_* */
62
};
63
64
/* ── Registry ────────────────────────────────────────────────────────────── */
65
66
#define BENTO_LINK_MAX_BACKENDS (4u)
67
69
bool
bento_link_register
(
bento_link_t
*link);
70
72
bento_link_t
*
bento_link_get
(
const
char
*name);
73
75
bento_link_t
*
bento_link_at
(uint32_t index);
76
77
#ifdef __cplusplus
78
}
79
#endif
80
81
#endif
/* BENTO_LINK_H */
bento_link_t
struct bento_link_s bento_link_t
Definition
bento_link.h:38
bento_link_at
bento_link_t * bento_link_at(uint32_t index)
ไล่รายการใน registry; คืน NULL เมื่อเลยรายการสุดท้าย
bento_link_register
bool bento_link_register(bento_link_t *link)
API สำหรับผู้เขียน backend: ลงทะเบียน bento_link_t ของ transport เพียงครั้งเดียว
bento_link_get
bento_link_t * bento_link_get(const char *name)
ค้นหา backend ตามชื่อ; คืน NULL เมื่อไม่มี — ต้องตรวจ NULL เสมอ
bento_link_s
Definition
bento_link.h:40
bento_link_s::send_data
bool(*) send_data(bento_link_t *self, uint8_t stream_id, const void *buf, uint16_t len)
Definition
bento_link.h:47
bento_link_s::flags
uint8_t flags
Definition
bento_link.h:61
bento_link_s::register_receive
void(*) register_receive(bento_link_t *self, void(*ctrl_cb)(uint8_t cmd, uint32_t value), void(*data_cb)(uint8_t stream_id, const void *buf, uint16_t len, uint16_t seq))
Definition
bento_link.h:52
bento_link_s::mtu
uint16_t mtu
Definition
bento_link.h:59
bento_link_s::name
const char * name
Definition
bento_link.h:58
bento_link_s::bandwidth_bps
uint32_t bandwidth_bps
Definition
bento_link.h:60
bento_link_s::send_ctrl
bool(*) send_ctrl(bento_link_t *self, uint8_t cmd, uint32_t value)
Definition
bento_link.h:43
dist
mpy_secure
include
bento_link.h
Generated by
1.18.0