發表文章

目前顯示的是有「程式語言」標籤的文章

Makefile的賦值運算符(=, :=, +=, ?=)

Makefile的賦值運算符(=, :=, +=, ?=) 總結: = 是最基本的賦值 := 會覆蓋變數之前的值 ?= 變數為空時才給值,不然則維持之前的值 += 將值附加到變數的後面 另外 =, :=這兩賦值運算符號在網路上查詢,常常會看到這種說法: = 在執行時擴展(values within it are recursively expanded when the variable is used, not when it's declared) := 在定義時擴展(values within it are expanded at declaration time) 而白話一點的說法如下範例所示   1. =   make會將整個makefile展開後,才決定變數的值。也就是说,變數的值會是整個Makefile中最後被指定的值。看例子: x = hello y = $(x) world! x = hi all: @echo $(y)   在上例中,輸出結果將會是 hi world! ,而不是 hello world!   2. :=   變數的值在Makefile展開途中就會被給定,而不是整個Makefile展開後的最终值。 x := hello y := $(x) world! x := hi all: @echo $(y)   輸出結果 ====> hello world!

編譯 binary 的時候自動加入 release version 與 date

Makefile   1 2 3 4 SVN_VERSION = "\"`svn info | grep Revision | sed 's/Revision: //g'`\"" BUILD_TIME = "\"`date '+%Y/%m/%d %H:%M:%S'`\""   CFLAGS += -DSVN_VERSION=$(SVN_VERSION) -DBUILD_TIME=$(BUILD_TIME) .c 檔   1 2 3 4 void show_version (void) {      printf ( "SVN Version: %s, Bulid time: %s\n" , SVN_VERSION, BUILD_TIME); } Preprocessing 的時候 macro 會自動被帶換掉啦!     reference: http://blog.yslin.tw/2012/03/binary-release-version-date.html

在 Linux 底下,如何讓 CPU 使用率達到 100% (使用 md5sum 與 gzip)

md5sum < /dev/urandom & cat /dev/urandom | gzip > /dev/null & reference: http://rainstingtw.blogspot.com/2013/07/Use-md5sum-gzip-CPU-fullloading.html

uboot fw_printenv & fw_setenv 用法

1. 在 uboot 下 make env --> 會在 tool/env 裡得到 fw_printenv. 2. fw_setenv 和 fw_printenv 是同一個執行檔, 用 copy 或 link 都可. fw_env.config 是 決定你的 uboot 的 設定, 必須放在 /etc 下. 範例如下: 因為我用 REDUNDAND 所以要建兩個 mtd, 如下, 下面兩個範例, 不同在於 reundand env 有沒有在不同的 mtd. ================================================================================================== # MTD device name       Device offset   Env. size       Flash sector size       Number of sectors /dev/mtd1               0x0000          0x2000          0x20000 1 /dev/mtd2               0x0000          0x2000          0x20000 1 /etc # cat /proc/mtd  dev:    size   erasesize  name mtd0: 00080000 00020000 "U-Boot" mtd1: 00040000 00020000 "U-Boot Env" mtd2: 00040000 00020000 "Backup U-Boot Env" =====...

linux gpio_led framework 用法

1. 先將 menuconfig 裡 LED Trigger support 打開  Device Drivers  --->  LED Support  --->  LED Trigger support  --->  LED Timer Trigger                                                                    |->  LED Heartbeat Trigger                                                                    |->  LED backlight Trigger                                                                    |->  LED GPIO Trigger ...

linux gpio_keys framework 用法

1. 先將 menuconfig 裡 GPIO Buttons 打開  Device Drivers  --->  Input device support  --->  Keyboards  --->  GPIO Buttons 2. 將 gpio-key 定義好, 並註冊. struct gpio_keys_button { /* Configuration parameters */ int code; /* input event code (KEY_*, SW_*) */ int gpio; int active_low; char *desc; int type; /* input event type (EV_KEY, EV_SW) */ int wakeup; /* configure the button as a wake-up source */ int debounce_interval; /* debounce ticks interval in msecs */ bool can_disable; }; struct gpio_keys_platform_data { struct gpio_keys_button *buttons; int nbuttons; unsigned int poll_interval; /* polling interval in msecs -   for polling driver only */ unsigned int rep:1; /* enable input subsystem auto repeat */ int (*enable)(struct device *dev); void (*disable)(struct device *dev); }; #include #include static struct gpio_keys_button bfin_gpio_keys_table[] = { { ....

C語言測試 想成為嵌入式程序員應知道的0x10個基本問題

============================================== C語言測試 想成為嵌入式程序員應知道的0x10個基本問題 原文出處 A 'C' Test: The 0x10 Best Questions for Would-be Embedded Programmers: http://www.embedded.com/2000/0005/0005feat2.htm 以下是網路上找到中文版,作者不詳。 ============================================== C語言測試是徵選嵌入式系統程式員過程中必須而且有效的方法。這些年我既參加也組織 了許多這種測試,在這過程中我意識到這些測試能為面試者和被面試者提供許多有用訊息 ,此外,撇開面試的壓力不談,這種測試也是相當有趣的。 從被面試者的角度來講,你能瞭解許多關於出題者或監考者的情況。這個測試只是出題者 出某個字符的ASCII值。這些問題著重考察你的系統調用(invoke)和記憶體分發策略方面 的能力嗎?這反映出出題者也許花時間在微處理機上而不在嵌入式系統上。 如果上述任何問題的答案是「是」的話,那麼我知道我得認真考慮我是否應該去做這份工 作。 從面試者的角度來講,一個測試也許能從多方面揭示應試者的素質。最基本的,你能瞭解 應試者C語言的水準。不管怎麼樣,看一下這人如何回答他不會的問題也是滿有趣。應試 者是以好的直覺做出明智的選擇,還是只是瞎蒙呢?當應試者在某個問題上卡住時是找藉 口呢,還是表現出對問題的真正的好奇心,把這看成學習的機會呢?我發現這些訊息與他 們的測試成績一樣有用。 有了這些想法,我決定出一些真正針對嵌入式系統的考題,希望這些令人頭痛的考題能給 正在謀職的人一點幫住。這些問題都是我這些年實際碰到的。其中有些題很難,但它們應 該都能給你一點啟發。 這個測試適用於不同水準的應試者,大多數初級水準的應試者的成績會很差,經驗豐富的 程式員應該有很好的成績。為了讓你能自己決定某些問題的偏好,每個問題沒有分發分數 ,如果選擇這些考題為你所用,請自行按你的意思分發分數。 ============================================== 預處理器 (Preprocessor) 1.用預處理指令#define 聲...