⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ecos-pci-library.html

📁 有关ecos2。0介绍了实时嵌入式的结构以及线程调度的实现和内存的管理等
💻 HTML
📖 第 1 页 / 共 2 页
字号:
            diag_printf("\n Command   0x%04x, Status 0x%04x\n",                        dev_info.command, dev_info.status);</PRE></TD></TR></TABLE><P>The command register can also be written to, controlling (amongother things) whether the device responds to IO and memory accessfrom the bus. </P></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN12737">Specific config information</H2><P>The above functions only allow access to generic PCI configregisters. A device can have extra config registers not specifiedby the PCI specification. These can be accessed with these functions:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">void cyg_pci_read_config_uint8(  cyg_pci_device_id devid,                                 cyg_uint8 offset, cyg_uint8 *val);void cyg_pci_read_config_uint16(  cyg_pci_device_id devid,                                  cyg_uint8 offset, cyg_uint16 *val);void cyg_pci_read_config_uint32(  cyg_pci_device_id devid,                                  cyg_uint8 offset, cyg_uint32 *val);void cyg_pci_write_config_uint8(  cyg_pci_device_id devid,                                  cyg_uint8 offset, cyg_uint8 val);void cyg_pci_write_config_uint16(  cyg_pci_device_id devid,                                   cyg_uint8 offset, cyg_uint16 val);void cyg_pci_write_config_uint32(  cyg_pci_device_id devid,                                   cyg_uint8 offset, cyg_uint32 val);</PRE></TD></TR></TABLE><P>The write functions should only be used for device-specificconfig registers since using them on generic registers may invalidatethe contents of a previously fetched cyg_pci_devicestructure.</P></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN12742">Allocating memory</H2><P>A PCI device ignores all IO and memory access from the PCIbus until it has been activated. Activation cannot happen untilafter device configuration. Configuration means telling the devicewhere it should map its IO and memory resources. This is done withone of the following functions::</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">cyg_bool cyg_pci_configure_device( cyg_pci_device *dev_info );cyg_bool cyg_pci_configure_bus( cyg_uint8 bus, cyg_uint8 *next_bus );</PRE></TD></TR></TABLE><P>The <TTCLASS="FUNCTION">cyg_pci_configure_device</TT> handles all IOand memory regions that need configuration on non-bridge devices. Onplatforms with multiple busses connected by bridges, the <TTCLASS="FUNCTION">cyg_pci_configure_bus</TT> function should be used. It will recursivelyconfigure all devices on the given <TTCLASS="PARAMETER"><I>bus</I></TT> and allsubordinate busses. <TTCLASS="FUNCTION">cyg_pci_configure_bus</TT> willuse <TTCLASS="FUNCTION">cyg_pci_configure_device</TT> to configureindividual non-bridge devices.</P><P> Each region is represented in the PCI device's config space by BARs(Base Address Registers) and is handled individually according to typeusing these functions:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">cyg_bool cyg_pci_allocate_memory(  cyg_pci_device *dev_info,                                   cyg_uint32 bar,                                    CYG_PCI_ADDRESS64 *base );cyg_bool cyg_pci_allocate_io(  cyg_pci_device *dev_info,                               cyg_uint32 bar,                                CYG_PCI_ADDRESS32 *base );</PRE></TD></TR></TABLE><P>The memory bases (in two distinct address spaces) are increasedas memory regions are allocated to devices. Allocation will fail(the function returns false) if the base exceeds the limits of theaddress space (IO is 1MB, memory is 2^32 or 2^64 bytes).</P><P>These functions can also be called directly by the application/driverif necessary, but this should not be necessary.</P><P>The bases are initialized with default values provided bythe HAL. It is possible for an application to override these usingthe following functions: </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">void cyg_pci_set_memory_base(  CYG_PCI_ADDRESS64 base );void cyg_pci_set_io_base( CYG_PCI_ADDRESS32 base );</PRE></TD></TR></TABLE><P>When a device has been configured, the cyg_pci_devicestructure will contain the physical address in the CPU'saddress space where the device's memory regions can beaccessed. </P><P>This information is provided in <TTCLASS="VARNAME">base_map[]</TT> -there is a 32 bit word for each of the device's BARs. For32 bit PCI memory regions, each 32 bit word will be an actual pointerthat can be used immediately by the driver: the memory space will normallybe linearly addressable by the CPU.</P><P>However, for 64 bit PCI memory regions, some (or all) of theregion may be outside of the CPUs address space. In this case thedriver will need to know how to access the region in segments. Thisfunctionality may be adopted by the eCos HAL if deemed useful inthe future. The 2GB available on many systems should suffice though.</P></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="PCI-INTERRUPTS">Interrupts</H2><P>A device may generate interrupts. The HAL vector associatedwith a given device on the bus is platform specific. This functionallows a driver to find the actual interrupt vector for a givendevice:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">cyg_bool cyg_pci_translate_interrupt(  cyg_pci_device *dev_info,                                       CYG_ADDRWORD *vec );</PRE></TD></TR></TABLE><P>If the function returns false, no interrupts will be generatedby the device. If it returns true, the CYG_ADDRWORD pointedto by vec is updated with the HAL interrupt vector the device willbe using. This is how the function is used in the <TTCLASS="FILENAME">pci1</TT>test:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">            if (cyg_pci_translate_interrupt(&amp;dev_info, &amp;irq))                diag_printf(" Wired to HAL vector %d\n", irq);            else                diag_printf(" Does not generate interrupts.\n");</PRE></TD></TR></TABLE><P>The application/drive should attach an interrupthandler to a device's interrupt before activating the device.</P></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN12770">Activating a device</H2><P>When the device has been allocated memory space it can beactivated. This is not done by the library since a driver may haveto initialize more state on the device before it can be safely activated.</P><P>Activating the device is done by enabling flags in its commandword. As an example, see the <TTCLASS="FILENAME">pci1</TT> test which can beconfigured to enable the devices it finds. This allows these to be accessed fromGDB (if a breakpoint is set on <TTCLASS="FUNCTION">cyg_test_exit</TT>):</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">#ifdef ENABLE_PCI_DEVICES      {          cyg_uint16 cmd;          // Don't use cyg_pci_set_device_info since it clears          // some of the fields we want to print out below.          cyg_pci_read_config_uint16(dev_info.devid,                                     CYG_PCI_CFG_COMMAND, &amp;cmd);          cmd |= CYG_PCI_CFG_COMMAND_IO|CYG_PCI_CFG_COMMAND_MEMORY;          cyg_pci_write_config_uint16(dev_info.devid,                                      CYG_PCI_CFG_COMMAND, cmd);      }      diag_printf(" **** Device IO and MEM access enabled\n");#endif</PRE></TD></TR></TABLE><DIVCLASS="NOTE"><BLOCKQUOTECLASS="NOTE"><P><B>Note: </B>The best way to activate a device is actuallythrough <TTCLASS="FUNCTION">cyg_pci_set_device_info()</TT>,but in this particular case the <SPANCLASS="STRUCTNAME">cyg_pci_device</SPAN>structure contents from before the activation is required for printoutfurther down in the code.</P></BLOCKQUOTE></DIV></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN12782">Links</H2><P>See these links for more information about PCI:</P><P></P><OLTYPE="1"><LI><P><ANAME="PCI-SPEC"></A><AHREF="http://www.pcisig.com/"TARGET="_top">http://www.pcisig.com/</A> - information on the PCI specifications</P></LI><LI><P><AHREF="http://www.yourvote.com/pci/"TARGET="_top">http://www.yourvote.com/pci/</A> - list of vendor and device IDs</P></LI><LI><P><AHREF="http://www.picmg.org/"TARGET="_top">http://www.picmg.org/</A> - PCI Industrial Computer Manufacturers Group</P></LI></OL></DIV></DIV></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="io-pci.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ecos-ref.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="pci-library-reference.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">PCI Library</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="io-pci.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">PCI Library reference</TD></TR></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

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