devices

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
elias

devices

Post by elias »

ive been hearing people on this site saying that they are making their OSes so that each device can have its own special functions. but what i dont get it, what else would you need to do with a device other then read/write/seek? what ideas have you guys come up with? because it seems to me that on the most basic level, everything boils down to that.
jrfritz

Re:devices

Post by jrfritz »

Hmm maybe:

pre calculate information...

Merge information

Other advanced stuff that makes it easier for the reg programmer....
elias

Re:devices

Post by elias »

yes but that could all be included in the write function. the programmer dosnt need that stuff, jsut to read and write. if all devices have a universal set of functions, it makes it so that you dotn need to know about specific devices
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:devices

Post by Pype.Clicker »

simply commercially speaking, if your system is 100% standard compliant -- fully implements the standard and nothing else -- it gives .the .product very few distinctions from .other .products ...

it suxx, but that's the way it is ... You cannot prevent cisco from doing 22Mbps wireless devices while the standard is 11Mbps ...
Tim

Re:devices

Post by Tim »

elias wrote:but what i dont get it, what else would you need to do with a device other then read/write/seek? what ideas have you guys come up with? because it seems to me that on the most basic level, everything boils down to that.
There are lots of things to do with devices other than read, write or seek. Most devices don't fit into a nice 'stream of bytes' metaphor. You could do as Unix does and define read, write and seek for every device, with all other functionality shoved into ioctl, or you could give each device its own set of methods.

It doesn't take long to think of examples that don't fit into the read/write/seek model. One that springs immediately to my mind is an accelerated video card: how do you get it to draw lines? To copy bitmaps? What should write() do when given a handle to a network card? How do you use read() to obtain the data of track 10 between 3'15" and 4'25" of an audio CD?
elias

Re:devices

Post by elias »

thats up to the driver programmer. i see what you mean, but if you make it so each device has its own set of functions, you get a big mess. lets say your creating a network program, how woudl you make it compatible with all different network cards, if they have differetn functions? this stuff should be hidden, so that the programmer jsut has to call read, and can read in data from a network. from what you were saying about the CD, i could be wrong, but it seems that you just need to seek up to 3'15", and read (4'25" - 3'15") bytes of data.
Tim

Re:devices

Post by Tim »

elias wrote:this stuff should be hidden, so that the programmer jsut has to call read, and can read in data from a network.
"Reading" from a network makes no sense. You have to be able to receive; maybe from a certain hardware or protocol address, or from a multicast or broadcast address; you have to know where a packet came from; you have to know what protocol it comes under. A single POSIX-style read() function can't represent all that; rather, it can, but it would be a mess.
from what you were saying about the CD, i could be wrong, but it seems that you just need to seek up to 3'15", and read (4'25" - 3'15") bytes of data.
Given a function like seek(handle, offset, origin):
  • What offset gives track 10?
  • What offset from there gives 3 minutes 15 seconds?
  • How many bytes is 4'25" - 3'15" of music?
  • Which channel of a stereo recording gets read? Which channel of a 5.1 recording gets read?
These are the kinds of problems you must solve. read/write/seek doesn't hack it; it's far less clean to shove every possible device interaction into these three functions than it is to define a standardised interface for invoking methods on devices.

I can't go into too much detail here, but I suggest you read up on the way the NT family handles these things, as an example of a non-POSIX kernel. IMHO it's far cleaner and more capable than the typical Unix kernel in this respect. Start at http://msdn.microsoft.com/library/en-us ... g_7ycn.asp and work your way down.
elias

Re:devices

Post by elias »

well you wouldnt read from a network, but from a port. the packet shoudl have all th enecessary information so you can track. there must be a way to get an offset for the CD, because somewhere along the line it has to be translated to an adress. the onyl problem i have with your idea, is that to write a program that uses some driver, you have to know how to use teh driver, and when we are talking about many devices that do things different ways, its gonna be a pain to support all hardware.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:devices

Post by Pype.Clicker »

Device drivers are a must. Without them, every application should know every hardware (just like in the old MS-DOS times : if the game you whish to play only accept GUS and you have a SB, you're limited to "nosound" version :( ).

Using drivers means that the OS will set up an abstraction that every application should know and use, and that every hardware manufacturer must provide software to implement this abstraction for their own device.

But of course, for the hobby-OS programmer, this does not help as he usually can't reuse the driver code the hardware manufacturer provided ... So it's up to him to redo everything from scratch to get drivers working ....
elias

Re:devices

Post by elias »

yes i know that, but if you make it so that every driver has a different set of functions, then it becomes jsut like in the MS-DOS days
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:devices

Post by Pype.Clicker »

elias wrote: yes i know that, but if you make it so that every driver has a different set of functions, then it becomes jsut like in the MS-DOS days
What do you mean by "every driver has a different set of function" ?
You don't expect to have the same API for a scanner, a 3D graphic card and for a network card, do you?

Each device usually have input and/or output, but also control (volume, video resolution setup, etc.) which requires another API.
Therx

Re:devices

Post by Therx »

Tim Robinson wrote: "Reading" from a network makes no sense. You have to be able to receive; maybe from a certain hardware or protocol address, or from a multicast or broadcast address;
I disagree. Using the conventional read, write and seek you can do this. In my OS I have a multi layered device structure. If you want to directly read 12 bytes from the Network Card (read only) you would do:-

Code: Select all

FILE *netread;
char *buffer
netread = open(":nic0", RO);
read(netread, buffer, 12);
close(netread);
But if you wanted to read 12 bytes which had been decoded by TCP/IP on port 25 you would do:-

Code: Select all

FILE *netread;
char *buffer
netread = open(":nic0/tcpip", RO);
seek(netread, 25);
read(netread, buffer, 12);
close(netread);
I see no obvious problem with this method
Post Reply