本章節主要介紹如何編寫應用程式執行在基於arm
的linux
上。對於linux
來說一切裝置皆檔案,比如開發板上的led
,在驅動程式中可以設定檔名為led
,存放在/dev
目錄中。可以使用open
、ioctl
等函式讀寫。
led.c
#include
#include
#include
#include
#include
#include
#include
#include
#define cmd_led_on (0)
#define cmd_led_off (1)
#define device_path "/dev/led"
static
void usage( const
char *module_name )
enum
;int main(int argc, char **argv)
sscanf(argv[1],"%d",&led_num);
led_num -= 1;
if (strcmp(argv[2],"on") == 0) else
if (strcmp(argv[2],"off") == 0)
if ( (led_num < 0) || (led_num > 3) || (device_status == device_err) )
fd = open(device_path,o_wronly);
if (fd < 0)
if (device_status == device_on) else
close(fd);
return
0;exception:
}
makefile
cc = arm-linux-gcc
cflags = -wall
target = led
source = led.c
$(target) : $(source)
$(cc) $(cflags) -o $@ $<
clean:
rm -rf *.o $(target)
在當前目錄下使用:
$ make
即可生成可執行檔案led
將檔案拷貝到開發板中:
$ ./led 1 on
led1
開啟。
$ ./led 2 off
led2
關閉。 編寫符合ANSI和Unicode的應用程式
世界真的很奇妙,分久必合,合久必分。計算機發展到今天,多國之間的交流日益廣泛,軟體本地化是重大趨勢。如果減少本地化工作就是一件值得考慮的事情。軟體本地化要解決的真正問題就是如何來處理不同的字符集。要知道,單位元組字元是乙個8位的資料來表示的。因此,它最多能表示256個字元。全世界那麼多個國家,256...
Spring 學習筆記1 編寫安裝程式
在程式設計ssh專案時,可能要寫乙個installer類來初始化資料庫,一般的編寫方式如下 component public class installer transactional public void install 這種方式的優點是可以直接使用 resource 注入的類,但是使用這種方式...
linux學習筆記 1
第一部分 shell 第一章 檔案安全與許可權 1 1 檔案 當你建立乙個檔案,系統儲存了關於有關該檔案的資訊,包括 檔案的位置 檔案型別 檔案長度 哪些使用者擁有該檔案,哪些使用者可以訪問該檔案i節點 檔案的修改時間 檔案的許可權位1 2檔案型別 d 目錄 l 符號鏈結 指向另一檔案 s 套接字檔...