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文库