??? 03/22/05 07:41 Read: times |
#90212 - well Responding to: ???'s previous message |
hi,
Jan Waclawek said:
With the "smarter" devices, for each parameter or set of parameters and each transmitted variable, a separate type of packet is added to the protocol stack. But for this little one, this approach increases the required code space beyond a tolerable limit (4kB in this case); so we implemented a single "write/read directly into/from RAM/FRAM" couple of request/response. Of course, this implies either to keep the position of the parameters/variables absolute for each modification/upgrade of the gadget, or to have a "relocation table" on the PC for each modification/upgrade.
I see yet another ways: 1) PC always see parameters/variables at fixed absolute addresses. PC may even call them not "addresses" but "parameters` numbers". Nevertheless, inside MCU they are placed as continuous array with dispacement which value may be different from modification/upgrade. Anyway, MCU knows this displacement and may easy calculate requisite absolute address. 2) MCU reserves upto 256 bytes in code segment for relocation table: one byte for each parameter number. These bytes define real absolute addresses of requisite parameters` numbers in current modification/upgrade. So: 2a) either MCU does relocation replacement itself; 2b) either PC asks for this table as first step and then uses it to get absolute address. By the way, method you described, is dangerous. I hope you have implemented a kind of sanity check when PC asks write to absolute RAM location. Otherwise due some network malfunction it may destroy a wrong variable or, for example, stack content. An another example I do it this way: Scramble EQU 030h ;-33h ;... other variables here SrcBuf EQU 040h ;-5Fh DstBuf EQU 060h ;-7Fh ;at start, r0 contains pointer to SrcBuf ; b contains message length mov r1,0 anl r1,#03h ;first, calculate pointer into Scramble orl r1,#Scramble Loop: mov a,@r0 ;get data from SrcBuf xrl a,@r1 ;perform scramble xrl 0,#SrcBuf XOR DstBuf ;get pointer to DstBuf mov @r0,a ;store scrambled data xrl 0,#SrcBuf XOR DstBuf ;restore pointer to SrcBuf inc r1 ;increment Scramble pointer anl 1,#0FBh ;wrap around Scramble pointer inc r0 ;increment SrcBuf pointer anl 0,#0DFh ;wrap around SrcBuf pointer djnz b,loop anl r1,#03h orl r1,#Scramble ...but I understand that it is just a typpo (should be anl 1,#03h etc). What I wish to say: good example. As for me, so with such strong requirements you shown us, I would preffer to use segments anyway, something like: Scramble_addr EQU 0x30 SrcBuf_addr EQU 0x40 DstBuf_addr EQU 0x60 ISEG AT Scramble_addr Scramble: DS 4 ISEG AT SrcBuf_addr SrcBuf: DS 32 ISEG AT DstBuf_addr DstBuf: DS 32 ;... ; ;at start, r0 contains pointer to SrcBuf ; b contains message length mov r1,0 anl 1,#03h ;first, calculate pointer into Scramble orl 1,#Scramble_addr Loop: mov a,@r0 ;get data from SrcBuf xrl a,@r1 ;perform scramble xrl 0,#(SrcBuf_addr XOR DstBuf_addr) ;get pointer to DstBuf mov @r0,a ;store scrambled data xrl 0,#(SrcBuf_addr XOR DstBuf_addr) ;restore pointer to SrcBuf inc r1 ;increment Scramble pointer anl 1,#0FBh ;wrap around Scramble pointer inc r0 ;increment SrcBuf pointer anl 0,#0DFh ;wrap around SrcBuf pointer djnz b,loopFor my point of view, this way helps locator to check memory usage and always gives me a chance to see warning/error if some other variables will overrun or are placed wrong. In your example, if you by ocasion define a variable inside any buffer then you will not be noticed about that during compiling. In my case, when all variables are defined with Keil assembler requirements, it is much more safe. This is not to say that it is necessary to use absolute variable positioning, or that this is a proper way of general programming.
Each method/tool has its right place and shall be used so. But, never say never. Agreed. Regards, Oleg |
Topic | Author | Date |
initializing SP to 7FH | 01/01/70 00:00 | |
why? | 01/01/70 00:00 | |
To Oleg & Russell | 01/01/70 00:00 | |
To Mehdi | 01/01/70 00:00 | |
To Mehdi | 01/01/70 00:00 | |
why not | 01/01/70 00:00 | |
for example, please | 01/01/70 00:00 | |
Oleg, why I do similar | 01/01/70 00:00 | |
here they are | 01/01/70 00:00 | |
well | 01/01/70 00:00 | |
well well | 01/01/70 00:00 | |
well, well - done | 01/01/70 00:00 | |
tight SRAM - use C | 01/01/70 00:00 | |
- or assembler![]() | 01/01/70 00:00 | |
Stack pointer | 01/01/70 00:00 | |
external stack | 01/01/70 00:00 | |
why not? | 01/01/70 00:00 | |
SDCC | 01/01/70 00:00 | |
Re:initializing SP to 7FH | 01/01/70 00:00 | |
very old assemblers only | 01/01/70 00:00 | |
Let the assembler do the work! | 01/01/70 00:00 |