Bienvenue visiteur (Inscription |  Connexion)
Qui est en ligne ?
Il y a : 22 utilisateurs en ligne, consultez le détail
Auteur Message
nuggets
#0 Message posté le : 12-07-2008 à 20:07:28


Scarabée


Forum : Inscrit
Association :
Arrivé(e) le : 09-12-2005
Nombre de messages : 189
Bonjour,

j'essaie d'utiliser le driver tiny_serial donné par Linux device driver.
Il compile et se charge mais quand je fais cat > /dev/mydriver et que je tape une lire j'obtiens l'erreur : Erreur d'écriture.: Erreur d'entrée/sortie

Est ce qu'il y a une erreur dans le driver ou bien une erreur d'utilisation ?
Merci



   1. /*

   2. * Tiny Serial driver

   3. *

   4. * Copyright (C) 2002-2004 Greg Kroah-Hartman (greg@kroah.com)

   5. *

   6. * This program is free software; you can redistribute it and/or modify

   7. * it under the terms of the GNU General Public License as published by

   8. * the Free Software Foundation, version 2 of the License.

   9. *

  10. * This driver shows how to create a minimal serial driver.  It does not rely on

  11. * any backing hardware, but creates a timer that emulates data being received

  12. * from some kind of hardware.

  13. */

  14.

  15. #include <linux/kernel.h>

  16. #include <linux/errno.h>

  17. #include <linux/init.h>

  18. #include <linux/slab.h>

  19. #include <linux/tty.h>

  20. #include <linux/tty_flip.h>

  21. #include <linux/serial.h>

  22. #include <linux/serial_core.h>

  23. #include <linux/module.h>

  24.

  25.

  26. #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>"

  27. #define DRIVER_DESC "Tiny serial driver"

  28.

  29. /* Module information */

  30. MODULE_AUTHOR( DRIVER_AUTHOR );

  31. MODULE_DESCRIPTION( DRIVER_DESC );

  32. MODULE_LICENSE("GPL" );

  33.

  34. #define DELAY_TIME  HZ * 2 /* 2 seconds per character */

  35. #define TINY_DATA_CHARACTER 't'

  36.

  37. #define TINY_SERIAL_MAJOR 240 /* experimental range */

  38. #define TINY_SERIAL_MINORS 1 /* only have one minor */

  39. #define UART_NR   1 /* only use one port */

  40.

  41. #define TINY_SERIAL_NAME "ttytiny"

  42.

  43. #define MY_NAME   TINY_SERIAL_NAME

  44.

  45. static struct timer_list *timer;

  46.

  47. static void tiny_stop_tx(struct uart_port *port)

  48. {

  49. }

  50.

  51. static void tiny_stop_rx(struct uart_port *port)

  52. {

  53. }

  54.

  55. static void tiny_enable_ms(struct uart_port *port)

  56. {

  57. }

  58.

  59. static void tiny_tx_chars(struct uart_port *port)

  60. {

  61.   struct circ_buf *xmit = &port->info->xmit;

  62.   int count;

  63.

  64.   printk(KERN_INFO "tx_char\n" );

  65.   if (port->x_char) {

  66.     pr_debug("wrote %2x", port->x_char);

  67.     port->icount.tx++;

  68.     port->x_char = 0;

  69.     return;

  70.   }

  71.   if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {

  72.     tiny_stop_tx(port);

  73.     return;

  74.   }

  75.

  76.   count = port->fifosize >> 1;

  77.   do {

  78.     pr_debug("wrote %2x", xmit->buf[xmit->tail]);

  79.     xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);

  80.     port->icount.tx++;

  81.     if (uart_circ_empty(xmit))

  82.       break;

  83.   } while (--count > 0);

  84.

  85.   if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)

  86.     uart_write_wakeup(port);

  87.

  88.   if (uart_circ_empty(xmit))

  89.     tiny_stop_tx(port);

  90. }

  91.

  92. static void tiny_start_tx(struct uart_port *port)

  93. {

  94. }

  95.

  96. static void tiny_timer(unsigned long data)

  97. {

  98.   struct uart_port *port;

  99.   struct tty_struct *tty;

 100.

 101.

 102.   port = (struct uart_port *)data;

 103.   if (!port)

 104.     return;

 105.   if (!port->info)

 106.     return;

 107.   tty = port->info->tty;

 108.   if (!tty)

 109.     return;

 110.

 111.   /* add one character to the tty port */

 112.   /* this doesn't actually push the data through unless tty->low_latency is set */

 113.   tty_insert_flip_char(tty, TINY_DATA_CHARACTER, 0);

 114.

 115.   tty_flip_buffer_push(tty);

 116.

 117.   /* resubmit the timer again */

 118.   timer->expires = jiffies + DELAY_TIME;

 119.   add_timer(timer);

 120.

 121.   /* see if we have any data to transmit */

 122.   tiny_tx_chars(port);

 123. }

 124.

 125. static unsigned int tiny_tx_empty(struct uart_port *port)

 126. {

 127.   return 0;

 128. }

 129.

 130. static unsigned int tiny_get_mctrl(struct uart_port *port)

 131. {

 132.   return 0;

 133. }

 134.

 135. static void tiny_set_mctrl(struct uart_port *port, unsigned int mctrl)

 136. {

 137. }

 138.

 139. static void tiny_break_ctl(struct uart_port *port, int break_state)

 140. {

 141. }

 142.

 143. static void tiny_set_termios(struct uart_port *port,

 144.                              struct ktermios *new, struct ktermios *old)

 145. {

 146.   int baud, quot, cflag = new->c_cflag;

 147.   /* get the byte size */

 148.   switch (cflag & CSIZE) {

 149.     case CS5:

 150.       printk(KERN_DEBUG " - data bits = 5\n" );

 151.       break;

 152.     case CS6:

 153.       printk(KERN_DEBUG " - data bits = 6\n" );

 154.       break;

 155.     case CS7:

 156.       printk(KERN_DEBUG " - data bits = 7\n" );

 157.       break;

 158.     default: // CS8

 159.       printk(KERN_DEBUG " - data bits = 8\n" );

 160.       break;

 161.   }

 162.

 163.   /* determine the parity */

 164.   if (cflag & PARENB)

 165.     if (cflag & PARODD)

 166.       pr_debug(" - parity = odd\n" );

 167.     else

 168.       pr_debug(" - parity = even\n" );

 169.   else

 170.     pr_debug(" - parity = none\n" );

 171.

 172.   /* figure out the stop bits requested */

 173.   if (cflag & CSTOPB)

 174.     pr_debug(" - stop bits = 2\n" );

 175.   else

 176.     pr_debug(" - stop bits = 1\n" );

 177.

 178.   /* figure out the flow control settings */

 179.   if (cflag & CRTSCTS)

 180.     pr_debug(" - RTS/CTS is enabled\n" );

 181.   else

 182.     pr_debug(" - RTS/CTS is disabled\n" );

 183.

 184.   /* Set baud rate */

 185.   //baud = uart_get_baud_rate(port, new, old, 0, port->uartclk/16);

 186.   //quot = uart_get_divisor(port, baud);

 187.

 188.   //UART_PUT_DIV_LO(port, (quot & 0xff));

 189.   //UART_PUT_DIV_HI(port, ((quot & 0xf00) >> 8));

 190. }

 191.

 192. static int tiny_startup(struct uart_port *port)

 193. {

 194.   /* this is the first time this port is opened */

 195.   /* do any hardware initialization needed here */

 196.

 197.   /* create our timer and submit it */

 198.   if (!timer) {

 199.     timer = kmalloc(sizeof(*timer), GFP_KERNEL);

 200.     if (!timer)

 201.       return -ENOMEM;

 202.   }

 203.   timer->data = (unsigned long)port;

 204.   timer->expires = jiffies + DELAY_TIME;

 205.   timer->function = tiny_timer;

 206.   add_timer(timer);

 207.   return 0;

 208. }

 209.

 210. static void tiny_shutdown(struct uart_port *port)

 211. {

 212.   /* The port is being closed by the last user. */

 213.   /* Do any hardware specific stuff here */

 214.

 215.   /* shut down our timer */

 216.   del_timer(timer);

 217. }

 218.

 219. static const char *tiny_type(struct uart_port *port)

 220. {

 221.   return "tinytty";

 222. }

 223.

 224. static void tiny_release_port(struct uart_port *port)

 225. {

 226.

 227. }

 228.

 229. static int tiny_request_port(struct uart_port *port)

 230. {

 231.   return 0;

 232. }

 233.

 234. static void tiny_config_port(struct uart_port *port, int flags)

 235. {

 236. }

 237.

 238. static int tiny_verify_port(struct uart_port *port, struct serial_struct *ser)

 239. {

 240.   return 0;

 241. }

 242.

 243. static struct uart_ops tiny_ops = {

 244.   .tx_empty = tiny_tx_empty,

 245.   .set_mctrl = tiny_set_mctrl,

 246.   .get_mctrl = tiny_get_mctrl,

 247.   .stop_tx = tiny_stop_tx,

 248.   .start_tx = tiny_start_tx,

 249.   .stop_rx = tiny_stop_rx,

 250.   .enable_ms = tiny_enable_ms,

 251.   .break_ctl = tiny_break_ctl,

 252.   .startup = tiny_startup,

 253.   .shutdown = tiny_shutdown,

 254.   .set_termios = tiny_set_termios,

 255.   .type  = tiny_type,

 256.   .release_port = tiny_release_port,

 257.   .request_port = tiny_request_port,

 258.   .config_port = tiny_config_port,

 259.   .verify_port = tiny_verify_port,

 260. };

 261.

 262. static struct uart_port tiny_port = {

 263.   .ops  = &tiny_ops,

 264. };

 265.

 266. static struct uart_driver tiny_reg = {

 267.   .owner  = THIS_MODULE,

 268.   .driver_name = TINY_SERIAL_NAME,

 269.   .dev_name = TINY_SERIAL_NAME,

 270.   .major  = TINY_SERIAL_MAJOR,

 271.   .minor  = TINY_SERIAL_MINORS,

 272.   .nr  = UART_NR,

 273. };

 274.

 275. static int __init tiny_init(void)

 276. {

 277.   int result;

 278.

 279.   printk(KERN_INFO "Tiny serial driver loaded\n" );

 280.

 281.   result = uart_register_driver(&tiny_reg);

 282.   if (result)

 283.     return result;

 284.

 285.   result = uart_add_one_port(&tiny_reg, &tiny_port);

 286.   if (result)

 287.     uart_unregister_driver(&tiny_reg);

 288.

 289.   return result;

 290. }

 291.

 292. module_init(tiny_init);