 |
 |
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
|
Posted: Thu Nov 24, 2005 11:07 am |
|
|
Got it!
I wish I could buy you a beer mate!!
Finally, would you provide any practical code doing the rom scanning? I certainly didn't come across this before.....
| Quote: | | I mentioned in one of the earlier posts, that I scan the area concerned during boot, to find the start of message characters. So the simple 'initialisation', involves setting msg[0] = 0, then scanning till I find the '~', and setting msg[1] to the next character. |
All the best |
|
 |
dyeatman
Joined: 06 Sep 2003 Posts: 1985 Location: Norman, OK
|
|
Posted: Thu Nov 24, 2005 11:17 am |
|
|
The "scanning" routine he refers to is nothing more than a FOR loop that starts testing at the first character in the message area.
Each iteration of the FOR loop you test the character in that message area position for the '~'. If you get a match you store the number of the next message char pos in the next sequential location in the msg[x] array then continue "scanning" for the next '~' until you reach the end of the message area. When you are done the msg[] array contains the position of the starting character for each message. From this info I think you can work it out....
P.S. To clarify what I was saying above.
Looking back at TTelmahs approach it appears he is actually storing the absolute memory location in msg[] rather than the character count location (offset from the beginning of the message area). I use the offset approach for all of my implementations of a similar message/menuing system.... I believe his approach will save a few bytes over mine since I have to "calculate the offset" when I access each messsage.
Last edited by dyeatman on Thu Nov 24, 2005 11:30 am; edited 2 times in total |
|
 |
Guest
|
|
Posted: Thu Nov 24, 2005 11:22 am |
|
|
| Thank you for all of it!! |
|
 |
Ttelmah Guest
|
|
Posted: Thu Nov 24, 2005 3:44 pm |
|
|
I do use the 'offset' approach on newer chips.
On chips with only 64K or less of ROM, using the direct address makes no difference. However on chips with more ROM than this, storing the absolute address, means you have to store a 32bit value. On these latter chips, I switched to using a 16bit 'offset', to save RAM.
Best Wishes |
|
 |
dyeatman
Joined: 06 Sep 2003 Posts: 1985 Location: Norman, OK
|
|
Posted: Thu Nov 24, 2005 3:55 pm |
|
|
Of course something that neither one of us mentioned is simply counting the positions and initializing the array with those values already stored.
The pro is that it would save having to initialize but the con is that it wouldn't automatically compensate if the messages got changed. (and it isn't as elegant!)  |
|
 |
ye
Joined: 11 May 2005 Posts: 57 Location: london
|
|
Posted: Fri Nov 25, 2005 4:46 am |
|
|
I actually write a simple code to implement the storage and retrieving according to your 'offset' approach. Can you have a quick look to see if it is efficient and if it is doing the same thing as you did?
| Code: |
// The following section demonstrates the approach of information storage
// using #ROM and scanning the message area to form an OFFSET TABLE that
// is stored in RAM. Messages stored in ROM will be retrieved using
// read_program_memory()
// e.g. I want to store 3 message arrays in a rom block
// The 3 arrays are: "abc", "123","defg"
// Use '~' as marker
// The whole block starts from address 0x0000
#define MAXMSGNO 3
#define STARTADDRESS 0x0000
#ROM STARTADDRESS = {"abc",'~',"123",'~',"defg"};
int length[3]; // Array where message lengths are stored
int16 start_address; // block starting address
int i,j;
start_address = (int16)STARTADDRESS; // The start address of the first msg is the start address of the whole block
for(i=0;i<MAXMSGNO;i++)
{
for(j=0;*(j+start_address) != '~'; j++) // keeping examining the contents
; // of the message area starting from
// the start address of the first message, until '~' encountered
length[i] = j; // Store the length
start_address += (j+1); // Move the start address to the start address of the second message
}
|
Please do comment.
Cheers |
|
 |
Ttelmah Guest
|
|
Posted: Fri Nov 25, 2005 5:22 am |
|
|
You cannot have 'STARTADDRESS' = 0...
You are trying to write the data right into the bottom of the program memory, which is where the processor boots, and the interrupt vectors reside.
Declare your 'start_address' variable as an int32, which is important if your total memory goes over 64K. Then store the message addresses, _less_ the 'STARTADDRESS' value, rather than the message lengths. Then to access a value, you just generate 'STARTADDRESS+address[i]', to access the actual message.
Change the STARTADDRESS define, to:
#define STARTADDRESS (int32)(0xnnnn)
Where 'nnnn' is the address the array is to go to.
This ensures again that you have int32 values when needed.
Note also my use of #ORG, to prevent the compiler re-using the memory area.
Best Wishes |
|
 |
ye
Joined: 11 May 2005 Posts: 57 Location: london
|
|
Posted: Fri Nov 25, 2005 5:41 am |
|
|
Thank you!  |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|