How to Store a Predefined Dataset in Flash / ROM Possibly a strut?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to Store a Predefined Dataset in Flash / ROM Possibly a strut?

2,154 Views
mjcoury
Contributor I
Hello All -

I need to have menu system so that I can navigate through many different functions and lists.  I want it to be generic using a simple function to be able to display a list of options and then call a function based on what is called.

I have the structure of this mapped out (whether or not its good or bad is for a different thread)  I am tight on RAM and I do not want a potentially 200 element menu system of pointers and identifiers stuffed in RAM.

Is there a way to put a large chunk of Hex directly into flash?  The hex would be in a format that I could point a structure pointer to a point in ROM (the head) and be able to navigate through all my selections?  Is there a menu scheme somewhere that is already done and works well?

Thanks for the help.
Labels (1)
0 Kudos
6 Replies

524 Views
UcTechnoGeek
Contributor II
I don't know if this is exactly what you are trying to do or not, but here it goes anyway.
 
Attached is some code I use based on using Processor Expert to create a serial port terminal menu system (in a previous version, so it may need to be updated a bit).  I use it to display a "help" menu.  You can then enter a command and possible variables, that will call subroutines in the main software file or sub-menus.
 
What it does:
CmdProc.c - reads characters from the serial port and echos them back to the terminal.  When enter is pressed (or one of a few other stop conditions), the command is processed by matching the characters entered to a command list.  If a match is found, that routine is called from the main file (in this case EPT_vMR32.c).
 
I've cut most of the code out of the main file for clairity, so hopefully you can still understand by the comments what is happening.
 
Good luck.
uCTechnoGeek
0 Kudos

524 Views
DustyStew
Contributor V
What language are you writing in?

I once wrote a command line interface for the 68HC11, in C, with an array of structures. You have at minimum a "text" field and a "pointer" field. You use a string ocmpare function (like strcmp) to search for a matching string. If found, call the function. You need to know how to deal with C pointers & structures.

In assembly, it is probably easiest to have two arrays, one of fixed length strings, and the other of pointers. Using fixed length strings makes it somewhat faster and easier to step through the array of what will likely be variable length strings.

But this is a command line interface. How will you display the menu? Will the user type a character to select an item?

...Dust
0 Kudos

524 Views
mjcoury
Contributor I
I'm programming in C to answer that question... so I don't think ORG or the DC command will help me.

The menu will display via LCD and will operate via a zigbee remote....


0 Kudos

524 Views
bigmac
Specialist III
Hello mjcoury,
 
The following thread may be useful for setting up an array of function pointers, to enable you to associate a function with each menu item -
 
With use of a LCD display, and a limit to the number of display lines, often only a single menu item would be displayed at one time, and keys/pushbuttons used to cycle through each item, or select the displayed item.  Is this your situation?
 
One possibily is to have an array of strings (as previously suggested by others), and also an array of functions, encompassing all menu items, not necessarily in a particular order.  This would mean that each menu item would be uniquely identified by a single index value.  It should then be a question of arranging various index values into the many tables (arrays) for each menu and sub-menu.  All the data should be located in flash.
 
For the functions referenced with the array of functions, you might consider passing a variable.  This may enable you to use a common function for the selection of the next sub-menu item, where the variable might represent an index to the required sub-menu.
 
Regards,
Mac
 
0 Kudos

524 Views
DustyStew
Contributor V
The answer is to use the "const" keyword.

For example, this array, which maps from an error code to a string, is stored in FLASH:

const char *cmd_messages[] =
{
"", // E_EMPTY
"OK", // E_SUCCESS
"System error", // E_SYSTEM
"Invalid address", // E_ADDRESS
"", // E_NO_CMD
"Command not found", // E_CMD_INVALID
"Command too long", // E_CMD_LENGTH
"Too few parameters", // E_ARG_COUNT
"Invalid parameter", // E_ARG_INVALID
"Too many parameters", // E_ARG_EXTRA
"Invalid parameter", // E_ARG_LENGTH
"Invalid parameter" // E_ARG_RANGE
};

Turns out I have a command line interface implemented in C for the HCS08. If you haven't yet worked out the syntax for calling a function with a pointer, I could dig that out for you as well.

Cheers
Tom
0 Kudos

524 Views
Curt
Contributor IV
You can use the ORG and DC directives in assembly language to put your menu item string/jump table anywhere in flash.  Your assembler docs. will show you how.
 
Hope that's helpful.
 
0 Kudos