NetHubVirtualChannel:修订间差异
跳转到导航
跳转到搜索
创建页面,内容为“= 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 = | ||
This document describes how to use the NetHub <code>USER virtual channel</code>. | |||
== 1. | == 1. Concept == | ||
<code>USER virtual channel</code> | <code>USER virtual channel</code> is a logical message channel carried on the current host link. | ||
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 | ||
For most customer integrations, only the <code>USER</code> type matters. | |||
== 2. | == 2. Bring-Up Prerequisites == | ||
Before using it, confirm: | |||
* device | * device side is built with <code>CONFIG_NETHUB=y</code> | ||
* device | * device side is built with <code>CONFIG_MR_VIRTUALCHAN=y</code> | ||
* host | * host side has already loaded <code>mr_sdio.ko</code> | ||
* host | * 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 | ||
* | * If the host control plane itself uses <code>vchan</code>, it uses the <code>AT</code> type | ||
* | * Customer private messages should stay on the <code>USER</code> type | ||
== 3. | == 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. | == 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 === | ||
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> | ||
** | ** the host has completed the handshake with the device | ||
=== 4.4 | === 4.4 Optional Link Event Callback === | ||
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> | ||
# | # Call <code>nethub_vchan_deinit()</code> when finished | ||
Example: | |||
<syntaxhighlight lang="c"> | <syntaxhighlight lang="c"> | ||
| 第136行: | 第136行: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== 6. | == 6. Limits and Notes == | ||
* | * 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 | ||
* | * If the device side does not enable <code>CONFIG_MR_VIRTUALCHAN</code>, the host-side <code>USER</code> channel will not work | ||
* | * 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| | * [[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
USERchannel and the control channel are parallel channels - If the host control plane itself uses
vchan, it uses theATtype - Customer private messages should stay on the
USERtype
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
nethub_vchan_init()nethub_vchan_user_register_callback()nethub_vchan_user_send()- 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
1500bytes - The
USERchannel 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-sideUSERchannel will not work - If host control-plane traffic and
USERtraffic coexist, do not reuse theATtype for customer private data