examples/tty/tty.c
changeset 1573 74bf584564b8
parent 1567 1babaa430b7b
child 1575 17598f2332b6
equal deleted inserted replaced
1572:b306e6976682 1573:74bf584564b8
    38 #else
    38 #else
    39 #include <asm/semaphore.h>
    39 #include <asm/semaphore.h>
    40 #endif
    40 #endif
    41 
    41 
    42 #include "../../include/ecrt.h" // EtherCAT realtime interface
    42 #include "../../include/ecrt.h" // EtherCAT realtime interface
       
    43 #include "../../include/ectty.h" // EtherCAT TTY interface
    43 
    44 
    44 /*****************************************************************************/
    45 /*****************************************************************************/
    45 
    46 
    46 // Module parameters
    47 // Module parameters
    47 #define FREQUENCY 100
    48 #define FREQUENCY 100
   115 } serial_device_t;
   116 } serial_device_t;
   116 
   117 
   117 static serial_device_t *ser = NULL;
   118 static serial_device_t *ser = NULL;
   118 static char tx_data[] = "ATZ\r\n";
   119 static char tx_data[] = "ATZ\r\n";
   119 static off_t tx_off = 0;
   120 static off_t tx_off = 0;
       
   121 static ec_tty_t *tty = NULL;
   120         
   122         
   121 /*****************************************************************************/
   123 /*****************************************************************************/
   122 
   124 
   123 /* Slave 1, "EL6002"
   125 /* Slave 1, "EL6002"
   124  * Vendor ID:       0x00000002
   126  * Vendor ID:       0x00000002
   442     ec_slave_config_t *sc;
   444     ec_slave_config_t *sc;
   443     
   445     
   444     printk(KERN_INFO PFX "Starting...\n");
   446     printk(KERN_INFO PFX "Starting...\n");
   445 
   447 
   446     ser = kmalloc(sizeof(*ser), GFP_KERNEL);
   448     ser = kmalloc(sizeof(*ser), GFP_KERNEL);
   447     if (ser == NULL) {
   449     if (!ser) {
   448         printk(KERN_ERR PFX "Failed to allocate serial device object.\n");
   450         printk(KERN_ERR PFX "Failed to allocate serial device object.\n");
   449         return -ENOMEM;
   451         ret = -ENOMEM;
   450     }
   452         goto out_return;
       
   453     }
       
   454 
   451     ret = serial_init(ser, 22, 22);
   455     ret = serial_init(ser, 22, 22);
   452     if (ret) {
   456     if (ret) {
   453         printk(KERN_ERR PFX "Failed to init serial device object.\n");
   457         printk(KERN_ERR PFX "Failed to init serial device object.\n");
   454         return ret;
   458         goto out_free_serial;
       
   459     }
       
   460 
       
   461     tty = ectty_create();
       
   462     if (IS_ERR(tty)) {
       
   463         printk(KERN_ERR PFX "Failed to create tty.\n");
       
   464         ret = PTR_ERR(tty);
       
   465         goto out_serial;
   455     }
   466     }
   456     
   467     
   457     master = ecrt_request_master(0);
   468     master = ecrt_request_master(0);
   458     if (!master) {
   469     if (!master) {
   459         ret = -EBUSY; 
   470         ret = -EBUSY; 
   460         printk(KERN_ERR PFX "Requesting master 0 failed.\n");
   471         printk(KERN_ERR PFX "Requesting master 0 failed.\n");
   461         goto out_return;
   472         goto out_tty;
   462     }
   473     }
   463 
   474 
   464     init_MUTEX(&master_sem);
   475     init_MUTEX(&master_sem);
   465     ecrt_master_callbacks(master, send_callback, receive_callback, master);
   476     ecrt_master_callbacks(master, send_callback, receive_callback, master);
   466 
   477 
   511     return 0;
   522     return 0;
   512 
   523 
   513 out_release_master:
   524 out_release_master:
   514     printk(KERN_ERR PFX "Releasing master...\n");
   525     printk(KERN_ERR PFX "Releasing master...\n");
   515     ecrt_release_master(master);
   526     ecrt_release_master(master);
       
   527 out_tty:
       
   528     ectty_free(tty);
       
   529 out_serial:
       
   530     serial_clear(ser);
       
   531 out_free_serial:
       
   532     kfree(ser);
   516 out_return:
   533 out_return:
   517     printk(KERN_ERR PFX "Failed to load. Aborting.\n");
   534     printk(KERN_ERR PFX "Failed to load. Aborting.\n");
   518     return ret;
   535     return ret;
   519 }
   536 }
   520 
   537 
   527     del_timer_sync(&timer);
   544     del_timer_sync(&timer);
   528 
   545 
   529     printk(KERN_INFO PFX "Releasing master...\n");
   546     printk(KERN_INFO PFX "Releasing master...\n");
   530     ecrt_release_master(master);
   547     ecrt_release_master(master);
   531 
   548 
       
   549     ectty_free(tty);
       
   550     serial_clear(ser);
       
   551     kfree(ser);
       
   552 
   532     printk(KERN_INFO PFX "Unloading.\n");
   553     printk(KERN_INFO PFX "Unloading.\n");
   533 }
   554 }
   534 
   555 
   535 /*****************************************************************************/
   556 /*****************************************************************************/
   536 
   557