From: Spiro Trikaliotis (ml-cbmhackers_at_trikaliotis.net)
Date: 2006-07-09 10:27:16
Hello, in the German forum C64forum (cf. http://www.c64forum.de/wbb2/thread.php?threadid=11558 ), an interesting question came up: The person posting there would like to see the following functionality added to OpenCBM: He wants a function which gives every device attached to the serial bus a unique device number. Ideally, the one nearest to the computer (or the farest one, it does not matter) gets the 8, the next one the 9, and so on. He says that he had had a C64 copy program with exactly that functionality, but he cannot find it anymore. All solutions for such a thing require very exact timing measurements, something which is not possible with the 154x/157x/1581 hardware. Does anyone here have a good idea how this could be accomplished? The person posting there already has some ideas: 0. He states that communicating from a C64 (or a PC) with many drives (that is, all drives as listeners) should not be a problem. I think the same. Thus, we can assume we can do anything we want in the floppy. He gives some ideas for an algorithm: 1. All drives get a random number as device address (for example, in the range 127-255) 2. Now, every drives waits for a random number (in the range 1..n) before asking if this number is already used. 3. If it is, go back to 2. (I think he means 1) 4. If there is no answer before 2*n, the address will be marked used officially. 4. If after 2*n, no other drive claims an address, it is assumed all drives already have a unique address. 5. Now, the computer finds out which floppies are on the bus 6. Now, the computer re-enumerates all drives to the normal address 8..x. Disadvantage: The numbers will not be sorted from the nearest to the farest, but completely random. Oh, another idea comes to my mind, similar to the protocol used on the CAN bus: 1. Let all drives pick a random number in the range 32..255 2. Now, after getting a signal from the computer, every drive outputs its bits of the device number from high to low for a fixed period of time. 3. If any drive determines that the bit on the bus is not the bit it is outputting itself, it "is out", and keeps calm until the next round starts. 4. After the last bit, (hopefully) only one drive is still there. It gets the lowest unused "real" device number (8, 9, 10, ...), and keeps calm, until all drives have been enumerated. 5. Start another round (starting from 2...4) If someone thinks the range 32..255 is not enough, we are free to use as much bits as we like for this arbitration. Again, the big disadvantage: The numbers will be random, not from nearest to farest. What do you think? Is there a better approach then the one proposed there? Additionally, from where could I get a true random number in the floppy? Regards, Spiro. -- Spiro R. Trikaliotis http://www.trikaliotis.net/ http://opencbm.sf.net/ Message was sent through the cbm-hackers mailing list
Archive generated by hypermail pre-2.1.8.