Learn to write low-level drivers (Linux).

So, I was playing with Raspberry Pi, and it just occurred to me that "Where do all these drivers come from." As, in particular, for SNES controllers using them ... how actually someone figured out how to write it.

I know C decently, and C ++ ... well. But that was always something I was thinking about. This is cool because it is low enough to understand, perhaps what is happening with the hardware wise ... but also great to learn about the OS.

Where to start with something like that? I assume that doing it for windows will be WAYYYY different.

thanks

+6
source share
2 answers

It seems to me that in fact there are two questions that really do not have much to do with each other.

First, "what does Linux require device drivers?" This will almost always be answered by reading the documentation. Although the device driver documentation may (possibly) be slightly less complete, complete, easy to read, etc., than documents for writing regular programs, it is still pretty decent. Probably the biggest difference from regular code is debugging, which is most often done by simply printing with printk .

Another question: "How do you determine which protocol (or" protocols ") are used by certain equipment, such as an SNES controller. When you design something like a regular hard drive or keyboard, you can pretty much just follow the documentation. You can (often (at least in my experience) to find that you need to compensate for some errors in the hardware, but besides this (again) pretty normal programming.Some of these cases just decide how you want to present the con the retrieval device in question to the rest of the system.For something like a hard drive, which is usually quite simple, but for something like an interface device for a person, it can be a little more complicated (for example, do you want to introduce it as it is, or do you want to emulate any existing type of device, such as a keyboard or mouse?)

For hardware that is not really documented, things can get a little more complicated. Of course, a universal tool for searching for logical signals is a logical analyzer. If you have something that uses a well-known hardware interface (e.g. PS / 2 keyboard / mouse, USB, SATA), you can find more specialized tools (and / or add-ins for the logic analyzer) that make life quite a bit easier. . Something like an NES controller or SNES will almost certainly use a proprietary interface, so for them you are likely to end up using a logic analyzer. Fortunately, they can also be a rather narrow, slow interface, so the logic analyzer does not have to be very fast or support a huge number of channels.

Using a logic analyzer, you can see all the individual signals, but for a proprietary interface, you still need to figure out which signals do what. In a typical case, you will have at least a few that are fairly obvious: power, land, quite possibly, hours, etc. In quite a few cases, you quickly find that even if it is not publicly documented, it can follow a well-known protocol, such as I 2 C, SPI, etc.

+4
source

Linux device drivers are the book you want.

While you wait for the book to arrive, I can tell you that knowing how the hardware works and how the Linux kernel works is only half the battle. You also need to know the hardware level interface for your specific device. Hope you can find documentation for this, but it can be tricky.

See this related question for an example of how someone came up with a driver for Linux by looking at the commands that came from the Windows driver: How are low-level drivers written for Linux?

For Windows, the process is not really much different. All the concepts are the same, because they are one and the same equipment. Of course, the differences are in the details.

+2
source

Source: https://habr.com/ru/post/957312/


All Articles