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

_______________________________________________
AVR-libc-dev mailing list
AVR-libc-dev@nongnu.org
https://lists.nongnu.org/mailman/listinfo/avr-libc-dev

Reply via email to