avasin
avasin

Reputation: 9736

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?

Upvotes: 0

Views: 227

Answers (1)

rodrigo
rodrigo

Reputation: 98496

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...

Upvotes: 2

Related Questions