??? 03/03/06 21:22 Read: times |
#111213 - let's take this a little at a time ... Responding to: ???'s previous message |
Jan Waclawek said:
Richard,
Thanks for your comments; but I would like to ask you to comment on your comments :-) further... Richard Erlacher said:
I keep wondering why one would want that software-FIFO. There's probably good reason, but I've not found it. The example is to be viewed in the context of Jon's document. Jon gives reasons for usage of interrupt-driven software-FIFO-buffered serial communication there; maybe an example would be fine. But one thing first: it really does not matter if software- or hardware-FIFO, the question is, whether FIFO is needed at all (using the internal UART of '51, the hardware FIFO is then ruled out). The answer is simple, this all is for the convenience of programmer. If the programmer can ensure that the receiver is checked often enough, and/or can spend time to trnasmit a string, then no need for FIFO. If the programmer wants to have some time for a relatively lengthy process and there is chance that bytes will arrive and he does not want to loose them; and/or if he wants to transmit a string (a packet of data) and don't want to wait until it gets actually transmitted, then he needs the FIFO. That's all. A good example is a packet-based communication network. Let's assume a simple example: a packet of 10 bytes arrives, say at 9600 bauds, the controller processes it and is supposed to transmit a 10 bytes packet answer. The "main" program is a loop, where the mcu reads status of some pushbuttons, displays some data, reads some ADC and writes ocassionally into an EEPROM - the loop may take more than 1ms, which is approximately the time it takes for one byte to arrive; hence more than one character might arrive while the loop is executing and if (without interrupt and FIFO) the receiver would be checked only once per loop, characters might get lost. The loop then would have to be broken up into pieces and the receiver checking routine would have to be inserted on more places. Using interrupt and FIFO, there is simply only one place in the loop, where a complete packet reception is checked; and only if it happens, then the packet processing routine is invoked. It produces an outgoing packet, and not to waste time transmitting it byte by byte (which would take 10 ms for 10 bytes), it simply stores it into the output FIFO and starts the transmission. While it happily can resume the main loop, the interrupt takes care of transmitting the whole packet "in background". Is this a good example? Richard Erlacher said:
Also, if I were presenting something to a group of neophytes, I'd certainly make it clear which assembler syntax was in use and what intrinsics there were. Not everybody knows what you assume they know, particularly when you assume certain, perhaps well-known, constants/parameters are known. Hmmmm... Maybe some specific header is missing, but I believe this can be assembled by any '51 assembler, can't it? I thought the '51 assemblers all assume a basic set of 8051 registers to be implicitly known; Keil for example requires to de-activate these to be able to include a custom set of register definitions, but I don't know all the '51 assemblers around... Can you perhaps correct it to be assembler-independent? first of all ... about the following ... Richard Erlacher said:
Long labels in assembler don't make for very pretty code, either, BTW. [...]
Creative use of upper and lower case is helpful, too. [...] Programming style... In asm, I think there are no established rules. We can try to put down some here, if you want, but don't expect everybody be happy with them; I think everybody makes up his own style. I just don't think this is the right place to discuss style; as I said the program itself is not of such importance as the comments on it are. Jan Waclawek Well if we're addressing neophytes, we have to show 'em something. I date back to when we didn't have compilers for micro-anythings, and the ones we had weren't very useable. 99.999% of the code I've written has been in assembler, whether for the CDC 6000-series, the IBM7090, or the PIC 8-pin guys. If the code is easily recognizable as what it is, then people will understand it, even if they don't exactly understand the assembly language. Symbol names that are too short are not very useful, and those that are too long just make the listings look terrible. If you want to show someone something, make it look good. Now ... Richard Erlacher said:
Another thing ... if you have routines that would be called putc or getc or the like in 'C', why not use those names in assembler? They're meaningful and easy to recall and that will help anybody to understand your code. The names of character input/output in C are a bad joke. There is getc, getch, getche, getchar, fgetc, fgetchar (maybe more) providing similar or same functionality with little differences. More importantly, don't expect this from ME, I hate C. Jan Waclawek Whether you like 'C' or not, the names of those routines are OK if you don't confuse 'em. If you use only one name of a given sort for a particular function, it will be clear enough. Yes, there's getc, getch, etc, but if your particular scope includes only one routine that gets a character from the input device, then you only need to use one such name. Everybody knows it's NOT 'C' so they won't get their neckties all wrapped-around-the-axle trying to figure out what's what. Shorter names are better than longer ones. <6-character ones fit before the first TAB. It's easy to figure out which is better. Better isn't ALWAYS possible, but it's always preferable. As for the FIFO question ... I'm not sure the software FIFO belongs in an ISR. The FIFO should, IMHO, be in the hardware, so you get fewer interrupts per character. Unfortunately, your interrupt is to tell you there's a character, or more. It depends entirely on what you're doing, so I'd say a FIFO is an inappropriate thing to implement in software IN AN ISR. That's just my opinion, though. RE |
Topic | Author | Date |
interrupt driven serial: RFC | 01/01/70 00:00 | |
It must be perfect! | 01/01/70 00:00 | |
I don't believe | 01/01/70 00:00 | |
Validation | 01/01/70 00:00 | |
well ... I've looked at it ... | 01/01/70 00:00 | |
request for comment on comment | 01/01/70 00:00 | |
let's take this a little at a time ... | 01/01/70 00:00 | |
OK then give yours | 01/01/70 00:00 | |
Intel Original | 01/01/70 00:00 | |
on byte buffer | 01/01/70 00:00 | |
c version | 01/01/70 00:00 | |
Coloring | 01/01/70 00:00 | |
html syntax colouring | 01/01/70 00:00 | |
to C or not to C | 01/01/70 00:00 | |
yeah but thats the point | 01/01/70 00:00 | |
How true for "real C" | 01/01/70 00:00 | |
excellent idea![]() | 01/01/70 00:00 | |
asm, in the same style | 01/01/70 00:00 | |
This may not work well ... | 01/01/70 00:00 | |
How? | 01/01/70 00:00 |