这里讲一下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. 【计算机网络】传输层 : TCP 协议 ( TCP 协议特点 | TCP 报文段首部格式 | TCP 报文段控制位 )
  2. 详解虚拟机中为Linux添加硬盘
  3. 《深入浅出vue.js》阅读笔记之数组变化侦测
  4. 现代软件工程讲义 个人项目和结对项目练习 四则运算
  5. NanShan开源即时通讯团队讨论程序员空闲期可以做的事
  6. linux挂载查看、添加与取消
  7. 大数据可视化的方法和价值
  8. 快速了解Linux ps命令
  9. 【考研数学】函数图像(三角函数、幂函数、指数函数等)
  10. 电动自行车出租管理系统VS开发sqlserver数据库web结构c#编程计算机网页
  11. 极化码 极化现象matlab仿真(信道容量,巴氏参数,高斯近似三种方法)
  12. 计算机操作系统核心知识点总结面试笔试要点
  13. opencv convertTo函数
  14. 企业邮箱哪家最优惠?企业邮箱最优惠价格来了
  15. 基于python的2048游戏设计_用python写一个2048游戏
  16. TensorFlow绘制loss/accuracy曲线
  17. oracle数据库的安装及配置方法
  18. keyshot聚光灯_KeyShot 6使用技巧
  19. 工作多年,我对架构的一些理解
  20. 定时脚本任务列子(crontab)

热门文章

  1. 计算机操作系统的基本概念
  2. 神器webssh学习笔记
  3. H.266/VVC代码学习:xCheckRDCostMerge2Nx2N函数
  4. android号码查询归属地,号码归属地识别-Android电话应用
  5. APISpace 手机号码归属地API
  6. 新中大财务软件服务器路径修改,新中大软件最常用的操作手册
  7. 线性代数科学出版社课后练习题答案
  8. 怎么在wps里做计算机,解决方案:如何在wps中制作电子小报
  9. 结构型模式分类与简介
  10. js 单精度浮点数转10进制_js浮点数精度问题的前世今生?