Nios ii--experiment 6--serial Software part

Source: Internet
Author: User
<span id="Label3"></p>Software development <ol> <ol> <li>first, Create a new software folder inside the hardware Engineering folder to place the software part; open tools<span style="font-family:Wingdings">à</span>Nios II 11.0 software Build Tools for Eclipse, need to workspace Launcher (workspace) Path settings, It is important to note that the path does not contain spaces, etc., and then click Ok.</li> </ol> </ol><p><p></p></p><p><p></p></p> <ol> <ol> <li>New Project. Click file--New->? Nios II application and BSP from template, pops up Nios II application and BSP from Template dialog box. Select the corresponding SOPC system first, Click the browse button after Sopc information file name, Select the soft core file that was previously done by the hardware section, The suffix name is. sopcinfo, It is important to note that the selected files must correspond, otherwise the system will fail because of a soft and hard mismatch. Here Select the <span style="color:red">lab5_uart.sopcinfo</span>, then the system will automatically read the CPU name, no more settings, the following fill out project name, here to fill in the <span style="color:red">lab5_uart</span>, project template (project Template) using the Default. Then click Finish to Finish. This will generate two project files in the Project Explorer on the left.</li> </ol> </ol><p><p></p></p><p style="margin-left: 18pt"><p style="margin-left: 18pt">Code Design concrete View Source project</p></p><p style="margin-left: 18pt"><p style="margin-left: 18pt"></p></p> <ol> <ol> <li>Right click on the project, select Nios ii, BSP editor, Enter the Nios II BSP editor configuration Interface. It is configured primarily under the Main tab in Hall. Then click Generate to generate the BSP Library. When the build is complete, click Exit to Quit.</li> </ol> </ol><p><p></p></p><p style="margin-left: 18pt"><p style="margin-left: 18pt"></p></p> <ol> <ol> <li>Compile the Project. Right-click to select Build Project. The first compile, the time will be more frequent, wait patiently.</li> <li>When the compilation is complete, download The. sof file to the FPGA first;</li> </ol> </ol><p><p>?</p></p> <ol> <ol> <li>Right-click the project, select Run As--Nios II Hardware, pop up the Run Configurations dialog box, The default project tab, project name and project ELF file name should all have content, Not a Choice. Then go to the target connection tab, and if there is nothing in connections, click on the Refresh connection on the right to find the downloader, then click System ID prroperties ..., Check if the ID number was set before, click apply, then click run, This is the program will be downloaded automatically, and finally in the Nios II Console tab will show the results of the program run after the download is Complete.</li> </ol> </ol><p><p></p></p><p style="margin-left: 18pt"><p style="margin-left: 18pt"></p></p> <ol> <ol> <li>Run the result, in the serial assistant input daxigua, the baud rate is set to 115200, and then send. Output Daxigua in the debug window.</li> </ol> </ol><p><p></p></p><p style="text-align: center"><p style="text-align: center">?</p></p>Experiment Code <table style="border-collapse:collapse; background: #bfbfbf" border="0"> <colgroup> <col style="width:590px"> </colgroup> <tbody valign="top"> <tr> <td style="padding-left: 7px; padding-right: 7px; border-top: solid 0.5pt; border-left: solid 0.5pt; border-bottom: solid 0.5pt; border-right: solid 0.5pt"><p><p><span style="color:green; font-family:Courier New; font-size:10pt; background-color:silver">/*</span></p></p><p><p><span style="color:green; font-family:Courier New; font-size:10pt; background-color:silver">* "Hello world" Example.</span></p></p><p><p><span style="color:green; font-family:Courier New; font-size:10pt; background-color:silver">*</span></p></p><p><p><span style="color:green; font-family:Courier New; font-size:10pt; background-color:silver">* This example prints ' Hello from Nios II ' to the STDOUT Stream. It runs on</span></p></p><p><p><span style="color:green; font-family:Courier New; font-size:10pt; background-color:silver">* The Nios II ' Standard ', ' full_featured ', ' fast ', and ' low_cost ' example</span></p></p><p><p><span style="color:green; font-family:Courier New; font-size:10pt; background-color:silver">* Designs. It runs with or without the microc/os-ii RTOS and requires a STDOUT</span></p></p><p><p><span style="color:green; font-family:Courier New; font-size:10pt; background-color:silver">* Device in your system ' s Hardware.</span></p></p><p><p><span style="color:green; font-family:Courier New; font-size:10pt; background-color:silver">* The memory footprint of this hosted application are ~69 Kbytes by default</span></p></p><p><p><span style="color:green; font-family:Courier New; font-size:10pt; background-color:silver">* Using the standard reference DESIGN.</span></p></p><p><p><span style="color:green; font-family:Courier New; font-size:10pt; background-color:silver">*</span></p></p><p><p><span style="color:green; font-family:Courier New; font-size:10pt; background-color:silver">* For a reduced footprint version of the This template, and the explanation of how</span></p></p><p><p><span style="color:green; font-family:Courier New; font-size:10pt; background-color:silver">* To reduce the memory footprint-a given application, see the</span></p></p><p><p><span style="color:green; font-family:Courier New; font-size:10pt; background-color:silver">* "small_hello_world" Template.</span></p></p><p><p><span style="color:green; font-family:Courier New; font-size:10pt; background-color:silver">*</span></p></p><p><p><span style="font-family:Courier New; font-size:10pt"><span style="color:green; background-color:silver">*/</span><span style="color:black; background-color:silver"></span></span></p></p><p><p><span style="color:#804000; font-family:Courier New; font-size:10pt; background-color:silver">#include <stdio.h></span></p></p><p><p><span style="color:#804000; font-family:Courier New; font-size:10pt; background-color:silver">#include <unistd.h></span></p></p><p><p><span style="color:#804000; font-family:Courier New; font-size:10pt; background-color:silver">#include <io.h></span></p></p><p><p><span style="color:#804000; font-family:Courier New; font-size:10pt; background-color:silver">#include <string.h></span></p></p><p><p><span style="color:#804000; font-family:Courier New; font-size:10pt; background-color:silver">#include "system.h"</span></p></p><p><p><span style="color:#804000; font-family:Courier New; font-size:10pt; background-color:silver">#include "alt_types.h"</span></p></p><p><p><span style="color:#804000; font-family:Courier New; font-size:10pt; background-color:silver">#include "altera_avalon_uart_regs.h"</span></p></p><p><p><span style="color:#804000; font-family:Courier New; font-size:10pt; background-color:silver">#include "sys\alt_irq.h"</span></p></p><p><p>?</p></p><p><p><span style="font-family:Courier New; font-size:10pt"><span style="color:#8000ff; background-color:silver">Static</span> <span style="color:black; background-color:silver">alt_u8 TxData</span> <span style="color:navy; background-color:silver"><strong>=</strong></span> <span style="color:black; background-color:silver"></span> <span style="color:#ff8000; background-color:silver">0</span><span style="color:navy; background-color:silver"><strong>;</strong></span><span style="color:black; background-color:silver"></span></span></p></p><p><p><span style="font-family:Courier New; font-size:10pt"><span style="color:#8000ff; background-color:silver">Static</span> <span style="color:black; background-color:silver">alt_u8 Rxdata</span> <span style="color:navy; background-color:silver"><strong>=</strong></span> <span style="color:black; background-color:silver"></span> <span style="color:#ff8000; background-color:silver">0</span><span style="color:navy; background-color:silver"><strong>;</strong></span><span style="color:black; background-color:silver"></span></span></p></p><p><p><span style="color:green; font-size:10pt"><span style="font-family:Courier New; background-color:silver">//uart</span> <span style="font-family:宋体; background-color:silver">Interrupt Service Function</span><span style="font-family:Courier New; background-color:silver"></span></span></p></p><p><p> <span style="font-family:courier New; font-size:10pt"><span style="color: #8000ff; background-color:silver">static </span> <span style="color:black; background-color:silver"> </span> <span style="color: #8000ff; background-color:silver"> void </span> <span style="color:black; background-color:silver"> Uart_isr </span> <span style="color:navy; Background-color:silver "> <strong> (</strong> </span> <span style=" color: #8000ff; background-color:silver ">void </span> <span style="color:black; background-color:silver"> </span> <span style="color:navy; background-color:silver"> <strong> * </strong> </span> <span style="color:black; background-color:silver"> context </span> <span style="color:navy; background-color:silver"> <strong>, </strong> </span> <span style="color:black; Background-color:silver ">alt_u32 ID </span> <span style=" color:navy; background-color:silver "> <strong>) </strong> </span> <span style="color:black; background-color:silver"> </span> </span> </p></p><p><p><span style="font-family:Courier New; font-size:10pt"><span style="color:navy; background-color:silver"><strong>{</strong></span><span style="color:black; background-color:silver"></span></span></p></p><p><p><span style="font-family:Courier New; font-size:10pt"><span style="color:black; background-color:silver">Rxdata</span> <span style="color:navy; background-color:silver"><strong>=</strong></span> <span style="color:black; background-color:silver">Iord_altera_avalon_uart_rxdata</span> <span style="color:navy; background-color:silver"><strong>(</strong></span><span style="color:black; background-color:silver">uart_base</span><span style="color:navy; background-color:silver"><strong>);</strong></span><span style="color:black; background-color:silver"></span></span></p></p><p><p><span style="font-family:Courier New; font-size:10pt"><span style="color:black; background-color:silver">TxData</span> <span style="color:navy; background-color:silver"><strong>=</strong></span> <span style="color:black; background-color:silver">Rxdata</span> <span style="color:navy; background-color:silver"><strong>;</strong></span><span style="color:black; background-color:silver"></span></span></p></p><p><p><span style="font-size:10pt"><span style="color:black; font-family:Courier New; background-color:silver"></span><span style="color:green"><span style="font-family:Courier New; background-color:silver">//</span> the <span style="font-family:宋体; background-color:silver">query sends ready signals and waits if not ready</span><span style="font-family:Courier New; background-color:silver"></span></span></span></p></p><p><p> <span style="font-family:courier New; font-size:10pt"><span style="color:black; background-color:silver"> </span> Strong><span style="color:blue; background-color:silver">while </span> <span style="color:navy; background-color:silver"> ( (</span> <span style="color:black; background-color:silver">iord_altera_avalon_uart_status </span> <span style="color:navy; Background-color:silver "> <strong> (</strong> </span> <span style=" color:black; background-color:silver ">uart_base </span> <span style="color:navy; background-color:silver"> <strong>) & </strong> </span> <span style="color:black ; Background-color:silver ">altera_avalon_uart_status_trdy_msk </span> <span style="color:navy; background-color:silver" , <strong>))); </span> <span style="color:black; background-color:silver"> </span> </span> </p></p><p><p><span style="font-size:10pt"><span style="color:black; font-family:Courier New; background-color:silver"></span><span style="color:green"><span style="font-family:Courier New; background-color:silver">//</span> <span style="font-family:宋体; background-color:silver">Send ready, Send</span> <span style="font-family:Courier New; background-color:silver">TxData</span></span></span></p></p><p><p><span style="font-family:Courier New; font-size:10pt"><span style="color:black; background-color:silver">Iowr_altera_avalon_uart_txdata</span> <span style="color:navy; background-color:silver"><strong>(</strong></span><span style="color:black; background-color:silver">uart_base</span><span style="color:navy; background-color:silver"><strong>,</strong></span><span style="color:black; background-color:silver">txdata</span><span style="color:navy; background-color:silver"><strong>);</strong></span><span style="color:black; background-color:silver"></span></span></p></p><p><p><span style="font-family:Courier New; font-size:10pt"><span style="color:navy; background-color:silver"><strong>}</strong></span><span style="color:black; background-color:silver"></span></span></p></p><p><p><span style="font-family:Courier New; font-size:10pt"><span style="color:#8000ff; background-color:silver">void</span> <span style="color:black; background-color:silver">Uart_init</span> <span style="color:navy; background-color:silver"><strong>()</strong></span><span style="color:black; background-color:silver"></span></span></p></p><p><p><span style="font-family:Courier New; font-size:10pt"><span style="color:navy; background-color:silver"><strong>{</strong></span><span style="color:black; background-color:silver"></span></span></p></p><p><p><span style="font-size:10pt"><span style="color:black; font-family:Courier New; background-color:silver"></span><span style="color:green"><span style="font-family:Courier New; background-color:silver">//</span> <span style="font-family:宋体; background-color:silver">clears the status register</span><span style="font-family:Courier New; background-color:silver"></span></span></span></p></p><p><p><span style="font-family:Courier New; font-size:10pt"><span style="color:black; background-color:silver">Iowr_altera_avalon_uart_status</span> <span style="color:navy; background-color:silver"><strong>(</strong></span><span style="color:black; background-color:silver">uart_base</span><span style="color:navy; background-color:silver"><strong>,</strong></span><span style="color:#ff8000; background-color:silver">0</span><span style="color:navy; background-color:silver"><strong>);</strong></span><span style="color:black; background-color:silver"></span></span></p></p><p><p><span style="font-size:10pt"><span style="color:black; font-family:Courier New; background-color:silver"></span><span style="color:green"><span style="font-family:Courier New; background-color:silver">//</span> <span style="font-family:宋体; background-color:silver">to be ready to accept the Interruption.</span><span style="font-family:Courier New; background-color:silver"></span></span></span></p></p><p><p><span style="font-family:Courier New; font-size:10pt"><span style="color:black; background-color:silver">Iowr_altera_avalon_uart_control</span> <span style="color:navy; background-color:silver"><strong>(</strong></span><span style="color:black; background-color:silver">uart_base</span><span style="color:navy; background-color:silver"><strong>,</strong></span><span style="color:#ff8000; background-color:silver">0X80</span><span style="color:navy; background-color:silver"><strong>);</strong></span><span style="color:black; background-color:silver"></span></span></p></p><p><p><span style="font-family:Courier New; font-size:10pt"><span style="color:navy; background-color:silver"><strong>}</strong></span><span style="color:black; background-color:silver"></span></span></p></p><p><p><span style="font-family:Courier New; font-size:10pt"><span style="color:#8000ff; background-color:silver">int</span> <span style="color:black; background-color:silver">Main</span> <span style="color:navy; background-color:silver"><strong>()</strong></span><span style="color:black; background-color:silver"></span></span></p></p><p><p><span style="font-family:Courier New; font-size:10pt"><span style="color:navy; background-color:silver"><strong>{</strong></span><span style="color:black; background-color:silver"></span></span></p></p><p><p><span style="font-family:Courier New; font-size:10pt"><span style="color:black; background-color:silver">printf</span> <span style="color:navy; background-color:silver"><strong>(</strong></span><span style="color:gray; background-color:silver">"please start!\n"</span><span style="color:navy; background-color:silver"><strong>);</strong></span><span style="color:black; background-color:silver"></span></span></p></p><p><p><span style="font-size:10pt"><span style="color:black; font-family:Courier New; background-color:silver"></span><span style="color:green"><span style="font-family:Courier New; background-color:silver">//</span> <span style="font-family:宋体; background-color:silver">Register</span> <span style="font-family:Courier New; background-color:silver">UART</span> <span style="font-family:宋体; background-color:silver">Interrupt Service Function</span><span style="font-family:Courier New; background-color:silver"></span></span></span></p></p><p><p> <span style="font-family:courier New; font-size:10pt"><span style="color:black; background-color:silver"> alt _ic_isr_register </span> <span style="color:navy; background-color:silver"> <strong> (</strong> </span> <span style=" color:black; Background-color:silver ">uart_irq_interrupt_controller_id </span> <span style="color:navy; background-color:silver"> <strong>, </strong> </span> <span style="color:black; Background-color:silver "> </span> </span> </p></p><p><p><span style="font-family:Courier New; font-size:10pt"><span style="color:black; background-color:silver">UART_IRQ</span> <span style="color:navy; background-color:silver"><strong>,</strong></span> <span style="color:black; background-color:silver">UART_ISR</span> <strong> <span style="color:navy; background-color:silver">,</span><span style="color:blue; background-color:silver">NULL</span><span style="color:navy; background-color:silver">,</span> </strong> <span style="color:#ff8000; background-color:silver">0x00</span> <span style="color:navy; background-color:silver"><strong>);</strong></span><span style="color:black; background-color:silver"></span></span></p></p><p><p><span style="font-family:Courier New; font-size:10pt"><span style="color:black; background-color:silver">Uart_init</span> <span style="color:navy; background-color:silver"><strong>();</strong></span><span style="color:black; background-color:silver"></span></span></p></p><p><p><span style="font-family:Courier New; font-size:10pt"><span style="color:black; background-color:silver"></span><strong><span style="color:blue; background-color:silver"></span> while <span style="color:navy; background-color:silver">(</span></strong><span style="color:#ff8000; background-color:silver">1</span><span style="color:navy; background-color:silver"><strong>) {}</strong></span><span style="color:black; background-color:silver"></span></span></p></p><p><p><span style="font-family:Courier New; font-size:10pt"><span style="color:black; background-color:silver"></span><span style="color:blue; background-color:silver"><strong>return</strong></span><span style="color:black; background-color:silver"></span><span style="color:#ff8000; background-color:silver">0</span><span style="color:navy; background-color:silver"><strong>;</strong></span><span style="color:black; background-color:silver"></span></span></p></p><p><p><span style="color:navy; font-family:Courier New; font-size:10pt; background-color:silver"><strong>}</strong></span></p></p></td> </tr> </tbody> </table><p><p>Nios ii--experiment 6--serial Software part</p></p></span>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.