[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [avr-gcc-list] Strings and structures in program memory
From: |
Eric Weddington |
Subject: |
RE: [avr-gcc-list] Strings and structures in program memory |
Date: |
Fri, 01 Dec 2006 09:55:12 -0700 |
Avr-libc FAQ #14:
<http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_rom_array>
> -----Original Message-----
> From:
> address@hidden
> [mailto:address@hidden
> org] On Behalf Of Trampas
> Sent: Friday, December 01, 2006 9:43 AM
> To: 'AVR GCC List'
> Subject: [avr-gcc-list] Strings and structures in program memory
>
> I am trying to create a simple command processor and was
> trying to figure out how to get strings and even the commands
> structure to live and operate from program memory. Can anyone
> show me how to do this?
>
>
>
> #define COMMAND(NAME, help) { PSTR( #NAME ), NAME ## _cmd,
> PSTR( help ) }
>
>
>
> //Command structure
>
> struct Command
>
> {
>
> PSTR name;
>
> int (*function) (int, char **);
>
> PSTR help;
>
> };
>
>
>
> //Prototypes
>
> int help_cmd(int, char **);
>
> int exit_cmd(int, char **);
>
>
>
> //List of supported commands
>
> struct Command commands[] =
>
> {
>
> {PSTR("help"), help_cmd, PSTR("help")}, //COMMAND
> (help, "Prints this message"),
>
> {PSTR("exit"), exit_cmd, PSTR("exit")},//COMMAND
> (exit, "Exits command mode"),
>
> {PSTR(""),0,PSTR("")}, //End of list signal
>
> };
>
>
>
> Then to parse commands I was trying:
>
>
>
> //now let's parse the command
>
> i=0;
>
> while(strlen_P(commands[i].name)!=0)
>
> {
>
> if (strcmp_P(buff,commands[i].name)==0)
>
> return
> (*commands[i].function)(numArgs,ptrArgv);
>
> i=i+1;
>
> }
>
>
>
> However this does not seem to work.
>
>
>
> Thanks
>
> Trampas
>
>
>
>
>
>