列车tcn网络mvb从站接收代码流程解析

本文详细描述了TCN列车通信网络中的MVB从站功能,包括WTB和MVB总线的使用,MVB板卡的配置要求,如初始化过程、源端口设置、设备地址设定,以及源代码实现的关键步骤,如过程数据初始化和数据接收等。还涉及了交叉编译和Makefile的使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

TCN-列车通信网络概述

机车车辆通信网络(TCN-列车通信网络)的基本组件是在整个列车单元中提供数据通信的有线列车总线(WTB)和用于在车辆或固定连接车辆组(组成)内进行数据交换(通信)的多功能车辆总线(MVB)。每个要连接到WTB网络的组件都必须配备WTB通信节点(称为WTB网关)。MVB通信网络也可以通过该节点连接。这称为 TCN WTB/MVB 网关。 

mvb板卡设置需求

需求:mvb板卡从站配置地址0x002,源端口0x500,端口大小32字节。

MVB从站源代码实现过程

1、板卡初始化
2、过程数据初始化
3、传输存储与新鲜度初始化
4、源端口初始化 PD_SOURCE_PORT
5、设备地址初始化
6、循环接收数据
7、交叉编译后生成arm64文件格式

1、板卡初始化

TCN_DECL_PUBLIC
AS_RESULT
as_init (void)
{
    LS_RESULT   ls_result = LS_OK;
    ENUM8       link_id;

    link_id = 0;
    while ((link_id < ls_max_links) && (LS_OK == ls_result))
    {
        ls_result = ls_init(link_id);
        /* ignore LS_UNKNOWN_LINK */
        if (LS_UNKNOWN_LINK == ls_result)
        {
            ls_result = LS_OK;
        } /* if (LS_UNKNOWN_LINK == ls_result) */
        link_id++;
    } /* while ((link_id < ls_max_links) && (LS_OK == ls_result)) */

    return((AS_RESULT)ls_result);

} /* as_init */

2、过程数据初始化

TCN_DECL_PUBLIC
AP_RESULT
ap_init (void)
{
    AP_RESULT   ap_result = AP_OK;
    LP_RESULT   lp_result = LP_OK;
    ENUM8       ts_id;

#if (TCN_AP_MUTEX_PORT == 1)
    /* initialise mutex for port access */
    if (FALSE == tcn_ap_mutex_status_port)
    {
        if (0 != pthread_mutex_init(&tcn_ap_mutex_object_port, NULL))
        {
            ap_result = AP_ERROR;
        } /* if (0 != pthread_mutex_init(&tcn_ap_mutex_object_port, NULL)) */
        else
        {
            tcn_ap_mutex_status_port = TRUE;
        } /* else */
    } /* if (FALSE == tcn_ap_mutex_status_port) */
    if (TRUE == tcn_ap_mutex_status_port)
    {
        if (0 != pthread_mutex_lock(&tcn_ap_mutex_object_port))
        {
            ap_result = AP_ERROR;
        } /* if (0 != pthread_mutex_lock(&tcn_ap_mutex_object_port)) */
        if (AP_OK == ap_result)
        {
            if (0 != pthread_mutex_unlock(&tcn_ap_mutex_object_port))
            {
                ap_result = AP_ERROR;
            } /* if (0 != pthread_mutex_unlock(&tcn_ap_mutex_object_port)) */
        } /* if (AP_OK == ap_result) */
    } /* if (TRUE == tcn_ap_mutex_status_port) */
#endif /* #if (TCN_AP_MUTEX_PORT == 1) */

    if (AP_OK == ap_result)
    {
        TCN_AP_MACRO_MUTEX_LOCK();

        ts_id = 0;
        while ((ts_id < lp_max_traffic_stores) && (LP_OK == lp_result))
        {
            lp_result = lp_init(ts_id, 0);
            /* ignore LP_UNKNOW_TS */
            if (LP_UNKNOW_TS  == lp_result)
            {
                lp_result = LP_OK;
            } /* if (LP_UNKNOW_TS  == lp_result) */
            ts_id++;
        } /* while ((ts_id < lp_max_traffic_stores) && (...)) */

        TCN_AP_MACRO_MUTEX_UNLOCK();

        ap_result = (AP_RESULT)lp_result;

    } /* if (AP_OK == ap_result) */

    return(ap_result);

} /* ap_init */

3、传输存储与新鲜度初始化

TCN_DECL_PUBLIC
AP_RESULT
ap_ts_config
(
    ENUM8       ts_id,
    UNSIGNED16  fsi
)
{
    LP_RESULT   lp_result;

    TCN_AP_MACRO_MUTEX_LOCK();

    lp_result = lp_init(ts_id, fsi);

    TCN_AP_MACRO_MUTEX_UNLOCK();

    return((AP_RESULT)lp_result);

} /* ap_ts_config */

4、源端口初始化 PD_SOURCE_PORT

        pd_port_address            = 0x500;
        pd_prt_attr.port_size      = 32;
        pd_prt_attr.port_config = PD_SOURCE_PORT;// PD_SINK_PORT;
        pd_prt_attr.p_bus_specific = NULL;
        ap_result =                 \
            ap_port_manage          \
            (                       \
                0,                  \
                pd_port_address,    \
                PD_PRT_CMD_CONFIG,  \
                &pd_prt_attr        \
            );

5、设备地址初始化

        mvb_control.device_address  = 0x002;
        mvb_control.reserved1       = 0x00;
        mvb_control.t_ignore        = 0x00;
        mvb_control.reserved2       = 0x00;
        mvb_control.command         = SV_MVB_CTRL_CMD_BIT_SLA;
        mvb_control.command        |= SV_MVB_CTRL_CMD_BIT_SLB;
        mvb_control.reserved3       = 0x0000;
        as_result =                             \
            as_service_handler                  \
            (                                   \
                0,                              \
                SV_MVB_SERVICE_WRITE_CONTROL,   \
                (void*)&mvb_control             \
            );

6、循环接收数据

        if (0 == result)
        {
            ds_name.traffic_store_id = 0;
            ds_name.port_address     = 0x500;
            ap_result = ap_put_dataset(&ds_name, &pd_port_data[0]);
            if (ap_result != AP_OK)
            {
                TCN_OSL_PRINTF("ERROR: ap_result=%u\n", ap_result);
                TCN_DEMO_ON_ERROR(ap_result);
                result = (UNSIGNED16)ap_result;
            } /* if (ap_result != AP_OK) */
        } /* if (0 == result) */

7、交叉编译后生成arm64文件格式

make 编译Makefile文件

slave: ELF 64-bit LSB executable, ARM aarch64, version 1 (GNU/Linux), statically linked, for GNU/Linux 3.7.0, BuildID[sha1]=4042a2f2a5d572698a6882f773b06be008799613, with debug_info, not stripped

8、mvb从站实测源代码下载地址

mvb从站接收源代码需求:mvb板卡从站配置地址0x002,源端口0x500,端口大小32字节Makefile编译方式资源-CSDN文库

关联:《列车tcn网络mvb主站发送代码流程解析》

列车tcn网络mvb主站发送代码流程解析-CSDN博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AppNinja

你的鼓励是我创作最大的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值