目录
- 前言
- 使用SSC工具生成XML
- 填充读写函数
- 测试
前言
EtherCAT协议栈生成参考https://blog.csdn.net/qq_42039294/article/details/144061669
本文默认大家有EtherCAT基础的移植经验
使用SSC工具生成XML
首先确保COE是开启的
打开表格,编辑内容如下
更多的数据类型参考 《Application Note ET9300 (EtherCAT Slave Stack Code)》,第十三节OD TOOL
填充读写函数
生成工程,应用层源文件中多出如下两个函数,这两个函数的函数名就是上面表格中填写的内容
UINT8 COE_VAR_Read(UINT16 index, UINT8 subindex, UINT32 dataSize, UINT16 MBXMEM * pData, UINT8 bCompleteAccess)
UINT8 COE_VAR_Write(UINT16 index, UINT8 subindex, UINT32 dataSize, UINT16 MBXMEM * pData, UINT8 bCompleteAccess)
填充内容如下
/
/**
\param index index of the requested object.
\param subindex subindex of the requested object.
\param objSize size of the requested object data, calculated with OBJ_GetObjectLength
\param pData Pointer to the buffer where the data can be copied to
\param bCompleteAccess Indicates if a complete read of all subindices of the
object shall be done or not
\return result of the read operation (0 (success) or an abort code (ABORTIDX_.... defined in
sdosrv.h))
*////
UINT8 COE_VAR_Read(UINT16 index, UINT8 subindex, UINT32 dataSize, UINT16 MBXMEM * pData, UINT8 bCompleteAccess) {
switch(subindex)
{
case 0: *((uint16_t *)pData) = CONFIG_GROUP0x8000.u16SubIndex0;
break;
case 1: *((uint32_t *)pData) = CONFIG_GROUP0x8000.Var1;
break;
case 2: *((uint32_t *)pData) = CONFIG_GROUP0x8000.Var2;
break;
}
SEGGER_RTT_printf(0, "COE_VAR_Read index:%04x subindex:%02x data:%d, ca = %d\n", index, subindex, *((uint32_t *)pData), bCompleteAccess);
return 0;
}
/
/**
\param index index of the requested object.
\param subindex subindex of the requested object.
\param objSize size of the requested object data, calculated with OBJ_GetObjectLength
\param pData Pointer to the buffer where the data can be copied to
\param bCompleteAccess Indicates if a complete read of all subindices of the
object shall be done or not
\return result of the read operation (0 (success) or an abort code (ABORTIDX_.... defined in
sdosrv.h))
*////
UINT8 COE_VAR_Write(UINT16 index, UINT8 subindex, UINT32 dataSize, UINT16 MBXMEM * pData, UINT8 bCompleteAccess) {
switch(subindex)
{
case 0: CONFIG_GROUP0x8000.u16SubIndex0 = *((uint16_t *)pData);
break;
case 1: CONFIG_GROUP0x8000.Var1 = *((uint32_t *)pData);
break;
case 2: CONFIG_GROUP0x8000.Var2 = *((uint32_t *)pData);
break;
}
SEGGER_RTT_printf(0, "COE_VAR_Write index:%04x subindex:%02x data:%d, ca = %d\n", index, subindex, *((uint32_t *)pData), bCompleteAccess);
return 0;
}
烧录程序,更新Twincat描述文件
测试
尝试对VAR1写入数据334
写入成功
上面的函数打印也正常