NetHubVirtualChannel:修订间差异

来自Bouffalo Lab Docs
跳转到导航 跳转到搜索
张良留言 | 贡献
创建页面,内容为“= NetHub USER Virtual Channel = 本文档描述 NetHub 的 <code>USER virtual channel</code> 用法。 == 1. 概念 == <code>USER virtual channel</code> 是承载在当前 host link 上的逻辑消息通道。 它不是独立物理接口,而是复用当前的 <code>SDIO / USB / SPI</code> 链路,把不同类型的数据拆分到不同逻辑通道中。 当前常用类型: * <code>USER</code> ** 客户或应用层私有数据 * <code>AT</code> ** hos…”
 
张良留言 | 贡献
Reduce overlap between NetHubArchitecture and NetHubVirtualChannel (2026-04-25)
 
(未显示同一用户的4个中间版本)
第1行: 第1行:
= NetHub USER Virtual Channel =
= NetHub USER Virtual Channel =


本文档描述 NetHub 的 <code>USER virtual channel</code> 用法。
This document describes the current NetHub USER virtual channel support.


== 1. 概念 ==
It focuses on USER virtual channel usage, prerequisites, APIs, and limits. For the full NetHub architecture and the broader interface support matrix, read [[NetHubArchitecture|NetHubArchitecture.md]].


<code>USER virtual channel</code> 是承载在当前 host link 上的逻辑消息通道。
== 1. Concept ==


它不是独立物理接口,而是复用当前的 <code>SDIO / USB / SPI</code> 链路,把不同类型的数据拆分到不同逻辑通道中。
USER virtual channel is a logical message channel carried on the active host interface.


当前常用类型:
It is not a separate physical interface. The public API is transport-neutral, while the current in-tree implementation is still centered on the default <code>SDIO</code> interface.


* <code>USER</code>
Common logical types:
** 客户或应用层私有数据
* <code>AT</code>
** host 控制面数据
* <code>SYSTEM</code>
** 系统内部协调消息


客户集成时,通常只需要关注 <code>USER</code> 类型。
{| class="wikitable"
|-
! Type !! Meaning
|-
| <code>USER</code> || private customer or application data
|-
| <code>AT</code> || control payloads
|-
| <code>SYSTEM</code> || internal coordination messages
|}


== 2. bringup 前提 ==
== 2. Current Scope ==


使用前建议确认:
Current implementation summary:


* device 侧已编入 <code>CONFIG_NETHUB=y</code>
* the public API is transport-neutral by design
* device 侧已编入 <code>CONFIG_MR_VIRTUALCHAN=y</code>
* the current in-tree end-to-end USER virtual channel path follows the default <code>SDIO</code> interface
* host 侧已经加载 <code>mr_sdio.ko</code>
* the device-side implementation is currently in <code>backend/host/sdio/virtualchan.c</code>
* host 与 device 的底层链路已经正常工作
* the host userspace library is currently aligned with <code>mr_sdio.ko + netlink</code>
* USB device-side ACM transport exists, but in-tree host <code>nethub_vchan</code> alignment is not finished
* SPI is not supported


补充说明:
== 3. Prerequisites ==


* <code>USER</code> 通道和控制通道是并列关系
Before using the current in-tree USER virtual channel path, confirm:
* 如果 host 控制面本身走 <code>vchan</code>,它使用的是 <code>AT</code> 类型
* 客户私有消息建议固定使用 <code>USER</code> 类型


== 3. Device 侧接口 ==
* device side is built with <code>CONFIG_NETHUB=y</code>
* device side enables <code>CONFIG_MR_VIRTUALCHAN=y</code>
* the selected bring-up path uses the default <code>SDIO</code> interface
* host side has loaded <code>mr_sdio.ko</code>
* the host-device link is already working


头文件:
Notes:
 
* USER and AT are parallel logical channels
* customer private data should stay on the <code>USER</code> type
* documentation should not describe USB and SPI as if they already share a finished end-to-end virtual channel stack
 
== 4. Device-Side API ==
 
Header:


* <code>components/net/nethub/include/nethub_vchan.h</code>
* <code>components/net/nethub/include/nethub_vchan.h</code>


常用接口:
Common APIs:


<syntaxhighlight lang="c">
<syntaxhighlight lang="c">
第48行: 第64行:
</syntaxhighlight>
</syntaxhighlight>


== 4. Host 侧接口 ==
== 5. Host-Side API ==


头文件:
Header:


* <code>bsp/common/msg_router/linux_host/userspace/nethub/virtualchan/nethub_vchan.h</code>
* <code>bsp/common/msg_router/linux_host/userspace/nethub/virtualchan/nethub_vchan.h</code>


=== 4.1 初始化与清理 ===
Initialization and cleanup:


<syntaxhighlight lang="c">
<syntaxhighlight lang="c">
第61行: 第77行:
</syntaxhighlight>
</syntaxhighlight>


=== 4.2 USER 通道 ===
USER channel:


<syntaxhighlight lang="c">
<syntaxhighlight lang="c">
第70行: 第86行:
</syntaxhighlight>
</syntaxhighlight>


=== 4.3 可选状态查询 ===
Optional state query:
 
如果需要判断当前 virtual channel 是否 ready,可选使用:


<syntaxhighlight lang="c">
<syntaxhighlight lang="c">
第83行: 第97行:
</syntaxhighlight>
</syntaxhighlight>


常用判断:
Optional link event callback:
 
* <code>link_state == NETHUB_VCHAN_LINK_UP</code>
** 表示链路已可收发
* <code>host_state == NETHUB_VCHAN_HOST_STATE_DEVICE_RUN</code>
** 表示 host 侧已经和 device 完成握手
 
=== 4.4 可选链路事件回调 ===
 
如果应用希望在链路 up/down 时被动收到通知,可选注册:


<syntaxhighlight lang="c">
<syntaxhighlight lang="c">
第100行: 第105行:
</syntaxhighlight>
</syntaxhighlight>


== 5. 典型使用顺序 ==
== 6. Typical Usage Order ==


# <code>nethub_vchan_init()</code>
# <code>nethub_vchan_init()</code>
# <code>nethub_vchan_user_register_callback()</code>
# <code>nethub_vchan_user_register_callback()</code>
# <code>nethub_vchan_user_send()</code>
# <code>nethub_vchan_user_send()</code>
# 使用完成后调用 <code>nethub_vchan_deinit()</code>
# <code>nethub_vchan_deinit()</code> when finished


示例:
Example:


<syntaxhighlight lang="c">
<syntaxhighlight lang="c">
第136行: 第141行:
</syntaxhighlight>
</syntaxhighlight>


== 6. 限制与注意事项 ==
== 7. Limits and Notes ==


* 单次消息最大长度为 <code>1500</code> 字节
* maximum payload length per message is <code>1500</code> bytes
* <code>USER</code> 通道是消息包语义,不是流式字节流
* USER virtual channel is packet-oriented, not a byte stream
* 使用前必须保证内核模块已经加载
* the current in-tree end-to-end path is SDIO-based
* 如果 device 侧未启用 <code>CONFIG_MR_VIRTUALCHAN</code>,host 侧 <code>USER</code> 通道无法工作
* if the device side does not enable <code>CONFIG_MR_VIRTUALCHAN</code>, the current in-tree USER virtual channel path will not work
* 如果同时使用 host 控制面和 <code>USER</code> 通道,客户私有数据不要复用 <code>AT</code> 类型
* if control traffic and USER traffic coexist, keep private application traffic on <code>USER</code> and do not reuse the <code>AT</code> type


== 7. 相关页面 ==
== 8. Related Pages ==


* [[NetHubQuickBringup|NetHub 快速上手]]
* [[NetHub|NetHub.md]]
* [[NetHubArchitecture|NetHub 架构说明]]
* [[NetHubQuickBringup|NetHubQuickBringup.md]]
* [[NetHubArchitecture|NetHubArchitecture.md]]

2026年4月24日 (五) 17:13的最新版本

NetHub USER Virtual Channel

This document describes the current NetHub USER virtual channel support.

It focuses on USER virtual channel usage, prerequisites, APIs, and limits. For the full NetHub architecture and the broader interface support matrix, read NetHubArchitecture.md.

1. Concept

USER virtual channel is a logical message channel carried on the active host interface.

It is not a separate physical interface. The public API is transport-neutral, while the current in-tree implementation is still centered on the default SDIO interface.

Common logical types:

Type Meaning
USER private customer or application data
AT control payloads
SYSTEM internal coordination messages

2. Current Scope

Current implementation summary:

  • the public API is transport-neutral by design
  • the current in-tree end-to-end USER virtual channel path follows the default SDIO interface
  • the device-side implementation is currently in backend/host/sdio/virtualchan.c
  • the host userspace library is currently aligned with mr_sdio.ko + netlink
  • USB device-side ACM transport exists, but in-tree host nethub_vchan alignment is not finished
  • SPI is not supported

3. Prerequisites

Before using the current in-tree USER virtual channel path, confirm:

  • device side is built with CONFIG_NETHUB=y
  • device side enables CONFIG_MR_VIRTUALCHAN=y
  • the selected bring-up path uses the default SDIO interface
  • host side has loaded mr_sdio.ko
  • the host-device link is already working

Notes:

  • USER and AT are parallel logical channels
  • customer private data should stay on the USER type
  • documentation should not describe USB and SPI as if they already share a finished end-to-end virtual channel stack

4. Device-Side API

Header:

  • components/net/nethub/include/nethub_vchan.h

Common APIs:

int nethub_vchan_user_send(const void *data, uint16_t len);
int nethub_vchan_user_recv_register(nethub_vchan_recv_cb_t recv_cb, void *cb_arg);

5. Host-Side API

Header:

  • bsp/common/msg_router/linux_host/userspace/nethub/virtualchan/nethub_vchan.h

Initialization and cleanup:

int nethub_vchan_init(void);
int nethub_vchan_deinit(void);

USER channel:

typedef void (*nethub_vchan_recv_callback_t)(const void *data, size_t len);

int nethub_vchan_user_send(const void *data, size_t len);
int nethub_vchan_user_register_callback(nethub_vchan_recv_callback_t callback);

Optional state query:

typedef struct {
    nethub_vchan_link_state_t link_state;
    nethub_vchan_host_state_t host_state;
} nethub_vchan_state_snapshot_t;

int nethub_vchan_get_state_snapshot(nethub_vchan_state_snapshot_t *snapshot);

Optional link event callback:

int nethub_vchan_register_link_event_callback(
    nethub_vchan_link_event_callback_t callback,
    void *user_data);

6. Typical Usage Order

  1. nethub_vchan_init()
  2. nethub_vchan_user_register_callback()
  3. nethub_vchan_user_send()
  4. nethub_vchan_deinit() when finished

Example:

#include <stdio.h>
#include <string.h>

#include "nethub_vchan.h"

static void user_rx_cb(const void *data, size_t len)
{
    printf("recv USER data: %.*s\n", (int)len, (const char *)data);
}

int main(void)
{
    const char *msg = "hello from host";

    if (nethub_vchan_init() != 0) {
        return -1;
    }

    nethub_vchan_user_register_callback(user_rx_cb);
    nethub_vchan_user_send(msg, strlen(msg));

    nethub_vchan_deinit();
    return 0;
}

7. Limits and Notes

  • maximum payload length per message is 1500 bytes
  • USER virtual channel is packet-oriented, not a byte stream
  • the current in-tree end-to-end path is SDIO-based
  • if the device side does not enable CONFIG_MR_VIRTUALCHAN, the current in-tree USER virtual channel path will not work
  • if control traffic and USER traffic coexist, keep private application traffic on USER and do not reuse the AT type

8. Related Pages