Introduction to device driver

來源:互聯網
上載者:User

As a programmer, you are able to make your own choices about your driver, and choose an acceptable trade-off between the programming time required and the flexibility of the result. Thought it may appear strange to say that a driver is "flexible," we like this word because it emphasizes that the
role of a device driver is providing mechanism
, not policy
.

 

Most programming problems can indeed be split into two parts:"what capabilities are to be provided"(the mechanism) and "how those capabilities can be used"(the policy). If the two issues are addressed by different parts of the program, or even by different programs altogether, the software packages is much easier to develop and to adapt to particular needs.

 

When writing drivers, a programmer should pay particular attention to this fundamental concept: write kernel code to access the hardware, but don't force particular policies on the user, since different users have different needs. The driver should deal with making the hardware available, leaving all the issues about how
to use the hardware to the applications. Sometimes, however, some policy dicisions must be made. For example, a digital I/O driver may only offer byte-wide access to the hardware in order to avoid the extra code needed to handle individual bits.

 

One major consideration is the trade-off between the desire to present the user with as many options as possible and the time you have to write the driver, as well as the need to keep things simple so that errors don't creep in.

 

Each piece of code that can be added to the kernel at runtime is called a module
. Each module is make up of object code (not linked into a complete executable) that can be dynamically linked to the running kernel by the insmod
program and can be unlinked by the rmmod
program.

 

The Linux way of looing at devices distinguishes between three fundamental devicee types. Each module usually implements one of these types, and thus is classifiable as a char module
, a block module
, or a network module
.

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.