 LED 를 직접 제어하는 디바이스 드라이버를 작성해 보자  Reminder: LED 는 SPI 를 통해 ARM7 과 연결된다. ◦ 그렇다면 고쳐야 하는 코드는 어디에 ?  linux-2.6.x/arch/arm/mach-nds/arm7 ◦ Hardware spec.

Slides:



Advertisements
Similar presentations
DEVICE DRIVER VINOD KAMATH CS691X PROJECT WORK. Introduction How to write/install device drivers Systems, Kernel Programming Character, Block and Network.
Advertisements

Linux device-driver issues
Device Drivers. Linux Device Drivers Linux supports three types of hardware device: character, block and network –character devices: R/W without buffering.
RT_FIFO, Device driver.
Lecture for Lab 3, Exp1 of EE505 (Developing Device Driver) T.A. Chulmin Kim CoreLab. Mar, 11, 2011 [XenSchedulerPaper_Hotcloud-commits] r21 - /
Computer System Laboratory
USERSPACE I/O Reporter: R 張凱富.
Union, bitfield, typedef, enum union nama_u{ }; union nama_u{ struct nama_s byte; }; enum{ }; Tipedef var BYTE.
Sleeping and waking An introduction to character-mode device-driver modules for Linux.
UNIX’s “grand illusion” How Linux makes a hardware device appear to be a ‘file’
Hardware-address filtering How can we send packets to just one node on our ‘anchor’ cluster?
Standard C Libraries Application Programmming Interface to System-Calls.
63 UQC152H3 Advanced OS Writing a Device Driver. 64 The SCULL Device Driver Simple Character Utility for Loading Localities 6 devices types –Scull-03.
Rings This chapter demonstrates how processes can be formed into a ring using pipes for communication purposes.
1 Speaker: I-Wei Chen Operating Systems, Spring 2002 Project #1: Adding a System Call.
CS 311 – Lecture 10 Outline Review open() and close() Difference between fopen() and open() File management system calls – read() – write() – lseek() –
I/O April 16, 2002 Topics Files Unix I/O Standard I/O Reading: (Beta) or (New) Problems: 12.9 (Beta) or 12.4 (New) class24.ppt
Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Writing/Registering to /proc Character Device Driver – Characteristics and functionality – Basic IO functions.
Device Drivers In Linux © Gregory Kesden Fall 2000.
EECS 498 Advanced Embedded Systems Lecture 4: Linux device drivers and loadable kernel modules.
POSIX: Files Introduction to Operating Systems: Discussion 1 Read Solaris System Interface Guide: Ch. 5.1 Basic File I/O.
Loadable Kernel Modules Dzintars Lepešs The University of Latvia.
Kernel module programming Nezer J. Zaidenberg. reference This guide is built on top of The Linux Kernel Module Programming Guide The guide is available.
Interrupt Handling Sarah Diesburg COP Interrupt Handling One big responsibility of an operating system is to handle hardware connected to the machine.
2012 내장형 시스템 설계  Full Color LED 디바이스 구성  Full Color LED 디바이스 드라이버  Full Color LED JNI 라이브러리 작성  Full Color LED 안드로이드 App 구현  JNI 라이브러리.
C questions A great programmer codes excellent code in C and Java. The code does video decoding. Java code works faster then C on my computer. how come?
OPERATING SYSTEMS 12 - FILES PIETER HARTEL 1. Files  Properties  Long term existence of data  Sharable between processes  Access control  Operations.
Pipes A pipe is a simple, synchronized way of passing information between processes A pipe is a special file/buffer that stores a limited amount of data.
Kernel Modules. Kernel Module Pieces of code that can be loaded and unloaded into the kernel upon demand. Compiled as an independent program With appropriate.
CS252: Systems Programming Ninghui Li Based on Slides by Prof. Gustavo Rodriguez-Rivera Topic 8: Opening Files and Starting Processes.
Implementation of Embedded OS Lab3 Linux Kernel Modules.
Stepper Motor 디바이스 드라이버
1 4-Development Environment Development processor  The processor on which we write and debug our programs Usually a PC Target processor  The processor.
K ERNEL D EVELOPMENT CSC585 Class Project Dawn Nelson December 2009.
Linux Device Driver 2009/04/08. Reference Book Another Reference Book Embedded Linux Primer: A Practical, Real-World Approach By Christopher Hallinan.
Interfacing Device Drivers with the Kernel
AT91Bootstrap. Introduction Device initialization such as clock speed configuration, PIO settings, etc. Peripheral drivers such as PIO, PMC, SDRAMC, etc.
Lab 12 Department of Computer Science and Information Engineering National Taiwan University Lab12 – Driver 2014/12/16 1 /21.
Interrupt Handling Ted Baker  Andy Wang CIS 4930 / COP 5641.
COMP 3438 – Part I - Lecture 5 Character Device Drivers
Introduction to FUSE (File system in USEr space) Speaker:Zong-shuo Jheng Date:March 14, 2008.
F28HS2 Hardware-Software Interface Lecture 6 - Programming in C 6.
OS interface: file and I/O system calls File operations in C/C++? –fopen(), fread(), fwrite(), fclose(), fseek() in C f.open(…), f.close(…) in C++ I/O.
CSC 271 – Software I: Utilities and Internals An Introduction to File I/O in Linux Credited to Dr. Robert Siegfried and Beginning Linux Programming by.
Using Linux with ARM Tutorial #3.
Finish up OS topics Group plans. Today Finish up and review Linux device driver stuff – Walk example again – See how it all goes together – Discuss talking.
 Backlight 에서 나온 백색광이 액정 셀을 통과하면 서 투과율이 조절되고 red, green, blue 의 color filter 를 투과해 나오는 빛의 혼합을 통해 색이 구 성됨  Color filter 는 셀사이의 빛을 차단하는 black matrix,
Lecture 3 Module Programming and Device Driver (Homework#1 included) Kyu Ho Park Sept. 15, 2015.
File table: a list of opened files Each entry contains: – Index: file descriptors – Pointer to the file in memory – Access mode File descriptor is a positive.
Using System Calls (Unix) Have to tell compiler (if C/C++) where to find the headers, etc. – i.e., the “include” files May have to tell compiler where.
Device Driver_Skeleton
Chapter 7-Android HAL 中国科学技术大学软件学院.
Introduction to Developing Embedded Linux Device Drivers
Chapter 3 General-Purpose Processors: Software
Lecture 3 Module Programming and Device Driver (Homework#1 included)
Lecture 31: Introduction to File System
Virtual Memory: Systems
I2C communication* I²C - Inter-Integrated Circuit – or –I squared C)
Linux Kernel Driver.
Scull device 사용 예 강서일( ) 최정욱( ).
Virtual Memory: Systems
Network Programming CSC- 341
הרצאה 08 פרמטרים ל- main קרן כליף.
“The course that gives CMU its Zip!”
CSE 333 – Section 3 POSIX I/O Functions.
Programming Language C Language.
Computer System Laboratory
Loadable Kernel Modules
File I/O & UNIX System Interface
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2016.
Presentation transcript:

 LED 를 직접 제어하는 디바이스 드라이버를 작성해 보자  Reminder: LED 는 SPI 를 통해 ARM7 과 연결된다. ◦ 그렇다면 고쳐야 하는 코드는 어디에 ?  linux-2.6.x/arch/arm/mach-nds/arm7 ◦ Hardware spec 은 ??  슬라이드 05

 Power management device ◦ Index register  0-1: register select (0~3)  2-6: not used  7: direction (0=write, 1=read) ◦ Register 0 : power management control  0: sound amplifier (0=disable, 1=enable)  1: sound related? (0=disable, 1=enable)  2: lower backlight (0=disable, 1=enable)  3: upper backlight (0=disable, 1=enable)  4: power LED blinking enable (0=always on, 1=blinking)  5: power LED blinking speed (0=slow, 1=fast)  6: DS system power (0=normal, 1=shut down)  7: not used ◦ Register 1: battery status  0: battery power LED status (0=Good/Green, 1=Low/Red) ◦ Register 2: microphone amplifier control  0: amplifier (0=disable, 1=enable) ◦ Register 3: microphone amplifier gain control  0-1: gain (0~3=gain 20, 40, 80, 160)

 다행히도, 이미 되어 있음.  linux-2.6.x/arch/arm/mach-nds/arm7/spi.c ◦ power_write(enum power_reg reg, u8 val)  …/spi.h #define POWER0_SOUND_AMP (1<<0) #define POWER0_LOWER_BACKLIGHT (1<<2) #define POWER0_UPPER_BACKLIGHT (1<<3) #define POWER0_LED_BLINK (1<<4) #define POWER0_LED_FAST (1<<5) #define POWER0_SYSTEM_POWER (1<<6) enum power_reg { POWER_CONTROL, POWER_BATTERY, POWER_MIC_CONTROL, POWER_MIC_GAIN };

 Power control (Register 0) 의 제어가 가능하도록 하는 디바이스 드라이버를 만들어 보자.  설계 사항 ◦ ARM9 에서 ARM7 으로 명령을 보내야 한다. ◦ ARM7 에서는 명령을 처리한다. ◦ Device driver 를 만들어야 한다. ◦ 파일 시스템에 device driver 를 만들어야 한다. ◦ 테스트할 응용 프로그램을 만들어야 한다.

 구현되어 있음  linux-2.6.x/include/asm/arch/fifo.h #define FIFO_FIRMWARE (0 << 29) #define FIFO_BUTTONS (1 << 29) #define FIFO_TOUCH (2 << 29) #define FIFO_MIC (3 << 29) #define FIFO_WIFI (4 << 29) #define FIFO_SOUND (5 << 29) #define FIFO_POWER (6 << 29) #define FIFO_TIME (7 << 29) #ifdef __DSLINUX_ARM7__ static inline void nds_fifo_send(u32 command) { while (NDS_REG_IPCFIFOCNT & FIFO_SEND_FULL) ; /* do nothing */ NDS_REG_IPCFIFOSEND = command; } #else static inline void nds_fifo_send(u32 command) { int fifo_full = 0; while (NDS_REG_IPCFIFOCNT & FIFO_SEND_FULL) fifo_full = 1; NDS_REG_IPCFIFOSEND = command; if (fifo_full) printk(KERN_WARNING "fifo: detected send attempt while " "fifo was full\n"); } #endif /* __DSLINUX_ARM7__ */

 어디서 처리하는가 ? ◦ arch/arm/mach-nds/arm7/main.c  static void receiveFIFOCommand(void) ◦ ARM9 에서 보낸 명령은 data = FIFO_GET_TYPE_DATA(fifo_recv);  여기에서 읽음 ◦ 처리는 case FIFO_POWER: power_write(POWER_CONTROL, POWER0_SYSTEM_POWER); break;  현재 구현은 명령이 들어오면 시스템을 끈다. ◦ 우리가 바라는 구현은 case FIFO_POWER: power_write(POWER_CONTROL, (data & 0xff) ); break;

 어디에 ? ◦ char device 에 만들자 ( 쉬우므로 ) ◦ drivers/char/ds_power.c

#include #define DEVNAME "/dev/dspower" int ds_power_major=254; // 에러인 경우 바꾸어야 함. 0 이면 자동 부여. int result; static int ds_power_open(struct inode *inode, struct file *flip); static int ds_power_release(struct inode *inode, struct file *flip); static int ds_power_ioctl(struct inode *inode, struct file *flip, unsigned int cmd, unsigned int arg); static ssize_t ds_power_read(struct file *flip, char *buf, size_t count, loff_t *f_pos); static ssize_t ds_power_write(struct file *flip, char *buf, size_t count, loff_t *f_pos); static int ds_power_open(struct inode *inode, struct file *flip)

static int ds_power_release(struct inode *inode, struct file *flip); static int ds_power_ioctl(struct inode *inode, struct file *flip, unsigned int cmd, unsigned int arg); static ssize_t ds_power_read(struct file *flip, char *buf, size_t count, loff_t *f_pos); static ssize_t ds_power_write(struct file *flip, char *buf, size_t count, loff_t *f_pos); static int ds_power_open(struct inode *inode, struct file *flip) { return 0; } static int ds_power_release(struct inode *inode, struct file *flip) { return 0; } static int ds_power_ioctl(struct inode *inode, struct file *flip, unsigned int cmd, unsigned int arg) { return 0; }

static ssize_t ds_power_read(struct file *flip, char *buf, size_t count, loff_t *f_pos) { return 0; } static ssize_t ds_power_write(struct file *flip, char *buf, size_t count, loff_t *f_pos) { nds_fifo_send(FIFO_POWER | (buf[0] & 0xff)); return 0; } static struct file_operations ds_power_fops = {.open = ds_power_open,.read = ds_power_read,.write = ds_power_write,.ioctl = ds_power_ioctl,.release = ds_power_release, };

static int ds_power_init() { result = register_chrdev(ds_power_major, DEVNAME, &ds_power_fops); if(result < 0) { printk(KERN_WARNING "%s: can't get major %d\n", DEVNAME, ds_power_major); return result; } printk(" init module succes: %s major number : %d\n", DEVNAME, result); devfs_mk_cdev(MKDEV(result,0), S_IFCHR|S_IRUGO|S_IWUGO, "dspower"); return 0; } static void ds_power_exit() { unregister_chrdev(result, DEVNAME); } module_init(ds_power_init); module_exit(ds_power_exit);

 이제 커널에 포함 시켜야 한다. ◦ drivers/char/Makefile obj-y += mem.o random.o tty_io.o n_tty.o tty_ioctl.o ds_power.o 추가

 이름이.. /dev/dspower  Major number  문제점 : DSLinux 는 ROMFS 를 쓴다. ◦ 부팅 후 디바이스 파일을 만들 수 없다. (mknod 안됨 )  빌드 시 ROMFS 를 만들어야 함.  만드는 파일 ◦ dslinux/vendors/Nintendo/DLDI/Makefile

 Devices :=  이 부분 에서 dldi,b,240,0 \ dldi1,b,240,1 dldi2,b,240,2 dldi3,b,240,3 dldi4,b,240,4 \ \ ptyp0,c,2,0 ptyp1,c,2,1 ptyp2,c,2,2 ptyp3,c,2,3 \ ptyp4,c,2,4 ptyp5,c,2,5 ptyp6,c,2,6 ptyp7,c,2,7 \ ptyp8,c,2,8 ptyp9,c,2,9 ptypa,c,2,10 ptypb,c,2,11 \ ptypc,c,2,12 ptypd,c,2,13 ptype,c,2,14 ptypf,c,2,15 \ \ dsp,c,14,3 dspower,c,254,0 \ \ fb0,c,29,0\ fb1,c,29,1\ 여기에 넣자

이제 make!

 romfs/dev 에 dspower 파일이 만들어졌는 지 확인 @fb0,c,29, ttyp6

 드라이버가 포함되었는 지 확인  linux-2.6.x 디렉터리에서 ◦ arm-linux-elf-nm linux | grep ds_power 020a3cf4 t ds_power_exit d ds_power_fops 020a3c80 tds_power_init 020a3c1c t ds_power_ioctl 02173b8c B ds_power_major 020a3c0c t ds_power_open 020a3c24 t ds_power_read 020a3c14 t ds_power_release 020a3c2c t ds_power_write 0200cd68 t __initcall_ds_power_init

 test_power.c #include int main(int argc, char* argv[]) { int fd; unsigned int cmd; fd = open("/dev/dspower", O_RDWR); if(fd<0) { printf("error(open):%d\n", fd); return -1; } if(argc>1) { sscanf(argv[1], "%x", &cmd); } else cmd = 0x1f; // 천천히 깜빡인다. write(fd, &cmd, 1); close(fd); return 0; } 이건 응용 프로그램이다. 운영체체 directory 안에다 만들면 안된다.

 test_power 1f ◦ LED 가 천천히 깜빡인다.  test_power 3f ◦ LED 가 빠르게 깜빡인다.  test_power f ◦ LED 가 깜빡이지 않는다.  test_power 7 ◦ 상단 LCD 백라이트가 꺼진다. ( 화면 안보임 )  test_power f ◦ 상단 LCD 백라이트가 켜진다.  test_power 0 ◦ NDSL 이 꺼진다. ( 완전히 꺼지는 것은 아님 )

 POWER_BATTERY 에 대하여 실습해 보자.  스스로 디바이스 드라이버를 만들어 보자. ◦ 설계 : 2 bytes 를 받아, 상위 바이트가 1 이면 BATTERY, 0 이면 CONTROL 로 설정 ◦ arch/arm/mach-nds/arm7/main.c  static void receiveFIFOCommand(void) case FIFO_POWER: if( (data >> 8) & 1) power_write(POWER_BATTERY, (data & 0xff) ); else power_write(POWER_CONTROL, (data & 0xff) ); break;

 디바이스 드라이버 제작 ◦ ds_battery.c  write 함수에서  nds_fifo_send(FIFO_POWER | ((1<<8) | (buf[0] & 0xff)));  /dev/ 에 들어갈 파일명을 정한다.  Major number 를 정한다. ◦ Makefile 을 수정  ROMFS ◦ 결정한 Major number 와 파일명으로 파일을 만든다.  DLDI/Makefile 수정  빌드  테스트할 응용을 만든다. ◦ 0: Green, 1: Red