1 / 11

Char Drivers

Char Drivers. Alexandre Madeira Taciano Rodolfo. Programação de Periféricos Eduardo Augusto Bezerra 30/06/2005. Char driver. Stream de caracteres, byte a byte O dispositivo é tratado como um arquivo. Char devices representados por arq especiais. /dev ex: / dev / console

Download Presentation

Char Drivers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Char Drivers Alexandre Madeira Taciano Rodolfo Programação de Periféricos Eduardo Augusto Bezerra 30/06/2005

  2. Char driver Stream de caracteres, byte a byte O dispositivo é tratado como um arquivo. Char devices representados por arq especiais. /dev ex: / dev / console / dev / ttyS0 / dev / lp0

  3. Char driver Identificação: crw-rw-rw- 1 root dialout 4, 64 Jun 30 11:19 ttyS0 crw-rw-rw- 1 root dialout 4, 65 Aug 16 00:00 ttyS1 crw------- 1 root sys 7, 1 Feb 23 1999 vcs1 crw------- 1 root sys 7, 129 Feb 23 1999 vcsa1 Major Number – identifica o driver associado ao dispositivo. Minor Number – identifica dispositivos que usam o mesmo driver.

  4. Char driver Major numbers estaticos: Documentation/devices.txt Registro de char drivers: int register_chrdev(unsigned int major, const char *name, struct file_operations *fops); int unregister_chrdev(unsigned int major, const char *name); Ex: result = register_chrdev(254, "scull", &scull_fops); Estático - 0 quando OK, numero negativo quando erro; Dinâmico – retorna um major number livre; 60 a 63, 120 a 127 e 240 a 254 para experimentos 2.0 – 7 bits – 128 dispositivos 2.2/2.4 – 8 bits – 256 dispositivos 2.5 – 16 bits – 65536 dispositivos

  5. Char driver Criando as entradas no /dev: mknod /dev/scull0 c 254 0 mknod /dev/scull1 c 254 1

  6. major = 254 minor = 0 scull0 Char driver /dev TABELA file_operations

  7. Char driver File operations structure: fops Conjunto de operações que podem ser executadas sobre o dispositivo gerenciado Exemplos de funções: ssize_t (*read) (struct file *, char *, size_t, loff_t *); ssize_t (*write) (struct file *, const char *, size_t, loff_t *); int (*open) (struct inode *, struct file *); int (*release) (struct inode *, struct file *);

  8. Char driver File structure Representa um arquivo aberto no kernel space F_mode : readable or writable F_pos : posição atual de leitura ou escrita F_flags : o_rdonly, o_nonblock *f_op : operações associadas ao arquivo

  9. Char driver devfs – device filesystem Introduzido no kernel 2.4 Opcional Apresenta problemas de incompatibilidade Arquivos /dev criados e removidos automaticamente Especificação de nomes e bits de permissão Não há necessidade de major e minor numbers

  10. Char drivers Scull (simple character utility for loading localities) Mapeado em memoria Independente de hardware Codigo simples Utilizado para demonstrar os conceitos de char devices

  11. Char driver

More Related