-
[linux] 디바이스 드라이버 만들기Programming/system programming 2015. 6. 1. 19:22
device등록
Device driver를 커널에 등록할때에는 register_chrdev(장치 주번호, 장치이름, file_operations)함수를 사용하고, module_init함수내에서 수행한다.
터미널 드라이버 경우에는 주번호 : 4, 디바이스 이름 : "tty” , 파일 연산 : tty_fops
struct file_operations
Linux/include/linux/fs.h http://lxr.free-electrons.com/source/include/linux/fs.h
리눅스에서 디바이스는 위의 함수들을 지원한다.led 디바이스에는 open, write, release만 있으면 되므로 아래와 같이 정의해주면 된다.struct file_operations iom_led_fops =
{
open: iom_led_open,
write: iom_led_write,
release: iom_led_release,
};
tty의 경우에는 다음과 같은 file_operations을 가진다.
컴파일, NFS
타겟 보드 부팅 후 NFS를 이용하여 모듈 파일을 보드로 복사
해당 디바이스 등록 : mkmod, insmod
(3) 드라이버 노드 생성 명령 입력
mknod /dev/led c 246 0
(4) 커널에 모듈 등록
insmod led_driver.ko
testing
LED_DEV 디바이스를 등록완료한 후에 위의 코드를 실행할 수 있다.
'Programming > system programming' 카테고리의 다른 글
[linux] mmap sys call (0) 2015.11.01 [네트워크]주소변환관련 API (0) 2014.10.03 [Linux] shared memory (0) 2013.06.19