From a163d3f1bdfc56b8dd26039ce8b4a7fff38022fa Mon Sep 17 00:00:00 2001 From: Florian Pose Date: Thu, 7 Jan 2010 17:26:39 +0100 Subject: [PATCH] Implemented ecrt_master() and ecrt_master_get_slave() in kernel space. --- include/ecrt.h | 8 ++------ master/master.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/include/ecrt.h b/include/ecrt.h index a3ebedbb..9b438c7c 100644 --- a/include/ecrt.h +++ b/include/ecrt.h @@ -208,8 +208,6 @@ typedef struct { /*****************************************************************************/ -#ifndef __KERNEL__ - /** Master information. * * This is used as an output parameter of ecrt_master(). @@ -246,8 +244,6 @@ typedef struct { char name[EC_MAX_STRING_LENGTH]; /**< Name of the slave. */ } ec_slave_info_t; -#endif // #ifndef __KERNEL__ - /*****************************************************************************/ /** Domain working counter interpretation. @@ -539,8 +535,6 @@ ec_slave_config_t *ecrt_master_slave_config( uint32_t product_code /**< Expected product code. */ ); -#ifndef __KERNEL__ - /** Obtains master information. * * No memory is allocated on the heap in @@ -573,6 +567,8 @@ int ecrt_master_get_slave( information */ ); +#ifndef __KERNEL__ + /** Returns the proposed configuration of a slave's sync manager. * * Fills a given ec_sync_info_t structure with the attributes of a sync diff --git a/master/master.c b/master/master.c index e312e0ff..0a78e2f4 100644 --- a/master/master.c +++ b/master/master.c @@ -2053,6 +2053,56 @@ ec_slave_config_t *ecrt_master_slave_config(ec_master_t *master, /*****************************************************************************/ +int ecrt_master(ec_master_t *master, ec_master_info_t *master_info) +{ + if (master->debug_level) + EC_DBG("ecrt_master(master = 0x%p, master_info = 0x%p)\n", + master, master_info); + + master_info->slave_count = master->slave_count; + master_info->link_up = master->main_device.link_state; + master_info->scan_busy = master->scan_busy; + master_info->app_time = master->app_time; + return 0; +} + +/*****************************************************************************/ + +int ecrt_master_get_slave(ec_master_t *master, uint16_t slave_position, + ec_slave_info_t *slave_info) +{ + const ec_slave_t *slave; + + if (down_interruptible(&master->master_sem)) { + return -EINTR; + } + + slave = ec_master_find_slave_const(master, 0, slave_position); + + slave_info->position = slave->ring_position; + slave_info->vendor_id = slave->sii.vendor_id; + slave_info->product_code = slave->sii.product_code; + slave_info->revision_number = slave->sii.revision_number; + slave_info->serial_number = slave->sii.serial_number; + slave_info->alias = slave->sii.alias; + slave_info->current_on_ebus = slave->sii.current_on_ebus; + slave_info->al_state = slave->current_state; + slave_info->error_flag = slave->error_flag; + slave_info->sync_count = slave->sii.sync_count; + slave_info->sdo_count = ec_slave_sdo_count(slave); + if (slave->sii.name) { + strncpy(slave_info->name, slave->sii.name, EC_MAX_STRING_LENGTH); + } else { + slave_info->name[0] = 0; + } + + up(&master->master_sem); + + return 0; +} + +/*****************************************************************************/ + void ecrt_master_callbacks(ec_master_t *master, void (*send_cb)(void *), void (*receive_cb)(void *), void *cb_data) { @@ -2133,6 +2183,8 @@ EXPORT_SYMBOL(ecrt_master_send); EXPORT_SYMBOL(ecrt_master_send_ext); EXPORT_SYMBOL(ecrt_master_receive); EXPORT_SYMBOL(ecrt_master_callbacks); +EXPORT_SYMBOL(ecrt_master); +EXPORT_SYMBOL(ecrt_master_get_slave); EXPORT_SYMBOL(ecrt_master_slave_config); EXPORT_SYMBOL(ecrt_master_state); EXPORT_SYMBOL(ecrt_master_application_time);