3학년2학기/임베디드시스템

문자 디바이스 드라이버 구조

hgglife 2019. 10. 19. 21:05

디바이스 드라이버 구성
• 모듈 관련 함수 및 디바이스드라이버 등록
• Module_init(), module_exit() 함수
• 디바이스 등록
• register_chrdev_region() 또는 alloc_chrdev_region()
• 파일 시스템 인터페이스
• 잘 정의된 인터페이스 : file_operations 이용
• open(), release(), read(), write(), ioctl()
• 하드웨어 인터페이스
• memory mapped I/O : 메모리 연산
• special in/out instruction – in(), out()


문자 디바이스 드라이버 구조

chrdev[] 테이블 구조

major number 가 chrdev[]에 있고

chrdev의 1개당 디바이스 구조체가 있으며그 구조체안에 파일 오퍼레이션 시스템이 있다다


디바이스 드라이버 초기화

문자드라이버 module_init()에서 등록

alloc_chrdev_region() : linux kernel 이 major 와 minor 번호 할당

register_chrdev_region() :  프로그래머가 major와 minor 번호 할당


cdev_alloc(): Cdev 구조체를 위치시킨다

cdev_init(struct cdev *cdev,const struct file_operations *fops) :initialize a cdev struture

• cdev_add(struct cdev *p, dev_t dev_id, unsigned count):
Add a char device to the system, count is the number of consecutive minor numbers
• cl=class_create(THIS_MODULE, “char”);
• struct class 생성, 이 구조체는 device_create() 함수에서 사용
• device_create(cl, NULL, dev, NULL, DEV_NAME);
• DEV_NAME의 디바이스 파일을 생성


디바이스 드라이버 제거

문자드라이버 제거 Module_exit() 함수에서 제거

device_destroy(cl,dev);

class_destroy(cl);

cdev_del(&mycdev);

unregister_chrdev_region(dev,MINOR_CNT);