Used ERR_PTR() macro for return value of ecrt_request_master().
This commit is contained in:
parent
1076cba8ca
commit
96d794582e
|
|
@ -35,6 +35,7 @@
|
|||
#include <linux/timer.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/err.h>
|
||||
|
||||
#include "../../include/ecrt.h" // EtherCAT realtime interface
|
||||
|
||||
|
|
@ -368,6 +369,7 @@ void release_lock(void *data)
|
|||
|
||||
int __init init_mini_module(void)
|
||||
{
|
||||
int ret = -1;
|
||||
#if CONFIGURE_PDOS
|
||||
ec_slave_config_t *sc;
|
||||
#endif
|
||||
|
|
@ -377,8 +379,10 @@ int __init init_mini_module(void)
|
|||
|
||||
printk(KERN_INFO PFX "Starting...\n");
|
||||
|
||||
if (!(master = ecrt_request_master(0))) {
|
||||
printk(KERN_ERR PFX "Requesting master 0 failed!\n");
|
||||
master = ecrt_request_master(0);
|
||||
if (IS_ERR(master)) {
|
||||
ret = PTR_ERR(master);
|
||||
printk(KERN_ERR PFX "Requesting master 0 failed.\n");
|
||||
goto out_return;
|
||||
}
|
||||
|
||||
|
|
@ -493,7 +497,7 @@ out_release_master:
|
|||
ecrt_release_master(master);
|
||||
out_return:
|
||||
printk(KERN_ERR PFX "Failed to load. Aborting.\n");
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
|
||||
// Linux
|
||||
#include <linux/module.h>
|
||||
#include <linux/err.h>
|
||||
|
||||
// RTAI
|
||||
#include <rtai_sched.h>
|
||||
|
|
@ -268,6 +269,7 @@ void release_lock(void *data)
|
|||
|
||||
int __init init_mod(void)
|
||||
{
|
||||
int ret = -1;
|
||||
RTIME tick_period, requested_ticks, now;
|
||||
#ifdef CONFIGURE_PDOS
|
||||
ec_slave_config_t *sc;
|
||||
|
|
@ -279,7 +281,10 @@ int __init init_mod(void)
|
|||
|
||||
t_critical = cpu_khz * 1000 / FREQUENCY - cpu_khz * INHIBIT_TIME / 1000;
|
||||
|
||||
if (!(master = ecrt_request_master(0))) {
|
||||
|
||||
master = ecrt_request_master(0);
|
||||
if (IS_ERR(master)) {
|
||||
ret = PTR_ERR(master);
|
||||
printk(KERN_ERR PFX "Requesting master 0 failed!\n");
|
||||
goto out_return;
|
||||
}
|
||||
|
|
@ -361,7 +366,7 @@ int __init init_mod(void)
|
|||
out_return:
|
||||
rt_sem_delete(&master_sem);
|
||||
printk(KERN_ERR PFX "Failed to load. Aborting.\n");
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
|||
|
|
@ -42,6 +42,10 @@
|
|||
* request a master, to map process data, to communicate with slaves via CoE
|
||||
* and to configure and activate the bus.
|
||||
*
|
||||
* Changes in version 1.5:
|
||||
*
|
||||
* - Changed the return value of ecrt_request_master().
|
||||
*
|
||||
* Changes in Version 1.4:
|
||||
*
|
||||
* - Replaced ec_slave_t with ec_slave_config_t, separating the bus
|
||||
|
|
@ -340,7 +344,11 @@ unsigned int ecrt_version_magic(void);
|
|||
* The first master has index 0, the n-th master has index n - 1. The number
|
||||
* of masters has to be specified when loading the master module.
|
||||
*
|
||||
* \return Pointer to reserved master, or \a NULL on error.
|
||||
* \attention In kernel context, the returned pointer has to be checked for
|
||||
* errors using the IS_ERR() macro.
|
||||
*
|
||||
* \return If \a IS_ERR() returns zero, the result is a pointer to the
|
||||
* reserved master, otherwise, the result is an error code.
|
||||
*/
|
||||
ec_master_t *ecrt_request_master(
|
||||
unsigned int master_index /**< Index of the master to request. */
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@
|
|||
|
||||
#include <linux/module.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/err.h>
|
||||
|
||||
#include "globals.h"
|
||||
#include "master.h"
|
||||
|
|
@ -463,39 +464,47 @@ ec_device_t *ecdev_offer(
|
|||
|
||||
ec_master_t *ecrt_request_master(unsigned int master_index)
|
||||
{
|
||||
ec_master_t *master;
|
||||
ec_master_t *master, *errptr = NULL;
|
||||
|
||||
EC_INFO("Requesting master %u...\n", master_index);
|
||||
|
||||
if (master_index >= master_count) {
|
||||
EC_ERR("Invalid master index %u.\n", master_index);
|
||||
errptr = ERR_PTR(-EINVAL);
|
||||
goto out_return;
|
||||
}
|
||||
master = &masters[master_index];
|
||||
|
||||
if (down_interruptible(&master_sem))
|
||||
if (down_interruptible(&master_sem)) {
|
||||
errptr = ERR_PTR(-EINTR);
|
||||
goto out_return;
|
||||
}
|
||||
|
||||
if (master->reserved) {
|
||||
up(&master_sem);
|
||||
EC_ERR("Master %u is already in use!\n", master_index);
|
||||
errptr = ERR_PTR(-EBUSY);
|
||||
goto out_return;
|
||||
}
|
||||
master->reserved = 1;
|
||||
up(&master_sem);
|
||||
|
||||
if (down_interruptible(&master->device_sem))
|
||||
if (down_interruptible(&master->device_sem)) {
|
||||
errptr = ERR_PTR(-EINTR);
|
||||
goto out_release;
|
||||
}
|
||||
|
||||
if (master->phase != EC_IDLE) {
|
||||
up(&master->device_sem);
|
||||
EC_ERR("Master %u still waiting for devices!\n", master_index);
|
||||
errptr = ERR_PTR(-ENODEV);
|
||||
goto out_release;
|
||||
}
|
||||
|
||||
if (!try_module_get(master->main_device.module)) {
|
||||
up(&master->device_sem);
|
||||
EC_ERR("Device module is unloading!\n");
|
||||
errptr = ERR_PTR(-ENODEV);
|
||||
goto out_release;
|
||||
}
|
||||
|
||||
|
|
@ -503,6 +512,7 @@ ec_master_t *ecrt_request_master(unsigned int master_index)
|
|||
|
||||
if (ec_master_enter_operation_phase(master)) {
|
||||
EC_ERR("Failed to enter OPERATION phase!\n");
|
||||
errptr = ERR_PTR(-EIO);
|
||||
goto out_module_put;
|
||||
}
|
||||
|
||||
|
|
@ -514,7 +524,7 @@ ec_master_t *ecrt_request_master(unsigned int master_index)
|
|||
out_release:
|
||||
master->reserved = 0;
|
||||
out_return:
|
||||
return NULL;
|
||||
return errptr;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
|||
Loading…
Reference in New Issue