am29xxxxx-instance.html

来自「ecos3.0 beta 的官方文档,html格式」· HTML 代码 · 共 1,368 行 · 第 1/3 页

HTML
1,368
字号
<!-- Copyright (C) 2009 Free Software Foundation, Inc.                                -->
<!-- This material may be distributed only subject to the terms      -->
<!-- and conditions set forth in the Open Publication License, v1.0  -->
<!-- or later (the latest version is presently available at          -->
<!-- http://www.opencontent.org/openpub/).                           -->
<!-- Distribution of the work or derivative of the work in any       -->
<!-- standard (paper) book form is prohibited unless prior           -->
<!-- permission is obtained from the copyright holder.               -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Instantiating an AM29xxxxx Device</TITLE
><meta name="MSSmartTagsPreventParsing" content="TRUE">
<META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="eCos Reference Manual"
HREF="ecos-ref.html"><LINK
REL="UP"
TITLE="AMD AM29xxxxx Flash Device Driver"
HREF="devs-flash-am29xxxxx.html"><LINK
REL="PREVIOUS"
TITLE="Overview"
HREF="am29xxxxx.html"><LINK
REL="NEXT"
TITLE="Intel Strata Flash Device Driver"
HREF="devs-flash-strata.html"></HEAD
><BODY
CLASS="REFENTRY"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>eCos Reference Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="am29xxxxx.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="devs-flash-strata.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="AM29XXXXX-INSTANCE"
></A
>Instantiating an AM29xxxxx Device</H1
><DIV
CLASS="REFNAMEDIV"
><A
NAME="AEN20613"
></A
><H2
>Name</H2
>Instantiating&nbsp;--&nbsp;including the driver in an eCos target</DIV
><DIV
CLASS="REFSYNOPSISDIV"
><A
NAME="AEN20616"
></A
><H2
>Synopsis</H2
><DIV
CLASS="FUNCSYNOPSIS"
><P
></P
><A
NAME="AEN20617"
></A
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="FUNCSYNOPSISINFO"
>#include &lt;cyg/io/am29xxxxx_dev.h&gt;
      </PRE
></TD
></TR
></TABLE
><P
><CODE
><CODE
CLASS="FUNCDEF"
>int cyg_am29xxxxx_init_check_devid_XX</CODE
>(struct cyg_flash_dev* device);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>int cyg_am29xxxxx_init_cfi_XX</CODE
>(struct cyg_flash_dev* device);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>int cyg_am29xxxxx_erase_XX</CODE
>(struct cyg_flash_dev* device, cyg_flashaddr_t addr);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>int cyg_am29xxxxx_program_XX</CODE
>(struct cyg_flash_dev* device, cyg_flashaddr_t addr, const void* data, size_t len);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>int cyg_at49xxxx_softlock</CODE
>(struct cyg_flash_dev* device, const cyg_flashaddr_t addr);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>int cyg_at49xxxx_hardlock</CODE
>(struct cyg_flash_dev* device, const cyg_flashaddr_t addr);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>int cyg_at49xxxx_unlock</CODE
>(struct cyg_flash_dev* device, const cyg_flashaddr_t addr);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>int cyg_am29xxxxx_read_devid_XX</CODE
>(struct cyg_flash_dev* device);</CODE
></P
><P
></P
></DIV
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AM29XXXXX-INSTANCE-DESCRIPTION"
></A
><H2
>Description</H2
><P
>The AM29xxxxx family contains some hundreds of different flash
devices, all supporting the same basic set of operations but with
various common or uncommon extensions. The devices vary in capacity,
performance, boot block layout, and width. There are also
platform-specific issues such as how many devices are actually present
on the board and where they are mapped in the address space. The
AM29xxxxx driver package cannot know the details of every chip and
every platform. Instead it is the responsibility of another package,
usually the platform HAL, to supply the necessary information by
instantiating some data structures. Two pieces of information are
especially important: the bus configuration and the boot block layout.
    </P
><P
>Flash devices are typically 8-bits, 16-bits, or 32-bits wide (64-bit
devices are not yet in common use). Most 16-bit devices will also
support 8-bit accesses, but not all. Similarly 32-bit devices can be
accessed 16-bits at a time or 8-bits at a time. A board will have one
or more of these devices on the bus. For example there may be a single
16-bit device on a 16-bit bus, or two 16-bit devices on a 32-bit bus.
The processor's bus logic determines which combinations are possible,
and there will be a trade off between cost and performance: two 16-bit
devices in parallel can provide twice the memory bandwidth of a single
device. The driver supports the following combinations:
    </P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>8</DT
><DD
><P
>A single 8-bit flash device on an 8-bit bus.
        </P
></DD
><DT
>16</DT
><DD
><P
>A single 16-bit flash device on a 16-bit bus.
        </P
></DD
><DT
>32</DT
><DD
><P
>A single 32-bit flash device on an 32-bit bus.
        </P
></DD
><DT
>88</DT
><DD
><P
>Two parallel 8-bit devices on an 16-bit bus.
        </P
></DD
><DT
>8888</DT
><DD
><P
>Four parallel 8-bit devices on a 32-bit bus.
        </P
></DD
><DT
>1616</DT
><DD
><P
>Two parallel 16-bit devices on a 32-bit bus, with one device providing
the bottom two bytes of each 32-bit datum and the other device
providing the top two bytes.
        </P
></DD
><DT
>16as8</DT
><DD
><P
>A single 16-bit flash device connected to an 8-bit bus.
        </P
></DD
></DL
></DIV
><P
>These configuration all require slightly different code to manipulate
the hardware. The AM29xxxxx driver package provides separate functions
for each configuration, for example
<CODE
CLASS="FUNCTION"
>cyg_am29xxxxx_erase_16</CODE
> and
<CODE
CLASS="FUNCTION"
>cyg_am29xxxxx_program_1616</CODE
>. 
    </P
><DIV
CLASS="CAUTION"
><P
></P
><TABLE
CLASS="CAUTION"
BORDER="1"
WIDTH="100%"
><TR
><TD
ALIGN="CENTER"
><B
>Caution</B
></TD
></TR
><TR
><TD
ALIGN="LEFT"
><P
>At the time of writing not all the configurations have been tested.
    </P
></TD
></TR
></TABLE
></DIV
><P
>The second piece of information is the boot block layout. Flash
devices are subdivided into blocks (also known as sectors - both terms
are in common use). Some operations such as erase work on a whole
block at a time, and for most applications a block is the smallest
unit that gets updated. A typical block size is 64K. It is inefficient
to use an entire 64K block for small bits of configuration data and
similar information, so many flash devices also support a number of
smaller boot blocks. A typical 2MB flash device could have a single
16K block, followed by two 8K blocks, then a 32K block, and finally 31
full-size 64K blocks. The boot blocks may appear at the bottom or the
top of the device. So-called uniform devices do not have boot blocks,
just full-size ones. The driver needs to know the boot block layout.
With modern devices it can work this out at run-time, but often it is
better to provide the information statically.
    </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AM29XXXXX-INSTANCE-EXAMPLE"
></A
><H2
>Example</H2
><P
>In most cases flash support is specific to a platform. Even if two
platforms happen to use the same flash device there are likely to be
differences such as the location in the address map. Hence there is
little possibility of re-using the platform-specific code, and this
code should be placed in the platform HAL rather than in a separate
package. Typically this involves a separate file and a corresponding
compile property in the platform HAL's CDL:
    </P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>cdl_package CYGPKG_HAL_M68K_ALAIA {
    &#8230;
    compile -library=libextras.a alaia_flash.c
    &#8230;
}
    </PRE
></TD
></TR
></TABLE
><P
>The contents of this file will not be accessed directly, only
indirectly via the generic flash API, so normally it would be removed
by link-time garbage collection. To avoid this the object file has to
go into <TT
CLASS="FILENAME"
>libextras.a</TT
>.
    </P
><P
>The actual file <TT
CLASS="FILENAME"
>alaia_flash.c</TT
> will look something like:
    </P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>#include &lt;pkgconf/system.h&gt;
#ifdef CYGPKG_DEVS_FLASH_AMD_AM29XXXXX_V2

#include &lt;cyg/io/flash.h&gt;
#include &lt;cyg/io/flash_dev.h&gt;
#include &lt;cyg/io/am29xxxxx_dev.h&gt;

static const CYG_FLASH_FUNS(hal_alaia_flash_amd_funs,
    &amp;cyg_am29xxxxx_init_check_devid_16,
    &amp;cyg_flash_devfn_query_nop,
    &amp;cyg_am29xxxxx_erase_16,
    &amp;cyg_am29xxxxx_program_16,
    (int (*)(struct cyg_flash_dev*, const cyg_flashaddr_t, void*, size_t))0,
    &amp;cyg_flash_devfn_lock_nop,
    &amp;cyg_flash_devfn_unlock_nop);

static const cyg_am29xxxxx_dev hal_alaia_flash_priv = {
    .devid      = 0x45,
    .block_info = {
        { 0x00004000, 1 },
        { 0x00002000, 2 },
        { 0x00008000, 1 },
        { 0x00010000, 63 }
    }
};

CYG_FLASH_DRIVER(hal_alaia_flash,
                 &amp;hal_alaia_flash_amd_funs,
                 0,
                 0xFFC00000,
                 0xFFFFFFFF,
                 4,
                 hal_alaia_flash_priv.block_info,
                 &amp;hal_alaia_flash_priv
);
#endif
    </PRE
></TD
></TR
></TABLE
><P
>The bulk of the file is protected by an <TT
CLASS="LITERAL"
>#ifdef</TT
> for
the AM29xxxxx flash driver. That driver will only be active if the
generic flash support is enabled. Without that support there will be
no way of accessing the device so instantiating the data structures
would serve no purpose. The rest of the file is split into three
structure definitions. The first supplies the functions which will be
used to perform the actual flash accesses, using a macro provided by
the generic flash code in <TT
CLASS="FILENAME"
>cyg/io/flash_dev.h</TT
>. The relevant ones
have an <TT
CLASS="LITERAL"
>_16</TT
> suffix, indicating that on this board
there is a single 16-bit flash device on a 16-bit bus. The second
provides information specific to AM29xxxxx flash devices.
The third provides the <CODE
CLASS="STRUCTNAME"
>cyg_flash_dev</CODE
>
structure needed by the generic flash code, which contains pointers to
the previous two.
    </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AM29XXXXX-INSTANCE-FUNCTIONS"
></A
><H2
>Functions</H2

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?