简体   繁体   中英

How i can retrieve data in my linux virtual device driver?

I have to implement virtual device driver, that will calculate sin of specified angle.

I found article how to write hello-world driver, it works nice, when i call cat on it.

But to calculate sin, i need to transfer some data to my driver. Which solution is most painless?

Should i first of all read all input data in separate method, remember it somewhere and then calculate & output?

The most painless solution would probably be to implement a ioctl .

The cat in the linked example uses read() , that is nice when your device generates data, such as a mouse or a video camera, but when a device replies to commands a ioctl is more appropriate: you send a command GET_SIN with an angle as argument and get a reply with the answer.

The alternative would be to write() the angle and then read() the solution: far more complicated, because there may be several processes reading and writing at the same time and it would be a mess!

BTW, beware! AFAIK, the kernel is not allowed to use floating point arithmentic, nor to link to -lm , so you will have to implement the sine as a fix-point integer function, maybe using a table...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM