--- a/examples/mini/mini.c Tue Mar 04 11:20:48 2008 +0000
+++ b/examples/mini/mini.c Tue Mar 04 11:37:51 2008 +0000
@@ -117,7 +117,6 @@
#ifdef SDO_ACCESS
static ec_sdo_request_t *sdo;
-static int not_first_time = 0;
#endif
/*****************************************************************************/
@@ -169,22 +168,21 @@
void read_sdo(void)
{
switch (ecrt_sdo_request_state(sdo)) {
- case EC_REQUEST_COMPLETE:
- if (not_first_time) {
- printk(KERN_INFO PFX "Sdo value: 0x%04X\n",
- EC_READ_U16(ecrt_sdo_request_data(sdo)));
- } else {
- not_first_time = 1;
- }
+ case EC_SDO_REQUEST_UNUSED: // request was not used yet
ecrt_sdo_request_read(sdo);
break;
- case EC_REQUEST_FAILURE:
+ case EC_SDO_REQUEST_BUSY:
+ printk(KERN_INFO PFX "Still busy...\n");
+ break;
+ case EC_SDO_REQUEST_SUCCESS:
+ printk(KERN_INFO PFX "Sdo value: 0x%04X\n",
+ EC_READ_U16(ecrt_sdo_request_data(sdo)));
+ ecrt_sdo_request_read(sdo);
+ break;
+ case EC_SDO_REQUEST_ERROR:
printk(KERN_INFO PFX "Failed to read Sdo!\n");
ecrt_sdo_request_read(sdo);
break;
- default:
- printk(KERN_INFO PFX "Still busy...\n");
- break;
}
}
#endif
--- a/include/ecrt.h Tue Mar 04 11:20:48 2008 +0000
+++ b/include/ecrt.h Tue Mar 04 11:37:51 2008 +0000
@@ -253,25 +253,16 @@
/*****************************************************************************/
-/** Generic request state.
+/** Sdo request state.
+ *
+ * This is used as return type of ecrt_sdo_request_state().
*/
typedef enum {
- EC_REQUEST_QUEUED,
- EC_REQUEST_IN_PROGRESS,
- EC_REQUEST_COMPLETE,
- EC_REQUEST_FAILURE
-} ec_request_state_t;
-
-/*****************************************************************************/
-
-/** Sdo request error.
- *
- * This is used as return type of ecrt_sdo_request_error().
- */
-typedef enum {
- EC_SDO_REQUEST_SUCCESS, /**< There is no error. */
- EC_SDO_REQUEST_TIMEOUT, /**< The request timed out. */
-} ec_sdo_request_error_t;
+ EC_SDO_REQUEST_UNUSED, /**< Not requested. */
+ EC_SDO_REQUEST_BUSY, /**< Request is being processed. */
+ EC_SDO_REQUEST_SUCCESS, /**< Request was processed successfully. */
+ EC_SDO_REQUEST_ERROR, /**< Request processing failed. */
+} ec_sdo_request_state_t;
/******************************************************************************
* Global functions
@@ -652,9 +643,8 @@
/** Access to the Sdo request's data.
*
- * \attention The return value is invalid during (ecrt_sdo_request_state() !=
- * EC_REQUEST_COMPLETE) a read operation, because the internal Sdo data
- * memory could be re-allocated.
+ * \attention The return value is invalid during a read operation, because the
+ * internal Sdo data memory could be re-allocated.
*
* \return Pointer to the internal Sdo data memory.
*/
@@ -666,16 +656,10 @@
*
* \return Request state.
*/
-ec_request_state_t ecrt_sdo_request_state(
+ec_sdo_request_state_t ecrt_sdo_request_state(
const ec_sdo_request_t *req /**< Sdo request. */
);
-/** Get the error code of the Sdo request.
- */
-ec_sdo_request_error_t ecrt_sdo_request_error(
- const ec_sdo_request_t *req /**< Sdo request. */
- );
-
/** Schedule an Sdo write operation.
*/
void ecrt_sdo_request_write(
@@ -685,8 +669,8 @@
/** Schedule an Sdo read operation .
*
* \attention After calling this function, the return value of
- * ecrt_sdo_request_data() will be invalid until ecrt_sdo_request_state()
- * is EC_REQUEST_COMPLETE.
+ * ecrt_sdo_request_data() will be invalid while ecrt_sdo_request_state()
+ * returns EC_SDO_REQUEST_BUSY.
*/
void ecrt_sdo_request_read(
ec_sdo_request_t *req /**< Sdo request. */
--- a/master/fsm_master.c Tue Mar 04 11:20:48 2008 +0000
+++ b/master/fsm_master.c Tue Mar 04 11:37:51 2008 +0000
@@ -238,7 +238,7 @@
up(&master->scan_sem);
}
else {
- master->scan_state = EC_REQUEST_IN_PROGRESS;
+ master->scan_state = EC_REQUEST_BUSY;
up(&master->scan_sem);
// topology change when scan is allowed:
@@ -258,7 +258,7 @@
if (!master->slave_count) {
// no slaves present -> finish state machine.
- master->scan_state = EC_REQUEST_COMPLETE;
+ master->scan_state = EC_REQUEST_SUCCESS;
wake_up_interruptible(&master->scan_queue);
fsm->state = ec_fsm_master_state_end;
return;
@@ -336,7 +336,7 @@
request = list_entry(master->eeprom_requests.next,
ec_eeprom_write_request_t, list);
list_del_init(&request->list); // dequeue
- request->state = EC_REQUEST_IN_PROGRESS;
+ request->state = EC_REQUEST_BUSY;
up(&master->eeprom_sem);
slave = request->slave;
@@ -386,7 +386,7 @@
continue;
list_for_each_entry(req, &slave->config->sdo_requests, list) {
if (req->state == EC_REQUEST_QUEUED) {
- req->state = EC_REQUEST_IN_PROGRESS;
+ req->state = EC_REQUEST_BUSY;
if (slave->current_state == EC_SLAVE_STATE_INIT ||
slave->error_flag) {
@@ -420,7 +420,7 @@
request = list_entry(master->slave_sdo_requests.next,
ec_master_sdo_request_t, list);
list_del_init(&request->list); // dequeue
- request->req.state = EC_REQUEST_IN_PROGRESS;
+ request->req.state = EC_REQUEST_BUSY;
up(&master->sdo_sem);
slave = request->slave;
@@ -499,7 +499,7 @@
if (fsm->config_error)
master->config_state = EC_REQUEST_FAILURE;
else
- master->config_state = EC_REQUEST_COMPLETE;
+ master->config_state = EC_REQUEST_SUCCESS;
wake_up_interruptible(&master->config_queue);
return 0;
}
@@ -522,7 +522,7 @@
if (!master->allow_config) {
up(&master->config_sem);
} else {
- master->config_state = EC_REQUEST_IN_PROGRESS;
+ master->config_state = EC_REQUEST_BUSY;
fsm->config_error = 0;
up(&master->config_sem);
@@ -938,7 +938,7 @@
ec_master_eoe_start(master);
#endif
- master->scan_state = EC_REQUEST_COMPLETE;
+ master->scan_state = EC_REQUEST_SUCCESS;
wake_up_interruptible(&master->scan_queue);
fsm->state = ec_fsm_master_state_end;
@@ -1007,7 +1007,7 @@
if (master->debug_level)
EC_DBG("Finished writing %u words of EEPROM data to slave %u.\n",
request->word_size, slave->ring_position);
- request->state = EC_REQUEST_COMPLETE;
+ request->state = EC_REQUEST_SUCCESS;
wake_up(&master->eeprom_queue);
// TODO: Evaluate new EEPROM contents!
@@ -1072,7 +1072,7 @@
}
// Sdo request finished
- request->state = EC_REQUEST_COMPLETE;
+ request->state = EC_REQUEST_SUCCESS;
wake_up(&master->sdo_queue);
if (master->debug_level)
--- a/master/globals.h Tue Mar 04 11:20:48 2008 +0000
+++ b/master/globals.h Tue Mar 04 11:37:51 2008 +0000
@@ -191,6 +191,21 @@
/*****************************************************************************/
+/** Generic request state.
+ *
+ * \attention If ever changing this, please be sure to adjust the \a
+ * state_table in master/sdo_request.c.
+ */
+typedef enum {
+ EC_REQUEST_INIT,
+ EC_REQUEST_QUEUED,
+ EC_REQUEST_BUSY,
+ EC_REQUEST_SUCCESS,
+ EC_REQUEST_FAILURE
+} ec_request_state_t;
+
+/*****************************************************************************/
+
/** Origin type.
*/
typedef enum {
--- a/master/master.c Tue Mar 04 11:20:48 2008 +0000
+++ b/master/master.c Tue Mar 04 11:37:51 2008 +0000
@@ -126,12 +126,12 @@
INIT_LIST_HEAD(&master->configs);
- master->scan_state = EC_REQUEST_COMPLETE;
+ master->scan_state = EC_REQUEST_SUCCESS;
master->allow_scan = 1;
init_MUTEX(&master->scan_sem);
init_waitqueue_head(&master->scan_queue);
- master->config_state = EC_REQUEST_COMPLETE;
+ master->config_state = EC_REQUEST_SUCCESS;
master->allow_config = 1;
init_MUTEX(&master->config_sem);
init_waitqueue_head(&master->config_queue);
@@ -446,7 +446,7 @@
// wait for slave configuration to complete
if (wait_event_interruptible(master->config_queue,
- master->config_state != EC_REQUEST_IN_PROGRESS)) {
+ master->config_state != EC_REQUEST_BUSY)) {
EC_INFO("Finishing slave configuration interrupted by signal.\n");
goto out_allow;
}
@@ -461,10 +461,10 @@
master->allow_scan = 0; // 'lock' the slave list
up(&master->scan_sem);
- if (master->scan_state == EC_REQUEST_IN_PROGRESS) {
+ if (master->scan_state == EC_REQUEST_BUSY) {
// wait for slave scan to complete
if (wait_event_interruptible(master->scan_queue,
- master->scan_state != EC_REQUEST_IN_PROGRESS)) {
+ master->scan_state != EC_REQUEST_BUSY)) {
EC_INFO("Waiting for slave scan interrupted by signal.\n");
goto out_allow;
}
@@ -1356,14 +1356,14 @@
if (master->main_device.link_state) {
// wait for configuration to complete
- master->config_state = EC_REQUEST_IN_PROGRESS;
+ master->config_state = EC_REQUEST_BUSY;
if (wait_event_interruptible(master->config_queue,
- master->config_state != EC_REQUEST_IN_PROGRESS)) {
+ master->config_state != EC_REQUEST_BUSY)) {
EC_INFO("Waiting for configuration interrupted by signal.\n");
return -1;
}
- if (master->config_state != EC_REQUEST_COMPLETE) {
+ if (master->config_state != EC_REQUEST_SUCCESS) {
EC_ERR("Failed to configure slaves.\n");
return -1;
}
--- a/master/sdo_entry.c Tue Mar 04 11:20:48 2008 +0000
+++ b/master/sdo_entry.c Tue Mar 04 11:37:51 2008 +0000
@@ -291,9 +291,9 @@
}
// wait until master FSM has finished processing
- wait_event(master->sdo_queue, request.req.state != EC_REQUEST_IN_PROGRESS);
-
- if (request.req.state != EC_REQUEST_COMPLETE)
+ wait_event(master->sdo_queue, request.req.state != EC_REQUEST_BUSY);
+
+ if (request.req.state != EC_REQUEST_SUCCESS)
return -EIO;
off += ec_sdo_entry_format_data(entry, &request.req, buffer);
--- a/master/sdo_request.c Tue Mar 04 11:20:48 2008 +0000
+++ b/master/sdo_request.c Tue Mar 04 11:37:51 2008 +0000
@@ -48,6 +48,18 @@
/*****************************************************************************/
+/** State type translation table.
+ */
+const ec_sdo_request_state_t state_table[] = {
+ EC_SDO_REQUEST_UNUSED, // EC_REQUEST_INIT,
+ EC_SDO_REQUEST_BUSY, // EC_REQUEST_QUEUED,
+ EC_SDO_REQUEST_BUSY, // EC_REQUEST_BUSY,
+ EC_SDO_REQUEST_SUCCESS, // EC_REQUEST_SUCCESS,
+ EC_SDO_REQUEST_ERROR // EC_REQUEST_FAILURE
+};
+
+/*****************************************************************************/
+
/** Sdo request constructor.
*/
void ec_sdo_request_init(
@@ -58,7 +70,7 @@
req->mem_size = 0;
req->data_size = 0;
req->dir = EC_DIR_OUTPUT;
- req->state = EC_REQUEST_COMPLETE;
+ req->state = EC_REQUEST_INIT;
}
/*****************************************************************************/
@@ -166,16 +178,9 @@
/*****************************************************************************/
-ec_request_state_t ecrt_sdo_request_state(const ec_sdo_request_t *req)
-{
- return req->state;
-}
-
-/*****************************************************************************/
-
-ec_sdo_request_error_t ecrt_sdo_request_error(const ec_sdo_request_t *req)
-{
- return EC_SDO_REQUEST_SUCCESS; // FIXME
+ec_sdo_request_state_t ecrt_sdo_request_state(const ec_sdo_request_t *req)
+{
+ return state_table[req->state];
}
/*****************************************************************************/
@@ -199,7 +204,6 @@
EXPORT_SYMBOL(ecrt_sdo_request_timeout);
EXPORT_SYMBOL(ecrt_sdo_request_data);
EXPORT_SYMBOL(ecrt_sdo_request_state);
-EXPORT_SYMBOL(ecrt_sdo_request_error);
EXPORT_SYMBOL(ecrt_sdo_request_read);
EXPORT_SYMBOL(ecrt_sdo_request_write);
--- a/master/slave.c Tue Mar 04 11:20:48 2008 +0000
+++ b/master/slave.c Tue Mar 04 11:37:51 2008 +0000
@@ -860,9 +860,9 @@
// wait until master FSM has finished processing
wait_event(master->eeprom_queue,
- request->state != EC_REQUEST_IN_PROGRESS);
-
- return request->state == EC_REQUEST_COMPLETE ? 0 : -EIO;
+ request->state != EC_REQUEST_BUSY);
+
+ return request->state == EC_REQUEST_SUCCESS ? 0 : -EIO;
}
/*****************************************************************************/