- 追加された行はこの色です。
- 削除された行はこの色です。
[[BeagleBone]]
*mmap [#rd2dff65]
-[[参考>http://www.atmarkit.co.jp/ait/articles/1201/18/news133.html]]
-機能:ファイルとメモリの同一視(仮想メモリ技術)
--読み込み専用なら,メモリから読み出しがそのままファイル読み出しに相当.
--書き込み専用なら,メモリへの書き込みがそのままファイル書き込みに相当.
-メリット
--カーネルとコピープログラムの間でデータのコピーが発生しないので,高速.
*void*のoffset [#k44c5f76]
#include <stdio.h>
int main(void)
{
void* a = (char*)0x01;
a = (void*)((char*)a + 0x0F);
printf("%p\n", a);
}
*inputデバイスに入出力 [#g4c1f436]
-Input Subsystem
--キーボード・マウス・ジョイスティックなどからの入力を受け取る
--キーボード・マウス・ジョイスティックが動いたと,システムに錯覚させる
--仮想キーボード・マウス・ジョイスティックを作る
**入力 [#i64137bb]
-キーボードを開いて,読み出す.
#include <stdio.h>
#include <stdlib.h>
#include <linux/input.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
int main(void)
{
// int fd = open("/dev/input/event0", O_RDONLY); // blocking
int fd = open("/dev/input/event0", O_NONBLOCK); // non-blocking
while (1) {
// Read
struct input_event event;
int a = read(fd, &event, sizeof(event));
if (a < 0 && errno == EAGAIN) {
// No Input
} else if (a < 0) {
fprintf(stderr, "read error\n");
return 1;
} else {
// Refer
if (event.type == EV_KEY) // EV_KEY: Keyboard, EV_REL: Mouse movement, EV_ABS: joystick/touch panel
if (event.value == 1) // 1: pushed, 0: released, 2: machinegun
printf("%d pushed\n", event.code); // code: info to detect!
}
}
}