Introduced ec_sdo_request_state_t, making ec_request_t private again;
therefore added EC_REQUEST_INIT and renamed EC_REQUEST_IN_PROGRESS to EC_REQUEST_BUSY and EC_REQUEST_COMPLETE to EC_REQUEST_SUCCESS.
This commit is contained in:
parent
a5e68a7f60
commit
f28f42ceb1
|
|
@ -117,7 +117,6 @@ static ec_pdo_info_t el2004_mapping[] = {
|
|||
|
||||
#ifdef SDO_ACCESS
|
||||
static ec_sdo_request_t *sdo;
|
||||
static int not_first_time = 0;
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
@ -169,22 +168,21 @@ void check_master_state(void)
|
|||
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
|
||||
|
|
|
|||
|
|
@ -253,25 +253,16 @@ typedef struct {
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
/** Generic request state.
|
||||
*/
|
||||
typedef enum {
|
||||
EC_REQUEST_QUEUED,
|
||||
EC_REQUEST_IN_PROGRESS,
|
||||
EC_REQUEST_COMPLETE,
|
||||
EC_REQUEST_FAILURE
|
||||
} ec_request_state_t;
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/** Sdo request error.
|
||||
/** Sdo request state.
|
||||
*
|
||||
* This is used as return type of ecrt_sdo_request_error().
|
||||
* This is used as return type of ecrt_sdo_request_state().
|
||||
*/
|
||||
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 @@ void ecrt_sdo_request_timeout(
|
|||
|
||||
/** 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,13 +656,7 @@ uint8_t *ecrt_sdo_request_data(
|
|||
*
|
||||
* \return Request state.
|
||||
*/
|
||||
ec_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(
|
||||
ec_sdo_request_state_t ecrt_sdo_request_state(
|
||||
const ec_sdo_request_t *req /**< Sdo request. */
|
||||
);
|
||||
|
||||
|
|
@ -685,8 +669,8 @@ void ecrt_sdo_request_write(
|
|||
/** 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. */
|
||||
|
|
|
|||
|
|
@ -238,7 +238,7 @@ void ec_fsm_master_state_broadcast(ec_fsm_master_t *fsm /**< master state machin
|
|||
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 @@ void ec_fsm_master_state_broadcast(ec_fsm_master_t *fsm /**< master state machin
|
|||
|
||||
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 @@ int ec_fsm_master_action_process_eeprom(
|
|||
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 @@ int ec_fsm_master_action_process_sdo(
|
|||
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 @@ int ec_fsm_master_action_process_sdo(
|
|||
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 @@ int ec_fsm_master_action_configure(
|
|||
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 @@ void ec_fsm_master_action_process_states(ec_fsm_master_t *fsm
|
|||
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 @@ void ec_fsm_master_state_scan_slaves(
|
|||
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 @@ void ec_fsm_master_state_write_eeprom(
|
|||
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 @@ void ec_fsm_master_state_sdo_request(ec_fsm_master_t *fsm /**< master state mach
|
|||
}
|
||||
|
||||
// Sdo request finished
|
||||
request->state = EC_REQUEST_COMPLETE;
|
||||
request->state = EC_REQUEST_SUCCESS;
|
||||
wake_up(&master->sdo_queue);
|
||||
|
||||
if (master->debug_level)
|
||||
|
|
|
|||
|
|
@ -191,6 +191,21 @@ typedef struct {
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
/** 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 {
|
||||
|
|
|
|||
|
|
@ -126,12 +126,12 @@ int ec_master_init(ec_master_t *master, /**< EtherCAT master */
|
|||
|
||||
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 @@ int ec_master_enter_operation_mode(ec_master_t *master /**< EtherCAT master */)
|
|||
|
||||
// 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 @@ int ec_master_enter_operation_mode(ec_master_t *master /**< EtherCAT master */)
|
|||
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 @@ int ecrt_master_activate(ec_master_t *master)
|
|||
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -291,9 +291,9 @@ ssize_t ec_sdo_entry_read_value(
|
|||
}
|
||||
|
||||
// wait until master FSM has finished processing
|
||||
wait_event(master->sdo_queue, request.req.state != EC_REQUEST_IN_PROGRESS);
|
||||
wait_event(master->sdo_queue, request.req.state != EC_REQUEST_BUSY);
|
||||
|
||||
if (request.req.state != EC_REQUEST_COMPLETE)
|
||||
if (request.req.state != EC_REQUEST_SUCCESS)
|
||||
return -EIO;
|
||||
|
||||
off += ec_sdo_entry_format_data(entry, &request.req, buffer);
|
||||
|
|
|
|||
|
|
@ -48,6 +48,18 @@ void ec_sdo_request_clear_data(ec_sdo_request_t *);
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
/** 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 @@ void ec_sdo_request_init(
|
|||
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 @@ uint8_t *ecrt_sdo_request_data(ec_sdo_request_t *req)
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
ec_request_state_t ecrt_sdo_request_state(const ec_sdo_request_t *req)
|
||||
ec_sdo_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
|
||||
return state_table[req->state];
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
@ -199,7 +204,6 @@ void ecrt_sdo_request_write(ec_sdo_request_t *req)
|
|||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -860,9 +860,9 @@ int ec_slave_schedule_eeprom_writing(
|
|||
|
||||
// wait until master FSM has finished processing
|
||||
wait_event(master->eeprom_queue,
|
||||
request->state != EC_REQUEST_IN_PROGRESS);
|
||||
request->state != EC_REQUEST_BUSY);
|
||||
|
||||
return request->state == EC_REQUEST_COMPLETE ? 0 : -EIO;
|
||||
return request->state == EC_REQUEST_SUCCESS ? 0 : -EIO;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
|||
Loading…
Reference in New Issue