static struct file_operations gpio_ctl_fops={ ioctl: gpio_ctl_ioctl, open : gpio_open, release: gpio_release, ; #defineled1_on() (GPBDAT &= ~0x1) #def

Similar documents
华恒家庭网关方案

<4D F736F F D20C7B6C8EBCABDCFB5CDB3BFAAB7A2CAB5D1E9CBC42E646F63>

C/C++ - 文件IO

Microsoft Word - 实用案例.doc

新・明解C言語入門編『索引』

CC213

C 1

C语言的应用.PDF

epub 33-8

untitled

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc

C

FY.DOC

CC213

A Preliminary Implementation of Linux Kernel Virus and Process Hiding

untitled

Oracle Solaris Studio makefile C C++ Fortran IDE Solaris Linux C/C++/Fortran IDE "Project Properties" IDE makefile 1.

新版 明解C++入門編

Abstract arm linux tool-chain root NET-Start! 2

C C

Microsoft Word - linux命令及建议.doc

ebook15-C

EK-STM32F

C PICC C++ C++ C C #include<pic.h> C static volatile unsigned char 0x01; static volatile unsigned char 0x02; static volatile unsigned cha

ebook35-21

字元設備字元設備 (char device) 和普通檔案系統的區別 : 普通檔案系統可以來回讀 / 寫, 而大多字元設備僅僅是資料通道, 只能順序讀 / 寫 應用程式使用標準系統調用打開 (open) 讀取(read) 寫(write) 和關閉 (close), 完全好像這個設備是一個普通檔一樣 初

C/C++ 语言 - 循环

bingdian001.com

C/C++语言 - C/C++数据

nooog

CC213

Oracle Oracle Solaris Studio IDE makefile C C++ Fortran makefile IDE Solaris Linux C/C++/Fortran Oracle IDE "P

1

C/C++程序设计 - 字符串与格式化输入/输出

ebook15-4

科学计算的语言-FORTRAN95

25.( 0 在 進 行 水 溫 與 溶 解 量 的 實 驗 時, 每 一 匙 糖 都 要 刮 平 的 主 要 目 的 為 何? 1 避 免 一 次 溶 解 太 多 糖 2 可 以 增 加 溶 解 糖 的 次 數 3 控 制 加 入 的 每 一 匙 糖 都 一 樣 多 4 可 以 減 少 溶 解 量

mvc

第3章.doc

JLX

ebook15-10

C/C++语言 - 分支结构

1 Project New Project 1 2 Windows 1 3 N C test Windows uv2 KEIL uvision2 1 2 New Project Ateml AT89C AT89C51 3 KEIL Demo C C File

Windows 2000 Server for T100

PowerPoint 演示文稿

untitled

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.07.doc

ICD ICD ICD ICD ICD

ebook15-12

Microsoft Word - 正文.doc

Windows 2000 Server for T100

[改訂新版]C言語による標準アルゴリズム事典

提纲 1 2 OS Examples for 3

全国计算机技术与软件专业技术资格(水平)考试


第一次寫Linux Driver就上手

Microsoft PowerPoint - Chapter7-DriverDevices.ppt

TCA Linux 相容性認證測試流程步驟

C++ 程式設計

6 C51 ANSI C Turbo C C51 Turbo C C51 C51 C51 C51 C51 C51 C51 C51 C C C51 C51 ANSI C MCS-51 C51 ANSI C C C51 bit Byte bit sbit

(Load Project) (Save Project) (OffLine Mode) (Help) Intel Hex Motor

Guide to Install SATA Hard Disks

C

Microsoft Word - 01.DOC

1.ai

LSI U320 SCSI卡用户手册.doc

1 LINUX IDE Emacs gcc gdb Emacs + gcc + gdb IDE Emacs IDE C Emacs Emacs IDE ICE Integrated Computing Environment Emacs Unix Linux Emacs Emacs Emacs Un

untitled

untitled

DVK530/531扩展板

嵌入式Linux入门学习调试笔记

第11章 可调内核参数

untitled

int *p int a 0x00C7 0x00C7 0x00C int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++;

untitled

Microsoft Word - CPE考生使用手冊 docx

2015年计算机二级(C语言)模拟试题及答案(四)

ebook70-14

untitled

2013 C 1 # include <stdio.h> 2 int main ( void ) 3 { 4 int cases, a, b, i; 5 scanf ("%d", & cases ); 6 for (i = 0;i < cases ;i ++) 7 { 8 scanf ("%d %d

C6_ppt.PDF

_汪_文前新ok[3.1].doc

ebook71-13

lect03.ppt

嵌入式Linux块设备驱动开发解析

( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023)

(Microsoft Word -

51 C 51 isp 10 C PCB C C C C KEIL

chap07.key

錄...1 說...2 說 說...5 六 率 POST PAY PREPAY DEPOSIT 更

ebook70-5

第 十 一 期 2015 年 2 月 关 于 车 辆 购 置 税 征 收 管 理 有 关 问 题 的 公 告 ( 点 击 跳 转 至 全 文 ) 国 家 税 务 总 局 公 告 2015 年 第 4 号 关 于 电 池 涂 料 消 费 税 征 收 管 理 有 关 问 题 的 公 告 ( 点 击 跳

ebook35-2

Microsoft Word - PS2_linux_guide_cn.doc

The golden pins of the PCI card can be oxidized after months or years

K7VT2_QIG_v3

BOOL EnumWindows(WNDENUMPROC lparam); lpenumfunc, LPARAM (Native Interface) PowerBuilder PowerBuilder PBNI 2

Generated by Unregistered Batch DOC TO PDF Converter , please register! 浙江大学 C 程序设计及实验 试题卷 学年春季学期考试时间 : 2003 年 6 月 20 日上午 8:3

, 7, Windows,,,, : ,,,, ;,, ( CIP) /,,. : ;, ( 21 ) ISBN : -. TP CIP ( 2005) 1

Transcription:

Kaise s 2410 Board setting [1]. Device Driver Device Driver Linux s Kernel ARM s kernel s3c2410_kernel2.4.18_r1.1_change.tar.bz2 /usr/src (1) #cd /usr/src<enter> (2) #tar xfj s3c2410_kernel2.4.18_r1.1_change.tar.bz2< enter> /usr/src s3c2410_kernel2.4.18_r1.1_change Compiler Make Include (a). Makefile INCLUDE = /usr/src/s3c2410_kernel2.4.18_r1.1_change/include<enter> (b) Compiler #arm-linux-gcc -D KERNEL -I/usr/src/s3c2410_kernel2.4.18_r1.1_change/include -DKBUILD_BASENAME=$1 -DMODULE -c -o $1.o $1.c<enter> <1>. QT2410 Linux LED Driver GPIO QT2410 2 LED 2 I/O GPB0 GPB1 GPB0 GPB1 LED ***** gpiodrv.c ***** #include <linux/config.h> #include <linux/init.h> #include <linux/module.h> #include <linux/fs.h> #include <linux/delay.h> #include <linux/iobuf.h> #include <linux/kernel.h> #include <linux/major.h> #include <asm/uaccess.h> #include <asm/hardware.h> #include <asm/arch/cpu_s3c2410.h> #include <asm/io.h> #include <linux/vmalloc.h> #define IOPORT_MAJOR 220 /* */ int gpio_open(struct inode *inode,struct file *file); int gpio_release(struct inode *inode,struct file *file); int gpio_ctl_ioctl(struct inode *inode,struct file *file,unsigned int command,unsigned long arg); 1

static struct file_operations gpio_ctl_fops={ ioctl: gpio_ctl_ioctl, open : gpio_open, release: gpio_release, ; #defineled1_on() (GPBDAT &= ~0x1) #defineled2_on() (GPBDAT &= ~0x2) #defineled1_off()(gpbdat = 0x1) #defineled2_off()(gpbdat = 0x2) static int LedStatus; void LedSet(int led) LedStatus = led; if(ledstatus & 1) LED1_ON(); else LED1_OFF(); if(ledstatus & 2) LED2_ON(); else LED2_OFF(); void LedDisp(void) LedSet(0x01); //LED / udelay(0x500000); LedSet(0x04); //LED / udelay(0x500000); LedSet(0x02); //LED / udelay(0x500000); LedSet(0x04); //LED / udelay(0x500000); static int init gpio_init(void) int err=0; printk("gpio_init\n"); 2

err=register_chrdev(ioport_major,"gpio",&gpio_ctl_fops); if(err) printk("fail to register\n"); return -1; printk("success to register\n"); return 0; int gpio_open(struct inode *inode,struct file *file) // GPBCON=0x5500; // GPBUP=0xff; GPBCON = 5<<0; GPBCON &= ~(10<<0); printk("open gpio devices\n"); return 0; int gpio_release(struct inode *inode,struct file *file) printk("release this device\n"); return 0; int gpio_ctl_ioctl(struct inode *inode,struct file *file,unsigned int command,unsigned long arg) int err=0; if(command==1){ while(arg--) LedDisp(); printk("..."); printk("\n"); return 0; return err; 3

module_init(gpio_init); module_exit(gpio_release); MODULE_LICENSE("GPL"); PC ifconfig eth0 192.168.1.2<enter> make<enter> chmod a+x gpiodrv.o<enter> cp gpiodrv.o /work<enter> ;/work PC NFS arm-linx-gcc -o gpio_test gpio_test.c<enter> cp gpio_test /work<enter> file_operations open/read/write/close ioctl inode /dev/drivername DriverName hda0 Linux register_chrdev int register_chrdev(unsigned int major,const char *name,struct file_operations *fops) Makefile # standards INCLUDE = /usr/src/s3c2410_kernel2.4.18_r1.1_change/include CC = arm-linux-gcc CFLAGS = -D KERNEL -I$(INCLUDE) -DMODULE -Wall -O2 -L$INCLUDE TARGET = gpiodrv SRC = gpiodrv.c all: $(TARGET).o clean: rm -f *.o *~ core gpiodrv.c Makefile make <enter> gpiodrv.o NFS gpiodrv.o 2410 /tmp insmod gpiodrv.o <enter> cat /proc/devices rmmod gpiodrv<enter> gpio_test.c #include <stdio.h> #include <stdlib.h> //system #include <fcntl.h> 4

#include <errno.h> #include <unistd.h> #include <linux/delay.h> #include <sys/ioctl.h> #define DEVICE_GPIOTEST "/dev/gpio" // int main(int argc, char *argv[]) int fd; int val=-1; fd=open(device_gpiotest,0);// if(fd<0) perror("can not open device"); exit(1); while(1){ printf("please select number to run program\n"); printf("1:led on \n2:quit\n "); scanf("%d",&val); if(val==1) ioctl(fd,1,10); if(val==2){ close(fd); break; return 0; gpio_test.c #arm-linux-gcc o gpio_test gpio_test.c<enter> NFS gpio_test 2410 /tmp 1 QT2410 Linux minicom Linux # ifconfig eth0 192.168.1.100<enter> # mount -t nfs 192.168.1.2:/work /tmp<enter> # cd /tmp<enter> # insmod gpiodrv.o<enter> ; gpiodrv.o 5

#cat /proc/devices<enter> ; (#insmod driver.o<enter>) Driver #cat /proc/modules<enter> ; module # mknod /dev/gpio c 220 0<enter> ; gpio /dev/gpio c 220 Major Number 0 Minor Number 2 #./gpio_test<enter> ; gpio_test open gpio devices please select number to run program 1:led on 2:quit 1<enter> QT2410 LED!!! rmmod gpiodrv<enter> ********Device Driver ARM **** # ifconfig eth0 192.168.1.100 # mount -t nfs 192.168.1.2:/work /tmp # cd /tmp # insmod gpiodrv.o gpio_init success to register # mknod /dev/gpio c 220 0 #./gpio_test open gpio devices please select number to run program 1:led on 2:quit 1 ********Device Driver PC ****- ifconfig eth0 192.168.1.2 make chmod a+x gpiodrv.o cp gpiodrv.o /work arm-linx-gcc -o gpio_test gpio_test.c cp gpio_test /work <2>. QT2410 Led_SW_Device_Driver 6

QT2410 LED3 LED4 1. (S4, S2) (LED3, LED4) 2. S4=ON LED4 3. S2=ON LED3 1. gpio-2410 make buttons2410.c buttons2410.o gpio-2410#make<enter> 2. gpio-2410#path=$path:/usr/local/arm/2.95.3/bin<enter> gpio-2410#export PATH<enter> btn_test.c gpio-2410#arm-linux-gcc -o btn_test btn_test.c<enter> btn_test 3. minicom buttons2410.o btn_test QT2410 /tmp tmp 4. #insmod /tmp/buttons2410.oc btn_test #./btn_test<enter> ctrl-c btn_test 1. command line compiler Makefile mk shell script file (a)arm-linux-gcc -D KERNEL -I/usr/src/s3c2410_kernel2.4.18_r1.1_change/include -DKBUILD_BASENAME=$1 -DMODULE -c -o $1.o $1.c<enter> (b)chmod +x $1.o<enter> chmod +x mk<enter> mk mk buttons2410<enter> buttons2410 $1 /*** gpio.sh *** insmod buttons2410.o mknod /dev/qt2410_btns c 232 0 chmod a+x btn_test./btn_test /*** Makefile *** # standards INCLUDE = /usr/src/s3c2410_kernel2.4.18_r1.1_change /include CC = arm-linux-gcc 7

CFLAGS = -D KERNEL -I$(INCLUDE) -DMODULE -Wall -O2 -L$INCLUDE TARGET = buttons2410 SRC = buttons2410.c all: $(TARGET).o clean: rm -f *.o *~ core /*** btn_test.c *** #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/ioctl.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <sys/select.h> #include <sys/time.h> int main(void) int buttons_fd; int key_value,key_bk; key_value=0; key_bk=0; buttons_fd = open("/dev/qt2410_btns", 0); if (buttons_fd < 0) { perror("open device buttons"); exit(1); for (;;) if (read(buttons_fd, &key_value, sizeof key_value)!= sizeof key_value) 8

perror("read buttons\n"); printf("error in read button /n"); continue; else key_value &= 0x000f; if(key_value!= key_bk) printf("buttons_value: %d\n", key_value); key_bk = key_value; close(buttons_fd); return 0; *** buttons2410.c ****** #include <linux/config.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/miscdevice.h> #include <linux/sched.h> #include <linux/delay.h> #include <linux/poll.h> #include <linux/spinlock.h> #include <linux/irq.h> #include <linux/delay.h> #include <asm/hardware.h> #define DEVICE_NAME "qt2410_btns" #define BUTTON_MAJOR 232 #define IRQ_BUTTONS IRQ_EINT7 //static int count = 0; //static int ready = 0; 9

static int key_value = 0; static int mask_key = 0; static DECLARE_WAIT_QUEUE_HEAD(buttons_wait); static void buttons_io_port_init(void) set_gpio_ctrl(gpio_f0 GPIO_PULLUP_DIS GPIO_MODE_IN);//added set_gpio_ctrl(gpio_f2 GPIO_PULLUP_DIS GPIO_MODE_IN);//added //set bits 3,2,1,0 of GBPCON to be 0101, so (GPB1,GPB0) are configured to be ouput mode GPBCON =5; GPBCON &=~(10); } static int qt2410_buttons_read(struct file * file, char * buffer, size_t count, loff_t *ppos) if (count!= sizeof key_value) return -EINVAL; key_value = GPFDAT;//added copy_to_user(buffer, &key_value, sizeof key_value); mask_key=key_value & 3; // mask bits 1,0 GPBDAT = mask_key; //set 1 bits mask_key = ~3; GPBDAT &= mask_key; // set 0 bits return sizeof key_value; static int qt2410_buttons_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) switch(cmd) { default: return -EINVAL; static struct file_operations qt2410_buttons_fops = { owner: THIS_MODULE, ioctl: qt2410_buttons_ioctl, // poll: qt2410_buttons_select, read: qt2410_buttons_read, 10

; static devfs_handle_t devfs_handle; static int init qt2410_buttons_init(void) int ret; ret = register_chrdev(button_major, DEVICE_NAME, &qt2410_buttons_fops); if (ret < 0) { printk(device_name " can't register major number\n"); return ret; buttons_io_port_init(); devfs_handle = devfs_register(null, DEVICE_NAME, DEVFS_FL_DEFAULT, BUTTON_MAJOR, 0, S_IFCHR S_IRUSR S_IWUSR, &qt2410_buttons_fops, NULL); return 0; static void exit qt2410_buttons_exit(void) devfs_unregister(devfs_handle); unregister_chrdev(button_major, DEVICE_NAME); module_init(qt2410_buttons_init); module_exit(qt2410_buttons_exit); MODULE_LICENSE("GPL"); 11