Linux device Driver Development detailed----first essay

Source: Internet
Author: User

1, the purpose of software design, is high cohesion, low coupling. It means a driver inside, try to get things done by yourself, do not involve too much with other modules or drivers. Otherwise, when the problem, it is not good to troubleshoot, of course, this is also conducive to the transplant, as long as the driver inside the code, then change a platform, also become easy.

2, drive is the bridge of communication hardware and application. Drivers with no operating system are generally composed of an H file and a C file. h files are definitions of some structures and function declarations provided to external calls, and C files are the concrete implementations of these functions.    The software architecture without operating system is this: in an infinite loop, the device interrupts are detected or polled, and processed. When the application engineer writes the code, the direct face is the drive interface.

3, drive with operating system. OK, we will find that with the operating system, the driver becomes complicated, not only to complete the operation of the hardware, but also to connect with the kernel, into the kernel. What do you do? Why the trouble? Remember, God is fair, in the drive this trouble point, add a variety of device registration functions, is for the convenience of the application. Makes the application look at the driver is a kind of. For example: Whether you are a i2c,spi or a simple gpio driver, it fopen/dev/xxx, it is open the driver, write is to write something inside.

4, drive the classification:

A character device refers to a device that must be accessed sequentially in a sequential order.

Block devices can be accessed in any order, why? The system has been quickly buffered.

The network device is designed for packet reception and delivery, and there is no corresponding file system node.

Another way to classify: I²c drive, USB drive, PCI driver. These drivers can be incorporated into the above three ways, but their application is complex and extensive, so the Linux system defines a unique drive architecture for them. (for example, some registered, read-write, etc.) 5, CPU architecture: von Neumann and Harvard. Von Neumann is the memory in which the program instruction and data memory are merged together, and the program instruction and data are the same width.   The Harvard structure stores program directives and data separately, and the width of instructions and data can have different data widths. From the instruction set perspective, it can be divided into thin instruction set (RISC) and complex instruction set (CISC). The refinement instructions emphasize minimizing the instruction set, instruction-cycle execution, but the target code is larger. The complex instruction set emphasizes the instruction's ability, its instruction is complex, the instruction period is long, and the corresponding target code is reduced. 6, NOR Flash features can be executed in-chip (XIP, execute in place), the program can be run directly within NOR. The NAND flash and the CPU interface must be converted by the corresponding control circuit, of course, can also generate the NAND flash interface signal through the address line or GPIO.  NAND Flash is accessed in block mode and does not support in-chip execution. The RAM is stored in the capacitor, so the capacitance leakage data is lost after power-down.  The 7,USB provides four modes of transmission: control transmission, synchronous transmission, interrupt transmission, and bulk transfer. The role of an Ethernet isolating Transformer: signal transmission, impedance matching, waveform repair, suppression of signal clutter and high voltage isolation. 8,linux Kernel components: 1) process scheduling; When the request resource is not satisfied, hibernate, and then wait for the resource to wake up after it is released. 2) memory management, control the shared main memory area of multiple processes, and complete the conversion of virtual memory to physical memory for each process. 3) virtual file; 4) network interface; 5) interprocess communication 9,container_of (PTR, type, member)ptr is a concrete pointer, type is a struct, member is the name of a formal parameter inside a struct. It does this by knowing that the pointer to the member inside the type struct is PTR, and then gets the pointer to the type struct body. Ten,Copy_to_user, Copy_from_user implements the interaction between kernel space and user-space data:

Copy_to_user need to detect the legitimacy of the pointer at each copy, that is, the user space pointer to the address is indeed a part of the process itself address, rather than point to the place does not belong to it, and each time the data is copied, frequent access to memory, due to the virtual address continuous, Physical addresses are not necessarily contiguous, causing the CPU cache to fail frequently, thus slowing down the speed.

In the system functions of Read and write, note the value of return, which is typically the number of bytes passed.

The 11,linux driver analysis method is entire areas, which puts the understanding of functions and data structures in the context of the overall architecture.

Linux device Driver Development detailed----first essay

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.