mirror of
https://gitlab.com/etherlab.org/ethercat.git
synced 2026-02-06 03:41:52 +08:00
Callback set via own structure.
This commit is contained in:
@@ -376,6 +376,12 @@ int el60xx_cflag_changed(void *data, tcflag_t cflag)
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static ec_tty_operations_t el60xx_tty_ops = {
|
||||
.cflag_changed = el60xx_cflag_changed,
|
||||
};
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
int el60xx_port_init(el60xx_port_t *port, ec_slave_config_t *sc,
|
||||
ec_domain_t *domain, unsigned int slot_offset, const char *name)
|
||||
{
|
||||
@@ -383,7 +389,7 @@ int el60xx_port_init(el60xx_port_t *port, ec_slave_config_t *sc,
|
||||
|
||||
strncpy(port->name, name, EL6002_PORT_NAME_SIZE);
|
||||
|
||||
port->tty = ectty_create(el60xx_cflag_changed, port);
|
||||
port->tty = ectty_create(&el60xx_tty_ops, port);
|
||||
if (IS_ERR(port->tty)) {
|
||||
printk(KERN_ERR PFX "Failed to create tty for %s.\n",
|
||||
port->name);
|
||||
|
||||
@@ -49,22 +49,27 @@
|
||||
struct ec_tty;
|
||||
typedef struct ec_tty ec_tty_t; /**< \see ec_tty */
|
||||
|
||||
/**
|
||||
* \param cflag_changed This callback function is called when the serial
|
||||
* settings shall be changed. The \a cflag argument contains the new settings.
|
||||
*/
|
||||
typedef struct {
|
||||
int (*cflag_changed)(void *, tcflag_t);
|
||||
} ec_tty_operations_t;
|
||||
|
||||
/******************************************************************************
|
||||
* Global functions
|
||||
*****************************************************************************/
|
||||
|
||||
/** Create a virtual TTY interface.
|
||||
*
|
||||
* \param cflag_cb This callback function is called when the serial settings
|
||||
* shall be changed. The \a cb_data argument is the same as the \a cb_data
|
||||
* given on device creation, while the \a cflag argument contains the new
|
||||
* settings.
|
||||
* \param cb_data Arbitrary data to pass to callbacks.
|
||||
* \param ops Set of callbacks.
|
||||
* \param cb_data Arbitrary data, that is passed to any callback.
|
||||
*
|
||||
* \return Pointer to the interface object, otherwise an ERR_PTR value.
|
||||
*/
|
||||
ec_tty_t *ectty_create(
|
||||
int (*cflag_cb)(void *cb_data, tcflag_t cflag),
|
||||
const ec_tty_operations_t *ops,
|
||||
void *cb_data
|
||||
);
|
||||
|
||||
|
||||
23
tty/module.c
23
tty/module.c
@@ -110,7 +110,7 @@ struct ec_tty {
|
||||
struct timer_list timer;
|
||||
struct tty_struct *tty;
|
||||
|
||||
int (*cflag_cb)(void *, tcflag_t);
|
||||
ec_tty_operations_t ops;
|
||||
void *cb_data;
|
||||
};
|
||||
|
||||
@@ -184,7 +184,7 @@ void __exit ec_tty_cleanup_module(void)
|
||||
*****************************************************************************/
|
||||
|
||||
int ec_tty_init(ec_tty_t *tty, int minor,
|
||||
int (*cflag_cb)(void *, tcflag_t), void *cb_data)
|
||||
const ec_tty_operations_t *ops, void *cb_data)
|
||||
{
|
||||
tty->minor = minor;
|
||||
tty->tx_read_idx = 0;
|
||||
@@ -194,7 +194,7 @@ int ec_tty_init(ec_tty_t *tty, int minor,
|
||||
tty->rx_write_idx = 0;
|
||||
init_timer(&tty->timer);
|
||||
tty->tty = NULL;
|
||||
tty->cflag_cb = cflag_cb;
|
||||
tty->ops = *ops;
|
||||
tty->cb_data = cb_data;
|
||||
|
||||
tty->dev = tty_register_device(tty_driver, tty->minor, NULL);
|
||||
@@ -343,7 +343,7 @@ void ec_tty_wakeup(unsigned long data)
|
||||
static int ec_tty_open(struct tty_struct *tty, struct file *file)
|
||||
{
|
||||
ec_tty_t *t;
|
||||
int line = tty->index, ret;
|
||||
int line = tty->index;
|
||||
|
||||
#if EC_TTY_DEBUG >= 1
|
||||
printk(KERN_INFO PFX "Opening line %i.\n", line);
|
||||
@@ -364,15 +364,6 @@ static int ec_tty_open(struct tty_struct *tty, struct file *file)
|
||||
|
||||
t->tty = tty;
|
||||
tty->driver_data = t;
|
||||
|
||||
// request initial settings
|
||||
ret = t->cflag_cb(t->cb_data, t->tty->termios->c_cflag);
|
||||
if (ret) {
|
||||
printk(KERN_ERR PFX "Error: Device does not accept"
|
||||
" initial configuration!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -552,7 +543,7 @@ static void ec_tty_set_termios(struct tty_struct *tty,
|
||||
old_termios->c_cflag, tty->termios->c_cflag);
|
||||
#endif
|
||||
|
||||
ret = t->cflag_cb(t->cb_data, tty->termios->c_cflag);
|
||||
ret = t->ops.cflag_changed(t->cb_data, tty->termios->c_cflag);
|
||||
if (ret) {
|
||||
printk(KERN_ERR PFX "ERROR: cflag 0x%x not accepted.\n",
|
||||
tty->termios->c_cflag);
|
||||
@@ -646,7 +637,7 @@ static const struct tty_operations ec_tty_ops = {
|
||||
* Public functions and methods
|
||||
*****************************************************************************/
|
||||
|
||||
ec_tty_t *ectty_create(int (*cflag_cb)(void *, tcflag_t), void *cb_data)
|
||||
ec_tty_t *ectty_create(const ec_tty_operations_t *ops, void *cb_data)
|
||||
{
|
||||
ec_tty_t *tty;
|
||||
int minor, ret;
|
||||
@@ -666,7 +657,7 @@ ec_tty_t *ectty_create(int (*cflag_cb)(void *, tcflag_t), void *cb_data)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
}
|
||||
|
||||
ret = ec_tty_init(tty, minor, cflag_cb, cb_data);
|
||||
ret = ec_tty_init(tty, minor, ops, cb_data);
|
||||
if (ret) {
|
||||
up(&tty_sem);
|
||||
kfree(tty);
|
||||
|
||||
Reference in New Issue
Block a user