文章總列表

Embedded System Studying note 10/26

下了班, 還是可以玩一下 ARM, 真是太幸福了 :D


----


上個禮拜把 MMU (Memory Management Unit)打開
順便開了 I-Cache 和 D-Cache
程式執行立刻加快 10 倍, 相當的愉快 !!

我還沒有要用 Virtual Address 的高級屬性 (比如 read on demand)
所以先讓所有 Virtual-addr 等於 Physical-addr
這樣現有的程式都可以繼續用

我在 Interview時, 寫過一個考題是這麼問的...
對於 CPU的 special function register, 可否對他開啟 cache ?
答案是no, 開了會出事, 這些 register 可能會自己更新, 而 cache 沒有同步更新
反應在 MMU的設定裡, 就有設定每一塊記憶體區域是否 cache-able


----


Keil ARM 提供了 Standard C Library, 我很需要格式化輸出的功能 (printf)
但是 Keil 的文件真是寫得落落長, 看了半天才慢慢拼湊出一些 idea...

首先程式的進入點是 __main(), 他要做的事如下...

void __main(void)
{
/*
* According to the manual, this function performs following tasks:
* 1. Copy the non-rooted execution (RO & RW) from their load addr to exec addr.
* 2. Zeros the ZI regions
* 3. Branches to __rt_entry()
*/

// In my implementation, these tasks are done by bootloader code
// So I just jump to __rt_entry()
__rt_entry();
}

然後 __rt_entry() 去初始化其他的東西, 包括 stack & heap, library
最後才是進入 main()

void __rt_entry(void)
{
__rt_stackheap_init();
__rt_lib_init();
main();
}

到這為止, 是使用 keil ARM 時, 如果想用 main(), 必須要做上面這些事


----


然後搭配我寫的 UART driver, 讓 printf() 能動作

// Tailor for C standard Library
// printf() requires low-level fputc(), below is its implementation: just
// uses UART driver. In the multi-thread environment, I wish to ensure that
// one task printing message won't be bothered by another task. So I rewrite
// OS_print() below. Low level-printing is handled by OS_uart_putstring(),
// which used semaphore.

int fputc(int ch, FILE *f)
{
OS_uart_sendbyte(ch);
return ch;
}

void OS_printf(const char *fmt, ...)
{
va_list ap;
char buf[1024];

va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);

OS_uart_putstring(buf);
}

這樣就能像以前一樣, 輸出格式化字串了 :D


----


TODO:

1. 加入一個 shell, 讓我可以下命令
2. 寫 USB driver

留言

這個網誌中的熱門文章

幼犬書桌椅選擇心得 升降桌 兒童桌椅

Herman Miller Aeron 一代氣壓棒維修

JUJU-250 升降桌 電腦主機 桌下安裝 調整心得