How to write Linux drivers

Source: Internet
Author: User

After a period of time-driven personal sentiment, no matter what drive, to less detours, common driving workflow should be as follows:

1, reading, look at the data, understand the driving principle: the kernel of this type of drive architecture, working mechanism, etc., recommended must read the document is the Linux kernel source code in the documents directory of this driver txt document, here the document most direct, the most core, the most critical ... That's all there is.

2, see Datasheet,datasheet often a lot of pages, need to look now? No, now look at the overall content, first understand the PIN definition, understand the overall architecture, understand register or memory allocation. Master the basic working principle of hardware.

The above two steps do not want to lazy skip, even if you have a ready to write a good driver, to debug to your platform to normal work, to the end of the N more detours will find that you do not read the document and save to any time, instead of wasting n more time. There is a saying is very right: "In the lakes and rivers mixed, sooner or later will have to also." ”

3, see example Drive, Linux kernel driver, generally have a relatively simple example code, specifically, see the first step of the TXT document. With this simple example code, we further clarify how the drive works.

4, good, ready to work to complete, here should formally start. Write it yourself? No, or secretly lazy, online to find ready-made, there is just your chip driver, really lucky, direct use, of course, often can not be used directly, to debug under the next line. No? Find the same series of chip drivers, modified under use, but also more fortunate. Or not? Be honest and start writing on the framework provided by the example code!

5, debugging process encountered problems? Honestly look at the relevant parts of datasheet, this related part is often not in the same chapter, most of the time will be distributed in many chapters, do not miss the details. Are your registers set to the right? All right? Use oscilloscope, logic Analyzer to catch the waveform, analyze the timing, see the hardware is not Luo. No, just look for the hardware engineer. Not yet? To the chip official website, see your datasheet is the latest version? There are no errata documents. Maybe you have errors in the documentation you have, of course you can't tune it!

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.