TOPPERSコンテスト受賞作品紹介(22)第八回(2018)アプリケーション開発部門金賞 TOPPERS/ATK2 カーネル向け実機レス開発環境(athrill2) 森崇((株)永和システムマネジメント)


TOPPERS「活用アイデア」・「アプリケーション開発」コンテスト
は、2011年から毎年実施されています。
https://www.toppers.jp/contest.html

「アプケーション開発」は、ソースコードの公開を前提としています。
「活用アイデア」でも、その後実現したソースコードなどもある。探しながら紹介。

なお、この記事は、TOPPERSプロジェクトの公式見解ではなく、
小川清 の 技術者個人の考えに基づいています。

目的(purpose)

TOPPERS開発アイデア・アプリケーション開発コンテスト受賞作品には、良質な算譜、技術的に崇高な志向、目的を達成するための意思などが感じられる。広く、source codeを表示して紹介し、次の応募作品を促す。

成果(outcome)

応募作品の算譜を眺めると、その技術者の得意分野や技法を感じることができる。応募作品のソースコードを使ってみようという気になる。ソースコードを一度コンパイルしたくなる。自分も良い作品を作ろうという気になる。

TOPPERSコンテスト受賞作品紹介(22)第八回(2018)アプリケーション開発部門金賞

TOPPERS/ATK2 カーネル向け実機レス開発環境(athrill2) 森崇((株)永和システムマネジメント)

応募資料(application material)等

athrill 機能マニュアルの整備(以下のサイトで公開中) https://qiita.com/kanetugu2018/items/cf3dea16710a3f0737e8

調査結果詳細
https://qiita.com/kanetugu2018/items/521bc56b39b82c1c8734

動作環境
https://qiita.com/kanetugu2018/items/1f2ef93c9e1fa7a29f97#%E5%8B%95% E4%BD%9C%E7%92%B0%E5%A2%83

事前準備
https://qiita.com/kanetugu2018/items/1f2ef93c9e1fa7a29f97#%E4%BA%8B %E5%89%8D%E6%BA%96%E5%82%99

インスト ール方法
https://qiita.com/kanetugu2018/items/1f2ef93c9e1fa7a29f97#%E3%82%A4% E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB%E6%96% B9%E6%B3%95

プログラム配置場所(github)
https://github.com/tmori/athrill/tree/master/sample/os/atk2-sc1_1.4.2/OBJ

動作確認結果詳細
https://qiita.com/kanetugu2018/items/d07dac56c4f57ce10f65

ダウンロード

$ git clone https://github.com/tmori/athrill.git
$ cd athrill/trunk/src
$ cat main/main.c
#include "front/parser/dbg_parser.h"
#include "loader/loader.h"
#include "option/option.h"
#include "cpu_control/dbg_cpu_control.h"
#include "cpu_control/dbg_cpu_thread_control.h"
#include "cpuemu_ops.h"
#include "cui/cui_ops.h"
#include "cui/stdio/cui_ops_stdio.h"
#include "cui/udp/cui_ops_udp.h"
#include "file_address_mapping.h"
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include "target/target_os_api.h"
#include <sched.h>
#include <limits.h>

static void do_cui(void)
{
    DbgCmdExecutorType *res;
    bool is_dbgmode;
    char buffer[1024];
    int len;

    while (TRUE) {
        is_dbgmode = cpuctrl_is_debug_mode();
        printf("%s", (is_dbgmode == TRUE) ? "[DBG>" : "[CPU>");
        fflush(stdout);
retry:
        len = cui_getline(buffer, 1024);
        if (len < 0) {
            cui_close();
            target_os_api_sleep(1000);
            goto retry;
        }
        buffer[len] = '\0';
        res = dbg_parse((uint8*)buffer, (uint32)len);

        if (res != NULL) {
            res->run(res);
        }
    }
}


/*
 * コマンドオプション仕様
 * -i       インタラクションモード
 *  ・あり:インタラクションモード
 *  ・なし:バックグラウンド実行モード
 * -r(インタラクションモードのみ有効)
 *  ・あり:リモートモード
 *  ・なし:直接モード
 * -t<time> 終了時間(単位:clock)
 *  ・あり:終了時間
 *  ・なし:無制限
 * -b   入力ファイル形式
 *  ・あり:バイナリデータ
 *  ・なし:ELFファイル
 * -p<fifo config file path>
 *  ・あり:対抗ECUとの通信あり
 *  ・なし:シングルECU構成
 */
int main(int argc, const char *argv[])
{
    Std_ReturnType err;
    CmdOptionType *opt;
    MemoryAddressMapType memmap;
    memmap.ram_num = 0;
    memmap.rom_num = 0;
    memmap.ram = NULL;
    memmap.rom = NULL;

    if (argc == 1) {
        printf("Usage:%s -m <memory config file> [OPTION]... <load_file>\n", "athrill");
        printf(" %-30s : execute on the interaction mode. if -i is not set, execute on the background mode.\n", "-i");
        printf(" %-30s : execute on the remote mode. this option is valid on the interaction mode.\n", "-r");
        printf(" %-30s : set program end time using <timeout> clocks. this option is valid on the background mode.\n", "-t<timeout>");
        printf(" %-30s : set athrill memory configuration. rom, ram region is configured on your system.\n", "-m<memory config file>");
        //printf(" %-30s : set communication path with an another emulator.\n", "-p<fifo config file>");
        printf(" %-30s : set device parameter.\n", "-d<device config file>");
        return -11;
    }

    winsock_init();
#if 0
    struct sched_param sp;

    sp.sched_priority = sched_get_priority_max(SCHED_FIFO);
    int ret = sched_setscheduler(0, SCHED_FIFO, &sp);
    if (ret) {
        perror("sched_setscheduler");
        return 1;
    }
#endif

    opt = parse_args(argc, argv);
    if (opt == NULL) {
        return 1;
    }
    printf("core id num=%u\n", opt->core_id_num);
    if (opt->fifocfgpath != NULL) {
        err = cpuemu_set_comm_fifocfg(opt->fifocfgpath);
        if (err != STD_E_OK) {
            return -1;
        }
    }
    if (opt->devcfgpath != NULL) {
        err = cpuemu_load_devcfg(opt->devcfgpath);
        if (err != STD_E_OK) {
            return -1;
        }
    }
    if (opt->memfilepath != NULL) {
        err = cpuemu_load_memmap(opt->memfilepath, &memmap);
        if (err != STD_E_OK) {
            return -1;
        }
    }

    if (opt->is_binary_data) {
        binary_load((uint8*)opt->load_file.buffer, 0U, opt->load_file.size);
    }
    else {
        elf_load((uint8*)opt->load_file.buffer, &memmap);
        if (cpuemu_symbol_set() != STD_E_OK) {
            return -1;
        }
        file_address_mapping_init();
    }

    if (opt->is_interaction == TRUE) {
        if (opt->is_remote == TRUE) {
            cui_ops_udp_init();
        }
        else {
            cui_ops_stdio_init();
        }

        cpuemu_init(cpuemu_thread_run, opt);
        do_cui();
    }
    else {
        cpuemu_init(NULL, opt);
        cpuemu_set_cpu_end_clock(opt->timeout);
        (void)cpuemu_thread_run(NULL);
    }

    return 0;
}

参考資料(reference)

「TOPPERS活用アイデア・アプリケーション開発コンテスト受賞作品紹介」まとめ
https://qiita.com/kaizen_nagoya/items/72b882d96b2841f25faf

TOPPERS活用アイデア・アプリケーション開発コンテストを振り返る
https://researchmap.jp/joxkbxlck-1778110/
「応募すると何が嬉しい」TOPPERS活用アイデア・ アプリケーション開発コンテスト
https://www.slideshare.net/kaizenjapan/ss-78528931

「TOPPERS活用アイデア・アプリケーション開発コンテスト」への道

文書履歴(document history)

ver. 0.01 初稿 20190223
ver. 0,02 誤植、ソース追記 20190224
ver. 0.03 はてなブックマーク 20190225