--- /dev/null
+# ----------------------------------------------------------------------------
+# Hyper Operating System V4 Advance
+#
+# Copyright (C) 1998-2011 by Project HOS
+# http://sourceforge.jp/projects/hos/
+# ----------------------------------------------------------------------------
+
+
+
+# --------------------------------------
+# %jp{各種設定}{setting}
+# --------------------------------------
+
+# %jp{ターゲット名}%en{target name}
+TARGET ?= sample
+
+
+# %jp{ツール定義}%en{tools}
+GCC_ARCH ?= mb-
+CMD_CC ?= $(GCC_ARCH)gcc
+CMD_ASM ?= $(GCC_ARCH)gcc
+CMD_LINK ?= $(GCC_ARCH)gcc
+CMD_OBJCNV ?= $(GCC_ARCH)objcopy
+
+
+# %jp{アーキテクチャ定義}%en{architecture}
+ARCH_NAME ?= mb_v8
+ARCH_CC ?= gcc
+EXT_EXE ?= elf
+
+
+# %jp{ディレクトリ定義}%en{directories}
+TOP_DIR = ../../../..
+KERNEL_DIR = $(TOP_DIR)/kernel
+KERNEL_CFGRTR_DIR = $(TOP_DIR)/cfgrtr/build/gcc
+KERNEL_MAKINC_DIR = $(KERNEL_DIR)/build/common/gmake
+KERNEL_BUILD_DIR = $(KERNEL_DIR)/build/mb/mb_v8/gcc
+
+
+# %jp{コンフィギュレータ定義}
+KERNEL_CFGRTR = $(KERNEL_CFGRTR_DIR)/h4acfg-$(ARCH_NAME)
+
+
+# %jp{共通定義読込み}%jp{common setting}
+include $(KERNEL_MAKINC_DIR)/common.inc
+
+
+# %jp{リンカスクリプト}%en{linker script}
+LINK_SCRIPT = rom.lds
+
+
+# %jp{内蔵RAM}%en{internal RAM}
+ifeq ($(MEMMAP),ram)
+LINK_SCRIPT = ram.lds
+TARGET := $(TARGET)_ram
+endif
+
+
+# %jp{パス設定}%en{add source directories}
+INC_DIRS += . ..
+SRC_DIRS += . ..
+
+
+# %jp{オプションフラグ}%en{option flags}
+AFLAGS = -mcpu=v8.00.a
+CFLAGS = -mcpu=v8.00.a
+LNFLAGS = -mcpu=v8.00.a
+# -nostartfiles -Wl,-Map,$(TARGET).map,-T$(LINK_SCRIPT)
+
+
+# %jp{コンパイラ依存の設定読込み}%en{compiler dependent definitions}
+include $(KERNEL_MAKINC_DIR)/$(ARCH_CC)_d.inc
+
+# %jp{実行ファイル生成用設定読込み}%en{definitions for exection file}
+include $(KERNEL_MAKINC_DIR)/makexe_d.inc
+
+
+# %jp{出力ファイル名}%en{output files}
+TARGET_EXE = $(TARGET).$(EXT_EXE)
+TARGET_MOT = $(TARGET).$(EXT_MOT)
+TARGET_HEX = $(TARGET).$(EXT_HEX)
+TARGET_BIN = $(TARGET).$(EXT_BIN)
+
+
+
+# --------------------------------------
+# %jp{ソースファイル}%en{source files}
+# --------------------------------------
+
+# %jp{アセンブラファイルの追加}%en{assembry sources}
+#ASRCS += ./crt0.S
+
+
+# %jp{C言語ファイルの追加}%en{C sources}
+CSRCS += ../main.c
+CSRCS += ../kernel_cfg.c
+CSRCS += ../sample.c
+CSRCS += ../uart.c
+CSRCS += ../ostimer.c
+
+
+
+# --------------------------------------
+# %jp{ルール定義}%en{rules}
+# --------------------------------------
+
+# %jp{ALL}%en{all}
+.PHONY : all
+all: kernel_make makeexe_all $(TARGET_EXE) $(TARGET_MOT) $(TARGET_HEX) $(TARGET_BIN)
+
+.PHONY : run
+run: $(TARGET_BIN)
+ jelly_loader -r $(TARGET_BIN)
+
+# %jp{クリーン}%en{clean}
+.PHONY : clean
+clean: makeexe_clean
+ rm -f $(TARGET_EXE) $(TARGET_EXE) $(OBJS) ../kernel_cfg.c ../kernel_id.h
+
+# %jp{依存関係更新}%en{depend}
+.PHONY : depend
+depend: makeexe_depend
+
+# %jp{ソース一括コピー}%en{source files copy}
+.PHONY : srccpy
+srccpy: makeexe_srccpy
+
+# %jp{カーネルごとクリーン}%en{mostlyclean}
+.PHONY : mostlyclean
+mostlyclean: clean kernel_clean
+
+
+# %jp{コンフィギュレータ実行}%en{configurator}
+../kernel_cfg.c ../kernel_id.h: ../system.cfg $(KERNEL_CFGRTR)
+ cpp -E ../system.cfg ../system.i
+ $(KERNEL_CFGRTR) ../system.i -c ../kernel_cfg.c -i ../kernel_id.h
+
+
+# %jp{実行ファイル生成用設定読込み}%en{rules for exection file}
+include $(KERNEL_MAKINC_DIR)/makexe_r.inc
+
+# %jp{コンパイラ依存のルール定義読込み}%en{rules for compiler}
+include $(KERNEL_MAKINC_DIR)/$(ARCH_CC)_r.inc
+
+
+
+
+# --------------------------------------
+# %jp{依存関係}%en{dependency}
+# --------------------------------------
+
+$(TARGET_EXE): $(LINK_SCRIPT)
+
+$(OBJS_DIR)/sample.$(EXT_OBJ) : ../kernel_id.h
+
+
+
+# end of file
+
--- /dev/null
+/**
+ * Sample program for Hyper Operating System V4 Advance
+ *
+ * @file main.c
+ * @brief %jp{メイン関数}%en{main}
+ *
+ * Copyright (C) 1998-2006 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+#include "kernel.h"
+#include "uart.h"
+
+
+
+/** %jp{メイン関数} */
+int main()
+{
+ /* %jp{カーネルの動作開始} */
+ vsta_knl();
+
+ return 0;
+}
+
+
+
+/* end of file */
--- /dev/null
+/**
+ * Sample program for Hyper Operating System V4 Advance
+ *
+ * @file ostimer.c
+ * @brief %jp{OSタイマ}%en{OS timer}
+ *
+ * Copyright (C) 1998-2008 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+#include "kernel.h"
+#include "ostimer.h"
+
+
+#define INTNO_TIMER0 0
+
+
+
+static void OsTimer_Isr(VP_INT exinf); /**< %jp{タイマ割込みサービスルーチン} */
+
+
+/** %jp{OS用タイマ初期化ルーチン} */
+void OsTimer_Initialize(VP_INT exinf)
+{
+ T_CISR cisr;
+
+ /* %jp{割込みサービスルーチン生成} */
+ cisr.isratr = TA_HLNG;
+ cisr.exinf = 0;
+ cisr.intno = INTNO_TIMER0;
+ cisr.isr = (FP)OsTimer_Isr;
+ acre_isr(&cisr);
+
+ /* 開始 */
+
+ /* 割込み許可 */
+ ena_int(INTNO_TIMER0);
+}
+
+
+/** %jp{タイマ割込みハンドラ} */
+void OsTimer_Isr(VP_INT exinf)
+{
+ /* %jp{タイムティック供給} */
+ isig_tim();
+}
+
+
+
+/* end of file */
--- /dev/null
+/**
+ * Sample program for Hyper Operating System V4 Advance
+ *
+ * @file ostimer.c
+ * @brief %jp{OSタイマ}%en{OS timer}
+ *
+ * Copyright (C) 1998-2006 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+#ifndef __ostimer_h__
+#define __ostimer_h__
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** %jp{OS用タイマ初期化ルーチン} */
+void OsTimer_Initialize(VP_INT exinf);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __ostimer_h__ */
+
+
+/* end of file */
--- /dev/null
+==============================================================================
+ Hyper Operating System V4 Advance
+ 用サンプル
+
+ Copyright (C) 2008-2011 by Project HOS
+==============================================================================
+
+
+<概要>
+ お題は例によって、「哲学者の食事の問題」です。
+ 5つのタスクを哲学者、5つのセマフォをフォークに見立てて、
+動作します。
+
+ 哲学者はランダムな時間考え事をするとおもむろに両サイドの
+フォークを取って食事を始めます。しかし左右どちらかの哲学者が
+すでにフォークを使って食事をしていると、フォークが使えず
+空腹状態になります。
+
+
+<環境>
+ XILINX EDK12
+
+<使い方>
+ GNU make が利用できる環境で
+
+ gcc の場合: hos-v4a/sample/mb/mb_v8/gcc
+
+ に移動して、gmake
+
+ と打ち込みます。
+
+ 出来上がった、sample.bin をROMに配置して合成することで動作します。
+
+ 5人の哲学者がそれぞれ、考えたり、お腹を空かせたり、食事したりする様子が
+シリアルに表示されれば成功です。
+
+<備考>
+ gmake MEMMAP=ram
+
+ としすると、RAMを0番地に配置したモデルで sample_ram.bin を生成します。
+ ROM化せずにRAMをマッピングしてデバッグする場合にご利用ください。
+
+
+==============================================================================
+ end of file
+==============================================================================
--- /dev/null
+/**
+ * Sample program for Hyper Operating System V4 Advance
+ *
+ * @file sample.c
+ * @brief %jp{サンプルプログラム}%en{Sample program}
+ *
+ * Copyright (C) 1998-2009 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+#include <stdlib.h>
+#include <string.h>
+#include "kernel.h"
+#include "kernel_id.h"
+#include "uart.h"
+
+
+#define LEFT(num) ((num) <= 1 ? 5 : (num) - 1)
+#define RIGHT(num) ((num) >= 5 ? 1 : (num) + 1)
+
+
+/** %jp{初期化ハンドラ} */
+void Sample_Initialize(VP_INT exinf)
+{
+ /* %jp{UART初期化} */
+ Uart_Initialize();
+
+ /* %jp{タスク起動} */
+ act_tsk(TSKID_SAMPLE1);
+ act_tsk(TSKID_SAMPLE2);
+ act_tsk(TSKID_SAMPLE3);
+ act_tsk(TSKID_SAMPLE4);
+ act_tsk(TSKID_SAMPLE5);
+}
+
+
+/** %jp{適当な時間待つ} */
+void Sample_RandWait(void)
+{
+ static unsigned long seed = 12345;
+ unsigned long r;
+
+ wai_sem(SEMID_RAND);
+ seed = seed * 22695477UL + 1;
+ r = seed;
+ sig_sem(SEMID_RAND);
+
+ dly_tsk((r % 1000) + 100);
+}
+
+
+/** %jp{状態表示} */
+void Sample_PrintSatet(int num, const char *text)
+{
+ int i;
+
+ wai_sem(SEMID_UART);
+
+ /* %jp{文字列出力} */
+ Uart_PutChar('0' + num);
+ Uart_PutChar(' ');
+ Uart_PutChar(':');
+ Uart_PutChar(' ');
+ for ( i = 0; text[i] != '\0'; i++ )
+ {
+ Uart_PutChar(text[i]);
+ }
+ Uart_PutChar('\r');
+ Uart_PutChar('\n');
+
+ sig_sem(SEMID_UART);
+}
+
+
+
+/** %jp{サンプルタスク} */
+void Sample_Task(VP_INT exinf)
+{
+ int num;
+
+ num = (int)exinf;
+
+ /* %jp{いわゆる哲学者の食事の問題} */
+ for ( ; ; )
+ {
+ /* %jp{適当な時間考える} */
+ Sample_PrintSatet(num, "thinking");
+ Sample_RandWait();
+
+ /* %jp{左右のフォークを取るまでループ} */
+ for ( ; ; )
+ {
+ /* %jp{左から順に取る} */
+ wai_sem(LEFT(num));
+ if ( pol_sem(RIGHT(num)) == E_OK )
+ {
+ break; /* %jp{両方取れた} */
+ }
+ sig_sem(LEFT(num)); /* %jp{取れなければ離す} */
+
+ /* %jp{適当な時間待つ} */
+ Sample_PrintSatet(num, "hungry");
+ Sample_RandWait();
+
+ /* %jp{右から順に取る} */
+ wai_sem(RIGHT(num));
+ if ( pol_sem(LEFT(num)) == E_OK )
+ {
+ break; /* %jp{両方取れた} */
+ }
+ sig_sem(RIGHT(num)); /* %jp{取れなければ離す} */
+
+ /* %jp{適当な時間待つ} */
+ Sample_PrintSatet(num, "hungry");
+ Sample_RandWait();
+ }
+
+ /* %jp{適当な時間、食べる} */
+ Sample_PrintSatet(num, "eating");
+ Sample_RandWait();
+
+ /* %jp{フォークを置く} */
+ sig_sem(LEFT(num));
+ sig_sem(RIGHT(num));
+ }
+}
+
+
+/* end of file */
--- /dev/null
+/**
+ * Sample program for Hyper Operating System V4 Advance
+ *
+ * @file sample.c
+ * @brief %jp{サンプルプログラム}%en{Sample program}
+ *
+ * Copyright (C) 1998-2006 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+
+#ifndef __sample_h__
+#define __sample_h__
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void Sample_Initialize(VP_INT exinf);
+void Sample_Task(VP_INT exinf);
+void Sample_Print(VP_INT exinf);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __sample_h__ */
+
+
+/* end of file */
--- /dev/null
+/**
+ * Sample program for Hyper Operating System V4 Advance
+ *
+ * @file system.cfg
+ * @brief %jp{サンプルのコンフィギュレーション}
+ *
+ * Copyright (C) 1998-2009 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+/* %jp{カーネル独自の設定}%en{kernel} */
+KERNEL_HEP_MEM(128, NULL);
+KERNEL_SYS_STK(256, NULL);
+KERNEL_INT_STK(256, NULL);
+KERNEL_MAX_TSKID(6);
+KERNEL_MAX_SEMID(7);
+KERNEL_MAX_FLGID(0);
+KERNEL_MAX_MBXID(0);
+KERNEL_MAX_MPFID(0);
+KERNEL_MAX_MTXID(1);
+KERNEL_MAX_ISRID(2);
+
+
+/* %jp{OSタイマの設定}%en{OS timer} */
+INCLUDE("\"ostimer.h\"");
+ATT_INI({TA_HLNG, 0, OsTimer_Initialize});
+
+/* %jp{サンプル}%en{Sample program} */
+INCLUDE("\"sample.h\"");
+ATT_INI({TA_HLNG, 0, Sample_Initialize});
+CRE_TSK(TSKID_SAMPLE1, {TA_HLNG, 1, Sample_Task, 2, 256, NULL});
+CRE_TSK(TSKID_SAMPLE2, {TA_HLNG, 2, Sample_Task, 2, 256, NULL});
+CRE_TSK(TSKID_SAMPLE3, {TA_HLNG, 3, Sample_Task, 2, 256, NULL});
+CRE_TSK(TSKID_SAMPLE4, {TA_HLNG, 4, Sample_Task, 2, 256, NULL});
+CRE_TSK(TSKID_SAMPLE5, {TA_HLNG, 5, Sample_Task, 2, 256, NULL});
+CRE_SEM(1, {TA_TFIFO, 1, 1});
+CRE_SEM(2, {TA_TFIFO, 1, 1});
+CRE_SEM(3, {TA_TFIFO, 1, 1});
+CRE_SEM(4, {TA_TFIFO, 1, 1});
+CRE_SEM(5, {TA_TFIFO, 1, 1});
+CRE_SEM(SEMID_RAND, {TA_TFIFO, 1, 1});
+CRE_SEM(SEMID_UART, {TA_TFIFO, 1, 1});
+
+
+/* end of file */
--- /dev/null
+/**
+ * Sample program for Hyper Operating System V4 Advance
+ *
+ * @file uart.c
+ * @brief %jp{UARTへの出力}%en{UART device driver}
+ *
+ * Copyright (C) 1998-2006 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+#include "kernel.h"
+
+
+
+/* %jp{UARTの初期化} */
+void Uart_Initialize(void)
+{
+}
+
+
+/* %jp{1文字入力} */
+char Uart_GetChar(void)
+{
+ return 0;
+}
+
+
+/* %jp{1文字出力} */
+void Uart_PutChar(int c)
+{
+}
+
+
+/* %jp{文字列出力} */
+void Uart_PutString(const char *text)
+{
+ while ( *text != '\0' )
+ {
+ if ( *text == '\n' )
+ {
+ Uart_PutChar('\r');
+ Uart_PutChar('\n');
+ }
+ else
+ {
+ Uart_PutChar(*text);
+ }
+
+ text++;
+ }
+}
+
+
+char Uart_hex2asc(int a)
+{
+ if ( a < 10 )
+ {
+ return '0' + a;
+ }
+ return 'a' + a - 10;
+}
+
+
+void Uart_PutHexByte(char c)
+{
+ Uart_PutChar(Uart_hex2asc((c >> 4) & 0xf));
+ Uart_PutChar(Uart_hex2asc((c >> 0) & 0xf));
+}
+
+
+void Uart_PutHexHalfWord(unsigned short h)
+{
+ Uart_PutHexByte((h >> 8) & 0xff);
+ Uart_PutHexByte((h >> 0) & 0xff);
+}
+
+void Uart_PutHexWord(unsigned long w)
+{
+ Uart_PutHexHalfWord((w >> 16) & 0xffff);
+ Uart_PutHexHalfWord((w >> 0) & 0xffff);
+}
+
+
+
+/* end of file */
--- /dev/null
+/**
+ * Sample program for Hyper Operating System V4 Advance
+ *
+ * @file uart.h
+ * @brief %jp{UARTへの出力}%en{UART device driver}
+ *
+ * Copyright (C) 1998-2006 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+#ifndef __ostimer_h__
+#define __ostimer_h__
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void Uart_Initialize(void); /* %jp{UART の初期化} */
+void Uart_PutChar(int c); /* %jp{1文字出力} */
+void Uart_PutString(const char *text); /* %jp{文字列出力} */
+
+void Uart_PutHexByte(char c);
+void Uart_PutHexHalfWord(unsigned short h);
+void Uart_PutHexWord(unsigned long w);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __ostimer_h__ */
+
+
+/* end of file */