diff options
author | alk3pInjection <webmaster@raspii.tech> | 2024-02-04 16:16:35 +0800 |
---|---|---|
committer | alk3pInjection <webmaster@raspii.tech> | 2024-02-04 16:16:35 +0800 |
commit | abdaadbcae30fe0c9a66c7516798279fdfd97750 (patch) | |
tree | 00a54a6e25601e43876d03c1a4a12a749d4a914c /share/doc/gcc/AVR-Variable-Attributes.html |
https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads
Change-Id: I7303388733328cd98ab9aa3c30236db67f2e9e9c
Diffstat (limited to 'share/doc/gcc/AVR-Variable-Attributes.html')
-rw-r--r-- | share/doc/gcc/AVR-Variable-Attributes.html | 246 |
1 files changed, 246 insertions, 0 deletions
diff --git a/share/doc/gcc/AVR-Variable-Attributes.html b/share/doc/gcc/AVR-Variable-Attributes.html new file mode 100644 index 0000000..98bc7ee --- /dev/null +++ b/share/doc/gcc/AVR-Variable-Attributes.html @@ -0,0 +1,246 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html> +<!-- This file documents the use of the GNU compilers. + +Copyright (C) 1988-2023 Free Software Foundation, Inc. + +Permission is granted to copy, distribute and/or modify this document +under the terms of the GNU Free Documentation License, Version 1.3 or +any later version published by the Free Software Foundation; with the +Invariant Sections being "Funding Free Software", the Front-Cover +Texts being (a) (see below), and with the Back-Cover Texts being (b) +(see below). A copy of the license is included in the section entitled +"GNU Free Documentation License". + +(a) The FSF's Front-Cover Text is: + +A GNU Manual + +(b) The FSF's Back-Cover Text is: + +You have freedom to copy and modify this GNU Manual, like GNU + software. Copies published by the Free Software Foundation raise + funds for GNU development. --> +<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ --> +<head> +<title>Using the GNU Compiler Collection (GCC): AVR Variable Attributes</title> + +<meta name="description" content="Using the GNU Compiler Collection (GCC): AVR Variable Attributes"> +<meta name="keywords" content="Using the GNU Compiler Collection (GCC): AVR Variable Attributes"> +<meta name="resource-type" content="document"> +<meta name="distribution" content="global"> +<meta name="Generator" content="makeinfo"> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> +<link href="index.html#Top" rel="start" title="Top"> +<link href="Indices.html#Indices" rel="index" title="Indices"> +<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> +<link href="Variable-Attributes.html#Variable-Attributes" rel="up" title="Variable Attributes"> +<link href="Blackfin-Variable-Attributes.html#Blackfin-Variable-Attributes" rel="next" title="Blackfin Variable Attributes"> +<link href="ARC-Variable-Attributes.html#ARC-Variable-Attributes" rel="previous" title="ARC Variable Attributes"> +<style type="text/css"> +<!-- +a.summary-letter {text-decoration: none} +blockquote.smallquotation {font-size: smaller} +div.display {margin-left: 3.2em} +div.example {margin-left: 3.2em} +div.indentedblock {margin-left: 3.2em} +div.lisp {margin-left: 3.2em} +div.smalldisplay {margin-left: 3.2em} +div.smallexample {margin-left: 3.2em} +div.smallindentedblock {margin-left: 3.2em; font-size: smaller} +div.smalllisp {margin-left: 3.2em} +kbd {font-style:oblique} +pre.display {font-family: inherit} +pre.format {font-family: inherit} +pre.menu-comment {font-family: serif} +pre.menu-preformatted {font-family: serif} +pre.smalldisplay {font-family: inherit; font-size: smaller} +pre.smallexample {font-size: smaller} +pre.smallformat {font-family: inherit; font-size: smaller} +pre.smalllisp {font-size: smaller} +span.nocodebreak {white-space:nowrap} +span.nolinebreak {white-space:nowrap} +span.roman {font-family:serif; font-weight:normal} +span.sansserif {font-family:sans-serif; font-weight:normal} +ul.no-bullet {list-style: none} +--> +</style> + + +</head> + +<body lang="en_US" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> +<a name="AVR-Variable-Attributes"></a> +<div class="header"> +<p> +Next: <a href="Blackfin-Variable-Attributes.html#Blackfin-Variable-Attributes" accesskey="n" rel="next">Blackfin Variable Attributes</a>, Previous: <a href="ARC-Variable-Attributes.html#ARC-Variable-Attributes" accesskey="p" rel="previous">ARC Variable Attributes</a>, Up: <a href="Variable-Attributes.html#Variable-Attributes" accesskey="u" rel="up">Variable Attributes</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indices.html#Indices" title="Index" rel="index">Index</a>]</p> +</div> +<hr> +<a name="AVR-Variable-Attributes-1"></a> +<h4 class="subsection">6.34.3 AVR Variable Attributes</h4> + +<dl compact="compact"> +<dd><a name="index-progmem-variable-attribute_002c-AVR"></a> +</dd> +<dt><code>progmem</code></dt> +<dd><p>The <code>progmem</code> attribute is used on the AVR to place read-only +data in the non-volatile program memory (flash). The <code>progmem</code> +attribute accomplishes this by putting respective variables into a +section whose name starts with <code>.progmem</code>. +</p> +<p>This attribute works similar to the <code>section</code> attribute +but adds additional checking. +</p> +<dl compact="compact"> +<dt>• Ordinary AVR cores with 32 general purpose registers:</dt> +<dd><p><code>progmem</code> affects the location +of the data but not how this data is accessed. +In order to read data located with the <code>progmem</code> attribute +(inline) assembler must be used. +</p><div class="smallexample"> +<pre class="smallexample">/* Use custom macros from AVR-LibC */ +#include <avr/pgmspace.h> + +/* Locate var in flash memory */ +const int var[2] PROGMEM = { 1, 2 }; + +int read_var (int i) +{ + /* Access var[] by accessor macro from avr/pgmspace.h */ + return (int) pgm_read_word (& var[i]); +} +</pre></div> + +<p>AVR is a Harvard architecture processor and data and read-only data +normally resides in the data memory (RAM). +</p> +<p>See also the <a href="Named-Address-Spaces.html#AVR-Named-Address-Spaces">AVR Named Address Spaces</a> section for +an alternate way to locate and access data in flash memory. +</p> +</dd> +<dt>• AVR cores with flash memory visible in the RAM address range:</dt> +<dd><p>On such devices, there is no need for attribute <code>progmem</code> or +<a href="Named-Address-Spaces.html#AVR-Named-Address-Spaces"><code>__flash</code></a> qualifier at all. +Just use standard C / C++. The compiler will generate <code>LD*</code> +instructions. As flash memory is visible in the RAM address range, +and the default linker script does <em>not</em> locate <code>.rodata</code> in +RAM, no special features are needed in order not to waste RAM for +read-only data or to read from flash. You might even get slightly better +performance by +avoiding <code>progmem</code> and <code>__flash</code>. This applies to devices from +families <code>avrtiny</code> and <code>avrxmega3</code>, see <a href="AVR-Options.html#AVR-Options">AVR Options</a> for +an overview. +</p> +</dd> +<dt>• Reduced AVR Tiny cores like ATtiny40:</dt> +<dd><p>The compiler adds <code>0x4000</code> +to the addresses of objects and declarations in <code>progmem</code> and locates +the objects in flash memory, namely in section <code>.progmem.data</code>. +The offset is needed because the flash memory is visible in the RAM +address space starting at address <code>0x4000</code>. +</p> +<p>Data in <code>progmem</code> can be accessed by means of ordinary C code, +no special functions or macros are needed. +</p> +<div class="smallexample"> +<pre class="smallexample">/* var is located in flash memory */ +extern const int var[2] __attribute__((progmem)); + +int read_var (int i) +{ + return var[i]; +} +</pre></div> + +<p>Please notice that on these devices, there is no need for <code>progmem</code> +at all. +</p> +</dd> +</dl> + +<a name="index-io-variable-attribute_002c-AVR"></a> +</dd> +<dt><code>io</code></dt> +<dt><code>io (<var>addr</var>)</code></dt> +<dd><p>Variables with the <code>io</code> attribute are used to address +memory-mapped peripherals in the io address range. +If an address is specified, the variable +is assigned that address, and the value is interpreted as an +address in the data address space. +Example: +</p> +<div class="smallexample"> +<pre class="smallexample">volatile int porta __attribute__((io (0x22))); +</pre></div> + +<p>The address specified in the address in the data address range. +</p> +<p>Otherwise, the variable it is not assigned an address, but the +compiler will still use in/out instructions where applicable, +assuming some other module assigns an address in the io address range. +Example: +</p> +<div class="smallexample"> +<pre class="smallexample">extern volatile int porta __attribute__((io)); +</pre></div> + +<a name="index-io_005flow-variable-attribute_002c-AVR"></a> +</dd> +<dt><code>io_low</code></dt> +<dt><code>io_low (<var>addr</var>)</code></dt> +<dd><p>This is like the <code>io</code> attribute, but additionally it informs the +compiler that the object lies in the lower half of the I/O area, +allowing the use of <code>cbi</code>, <code>sbi</code>, <code>sbic</code> and <code>sbis</code> +instructions. +</p> +<a name="index-address-variable-attribute_002c-AVR"></a> +</dd> +<dt><code>address</code></dt> +<dt><code>address (<var>addr</var>)</code></dt> +<dd><p>Variables with the <code>address</code> attribute are used to address +memory-mapped peripherals that may lie outside the io address range. +</p> +<div class="smallexample"> +<pre class="smallexample">volatile int porta __attribute__((address (0x600))); +</pre></div> + +<a name="index-absdata-variable-attribute_002c-AVR"></a> +</dd> +<dt><code>absdata</code></dt> +<dd><p>Variables in static storage and with the <code>absdata</code> attribute can +be accessed by the <code>LDS</code> and <code>STS</code> instructions which take +absolute addresses. +</p> +<ul> +<li> This attribute is only supported for the reduced AVR Tiny core +like ATtiny40. + +</li><li> You must make sure that respective data is located in the +address range <code>0x40</code>…<code>0xbf</code> accessible by +<code>LDS</code> and <code>STS</code>. One way to achieve this as an +appropriate linker description file. + +</li><li> If the location does not fit the address range of <code>LDS</code> +and <code>STS</code>, there is currently (Binutils 2.26) just an unspecific +warning like +<blockquote> +<p><code>module.cc:(.text+0x1c): warning: internal error: out of range error</code> +</p></blockquote> + +</li></ul> + +<p>See also the <samp>-mabsdata</samp> <a href="AVR-Options.html#AVR-Options">command-line option</a>. +</p> +</dd> +</dl> + +<hr> +<div class="header"> +<p> +Next: <a href="Blackfin-Variable-Attributes.html#Blackfin-Variable-Attributes" accesskey="n" rel="next">Blackfin Variable Attributes</a>, Previous: <a href="ARC-Variable-Attributes.html#ARC-Variable-Attributes" accesskey="p" rel="previous">ARC Variable Attributes</a>, Up: <a href="Variable-Attributes.html#Variable-Attributes" accesskey="u" rel="up">Variable Attributes</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indices.html#Indices" title="Index" rel="index">Index</a>]</p> +</div> + + + +</body> +</html> |