FND 디바이스 드라이버 Lecture #13.

Slides:



Advertisements
Similar presentations
RT_FIFO, Device driver.
Advertisements

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
The Practice of Micro-processor Yonam Institute of Digital Technology 06. LCD Control.
USERSPACE I/O Reporter: R 張凱富.
Smashing the Stack for Fun and Profit
1 Chapter 10 Strings and Pointers. 2 Introduction  String Constant  Example: printf(“Hello”); “Hello” : a string constant oA string constant is a series.
Chapter 7 Process Environment Chien-Chung Shen CIS, UD
Hello World Program The source code #include int main() { printf("Hello World\n"); return(0); }
C Programming - Lecture 5
Introduction to C Programming in Unix Environment - II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2014/2015 Some slides.
C Programming Revision Malcolm Wilson. Variables Types int, char, double, long. NO type for string see later. unsigned above. assignment X=2 ; C=‘v’;
Embedded Systems Programming Writing Device Drivers.
7-Segment Displays Module M7.2 Section 6.5. Turning on an LED Common Anode.
1 Intro to C/C++ #include using namespace std; int main() { cout
Device Drivers In Linux © Gregory Kesden Fall 2000.
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.
KyungHee Univ. 1-0 문자열 입 · 출력 프로그램 작성 예. KyungHee Univ. 1-1  모니터에 문자열 출력 하는 프로그램 작성  표준 출력 장치에 문자를 출력 하는 함수 함수의 기본형 : void SCI_OutChar(letter)  문자를.
KyungHee Univ. 2-0 Parallel Port LED Interfaces. KyungHee Univ. 2-1 Output LEDs.
Character LCD 디바이스 드라이버
2012 내장형 시스템 설계  Full Color LED 디바이스 구성  Full Color LED 디바이스 드라이버  Full Color LED JNI 라이브러리 작성  Full Color LED 안드로이드 App 구현  JNI 라이브러리.
C Tokens Identifiers Keywords Constants Operators Special symbols.
TEXT-LCD 디바이스 드라이버 Lecture #16.
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.
File IO and command line input CSE 2451 Rong Shi.
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.
VME Access Test Program int main(int argc, long Data1, long Data, long Data2, long Data3, long a, long dw, long dv, long b, long c, long Da32, long Da1,
(language, compilation and debugging) David 09/16/2011.
Data Structure and c K.S.Prabhu Lecturer All Deaf Educational Technology.
Linux Device Driver 2009/04/08. Reference Book Another Reference Book Embedded Linux Primer: A Practical, Real-World Approach By Christopher Hallinan.
Internal Device Driver
Interfacing Device Drivers with the Kernel
CS415 C++ Programming Takamitsu Kawai x4212 G11 CERC building WV Virtual Environments Lab West Virginia University.
// A // --- // F| G |B // --- // E| |C // ---.Dp // D // My LED Functions Scott Nichols.
C Programming Lecture 12 : File Processing
Lab 12 Department of Computer Science and Information Engineering National Taiwan University Lab12 – Driver 2014/12/16 1 /21.
COMP 3438 – Part I - Lecture 5 Character Device Drivers
망고100 보드로 놀아보자-14 디바이스 드라이버 작성 기초
Introduction to FUSE (File system in USEr space) Speaker:Zong-shuo Jheng Date:March 14, 2008.
Yared Woldekiros Western Washington university WEB ENABLE HOME AUTOMATION.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2014.
NAM S.B MDLAB. Electronic Engineering, Kangwon National University 1.
Lecture 3 Module Programming and Device Driver (Homework#1 included) Kyu Ho Park Sept. 15, 2015.
Embedded Linux Kernel Porting & Device Driver - 유柳 명明 환桓유柳 명明 환桓 [  ]
전자공학과 유승민 FND 과제. 1. 과제 내용 A~F 까지 십진수로 나타내기 이 진 수이 진 수 십진수 gfedcba A b C d E F
“Success consists of going from failure to failure without loss of enthusiasm.” Winston Churchill.
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
 LED 를 직접 제어하는 디바이스 드라이버를 작성해 보자  Reminder: LED 는 SPI 를 통해 ARM7 과 연결된다. ◦ 그렇다면 고쳐야 하는 코드는 어디에 ?  linux-2.6.x/arch/arm/mach-nds/arm7 ◦ Hardware spec.
Device Driver_Skeleton
Chapter 7-Android HAL 中国科学技术大学软件学院.
Chapter 3 General-Purpose Processors: Software
Embedded Systems Programming Examples and Comparison
Lecture 3 Module Programming and Device Driver (Homework#1 included)
A bit of C programming Lecture 3 Uli Raich.
Linux Kernel Driver.
Scull device 사용 예 강서일( ) 최정욱( ).
Example 15 Interrupt-Driven Controller
null, true, and false are also reserved.
פרטים נוספים בסילבוס של הקורס
פרטים נוספים בסילבוס של הקורס
SPI Protocol and Programming
Programming Language C Language.
Computer System Laboratory
프로그래밍2 및 실습 Sort Code 전명중.
Loadable Kernel Modules
Functions Reasons Concepts Passing arguments to a function
Presentation transcript:

FND 디바이스 드라이버 Lecture #13

목 차 7-Segment FND 구동 원리 디바이스 드라이버 프로그램 시 필요한 함수 FND 디바이스 드라이버 fnd-driver.c FND 응용 프로그램 fnd-app.c FND 디바이스 드라이버 시험

발광다이오드(LED) LED(Light Emitting Diode) 화합물 반도체의 PN접합 다이오드로 양단에 전압의 차를 가하면 빛을 방출하는 발광소자 그림 (A)와 같이 2개의 다리가 나와있는데 긴 쪽이 anode(+)이며 짧은 쪽이 cathode(-)이다 약 2.5V정도의 전압차가 2개의 다리 양단에 걸리면 빛을 방출하는 데, 보통 디지털소자의 출력이 5V이므로 그림 (B)와 같이 저항을 직렬로 연결하여 다이오드를 보호한다 그림 (A) 그림 (B)

7-Segment LED (1) 7-Segment LED FND 라고도 불리는데, 숫자나 문자를 표시하는데 사용되는 7개의 발광다이오드(LED)의 모임 공통 애노드(Common Anode) 형 :  다이오드의 애노드를 공통 단자로 사용한다 애노드 단자에 5V를 주고 캐소드의 각 단자 a~g 까지 0V를 주면 다이오 드에 전류가 흐르게 되어 발광한다 다이오드의 파손 방지를 위해 저항을 연결 한다 Common Anode 형

7-Segment LED (2) 7-Segment LED 공통 캐소드(Common Cathode) 형 : 다이오드의 캐소드를 공통 단자로 사용한다 캐소드를 접지 시키고, 다이오드의 애노드 단자에 5V를 주면 전류가 흐 른다 다이오드의 파손 방지를 위해 저항을 연결 한다 Common Cathode 형

7-Segment LED Array (1) Common Cathode 형 7-Segment LED 4 ARRAY 공통단자가 캐소드형으로 com0, com1, com2, com3로 4개 있으며, 애노드 단자 a,b,c,d,e,f,g,dp는 공통으로 사용한다 LED를 제어하기 위한 전체 핀의 개수를 줄일 수 있는 장점이 있으 나 컨트롤은 조금 복잡해진다

7-Segment LED Array (2) Common Cathode 형 7-Segment LED 4 ARRAY Com0=0, Com1=Com2=Com3=1인 경우, 입력 a,b,c,d,e,f,g중의 어 느 하나가 1이면 가장 왼쪽에 해당되는 Segment LED가 발광한다

7-Segment LED Array (3) PXA255-FPGA Board – 7-Segment LED 6 Array

7-Segment LED Array (4) FND 포트의 물리 주소 FND digit 및 segment 위치와 데이터 bit 0xC0000002 FND digit 및 segment 위치와 데이터 bit digit 부분(dig1~dig6)에는 0을, segment(a~dp) 부분에는 1을 write 하면 주어진 digit의 segment에 불이 켜짐 e.g) FND의 digit 3에 숫자 3(=segment abcdg)을 출력하려면 0xC0000002 번지에 0x4FFB을 출력하면 됨 FND dp g f e d c b a x dig6 dig5 dig4 dig3 dig2 dig1 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1

7-Segment LED Array (5) FND를 이용한 데이터 표현 예: Common Cathod 단자 Anode 단자

PXA255-FPGA – FND 회로 구성 (1)

PXA255-FPGA – FND 회로 구성 (2)

PXA255-FPGA – FND 회로 구성 (3)

PXA255-FPGA – FND 회로 구성 (4)

디바이스 드라이버 프로그램 시 필요한 함수 get_user(void *x, const void *addr) 사용자 영역의 *addr의 값을 커널 영역인 x로 sizeof(addr) 만큼 복사 put_user(void *x, const void *addr) 커널 영역의 *x의 값을 사용자 영역인 addr로 sizeof(addr) 만큼 복사 copy_to_user(void *to, void *from, unsigned long size) 커널 영역의 from에서 size 만큼을 사용자 영역의 to로 복사 copy_from_user(void *to, void *from, unsigned long size) 사용자 영역의 from에서 size 만큼을 커널 영역의 to로 복사 I/O로 부터 값을 읽는 함수 __u8 inb(unsigned int port) __u16 inw(unsigned int port) __u32 inl(unsigned int port) I/O에 값을 쓰는 함수 void outb(__u8 data, unsigned int port) void outw(__u16 data, unsigned int port) void outl(__u32 data, unsigned int port)

FND Device Driver – 매크로/전역 변수 (fnd_driver.c) #include <asm-arm/hardware.h> #include <asm-arm/uaccess.h> #include <asm-arm/io.h> #include <asm-arm/ioctl.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/fs.h> #include <linux/errno.h> #include <linux/types.h> #include <linux/ioport.h> #include <linux/delay.h> #include <linux/sched.h> #include <linux/init.h> #include <linux/version.h> #define IOM_FND_MAJOR 260 // ioboard fnd device major number #define IOM_FND_NAME "FNDS“ // ioboard fnd device name #define IOM_FND_ADDRESS 0x0C000002 // pysical address

FND Device Driver – 매크로/전역 변수 (fnd_driver.c) int iom_fnd_open(struct inode *, struct file *); int iom_fnd_release(struct inode *, struct file *); ssize_t iom_fnd_write(struct file *, const char *, size_t, loff_t *); unsigned char Getsegcode(int x); //Global variable static int fnd_usage = 0; static unsigned short *iom_fnd_addr; static struct file_operations iom_fnd_fops = { open: iom_fnd_open, write: iom_fnd_write, release: iom_fnd_release, };

FND Device Driver – open/release (fnd_driver.c) int iom_fnd_open(struct inode *minode, struct file *mfile) { if(fnd_usage != 0) return -EBUSY; fnd_usage = 1; return 0; } int iom_fnd_release(struct inode *minode, struct file *mfile) fnd_usage = 0;

FND Device Driver – Getsegcode (fnd_driver.c) unsigned char Getsegcode(int x) { char code; switch (x) { case 0x0 : code = 0x3f; break; case 0x1 : code = 0x06; break; case 0x2 : code = 0x5b; break; case 0x3 : code = 0x4f; break; case 0x4 : code = 0x66; break; case 0x5 : code = 0x6d; break; case 0x6 : code = 0x7d; break; case 0x7 : code = 0x07; break; case 0x8 : code = 0x7f; break; case 0x9 : code = 0x6f; break; case 0xA : code = 0x77; break; case 0xB : code = 0x7c; break; case 0xC : code = 0x39; break; case 0xD : code = 0x5e; break; case 0xE : code = 0x79; break; case 0xF : code = 0x71; break; default : code = 0; break; } return code;

FND Device Driver – write (fnd_driver.c) ssize_t iom_fnd_write(struct file *inode, const char *gdata, size_t length, loff_t *off_what) { const char *tmp = gdata; unsigned char value,cathode = 0xff; int i; unsigned char fnd_buff[4]; memset( fnd_buff, '0', sizeof(fnd_buff) ); if (copy_from_user(fnd_buff, tmp, length))// 3byte receive from application return -EFAULT; for(i = 0; i < 6; i++){ if(i %2) value = Getsegcode((fnd_buff[i/2]>>4) & 0xf); else value = Getsegcode(fnd_buff[i/2] & 0xf); outw ( (unsigned short)((value << 8)|(cathode & ~(0x1 << (5-i)))), iom_fnd_addr ); } return length;

FND Device Driver – init/cleanup (fnd_driver.c) int __init iom_fnd_init(void) { int result; result = register_chrdev(IOM_FND_MAJOR, IOM_FND_NAME, &iom_fnd_fops); if(result < 0) { printk(KERN_WARNING"Can't get any major\n"); return result; } iom_fnd_addr = ioremap(IOM_FND_ADDRESS,0x02); printk("init module, %s major number : %d\n",IOM_FND_NAME, IOM_FND_MAJOR); return 0; void __exit iom_fnd_exit(void) // fnd clear outw(0x00FE, iom_fnd_addr); outw(0x00FD, iom_fnd_addr); outw(0x00FB, iom_fnd_addr); outw(0x00F7, iom_fnd_addr); outw(0x00EF, iom_fnd_addr); outw(0x00DF, iom_fnd_addr); iounmap(iom_fnd_addr); if(unregister_chrdev(IOM_FND_MAJOR, IOM_FND_NAME)) printk(KERN_WARNING"%s DRIVER CLEANUP FALLED\n", IOM_FND_NAME);

FND Device Driver – init/cleanup (fnd_driver.c) MODULE_LICENSE("GPL"); module_init(iom_fnd_init); module_exit(iom_fnd_exit);

FND Device Driver – Test Application Program (test_fnd.c) #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <fcntl.h> int main(int argc, char **argv) { int dev; unsigned long buff; if(argc <= 1) { printf("please input the parameter!\n"); printf("ex)./test_fnd 0x123456\n"); printf("ex)./test_fnd 123456\n"); return -1; } dev = open("/dev/FNDS", O_WRONLY); if (dev != -1){ if(argv[1][0] == '0' && (argv[1][1] =='x'||argv[1][1] == 'X')) buff = (unsigned long)strtol(&argv[1][2], NULL,16); else buff = (unsigned long)strtol(&argv[1][0], NULL,16); write(dev,&buff,3); close(dev); else{ printf( "Device Open ERROR!\n"); exit(-1); return(0);

FND Device Driver – Makefile #Makefile for a basic kernel module obj-m := fnd_driver.o KDIR :=/root/pxa255-pro3/kernel/linux-2.6.21 PWD :=$(shell pwd) all: driver app driver: $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules app: arm-linux-gcc -o test_fnd test_fnd.c clean: rm -rf *.ko rm -rf *.mod.* rm -rf *.o rm -rf test_fnd rm -rf Module.symvers

FND Device Driver – Testing 타겟보드를 부팅하고 드라이버 모듈과 테스트 프로그램을 nfs 마 운트 디렉토리로 복사한 후에 아래와 같이 진행한다. # insmod ./fnd_driver.ko init module, FNDS major number : 260 # mknod /dev/FNDS c 260 0 # ./test_fnd 123456