linux4.10.8 Kernel porting (quad)---character device driver _led driver

Source: Internet
Author: User

Introduction of character device driver

  

The app uses open, read, write, and other functions to operate the underlying hardware. The driver also has corresponding functions such as Xxx_open. How to find a driver in a function depends on the driver framework.

II. Building a Driver Framework 2.1 preliminary Framework 2.1.1 Makefile

  

2.1.2 JZ2440_LED.C
1#include <linux/module.h>2#include <linux/of.h>3#include <linux/of_device.h>4#include <linux/regmap.h>5#include <linux/fs.h>6 7 #defineJz2440_leds_major 111/* Main device number */8 9 Ten Static intJz2440_drv_open (structInode *inode,structFile *file) One { APrintk"Jz2440_drv_open"); -     return 0; - } the  - Static intJz2440_drv_close (structInode *inode,structFile *file) - { -Printk"Jz2440_drv_close"); +     return 0;  - } +  A Staticssize_t Jz2440__drv_read (structFile *file,Char__user * buf, size_t count, loff_t *PPOs) at { -Printk"Jz2440__drv_read"); -     return 0; - } -  - Staticssize_t Jz2440_drv_write (structFile *file,Const Char__user * buf, size_t count, loff_t *PPOs) in { -Printk"Jz2440_drv_write"); to     return 0; + } -  the Static structFile_operations Jz2440_leds_ops = { *. Owner =This_module, $. Read =Jz2440__drv_read,Panax Notoginseng. Open =Jz2440_drv_open, -. Write =Jz2440_drv_write, the. Release =Jz2440_drv_close, + }; A  the Static int__init Jz2440_drv_leds_init (void) + { -Register_chrdev (Jz2440_leds_major,"jz2440_drv_leds", &jz2440_leds_ops);//register the driver, which tells the kernel $     return 0; $ } -  - Static void__exit Jz2440_drv_leds_exit (void) the { -Unregister_chrdev (Jz2440_leds_major,"jz2440_drv_leds");Wuyi } the  - //point to Entry function Jz2440_drv_leds_init Wu Module_init (jz2440_drv_leds_init); - //Export function Unload drive About Module_exit (jz2440_drv_leds_exit); $  -Module_license ("GPL"); -Module_description ("jz2440 LEDs driver");

Compile:

  

Burn Write Run:

  

  

Go to the Development Board U-boot interface:

Set command line startup parameters

Set Bootargs noinitrd root=/dev/nfs Nfsroot=192.168.0.192:/home/ubuntu/work/nfs_root/fs_mini ip= 192.168.0.191:192.168.0.192:192.168.0.1:255.255.255.0::eth0:off INIT=/LINUXRC console=ttySAC0,115200

Boot kernel: Boot

  

NFS Directory Mount succeeded.

To view the proc directory:

  

The device number is available.

Load module:

  

Check to see if loading is in:

  

Test program

1#include <sys/types.h>2#include <sys/stat.h>3#include <fcntl.h>4#include <stdio.h>5#include <unistd.h>6 7 intMainintargcChar**argv)8 {9     intFD;Ten     intval =1; One      AFD = open ("/dev/xxx", O_RDWR); -     if(FD <0) -     { theprintf"can ' t open!\n"); -     } -      -Write (FD, &val,4); +     return 0; -}

Compile burn write into board, execute

  

Create a device node;

  

Executive A.out

  

  

  

  

linux4.10.8 Kernel porting (quad)---character device driver _led driver

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.