[En-Nut-Discussion] How do I convert PROGMEM(gcc) to ICCAVR? (Please)

Harald Kipp harald.kipp at egnite.de
Fri Jun 17 15:39:35 CEST 2005


Brett,

That may not be the only pitfall. The 'const' keyword in
the parameter list hits me too.

PROGMEM is

   #define __ATTR_PROGMEM__ __attribute__((__progmem__))

which is not portable. GCC is the only compiler I know of,
which uses attributes. In my opinion this is the smartest
solution and superior to this pragma stuff used by other
compilers. Anyhow...

ICCAVR uses the 'const' keyword to achieve the same. ICC is
generally a nice compiler, but that feature is the worst
solution I can think of, completely breaks portability and
is simply wrong.

Because of this Nut/OS has to use 'CONST' (capital letters)
instead of ANSI C 'const'.

The GCC
   ee_tbl_data ee_tbl_def_P PROGMEM = {
should be translated to
   const ee_tbl_data ee_tbl_def_P = {
for ICC.

GCC
   static u_char eeprom_upgrade(register const ee_tbl * old_tablep,
should become
   static u_char eeprom_upgrade(register ee_tbl * old_tablep,
for ICC, which is also acceptable for GCC. Or use
   static u_char eeprom_upgrade(register CONST ee_tbl * old_tablep,
to serve both.

Actually 'const' is not required by GCC, but it provides
additional checks and can be used by the compiler for a
number of very effective optimizations. No idea why Richard
threw away this possibility by redefining the meaning of
'const'.

Harald


At 00:45 18.06.2005 +1200, you wrote:
>Hi
>
>Im porting the Flash sample application by Dusan Ferbas to ICCAVR but have 
>hit a gcc function Im unaware of.  Could I ask if someone could advise the 
>ICCAVR equivalent of PROGMEM?  I include the definition below which gives 
>an error in ICCAVR - Im unsure of what the correct syntax should be.  Ive 
>also included a function using it.
>
>Any help very greatfully appreciated.
>
>Thanks in advance
>Brett
>
>from eeparams.c (flash Project)
>//************************************
>// EEPROM upgrade/downgrade routines
>//************************************
>ee_tbl_data ee_tbl_def_P PROGMEM = {    // THIS LINE GIVES THE ERROR
>    {
>     EEPROM_TBL_PTRN,
>     offsetof(ee_tbl_data, e_elem),
>     EE_VAR_NUM,
>     {{{0x00, 0x0a, 0x59, 0x63, 0x08, 0x27}
>       }
>      }
>     /* default which will be overloaded, see below
>      * - loading MAC from non table version
>      * - preserving MAC  */
>     }
>    ,
>
>    EE_VPTRN,
>
>    {
>     {EE_VAR_BAUDRATE, CFG_ITEM_LEN(BaudRate), CFG_ITEM_OFFS(BaudRate)}
>     ,
>     {EE_VAR_DATA_LENGTH, CFG_ITEM_LEN(DataLength), CFG_ITEM_OFFS(DataLength)}
>     ,
>     {EE_VAR_STOP_BITS, CFG_ITEM_LEN(StopBits), CFG_ITEM_OFFS(StopBits)}
>     ,
>     {EE_VAR_PARITY, CFG_ITEM_LEN(Parity), CFG_ITEM_OFFS(Parity)}
>     ,
>     {EE_VAR_COMM_TIMEOUT, CFG_ITEM_LEN(CommTimeout), 
> CFG_ITEM_OFFS(CommTimeout)}
>     ,
>
>     {EE_VAR_IPA, CFG_ITEM_LEN(aux_my_ip_addr), CFG_ITEM_OFFS(aux_my_ip_addr)}
>     ,
>     {EE_VAR_MASK, CFG_ITEM_LEN(aux_my_ip_mask), 
> CFG_ITEM_OFFS(aux_my_ip_mask)}
>     ,
>     {EE_VAR_GW, CFG_ITEM_LEN(aux_gw_ip_addr), CFG_ITEM_OFFS(aux_gw_ip_addr)}
>     ,
>     {EE_VAR_HTTP_PORT, CFG_ITEM_LEN(http_port), CFG_ITEM_OFFS(http_port)}
>     ,
>     {EE_VAR_USER_SETTINGS, CFG_ITEM_LEN(UserSettings), 
> CFG_ITEM_OFFS(UserSettings)}
>     }
>};
>
>static u_char eeprom_upgrade(register const ee_tbl * old_tablep,
>                             ee_tbl_data * ee_tbl_defp, u_char init_flg)
>{
>    u_char  tbl_upgrade[EE_VAR_NUM];
>    /* these values has been read from previous table */
>    u_char  ee_pass = 1;
>
>    memset(tbl_upgrade, 0, sizeof(tbl_upgrade));
>    /* assume nothing read from previous version */
>    memset(gBoardDatap, 0, sizeof(BoardDataS));
>    /* reset EEPROM contents to a known state (better for debugging) */
>
>
>--




More information about the En-Nut-Discussion mailing list