这里讲一下soem的网卡驱动

大小端序

ethercattype.h文件夹里有一些关于大端序、小端序的宏定义。

#if !defined(EC_BIG_ENDIAN) && defined(EC_LITTLE_ENDIAN)#define htoes(A) (A)#define htoel(A) (A)#define htoell(A) (A)#define etohs(A) (A)#define etohl(A) (A)#define etohll(A) (A)#elif !defined(EC_LITTLE_ENDIAN) && defined(EC_BIG_ENDIAN)#define htoes(A) ((((uint16)(A) & 0xff00) >> 8) | \(((uint16)(A) & 0x00ff) << 8))#define htoel(A) ((((uint32)(A) & 0xff000000) >> 24) | \(((uint32)(A) & 0x00ff0000) >> 8)  | \(((uint32)(A) & 0x0000ff00) << 8)  | \(((uint32)(A) & 0x000000ff) << 24))#define htoell(A) ((((uint64)(A) & (uint64)0xff00000000000000ULL) >> 56) | \(((uint64)(A) & (uint64)0x00ff000000000000ULL) >> 40) | \(((uint64)(A) & (uint64)0x0000ff0000000000ULL) >> 24) | \(((uint64)(A) & (uint64)0x000000ff00000000ULL) >> 8)  | \(((uint64)(A) & (uint64)0x00000000ff000000ULL) << 8)  | \(((uint64)(A) & (uint64)0x0000000000ff0000ULL) << 24) | \(((uint64)(A) & (uint64)0x000000000000ff00ULL) << 40) | \(((uint64)(A) & (uint64)0x00000000000000ffULL) << 56))#define etohs  htoes#define etohl  htoel#define etohll htoell#else#error "Must define one of EC_BIG_ENDIAN or EC_LITTLE_ENDIAN"#endif

这里选择小端序(默认)。

nicdiv文件修改

这里只罗列了一部分

ecx_setupnic

/** Basic setup to connect NIC to socket.* @param[in] port        = port context struct* @param[in] ifname      = Name of NIC device, f.e. "eth0"* @param[in] secondary   = if >0 then use secondary stack instead of primary* @return >0 if succeeded*/
int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary)
{int i;int rVal;int *psock;//   port->getindex_mutex = mtx_create();
//   port->tx_mutex = mtx_create();
//   port->rx_mutex = mtx_create();//   rVal = bfin_EMAC_init((uint8_t *)priMAC);
//   if (rVal != 0)
//      return 0;if (secondary){/* secondary port stuct available? */if (port->redport){/* when using secondary socket it is automatically a redundant setup *///psock = &(port->redport->sockhandle);*psock = -1;port->redstate                   = ECT_RED_DOUBLE;//port->redport->stack.sock        = &(port->redport->sockhandle);port->redport->stack.txbuf       = &(port->txbuf);port->redport->stack.txbuflength = &(port->txbuflength);port->redport->stack.tempbuf     = &(port->redport->tempinbuf);port->redport->stack.rxbuf       = &(port->redport->rxbuf);port->redport->stack.rxbufstat   = &(port->redport->rxbufstat);port->redport->stack.rxsa        = &(port->redport->rxsa);ecx_clear_rxbufstat(&(port->redport->rxbufstat[0]));}else{/* fail */return 0;}}else{//      port->getindex_mutex = mtx_create();
//      port->tx_mutex = mtx_create();
//      port->rx_mutex = mtx_create();port->sockhandle        = -1;port->lastidx           = 0;port->redstate          = ECT_RED_NONE;//port->stack.sock        = &(port->sockhandle);port->stack.txbuf       = &(port->txbuf);port->stack.txbuflength = &(port->txbuflength);port->stack.tempbuf     = &(port->tempinbuf);port->stack.rxbuf       = &(port->rxbuf);port->stack.rxbufstat   = &(port->rxbufstat);port->stack.rxsa        = &(port->rxsa);ecx_clear_rxbufstat(&(port->rxbufstat[0]));psock = &(port->sockhandle);}  /* setup ethernet headers in tx buffers so we don't have to repeat it */for (i = 0; i < EC_MAXBUF; i++){ec_setupheader(&(port->txbuf[i]));port->rxbufstat[i] = EC_BUF_EMPTY;}ec_setupheader(&(port->txbuf2));return 1;
}

ecx_outframe

/** Transmit buffer over socket (non blocking).* @param[in] port        = port context struct* @param[in] idx         = index in tx buffer array* @param[in] stacknumber  = 0=Primary 1=Secondary stack* @return socket send result*/
int ecx_outframe(ecx_portt *port, int idx, int stacknumber)
{int lp, rval;ec_stackT *stack;if (!stacknumber){stack = &(port->stack);}else{stack = &(port->redport->stack);}lp = (*stack->txbuflength)[idx];//rval = bfin_EMAC_send((*stack->txbuf)[idx], lp);rval = EthWrPacket((*stack->txbuf)[idx], lp);(*stack->rxbufstat)[idx] = EC_BUF_TX;return rval;
}

ecx_recvpkt

/** Non blocking read of socket. Put frame in temporary buffer.* @param[in] port        = port context struct* @param[in] stacknumber = 0=primary 1=secondary stack* @return >0 if frame is available and read*/
static int ecx_recvpkt(ecx_portt *port, int stacknumber)
{int lp, bytesrx;ec_stackT *stack;if (!stacknumber){stack = &(port->stack);}else{stack = &(port->redport->stack);}lp = sizeof(port->tempinbuf);//bytesrx = bfin_EMAC_recv((*stack->tempbuf), lp);bytesrx = EthRdPacket((*stack->tempbuf));port->tempinbufs = bytesrx;return (bytesrx > 0);
}

基于STM32构建EtherCAT主站(SOEM方案)5相关推荐

  1. 基于rt thread smart构建EtherCAT主站

    我把源码开源到到了gitee,https://gitee.com/rathon/rt-thread-smart-soem 有兴趣的去可以下载下来跑一下 软件工程推荐用vscode 打开.rt thre ...

  2. ethercat主站soem开发板,stm32f407/stm32h7低成本主站方案,带台达伺服电机,ls伺服电机

    ethercat主站soem开发板,stm32f407/stm32h7低成本主站方案,带台达伺服电机,ls伺服电机,三洋伺服电机,汇川伺服电机,雷塞智能步进电机等支持ethercat的设备. 支持DC ...

  3. EtherCAT主站SOEM函数详解---- ecx_readstate、ecx_writestate

    EtherCAT主站SOEM函数详解----状态读取函数 ecx_readstate ecx_writestate 在控制驱动器等从站中,经常需要只知道从站的状态,在SOEM开发的主站中,如何读取从站 ...

  4. EtherCAT主站SOEM在Ubuntu上的移植

    EtherCAT主站SOEM在Ubuntu上的移植 原文:https://blog.csdn.net/ethercat_i7/article/details/52794069?utm_medium=d ...

  5. 基于STM32的EtherCAT从站IO讲解

    特别说明: 1.这是一个大佬的tao店:1.0 ha:/₴sklPcDGhJOy₤(我是买他的开发板的) 2.源代码设涉及版权问题,所以博客将不提供源码,请大家谅解 3.欢迎大家加我wx:wxk101 ...

  6. 基于MRS-ClickHouse构建用户画像系统方案介绍

    业务场景 用户画像是对用户信息的标签化.用户画像系统通过对收集的各维度数据,进行深度的分析和挖掘,给不同的用户打上不同的标签,从而刻画出客户的全貌.通过用户画像系统,可以对各个用户进行精准定位,从而将 ...

  7. 基于 EventBridge 构建 SaaS 应用集成方案

    引言 事件驱动架构(EDA)是一种以事件为纽带,将不同系统进行解耦的异步架构设计模型.在 EDA 中,事件驱动的运行流程天然地划分了各个系统的业务语义,用户可以根据需求对事件与针对此事件做出的响应灵活 ...

  8. EtherCAT主站SOEM源码解析----分布时钟DC

    分布时钟(DC,Dsitributed Clock)可以使所有EtherCAT设备使用相同的系统时间,从而控制各设备任务的同步执行. 1.DC从站 支持分布式时钟的从站称为DC从站,同步原理如下所示: ...

  9. EtherCAT主站SOEM源码解析----ecx_siiPDO()

    1.从站EEPROM的PDO信息 从站EEPROM存储的PDO信息如下如所示: TxPDO的类型名为50(0x0032),RxPDO的类型名为51(0x0033). 每个PDO占用的EEPROM字节数 ...

  10. EtherCAT主站SOEM —— 分布式时钟(Distributed Clock)抓包分析

    函数ecx_configdc的作用是测量传输时延(仅限当前slave不是第一个slave时,才计算时延) 1. 只连接一个从站时,ESC为LAN9252芯片.(不计算propagation delay ...

最新文章

  1. js的时间 java怎么处理,JS实现处理时间,年月日,星期的公共方法示例
  2. Class类文件结构、类加载机制以及字节码执行
  3. golang post发送 json请求
  4. python装饰器原理-python 中的装饰器及其原理
  5. 服务端支持的session
  6. 晨哥真有料丨为什么女生从来不主动找你聊天
  7. python 下载文件-Python实现HTTP协议下的文件下载方法总结
  8. 零基础学python还是c语言-学习python还是c语言?
  9. 数学建模——人口增长模型的matlab实现以及对2010年人口预测
  10. 压缩包上传 压缩并解压缩Rar/Zip
  11. fgo最新服务器,如何看fgo是什么服务器 | 手游网游页游攻略大全
  12. elixir 简单的server,client
  13. 第4讲 组合逻辑电路实例:编码器、译码器、数据选择器、加法器、数值比较器、代码转换器——计算机逻辑基础
  14. P7939 [B1] Alice Wins(easy version)
  15. 文本语义相似度检测 API 数据接口
  16. Fabled Rooks UVA - 11134
  17. 我撑伞,在石桥上等你
  18. 3_按钮开关控制的计算机串口通信
  19. 【签证】办理签证有特别要求的国家【签证办理必看】
  20. python中的networkx库

热门文章

  1. 计算机机房空调设计规范,计算机机房空调设计规范
  2. VTM3.0代码阅读:xCheckRDCostMerge2Nx2N函数
  3. MSDN 离线帮助文档 官网极速下载直达
  4. 瑞友天翼服务器ip地址怎么修改,瑞友天翼6.0版本iphone移动客户端操作手册
  5. 高中计算机会考excel试题及答案,高中计算机会考EXCEL会考练习试题
  6. 完善征信+垂直创新 助力有融网“剩者为王”
  7. html登录页面代码Java,html简单登录页面代码
  8. (已更新)外卖侠3.10.27版本外卖+售卖影票+任务功能微擎版本程序源码下载
  9. 标准正态分布怎么算_如何使用标准正态分布表?
  10. linux防火墙 限制流量,linux – iptables和阻止可能不可能的流量