nios II--實驗6——串口軟體部分

來源:互聯網
上載者:User

標籤:

軟體開發
  1. 首先,在硬體工程檔案夾裡面建立一個software的檔案夾用於放置軟體部分;開啟toolsàNios II 11.0 Software Build Tools for Eclipse,需要進行Workspace Launcher(工作空間)路徑的設定,需要注意的是路徑中不要含有空格等,然後單擊OK即可。

  1. 建立工程。單擊File -> New ->?Nios II Application and BSP from Template,彈出Nios II Application and BSP from Template對話方塊。先選擇對應的SOPC系統,單擊SOPC Information File name後面的瀏覽按鈕,選擇之前硬體部分做好的軟核檔案,尾碼名為.sopcinfo,這裡一定要注意,選擇的檔案一定要對應起來,否則會因為軟硬不匹配導致系統失敗。這裡選擇的lab5_uart.sopcinfo,然後系統會自動讀取CPU name,不用再進行設定,下面填寫Project name,這裡填寫為lab5_uart,工程模板(Project template)使用預設的即可。然後單擊Finish完成即可。這時候會在左側的Project Explorer中產生兩個工程檔案。

代碼設計具體看源工程

  1. 右擊工程,選擇Nios II -> BSP Editor,進入Nios II BSP Editor配置介面。主要在main選項卡下hall中進行配置。然後單擊Generate,產生BSP庫。產生完成後,單擊Exit退出即可。

  1. 編譯工程。右擊選擇Build Project。第一次編譯的話,時間也會比較常,耐心等待一下。
  2. 編譯完成後,先將.sof檔案下載到FPGA;

?

  1. 右擊工程,選擇Run As -> Nios II Hardware,彈出Run Configurations對話方塊,預設Project選項卡中Project name和Project ELF file name應該都是有內容的,沒有的選一下。然後進入Target Connection選項卡,Connections中如果沒有東西的話,單擊右側的Refresh Connection來尋找下載器,尋找後單擊System ID Prroperties…,進行系統ID檢測,檢查是否是之前設定的ID號,無誤後點擊Apply,然後再點擊Run,這是程式會被自動下載,最終在Nios II Console選項卡中會顯示下載完成後程式啟動並執行結果。

  1. 運行結果,在串口助手輸入daxigua,傳輸速率設定為115200,然後進行發送。在調試視窗輸出daxigua。

?

實驗代碼

/*

* "Hello World" example.

*

* This example prints ‘Hello from Nios II‘ to the STDOUT stream. It runs on

* the Nios II ‘standard‘, ‘full_featured‘, ‘fast‘, and ‘low_cost‘ example

* designs. It runs with or without the MicroC/OS-II RTOS and requires a STDOUT

* device in your system‘s hardware.

* The memory footprint of this hosted application is ~69 kbytes by default

* using the standard reference design.

*

* For a reduced footprint version of this template, and an explanation of how

* to reduce the memory footprint for a given application, see the

* "small_hello_world" template.

*

*/

#include <stdio.h>

#include <unistd.h>

#include <io.h>

#include <string.h>

#include "system.h"

#include "alt_types.h"

#include "altera_avalon_uart_regs.h"

#include "sys\alt_irq.h"

?

static alt_u8 txdata =0;

static alt_u8 rxdata =0;

//UART中斷服務函數

staticvoid uart_isr(void* context,alt_u32 id)

{

rxdata = IORD_ALTERA_AVALON_UART_RXDATA(UART_BASE);

txdata = rxdata;

//查詢發送準備好訊號,如果沒有準備好,則等待

while(!((IORD_ALTERA_AVALON_UART_STATUS(UART_BASE)&ALTERA_AVALON_UART_STATUS_TRDY_MSK)));

//發送準備好,發送txdata

IOWR_ALTERA_AVALON_UART_TXDATA(UART_BASE,txdata);

}

void uart_init()

{

//清除狀態寄存器

IOWR_ALTERA_AVALON_UART_STATUS(UART_BASE,0);

//使能接受準備好中斷

IOWR_ALTERA_AVALON_UART_CONTROL(UART_BASE,0X80);

}

int main()

{

printf("Please Start!\n");

//註冊UART中斷服務函數

alt_ic_isr_register(UART_IRQ_INTERRUPT_CONTROLLER_ID,

UART_IRQ,uart_isr,NULL,0x00);

uart_init();

while(1){}

return0;

}

nios II--實驗6——串口軟體部分

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.