How to control video card in my self-developed OS? - c

I am developing my own OS and for days I’ve been wondering how to control video card, audio card to build a delicate GUI. It seems that the procedure is a bit different from that of controlling mouse or keyboard.
By the way,
1.How does an OS recognize hardware drivers?
2.Are all hardware drivers written for specific platforms (such as Windows,Linux,etc.)?
Still freshman in the university and failed to find relevant information
thanks for help =)

how to control video card
Graphics cards typically support a VGA mode and the VESA 2.0 standard. So this could be a good starting point for your first video driver.
How does an OS recognize hardware drivers?
Linux uses a device tree describing the hardware which has a compatible field for every item that needs a driver. All hardware drivers are kept in linker generated lists. If a driver has the same compatible value it can be used to drive the hardware. The linker list item is generated from a macro in the driver code using a specialized linker script.
Are all hardware drivers written for specific platforms (such as Windows, Linux, etc.)?
If you provide the right wrappers you may be able to reuse existing drivers. E.g. U-Boot reuses Linux drivers for USB devices. And the NDISwrapper can be used to run Windows WLAN drivers on Linux.

Related

CMSIS-Driver peripherals

I was wandering, why there are no implementations of the devices written in CMSIS-Driver?
I mean that I have few peripherals: LCD, temperature and pressure sensor, current meter etc. - all of them very popular used in arduino and learning sets.
Each of these devices uses some protocol to communicate with the uC. some are for i2C, some communicate by SPI, some by UART. I was wondering if there are drivers that handle those devices, and as a backend use CMSIS-Driver API.
I think that it is a decent api, and after all standard develop by ARM, so why I can not find any drivers using it?
For example when I was looking for s18b20 (temperature sensor for 1-wire), I was easily able to find driver for this device written in RUST language, but I was not able to find any implementation for C that would use CMSIS. (in this case compare to rust is quite solid, because Rust has nice embedded API, and you can easily use the driver on multiple targets, just like CMSIS-Driver is spouse to work)
I was able to find some projects using this peripheral, but they all operated on HAL that is different for every uC, so the implementation is not portable ( unlike RUST, and potentially CMSIS-Driver)
So my main questions are:
Why there are so little implementations based on CMSIS-Driver? Maybe there is some hidden implementation repository that I do not know about?
Am I missing something? Is the CMSIS-Driver not designed for the casual developers? Who is it designed for then ?
CMSIS is not concerned with external devices, it deals primarily with interface drivers for interfaces on the microcontroller die. So if you have an SPI device, you might use the CMSIS. SPI driver for that part, but it is then your responsibility as a developer to write the higher-level driver for the external device.
Higher-level software platforms such as ARM's embed, or ST's CubeMX use CMSIS interface drivers, and include drivers for common higher level devices. They tend to be for more complex devices related to networking, filesystems and displays. I would not expect much support for such trivially simple devices such as a temperature sensor.

Driver Templates, Minimum Kernel Distro., drivers community, driver for Microcontroller?

I am post-newbie to Embedded Linux driver development, have developed Character, UART & simple USB drivers, and have worked with SBC (Raspberry Pi 2). My main learning resources are: Essential Linux Device Drivers, Embedded Linux System Design & Development, youtube tutorials and LDD3. Because of lack of real life driver experience, I have some questions that I would like to share:
Templates: are there some sort of driver templates for speeding up the coding process e.g. have the regularly used structures & functions for being modified & customized for the specific drivers.
What’s suitable minimum distribution:
What I am doing now is either building a kernel image using Buildroot then inserting the developed USB driver into it OR inserting the developed USB driver into a Ubuntu. And for proper testing I have to unload the default USB driver (usb_storage); otherwise can’t test my module. So, my question is regarding real-life development & how-to get minimum kernel that has no drivers, & how-to include my module into it (to be part of it) while building with Buildroot?
What Embedded Linux Driver Development community do you suggest for detailed Q&A?
i.e. In future if I want to ask about low level detail such as what is this x structure, or I am getting this error while using this y function .... is there a specialized community? because all I found are for Linux in general, for Kernel hacking, or don’t have experiences.
What is the missed link in the chain?
Developing applications for Microcontrollers relies on Datasheet, User Guide, Registers, C, etc. Developing Drivers for Embedded Linux relies on C, Linux API, Subsystems, etc. In most learning resources, I never found a relationship between both. So, are there really separated? OR there is a missed link between them??
e.g. for this I2C sensor http://www.robot-electronics.co.uk/htm/srf10tech.htm we have to manipulate it (send hexa to & receive values from its registers). If we imagine that we want to develop an I2C driver for it, then for sure we would need to do the same from within the driver, which is explained in Essential Linux Device Drivers (page#278). The main point behind it is that I2C core hides many complexes & simplifies driver development process.
However, I expect the case in real life is not for a sensor, instead it might be a Microcontroller or a complicated device. So, how would we manipulate the Registers & Peripherals of this Microcontroller? Also, I didn’t find tutorial for such a case!

How to read and play an audio file for my OS?

I am building a small OS. For that i wanted to play audio. I can use ports,interrupts. I have no restrictions as i am building an OS itself.
So how can i play an audio file using a C program. Please remember that I cannot and don't want to use any ready made library or so.
If you're building your own OS, you also need to care about the physical details of your audio hardware.
Differences in hardware is why operating systems introduced the concept of the device driver.
If your audio hardware is sound blaster compatible, have a look here:
http://www.phatcode.net/res/243/files/sbhwpg.pdf
There's an archive of lots of hardware-near audio code here (various hardware platforms):
http://www.dcee.net/Files/Programm/Sound/
Here's a chapter on programming sound devices:
http://www.oreilly.de/catalog/multilinux/excerpt/ch14-01.htm

Download control board software simulators

I am interested in learning how to do embedded system programming in c. However, I will need some hardware.
I am wondering is there any software that can simulate what the control board will do?
The control board is listed in the following tutorial
http://www.learn-c.com/hardware.htm
Many thanks for any advice
The board you linked to is not an embedded system board, it is an I/O interface for a PC. If you want to simulate that, you can simply write PC code stubs for the I/O functions that simulate connected devices' behaviour. However, you will not learn much about embedded systems from this. You may learn a little about PC based control, but since the board does not support interrupts or DMA, I suggest again that you will not learn much of that either.
Moreover the board is designed for an ISA bus slot. Modern PCs no longer have such slots. And modern operating systems prevent access to hardware I/O in user level code.
If you are serious about learning embedded systems development, you might for example download Keil's MDK-ARM evaluation; it includes an ARM simulator with on-chip peripheral simulation for a number of commonly available ARM based micro-controllers, and real hardware is available at reasonable cost.
If PC based control is of more interest, then you would be better off starting with a USB based I/O device, such as this example.

How to implement a USB device driver for Windows?

How should I approach implementing a USB device driver for Windows? How should I take into account different versions of windows e.g:
- Windows XP
- Windows Vista
- Windows 7
Is there open source solutions which could be used as a starting point? I'm a total newbie to windows driver development.
We have an embedded device with USB device port and we would like to have as low latency communication from the application level to the device as possible without sacrificing the data throughput. The actual data transferred is ADC/DAC data. Basically there is a lot of data which we need to transfer to a Windows machine as fast as possible.
We need more information about the device to point you in the right direction, but here are a few steps to get you started:
register with Microsoft Connect so you can download the Windows Driver Kit
register with osr-online as you'll find great articles, plenty of information, and a newsgroup dediciated just to Windows drivers -- this place is a goldmine
buy Developing Drivers with WDF, which will help you make sense of driver development on Windows and give you a good foundation to read articles from OSR and Microsoft
Hope that you can use UMDF (user-mode drivers) as you can use C++ and just write COM code. If you're doing anything with USB that requires kernel-space....you've got a lot of reading and learning to do for the next year!
To answer your question on versions, the Driver Kit has tools that will help you manage creating different drivers. If you write a good driver, it should run on all three OS with no problems, and the differences will just be in the config area (not the binary)
Basically, it depends on how complex your device is. What type of driver are you trying to write? File system? MP3 player? Camera? Modem?
If you end up having to write a kernel mode driver, let me know and I can point you to some good articles and what not.
I should also add that for around US $5,000, you can buy a license for WinDriver, a tool that takes all of the hard stuff out of driver development. You can use C++ or C# user-mode code to communicate with their driver that is custom generated for your device. This is the way to go if you have a tight deadline.
You can take a look at windows variant of libusb *here*. There are wrappers for many programming languages on official libusb site and on the web.
Start here: Windows Driver Kit Introduction
If you have some form of control over the device side, have it implement an interface for which Windows already provides drivers. E.g. the USB HID class (literally Human Input Device, but neither the Human nor the Input is mandatory) already has Windows drivers, and there is a reasonable Win32 API on top. You're not going to get data rates anywhere near 480 Mbps, though.

Resources