examples/tty/serial.c
changeset 1779 9fab229d6ca9
parent 1615 020ad9ad3afb
child 1780 11f452ca4d7a
equal deleted inserted replaced
1778:94dbb44884ec 1779:9fab229d6ca9
    27  *
    27  *
    28  *****************************************************************************/
    28  *****************************************************************************/
    29 
    29 
    30 #include <linux/module.h>
    30 #include <linux/module.h>
    31 #include <linux/err.h>
    31 #include <linux/err.h>
       
    32 #include <linux/termios.h>
    32 
    33 
    33 #include "../../include/ecrt.h" // EtherCAT realtime interface
    34 #include "../../include/ecrt.h" // EtherCAT realtime interface
    34 #include "../../include/ectty.h" // EtherCAT TTY interface
    35 #include "../../include/ectty.h" // EtherCAT TTY interface
    35 
    36 
    36 /*****************************************************************************/
    37 /*****************************************************************************/
   198    {0xff}
   199    {0xff}
   199 };
   200 };
   200 
   201 
   201 /****************************************************************************/
   202 /****************************************************************************/
   202 
   203 
       
   204 int el6002_cflag_changed(void *data, unsigned short cflag)
       
   205 {
       
   206     el6002_t *ser = (el6002_t *) data;
       
   207     int cs = 0, stop, par;
       
   208 
       
   209     printk(KERN_INFO PFX "%s(data=%p, cflag=%x).\n", __func__, ser, cflag);
       
   210 
       
   211     switch (cflag & CSIZE) {
       
   212         case CS7:
       
   213             cs = 7;
       
   214             break;
       
   215         case CS8:
       
   216             cs = 8;
       
   217             break;
       
   218         default: /* CS5 or CS6 */
       
   219             return -EINVAL; // not supported
       
   220     }
       
   221 
       
   222     stop = (cflag & CSTOPB) ? 2 : 1;
       
   223 
       
   224     if (cflag & PARENB) {
       
   225         par = (cflag & PARODD) ? 1 : 2;
       
   226     } else {
       
   227         par = 0;
       
   228     }
       
   229 
       
   230     printk(KERN_INFO PFX "CS%u stopb=%u par=%i.\n", cs, stop, par);
       
   231 
       
   232     return 0;
       
   233 }
       
   234 
       
   235 /****************************************************************************/
       
   236 
   203 int el6002_init(el6002_t *ser, ec_master_t *master, u16 position,
   237 int el6002_init(el6002_t *ser, ec_master_t *master, u16 position,
   204         ec_domain_t *domain)
   238         ec_domain_t *domain)
   205 {
   239 {
   206     int ret = 0;
   240     int ret = 0;
   207 
   241 
   208     ser->tty = ectty_create();
   242     ser->tty = ectty_create(el6002_cflag_changed, ser);
   209     if (IS_ERR(ser->tty)) {
   243     if (IS_ERR(ser->tty)) {
   210         printk(KERN_ERR PFX "Failed to create tty.\n");
   244         printk(KERN_ERR PFX "Failed to create tty.\n");
   211         ret = PTR_ERR(ser->tty);
   245         ret = PTR_ERR(ser->tty);
   212         goto out_return;
   246         goto out_return;
   213     }
   247     }