[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-libc-dev] New pgm_read_ptr() macro?

From: Jan Waclawek
Subject: Re: [avr-libc-dev] New pgm_read_ptr() macro?
Date: Thu, 3 Jun 2010 17:03:04 +0200


We are not talking about macros exactly.

1. pgm_read_xxx_far() macros are contained in the "original" <avr/pgmspace.h>
2. the major "component" of Carlos' morepgmspace.h is the GET_FAR_POINTER 
macro, which allows to access objects placed in far FLASH (rather than having 
them placed at an absolute address)
3. Carlos also provided a couple of memxxx() and strxxx() routines with far 
access (suffixed _PF), which are also prototyped in morepgmspace.h. See 
4. In 
 I described a simple change in the linker script to allow placing unessential 
constants (e.g. strings) to far FLASH (Dale did essentially the same 
independently, so there must be some rationale in doing that). I've added a 
couple of macros to morepgmspace.h to support that; the modified morepgmspace.h 
is appended to the same avrfreaks thread.
5. In http://lists.gnu.org/archive/html/avr-libc-dev/2010-06/msg00004.html I 
described my attempt to merge the GET_FAR_POINTER macro with the ELPMs 
themselves. in the spirit of "universal" access macro you've suggested, but as 
I report there, the result is disappointing (for some entertainment, I am 
appending here the final result of that attempt).


#define pgm_read_far_var(var)                               \
(__extension__ ({                                           \
  union {                                                   \
    __typeof__(var)        original;                        \
    uint8_t                placeholder;                     \
  } __result;                                               \
  __asm__ __volatile__(                                     \
      "ldi  r30, hlo8(%[__ADDR])                      \n\t" \
      "out  %[__RAMPZ], r30                           \n\t" \
      "ldi  r30, lo8(%[__ADDR])                       \n\t" \
      "ldi  r31, hi8(%[__ADDR])                       \n\t" \
      "elpm %A[__RESULT], Z+                          \n\t" \
      ".if (%[__SIZE] > 1)                            \n\t" \
      "elpm %B[__RESULT], Z+                          \n\t" \
      ".endif                                         \n\t" \
      ".if (%[__SIZE] > 2)                            \n\t" \
      "elpm %C[__RESULT], Z+                          \n\t" \
      "elpm %D[__RESULT], Z+                          \n\t" \
      ".endif                                         \n\t" \
    : [__RESULT]   "=r"  (__result.placeholder)             \
    : [__ADDR]     "p"  (&amp;(var))                            \
    , [__RAMPZ]    "I"  (_SFR_IO_ADDR(RAMPZ))               \
    , [__SIZE]     "X"  (sizeof(var))                       \
    : "r30", "r31"                                          \
  );                                                        \
  __result.original;                                        \

----- Original Message ---------------

>On 03/06/2010 14:55, Jan Waclawek wrote:
>>> I would also like very much to finally add the FAR macros that
>>> Carlos put together a long time ago, or something very similar. I
>>> don't remember if there was ever any issues with them that need to
>>> get resolved, or if there is basic agreement that these should be
>>> added the way they are etc. But I would like to put the issue to
>>> rest and get them added in some fashion.
>> I am using Carlos' work daily for more than a year now and there's no
>> issue with it. There might be some functions added - I've written for
>> example a memcmp_PF() for my own purposes.
>> Recently, I've summarized some of my experience in
>> http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=93874&highlight=
>> . Mostly minor issues, but if I've had that information on hand when
>> I started using the "far FLASH" it would spare me some time and
>> experimentation.
>> I've also posted a couple of more pgmspace.h-related remarks in
>> https://savannah.nongnu.org/bugs/?28058 .
>> JW
>Jan, could you email me a copy of Carlos' macros, or your current 
>macros?  I'd like to have a look at them and see if I can find a way to 
>get the FAR stuff working without the overhead when it's not needed.  I 
>don't know if it's possible, but it could be fun to try.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]