基于soc的嵌入式系統(tǒng)解析方案
2.1.3 加載應用程序
用戶應用程序可通過target目錄加載到根文件系統(tǒng)中,可根據(jù)需要重建romdisk映像。應用程序在userland目錄下,編譯生成運行文件后拷貝到target目錄樹中,并根據(jù)target目錄的內容創(chuàng)建romdisk.flash文件。新建一個應用程序,首先打開一個 linuxdeveloperbash窗,在userland目錄中創(chuàng)建一個目錄app,應用程序源文件存放在此目錄中,然后在 userland/app/中建立一個makefile文件。
makefile內容如下所示,其中appfile為應用程序名。
stackslze=8192
include../../rules.mak
all:appfile.relocbflt
sources=appfile.c
install:
$(romfsinst)appfile.reloebfh
$(romfsdir)/bin/appfile$(execsuffix)
clean:
rm-f *.[iods]core appfile appfile.*elf appfile.*bflt
運行make對應用程序進行編譯并修改userland/.eonfig和/userland/makefile文件。在userland/. config文件中,增加一行config_my_app=y,在userland/makefile文件中,增加dir_$ (config_my_app)+=app,進入userland子目錄,運行make,即可將應用程序安裝到userland/bin中,并根據(jù) userland/.config文件中相應變量的指示將應用程序二進制拷貝到target目錄中。
最后,鍵入以下命令重新構建romdisk映像文件(romdisk.flash),并下載到目標板上。
[linux developer]…uclinux/:make clean_target
[linux developer]…uclinux/:make romfs
[linux developer]…uclinux/:nios-run romdisk.flash
2.1.4 運行μclinux
完成μclinux內核及文件系統(tǒng)的裝載后,即可運行μclinux。鍵入g800000(800000為啟動代碼地址,在sopc builder中設置),μclinux自動完成初始化過程,用戶輸入登錄用戶名nios,密碼μclinux,出現(xiàn)μclinux的提示符#,表示已進入μclinux運行環(huán)境。
2.2 轉換器應用程序的實現(xiàn)
轉換器應用系統(tǒng)主要完成網(wǎng)絡接口和串行接口間的數(shù)據(jù)傳輸,所傳輸?shù)臄?shù)據(jù)流如圖4所示。μclinux操作系統(tǒng)中提供了網(wǎng)絡驅動程序和串口驅動程序,并提供了多線程的支持。
轉換器應用系統(tǒng)中的串口收發(fā)數(shù)據(jù)和網(wǎng)絡口收發(fā)數(shù)據(jù)是異步進行的,可分別作為一個任務來對待,任務間是并發(fā)的,因此可采用多線程程序設計技術來實現(xiàn)多任務間的并發(fā)執(zhí)行,系統(tǒng)主程序流程圖如圖5所示。
評論