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…”
 
张良留言 | 贡献
Sync NetHub docs from local Markdown
 
第1行: 第1行:
= NetHub USER Virtual Channel =
= NetHub USER Virtual Channel =


本文档描述 NetHub <code>USER virtual channel</code> 用法。
This document describes how to use the NetHub <code>USER virtual channel</code>.


== 1. 概念 ==
== 1. Concept ==


<code>USER virtual channel</code> 是承载在当前 host link 上的逻辑消息通道。
<code>USER virtual channel</code> is a logical message channel carried on the current host link.


它不是独立物理接口,而是复用当前的 <code>SDIO / USB / SPI</code> 链路,把不同类型的数据拆分到不同逻辑通道中。
It is not a separate physical interface. It reuses the current <code>SDIO / USB / SPI</code> transport and multiplexes different payload types into separate logical channels.


当前常用类型:
Commonly used types:


* <code>USER</code>
* <code>USER</code>
** 客户或应用层私有数据
** private customer or application data
* <code>AT</code>
* <code>AT</code>
** host 控制面数据
** host control-plane data
* <code>SYSTEM</code>
* <code>SYSTEM</code>
** 系统内部协调消息
** internal system coordination messages


客户集成时,通常只需要关注 <code>USER</code> 类型。
For most customer integrations, only the <code>USER</code> type matters.


== 2. bringup 前提 ==
== 2. Bring-Up Prerequisites ==


使用前建议确认:
Before using it, confirm:


* device 侧已编入 <code>CONFIG_NETHUB=y</code>
* device side is built with <code>CONFIG_NETHUB=y</code>
* device 侧已编入 <code>CONFIG_MR_VIRTUALCHAN=y</code>
* device side is built with <code>CONFIG_MR_VIRTUALCHAN=y</code>
* host 侧已经加载 <code>mr_sdio.ko</code>
* host side has already loaded <code>mr_sdio.ko</code>
* host device 的底层链路已经正常工作
* the underlying host-device link is already working


补充说明:
Additional notes:


* <code>USER</code> 通道和控制通道是并列关系
* The <code>USER</code> channel and the control channel are parallel channels
* 如果 host 控制面本身走 <code>vchan</code>,它使用的是 <code>AT</code> 类型
* If the host control plane itself uses <code>vchan</code>, it uses the <code>AT</code> type
* 客户私有消息建议固定使用 <code>USER</code> 类型
* Customer private messages should stay on the <code>USER</code> type


== 3. Device 侧接口 ==
== 3. device-side Interfaces ==


头文件:
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行: 第48行:
</syntaxhighlight>
</syntaxhighlight>


== 4. Host 侧接口 ==
== 4. host-side Interfaces ==


头文件:
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 初始化与清理 ===
=== 4.1 Initialization and Cleanup ===


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


=== 4.2 USER 通道 ===
=== 4.2 USER Channel ===


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


=== 4.3 可选状态查询 ===
=== 4.3 Optional State Query ===


如果需要判断当前 virtual channel 是否 ready,可选使用:
If you need to know whether the virtual channel is ready, you can optionally use:


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


常用判断:
Typical checks:


* <code>link_state == NETHUB_VCHAN_LINK_UP</code>
* <code>link_state == NETHUB_VCHAN_LINK_UP</code>
** 表示链路已可收发
** the link is ready for TX/RX
* <code>host_state == NETHUB_VCHAN_HOST_STATE_DEVICE_RUN</code>
* <code>host_state == NETHUB_VCHAN_HOST_STATE_DEVICE_RUN</code>
** 表示 host 侧已经和 device 完成握手
** the host has completed the handshake with the device


=== 4.4 可选链路事件回调 ===
=== 4.4 Optional Link Event Callback ===


如果应用希望在链路 up/down 时被动收到通知,可选注册:
If the application wants passive notification when the link goes up or down, it can optionally register:


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


== 5. 典型使用顺序 ==
== 5. 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>
# Call <code>nethub_vchan_deinit()</code> when finished


示例:
Example:


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


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


* 单次消息最大长度为 <code>1500</code> 字节
* Maximum payload length per message is <code>1500</code> bytes
* <code>USER</code> 通道是消息包语义,不是流式字节流
* The <code>USER</code> channel is packet-oriented, not a byte stream
* 使用前必须保证内核模块已经加载
* The kernel module must be loaded before use
* 如果 device 侧未启用 <code>CONFIG_MR_VIRTUALCHAN</code>,host 侧 <code>USER</code> 通道无法工作
* If the device side does not enable <code>CONFIG_MR_VIRTUALCHAN</code>, the host-side <code>USER</code> channel will not work
* 如果同时使用 host 控制面和 <code>USER</code> 通道,客户私有数据不要复用 <code>AT</code> 类型
* If host control-plane traffic and <code>USER</code> traffic coexist, do not reuse the <code>AT</code> type for customer private data


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


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

2026年3月17日 (二) 05:33的最新版本

NetHub USER Virtual Channel

This document describes how to use the NetHub USER virtual channel.

1. Concept

USER virtual channel is a logical message channel carried on the current host link.

It is not a separate physical interface. It reuses the current SDIO / USB / SPI transport and multiplexes different payload types into separate logical channels.

Commonly used types:

  • USER
    • private customer or application data
  • AT
    • host control-plane data
  • SYSTEM
    • internal system coordination messages

For most customer integrations, only the USER type matters.

2. Bring-Up Prerequisites

Before using it, confirm:

  • device side is built with CONFIG_NETHUB=y
  • device side is built with CONFIG_MR_VIRTUALCHAN=y
  • host side has already loaded mr_sdio.ko
  • the underlying host-device link is already working

Additional notes:

  • The USER channel and the control channel are parallel channels
  • If the host control plane itself uses vchan, it uses the AT type
  • Customer private messages should stay on the USER type

3. device-side Interfaces

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);

4. host-side Interfaces

Header:

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

4.1 Initialization and Cleanup

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

4.2 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);

4.3 Optional State Query

If you need to know whether the virtual channel is ready, you can optionally use:

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);

Typical checks:

  • link_state == NETHUB_VCHAN_LINK_UP
    • the link is ready for TX/RX
  • host_state == NETHUB_VCHAN_HOST_STATE_DEVICE_RUN
    • the host has completed the handshake with the device

4.4 Optional Link Event Callback

If the application wants passive notification when the link goes up or down, it can optionally register:

int nethub_vchan_register_link_event_callback(
    nethub_vchan_link_event_callback_t callback,
    void *user_data);

5. Typical Usage Order

  1. nethub_vchan_init()
  2. nethub_vchan_user_register_callback()
  3. nethub_vchan_user_send()
  4. Call 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;
}

6. Limits and Notes

  • Maximum payload length per message is 1500 bytes
  • The USER channel is packet-oriented, not a byte stream
  • The kernel module must be loaded before use
  • If the device side does not enable CONFIG_MR_VIRTUALCHAN, the host-side USER channel will not work
  • If host control-plane traffic and USER traffic coexist, do not reuse the AT type for customer private data

7. Related Pages