BeRTOS
cpu/pgm.h File Reference

Support for reading program memory on Harvard architectures. More...

#include <cfg/compiler.h>
#include <cpu/detect.h>
#include <cpu/attr.h>
#include <cpu/types.h>

Go to the source code of this file.

Defines

PGM support macros.

These macros enable dual compilation of code for both program and data memory.

Such a function may be defined like this:

    void PGM_FUNC(lcd_puts)(PGM_ATTR const char *str)
    {
        char c;
        while ((c = PGM_READ_CHAR(str++))
            lcd_putchar(c);
    }

The above code can be compiled twice: once with the _PROGMEM preprocessor symbol defined, and once without. The two object modules can then be linked in the same application for use by client code:

    lcd_puts("Hello, world!");
    lcd_puts_P(PSTR("Hello, world!"));

    // To be used when invoking inside other PGM_FUNC functions:
    PGM_FUNC(lcd_puts)(some_string);
#define PGM_READ8(a)   (*(const uint8_t *)(a))
#define PGM_READ16(a)   (*(const uint16_t *)(a))
#define PGM_READ32(a)   (*(const uint32_t *)(a))
#define PGM_FUNC(x)   x
#define PGM_STR(x)   x
#define PGM_ATTR
#define PGM_READ_CHAR(addr)   PGM_READ8(addr)

Typedefs

Types for variables stored in program memory (harvard processors).
typedef PROGMEM char pgm_char
typedef PROGMEM int8_t pgm_int8_t
typedef PROGMEM uint8_t pgm_uint8_t
typedef PROGMEM int16_t pgm_int16_t
typedef PROGMEM uint16_t pgm_uint16_t
typedef PROGMEM int32_t pgm_int32_t
typedef PROGMEM uint32_t pgm_uint32_t

Detailed Description

Support for reading program memory on Harvard architectures.

Support is currently provided for AVR microcontrollers only.

These macros allow building code twice, with and without pgm support (e.g.: strcpy() and strcpy_P()).

Set the _PROGMEM predefine to compile in conditional program-memory support.

Note:
This module contains code ripped out from avr-libc, which is distributed under a 3-clause BSD license.
Author:
Bernie Innocenti <bernie@codewiz.org>

Definition in file cpu/pgm.h.