BeagleBone

mmap

  • 参考
  • 機能:ファイルとメモリの同一視(仮想メモリ技術)
    • 読み込み専用なら,メモリから読み出しがそのままファイル読み出しに相当.
    • 書き込み専用なら,メモリへの書き込みがそのままファイル書き込みに相当.
  • メリット
    • カーネルとコピープログラムの間でデータのコピーが発生しないので,高速.

void*のoffset

#include <stdio.h>

int main(void)
{
        void* a = (char*)0x01;
        a = (void*)((char*)a + 0x0F);
        printf("%p\n", a);
}

inputデバイスに入出力

  • Input Subsystem
    • キーボード・マウス・ジョイスティックなどからの入力を受け取る
    • キーボード・マウス・ジョイスティックが動いたと,システムに錯覚させる
    • 仮想キーボード・マウス・ジョイスティックを作る

入力

  • キーボードを開いて,読み出す.
#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!
                }
        }

}

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS