05 Master methods 主站方法

主站操作函数比较多,仅摘取对PDO数据处理的部分仅供参考。

/**03 Creates a new process data domain.
 *创建一个新的流程数据域。
 * For process data exchange, at least one process data domain is needed.
 * This method creates a new process data domain and returns a pointer to the
 * new domain object. This object can be used for registering PDOs and
 * exchanging them in cyclic operation.
 *对于进程数据交换,至少需要一个进程数据域。此方法创建一个新的进程数据域,
 *并返回一个指向新域对象的指针。该节点可用于注册和循环操作的pdo交换。
 * This method allocates memory and should be called in non-realtime context
 * before ecrt_master_activate().
 *这个方法分配内存,并且应该在非实时环境中'在ecrt master activate()之前'被调用。
 * \return Pointer to the new domain on success, else NULL.
 */
ec_domain_t *ecrt_master_create_domain(
        ec_master_t *master /**< EtherCAT master. */
        );

/**04 Obtains a slave configuration.
 *获取slave配置。
 * Creates a slave configuration object for the given \a alias and \a position
 * tuple and returns it. If a configuration with the same \a alias and \a
 * position already exists, it will be re-used. In the latter case, the given
 * vendor ID and product code are compared to the stored ones. On mismatch, an
 * error message is raised and the function returns \a NULL.
 *为给定的一个别名和一个位置元组创建一个从属配置对象并返回它。如果具有相同的别名和位置
 *的配置已经存在,它将被重用。在后一种情况下,将给定的供应商ID和产品代码与存储的ID和产品
 *代码进行比较。如果不匹配,则抛出一个错误消息并返回一个NULL。
 * Slaves are addressed with the \a alias and \a position parameters.
 * - If \a alias is zero, \a position is interpreted as the desired slave's
 *   ring position.
 * - If \a alias is non-zero, it matches a slave with the given alias. In this
 *   case, \a position is interpreted as ring offset, starting from the
 *   aliased slave, so a position of zero means the aliased slave itself and a
 *   positive value matches the n-th slave behind the aliased one.
 *从机是用一个别名和一个位置参数寻址的。—如果一个别名为零,一个位置将被解释为
 所需的从属环位置。如果一个别名是非零的,它将用给定的别名匹配一个slave。在这种
 情况下,\a的位置被解释为环形偏移,从别名从属器开始,所以零的位置意味着别名从属
 器本身,一个正值匹配别名从属器后面的第n个从属器。
 * If the slave with the given address is found during the bus configuration,
 * its vendor ID and product code are matched against the given value. On
 * mismatch, the slave is not configured and an error message is raised.
 *如果在总线配置期间找到具有给定地址的从服务器,则它的供应商ID和产品代码
 与给定值匹配。如果不匹配,则不配置从服务器并引发错误消息。
 * If different slave configurations are pointing to the same slave during bus
 * configuration, a warning is raised and only the first configuration is
 * applied.
 *如果在总线. configuration期间不同的从服务器配置指向相同的从服务器,则会引发一个警告,并且只应用第一个配置。
 * This method allocates memory and should be called in non-realtime context
 * before ecrt_master_activate().
 *这个方法分配内存,并且应该在非实时环境中在ecrt master activate()之前被调用。
 * \retval >0 Pointer to the slave configuration structure.
 * \retval NULL in the error case.
 */
ec_slave_config_t *ecrt_master_slave_config(
        ec_master_t *master, /**< EtherCAT master 主站*/
        uint16_t alias, /**< Slave alias. 从站假名*/
        uint16_t position, /**< Slave position.从站位置 */
        uint32_t vendor_id, /**< Expected vendor ID.期望的供应商ID */
        uint32_t product_code /**< Expected product code. 期望的产品代码*/
        );

/**05 Selects the reference clock for distributed clocks.
 *为分布式时钟选择参考时钟。
 * If this method is not called for a certain master, or if the slave
 * configuration pointer is NULL, then the first slave with DC functionality
 * will provide the reference clock.
 *如果某个主服务器没有调用此方法,或者从服务器的. configuration指针为NULL,
 那么第一个具有DC功能的从服务器将提供参考时钟。
 * \return 0 on success, otherwise negative error code.
 */
int ecrt_master_select_reference_clock(
        ec_master_t *master, /**< EtherCAT master. 主站*/
        ec_slave_config_t *sc /**< Slave config of the slave to use as the
                               * reference slave (or NULL).作为参考从站的从站配置(或为空) */
        );

/**06 Obtains master information.
 *得到主站的信息。
 * No memory is allocated on the heap in
 * this function.
 *在这个函数中,没有在堆上分配内存。
 * \attention The pointer to this structure must point to a valid variable.
 *
 * \return 0 in case of success, else < 0
 */
int ecrt_master(
        ec_master_t *master, /**< EtherCAT master 主站*/
        ec_master_info_t *master_info /**< Structure that will output the
                                        information 输出信息的结构体*/
        );

/**07 Obtains slave information.
 *获得从站信息。
 * Tries to find the slave with the given ring position. The obtained
 * information is stored in a structure. No memory is allocated on the heap in
 * this function.
 *尝试在给定的环位置找到从站。获得的信息存储在一个结构中。在这个函数中,没有在堆上分配内存。
 * \attention The pointer to this structure must point to a valid variable.
 *指向这个结构的指针必须指向一个有效的变量。
 * \return 0 in case of success, else < 0
 */
int ecrt_master_get_slave(

/**16 Finishes the configuration phase and prepares for cyclic operation.
 *完成配置阶段并准备循环操作。
 * This function tells the master that the configuration phase is finished and
 * the realtime operation will begin. The function allocates internal memory
 * for the domains and calculates the logical FMMU addresses for domain
 * members. It tells the master state machine that the bus configuration is
 * now to be applied.
 *这个函数告诉主机配置阶段已经完成,实时操作将开始。该函数为域分配内部内存,
 并计算域成员的逻辑FMMU地址。它告诉主状态机现在要应用总线配置。
 * \attention After this function has been called, the realtime application is
 * in charge of cyclically calling ecrt_master_send() and
 * ecrt_master_receive() to ensure bus communication. Before calling this
 * function, the master thread is responsible for that, so these functions may
 * not be called! The method itself allocates memory and should not be called
 * in realtime context.
 *这个函数被调用后,实时应用程序负责循环调用ecrt master send()和Ecrt master receive()
 *确保总线通信。在调用这个函数之前,主线程负责这个,所以这些函数可能不会被调用!方法本身
 *分配内存,不应该在实时上下文中调用。
 * \return 0 in case of success, else < 0
 */
int ecrt_master_activate(
        ec_master_t *master /**< EtherCAT master. */
        );

/**17 Deactivates the master.
 *
 * Removes the bus configuration. All objects created by
 * ecrt_master_create_domain(), ecrt_master_slave_config(), ecrt_domain_data()
 * ecrt_slave_config_create_sdo_request() and
 * ecrt_slave_config_create_voe_handler() are freed, so pointers to them
 * become invalid.
 *
 * This method should not be called in realtime context.
 */
void ecrt_master_deactivate(
        ec_master_t *master /**< EtherCAT master. */
        );

/**19 Sends all datagrams in the queue.
 *发送队列中的所有数据报。
 * This method takes all datagrams, that have been queued for transmission,
 * puts them into frames, and passes them to the Ethernet device for sending.
 *该方法将已排队等待传输的所有数据报放入帧中,并将其传递给以太网设备进行发送。
 * Has to be called cyclically by the application after ecrt_master_activate()
 * has returned.
 *必须在ecrt master activate()返回后由应用程序循环调用。
 */
void ecrt_master_send(
        ec_master_t *master /**< EtherCAT master. */
        );

/**20 Fetches received frames from the hardware and processes the datagrams.
 *从硬件中获取接收的帧并处理数据报。
 * Queries the network device for received frames by calling the interrupt
 * service routine. Extracts received datagrams and dispatches the results to
 * the datagram objects in the queue. Received datagrams, and the ones that
 * timed out, will be marked, and dequeued.
 *通过调用中断服务程序来查询网络设备接收到的帧。提取接收到的数据报,并将结果
 *分派给队列中的数据报对象。接收到的数据报和超时的数据报将被标记并退出队列。
 * Has to be called cyclically by the realtime application after
 * ecrt_master_activate() has returned.
 */
void ecrt_master_receive(
        ec_master_t *master /**< EtherCAT master. */
        );

/**22 Reads the current master state.
 *
 * Stores the master state information in the given \a state structure.
 *
 * This method returns a global state. For the link-specific states in a
 * redundant bus topology, use the ecrt_master_link_state() method.
 */
void ecrt_master_state(
        const ec_master_t *master, /**< EtherCAT master. */
        ec_master_state_t *state /**< Structure to store the information. */
        );
/**31 Retry configuring slaves.
 *重试配置从站
 * Via this method, the application can tell the master to bring all slaves to
 * OP state. In general, this is not necessary, because it is automatically
 * done by the master. But with special slaves, that can be reconfigured by
 * the vendor during runtime, it can be useful.
 *通过这个方法,应用程序可以告诉主站将所有从站设置为OP状态。一般来说,
 *这是不必要的,因为它是由主程序自动完成的。但是对于特殊的从站(可以由供应商
 *在运行时重新配置),它可能很有用。
 */
void ecrt_master_reset(
        ec_master_t *master /**< EtherCAT master. */
        );

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值