Skip to content
Snippets Groups Projects
Commit a9fbf2c2 authored by Florian Pose's avatar Florian Pose
Browse files

Create tty.

parent a2464ebe
No related branches found
No related tags found
No related merge requests found
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#endif #endif
#include "../../include/ecrt.h" // EtherCAT realtime interface #include "../../include/ecrt.h" // EtherCAT realtime interface
#include "../../include/ectty.h" // EtherCAT TTY interface
/*****************************************************************************/ /*****************************************************************************/
...@@ -117,6 +118,7 @@ typedef struct { ...@@ -117,6 +118,7 @@ typedef struct {
static serial_device_t *ser = NULL; static serial_device_t *ser = NULL;
static char tx_data[] = "ATZ\r\n"; static char tx_data[] = "ATZ\r\n";
static off_t tx_off = 0; static off_t tx_off = 0;
static ec_tty_t *tty = NULL;
/*****************************************************************************/ /*****************************************************************************/
...@@ -444,21 +446,30 @@ int __init init_mini_module(void) ...@@ -444,21 +446,30 @@ int __init init_mini_module(void)
printk(KERN_INFO PFX "Starting...\n"); printk(KERN_INFO PFX "Starting...\n");
ser = kmalloc(sizeof(*ser), GFP_KERNEL); ser = kmalloc(sizeof(*ser), GFP_KERNEL);
if (ser == NULL) { if (!ser) {
printk(KERN_ERR PFX "Failed to allocate serial device object.\n"); printk(KERN_ERR PFX "Failed to allocate serial device object.\n");
return -ENOMEM; ret = -ENOMEM;
goto out_return;
} }
ret = serial_init(ser, 22, 22); ret = serial_init(ser, 22, 22);
if (ret) { if (ret) {
printk(KERN_ERR PFX "Failed to init serial device object.\n"); printk(KERN_ERR PFX "Failed to init serial device object.\n");
return ret; goto out_free_serial;
}
tty = ectty_create();
if (IS_ERR(tty)) {
printk(KERN_ERR PFX "Failed to create tty.\n");
ret = PTR_ERR(tty);
goto out_serial;
} }
master = ecrt_request_master(0); master = ecrt_request_master(0);
if (!master) { if (!master) {
ret = -EBUSY; ret = -EBUSY;
printk(KERN_ERR PFX "Requesting master 0 failed.\n"); printk(KERN_ERR PFX "Requesting master 0 failed.\n");
goto out_return; goto out_tty;
} }
init_MUTEX(&master_sem); init_MUTEX(&master_sem);
...@@ -513,6 +524,12 @@ int __init init_mini_module(void) ...@@ -513,6 +524,12 @@ int __init init_mini_module(void)
out_release_master: out_release_master:
printk(KERN_ERR PFX "Releasing master...\n"); printk(KERN_ERR PFX "Releasing master...\n");
ecrt_release_master(master); ecrt_release_master(master);
out_tty:
ectty_free(tty);
out_serial:
serial_clear(ser);
out_free_serial:
kfree(ser);
out_return: out_return:
printk(KERN_ERR PFX "Failed to load. Aborting.\n"); printk(KERN_ERR PFX "Failed to load. Aborting.\n");
return ret; return ret;
...@@ -529,6 +546,10 @@ void __exit cleanup_mini_module(void) ...@@ -529,6 +546,10 @@ void __exit cleanup_mini_module(void)
printk(KERN_INFO PFX "Releasing master...\n"); printk(KERN_INFO PFX "Releasing master...\n");
ecrt_release_master(master); ecrt_release_master(master);
ectty_free(tty);
serial_clear(ser);
kfree(ser);
printk(KERN_INFO PFX "Unloading.\n"); printk(KERN_INFO PFX "Unloading.\n");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment