2011年7月3日 星期日

學習 Android/Linux Kernel 編譯

使用 Ubuntu 11.04 (安裝在 VirtualBox 4.08) 在 emulator 上跑 Android,大致記錄過程,待有硬體再來學習實機移植…

一、安裝 git 原始碼管理套件…
sudo apt-get install git-core gnupg

二、安裝 java jre / jdk…
sudo add-apt-repository ppa:ferramroberto/java
sudo apt-get update
sudo apt-get install sun-java6-jre sun-java6-plugin
sudo apt-get install sun-java6-jdk

三、安裝其它需要的套件…
sudo apt-get install flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl valgrind

四、準備下載 Android 原始碼 (不包含Linux核心)
cd ~
wget http://Android.git.kernel.org/repo
chmod 777 repo
sudo cp repo /bin/
mkdir Android
cd Android
repo init -u git://android.git.kernel.org/platform/manifest.git
repo sync        /// 這邊會下載幾小時

五、編譯/執行…
make        /// 這邊會編譯幾小時
export PATH=$PATH:~/Android/out/host/linux-x86/bin
export ANDROID_PRODUCT_OUT=~/Android/out/target/product/generic
emulator

至此是 Android 的編譯,若要進行 Linux Kernel 編譯…
六、下載 Linux Kernel for Android…
mkdir kernel
cd kernel
git clone git://android.git.kernel.org/kernel/common.git        /// 這邊會下載幾小時

七、透過 emulator 截取 config 檔…
cd common
emulator &
adb pull /proc/config.gz
gunzip config.gz
mv config .config

八、修改 Makefile 檔…
nano Makefile
===========================
ARCH=arm
CROSS_COMPILE ?= arm-eabi-
===========================

九、編譯…
make menuconfig
make        /// 這邊會編譯幾小時

十、使用剛編譯出的核心執行 emulator…
cd ~/Android
emulator -kernel ./kernel/common/arch/arm/boot/zImage &

十一、進 Android 後台確認核心版本…
adb shell
root@android:/ # cd /proc
root@android:/proc # cat version
Linux version 2.6.29-gb0d93fb-dirty (fellong@fellong-VirtualBox) (gcc version 4.4.3 (GCC) ) #5 Sun Jul 3 14:31:58 CST 2011

2011年6月28日 星期二

Android Starter

一、下載 JAVA SE JDK,安裝


二、下載 Android SDK,安裝






三、下載 Eclipse Classic,安裝


四、執行 Eclipse,按下列步驟安裝 ADT  Plug-in (摘自 http://developer.android.com/sdk/eclipse-adt.html#installing)

  1. Start Eclipse, then select Help > Install New Software....
  2. Click Add, in the top-right corner.
  3. In the Add Repository dialog that appears, enter "ADT Plugin" for the Name and the following URL for the Location:
    https://dl-ssl.google.com/android/eclipse/
  4. Click OK Note: If you have trouble acquiring the plugin, try using "http" in the Location URL, instead of "https" (https is preferred for security reasons).
  5. In the Available Software dialog, select the checkbox next to Developer Tools and click Next.
  6. In the next window, you'll see a list of the tools to be downloaded. Click Next.
  7. Read and accept the license agreements, then click Finish. Note: If you get a security warning saying that the authenticity or validity of the software can't be established, click OK.
  8. When the installation completes, restart Eclipse. 這邊會開始下載安裝比較久的時間。

五、 執行 Eclipse,到選單 > Windows > Android SDK and ADV Manager 開啟 ADV Manager (或透過直接執行 ADV Manager 亦可)。
此時若出現找不到 ADV Manager 位置的話,則要到選單 > Windows > Preferences > Andriod 頁面進行設定。




六、第一次執行 ADV Manager 要先安裝相關套件,這邊也是會開始下載安裝一段時間




七、新增加一個 ADV (Android模擬器),名稱自己取



八、OK 後就可以在 ECLIPSE 開 Android 專案了,Build Target 記得選剛剛建立好的 ADV 版本。





九、寫個範例程式…(摘自 http://developer.android.com/resources/tutorials/hello-world.html)

package example.HelloAndroid;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class HelloAndroidActivity extends Activity {
       /** Called when the activity is first created. */
       @Override
       public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           TextView tv = new TextView(this);
           tv.setText("Hello, Android");
           setContentView(tv);
       }
}

十、執行結果…

2011年6月20日 星期一

MIDI Code 在 Windows & Apple - Mac 的差別

同樣是 MIDI out 到 device,Windows 跟 Mac 卻有差別…

-----------------------------
差別一:
例如:一個 Note 「09 90 01 7f」,在 Windows 作輸出時,透過 Bus Hound (監視 USB 通訊的軟體) 來看是底下這樣…
Device  Length    Phase  Data         Description       Delta  Cmd.Phase.Ofs(rep)
------  --------  -----  -----------  ----------------  -----  ------------------
  27.4        64  OUT    09 90 01 7f  ....              5.1sc        28.1.0       
                         00 00 00 00  ....                           28.1.4       
                         00 00 00 00  ....                           28.1.8       
                         00 00 00 00  ....                           28.1.12      
                         00 00 00 00  ....                           28.1.16      
                         00 00 00 00  ....                           28.1.20      
                         00 00 00 00  ....                           28.1.24      
                         00 00 00 00  ....                           28.1.28      
                         00 00 00 00  ....                           28.1.32      
                         00 00 00 00  ....                           28.1.36      
                         00 00 00 00  ....                           28.1.40      
                         00 00 00 00  ....                           28.1.44      
                         00 00 00 00  ....                           28.1.48      
                         00 00 00 00  ....                           28.1.52      
                         00 00 00 00  ....                           28.1.56      
                         00 00 00 00  ....                           28.1.60      

Windows 一次「至少」就傳了 64 bytes 的資料給 device ,後面無用的資料都補 0。

但是 Mac 卻只有傳了…「09 90 01 7f」這 4 個 bytes,並且沒有 0 作結尾。

-----------------------------
差別二:
很多 MIDI Code 要傳輸時,Windows 都是遵照上述的原則,一定會傳出 64 bytes (或許有別的 MIDI API 可以作不一樣長度的輸出,但以音控軟體 Traktor 而言是如此)

但是 Mac 在這個情況下有可能會傳出 4*N 個 bytes,也就是 4、8、12、16…。

------------------------------------
於是在韌體的撰寫上就要特別注意這二個不同的差別來作 MIDI Code 的解析,才能同時相容於 Windows 及 Mac!!!

看起來 Mac 的效能會比較好。

2010年12月16日 星期四

ARM7-TDMI 第一步 - 使用 Winbond W90P710CDG 記錄

一、系統已經內建 uCLinux,先學習在上面開發 AP。
二、主板開機後連接網路線(對接或透過HUB)
三、使用 IP-Search-Utility - Etm.exe 或其它方式查詢主板 IP。
四、telnet 進去主板,登入 admin 確定 uCLinux 有跑起來。
五、安裝 Virtual Box 及 linux-Demo.vdi. 下載網址 http://www.metavert.com/public/Virtual-Linux/
六、參照 http://www.metavert.com/public/htm-w90f/21-virtual_linux.htm 說明,設定 Virtual Box 並載入 linux-Demo.vdi,或自行摸索把 linux-Demo.vdi 建成虛擬機器就是了。
七、在 Virtual Box 中啟動 linux-Demo。(Ubuntu)
八、進入 Ubuntu 後查看虛擬電腦 ip 是不是跟主板在同一子網域,若沒則作修改。看要改主板或 Ubuntu 都可。
九、將範例 g03a.tar.gz 、上載工具 tools.tar.gz 及安裝 scripts install.sh 透過共享資料夾或其它方式上傳到 Ubuntu。
十、執行 install.sh (注意查看 scripts 內容 PRJ=xxx 是否正確)
十一、安裝成功會在 home 資料夾建立範例程式,並安裝好上載工具 eUpg90
十二、開發、編輯、編譯程式,產生 目的檔 i.e. example。(最好使用 Eclipse,開發環境都設定好了,只需將 example Import 進 project 即可,真方便)
十三、在 Ubuntu 命令列,切到目的檔所在目錄,下達「eUpg90 -file -a192.168.1.10 example /usr/example」指令將 example 上傳到主板的 /usr/example 。此處 192.168.1.10 是主板的 IP。(程式需透過 eUpg90 上載,用 ftp 上傳的不行,原因還不知)
十四、telnet 主板切至 /usr 目錄應會看到上載的程式 example,執行、驗證。Good!!
完成。

*到它內建的 www 首頁就有很多範例可供參考。

2010年12月4日 星期六

STM32 多個外部中斷設定方式(使用stm32f10x_lib)

一、打開 GPIO 時鐘及重映射功能時鐘。

/* System Clocks Configuration */
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE );



二、打開/設定 外部中斷的 中斷套嵌。

/* NVIC configuration */
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQChannel;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQChannel;
NVIC_Init(&NVIC_InitStructure);

注意:不同的外部中斷需各別使用 NVIC_Init() 函式來設定,不可以用「|」OR 運算來同時設定。


三、設置 GPIO 腳位、屬性。

/* Configure the GPIO ports */
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOE, &GPIO_InitStructure);

注意:不同的 IO PORT 需各別使用 GPIO_Init() 函式來設定,但同一個 PORT 可以用「|」OR 運算來同時設定。


四、連結 外部中斷線 到 GPIO線(PIN0~PIN15)

/* Connect EXTI Line to GPIO Pin */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource2);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource3);

注意:不同 GPIO Pin 需各別使用 GPIO_EXTILineConfig() 函式來設定,不可以用「|」OR 運算來同時設定。


五、設置外部中斷反應方式並打開外部中斷

/* Configure EXTI Line to generate an interrupt on falling edge */
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_InitStructure.EXTI_Line = EXTI_Line2 | EXTI_Line3;
EXTI_Init(&EXTI_InitStructure);

注意:所有的外部中斷可以使用一次/多次 EXTI_Init() 函式來設定,並可以用「|」OR 運算來同時設定。


六、最後在 stm32f10x_it.c 處理中斷函式…

void EXTIx_IRQHandler(void)
{
}

2010年12月2日 星期四

RL-ARM 使用 user timer 的方法

一、在 RTX_Config.c 修改 OS_TIMERCNT。(預設是 0 記得要修改)

#ifndef OS_TIMERCNT
#define OS_TIMERCNT 5
#endif


二、在 task 中建立 timer。

OS_ID tmr1;
tmr1 = os_tmr_create (300, 1); /// after 300 system_tick, callback.
if (tmr1 == NULL) {
printf ("Failed to create user timer.\n");
}


三、在 RTX_Config.c 修改 timer 的 callback 函式 os_tmr_call。

void os_tmr_call (U16 info) {
/* This function is called when the user timer has expired. Parameter */
/* 'info' holds the value, defined when the timer was created. */
/* HERE: include optional user code to be executed on timeout. */
}

VirtualBox 空間減肥

sdelete64 -z c: VBoxManage  modifymedium  disk  "/Users/fellow/VirtualBox VMs/Win10/Win10.vdi"  --compact *.vdi 路徑可以在 VirtualBox 儲...