LoginSignup
0
0

More than 1 year has passed since last update.

osを作る その16

Posted at

概要

osを作る。
setjmpで、カーネルモード、ユーザーモードを行ったり来たりする、システムコールを実装した。

サンプルコード


#include <setjmp.h>

static jmp_buf kernel_context;
static jmp_buf user_context;
static int mode = 0;

void task1() {
    Serial.print("task1  ");
    Serial.println(millis());
}

void task2() {
    Serial.print("task2  ");
    Serial.println(millis());
}

void task3() {
    Serial.print("task3  ");
    Serial.println(millis());
}

void system_call() {
    if (setjmp(user_context))
    {

    }
    else
    {
        longjmp(kernel_context, 1);
    }
}

void setup() {
    Serial.begin(9600);
    if (setjmp(kernel_context))
    {
        if (mode == 1)
        {
            task1();
        }
        if (mode == 2)
        {
            task2();
        }
        if (mode == 3)
        {
            task3();
        }
        longjmp(user_context, 1);
    }
    else
    {

    }
}

void loop() {
    mode = 1;
    system_call();
    mode = 2;
    system_call();
    mode = 3;
    system_call();
    delay(800);
}





以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0