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