avr-libc-dev
[Top][All Lists]
Advanced

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

[avr-libc-dev] Suggested improvement to <avr/pgmspace.h>


From: Marko Mäkelä
Subject: [avr-libc-dev] Suggested improvement to <avr/pgmspace.h>
Date: Mon, 2 Jan 2017 12:58:15 +0200
User-agent: NeoMutt/20161126 (1.7.1)

Hi all,

I am trying to revive my AVR hobby again, this time using the avr-libc, mainly to introduce my kids to low-level programming. I am using a couple of Arduino boards with the ATmega328P.

I started with a simple "hello world" program that outputs a NUL-terminated string to the UART:

static void msg(const char* PROGMEM msg)
{
 char c;
 while ((c = pgm_read_byte_postinc (&msg))) {
   UDR0 = c;
   loop_until_bit_is_set(UCSR0A, UDRE0);
 }
}

For optimal AVR implementation, this would require some inline assembly:

static char pgm_read_byte_postinc (const char** PROGMEM s)
{
#ifdef __AVR_HAVE_LPMX__
 char c;
 asm volatile ("lpm %0, %a1+" "\n\t" : "=r" (c), "+z" (*s));
 return c;
#else
 return pgm_read_byte((*s)++);
#endif
}

I would like to have pre/post-increment/decrement variants of all pgm_read_* functions in <avr/pgmspace.h> that are natively supported on some AVR platform. I wonder what would be the practical way to achieve this. Contribute a patch myself? I hereby contribute the above idea to the public domain.

Best regards,

        Marko



reply via email to

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