174 lines
7.5 KiB
HTML
174 lines
7.5 KiB
HTML
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||
|
<html>
|
||
|
<!-- Copyright (C) 1988-2016 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.2, 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="Option-Index.html#Option-Index" rel="index" title="Option Index">
|
||
|
<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="Common-Variable-Attributes.html#Common-Variable-Attributes" rel="prev" title="Common 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" 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="Common-Variable-Attributes.html#Common-Variable-Attributes" accesskey="p" rel="prev">Common 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="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
|
||
|
</div>
|
||
|
<hr>
|
||
|
<a name="AVR-Variable-Attributes-1"></a>
|
||
|
<h4 class="subsection">6.32.2 AVR Variable Attributes</h4>
|
||
|
|
||
|
<dl compact="compact">
|
||
|
<dt><code>progmem</code></dt>
|
||
|
<dd><a name="index-progmem-variable-attribute_002c-AVR"></a>
|
||
|
<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. Notice that just like the
|
||
|
<code>section</code> attribute, <code>progmem</code> affects the location
|
||
|
of the data but not how this data is accessed.
|
||
|
</p>
|
||
|
<p>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 <a href="http://nongnu.org/avr-libc/user-manual/">AVR-LibC</a><!-- /@w --> */
|
||
|
#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><code>io</code></dt>
|
||
|
<dt><code>io (<var>addr</var>)</code></dt>
|
||
|
<dd><a name="index-io-variable-attribute_002c-AVR"></a>
|
||
|
<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>
|
||
|
|
||
|
</dd>
|
||
|
<dt><code>io_low</code></dt>
|
||
|
<dt><code>io_low (<var>addr</var>)</code></dt>
|
||
|
<dd><a name="index-io_005flow-variable-attribute_002c-AVR"></a>
|
||
|
<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>
|
||
|
</dd>
|
||
|
<dt><code>address</code></dt>
|
||
|
<dt><code>address (<var>addr</var>)</code></dt>
|
||
|
<dd><a name="index-address-variable-attribute_002c-AVR"></a>
|
||
|
<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>
|
||
|
|
||
|
</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="Common-Variable-Attributes.html#Common-Variable-Attributes" accesskey="p" rel="prev">Common 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="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
|
||
|
</body>
|
||
|
</html>
|