.syntax unified
+
.text
.align 2
--- /dev/null
+# ----------------------------------------------------------------------------
+# Hyper Operating System V4 Advance
+#
+# Copyright (C) 1998-2011 by Project HOS
+# http://sourceforge.jp/projects/hos/
+# ----------------------------------------------------------------------------
+
+
+KERNEL_DEBUG ?= Yes
+DEBUG ?= Yes
+
+
+# --------------------------------------
+# %jp{各種設定}{setting}
+# --------------------------------------
+
+# %jp{ターゲット名}%en{target name}
+TARGET ?= sample
+
+
+# %jp{ツール定義}%en{tools}
+GCC_ARCH ?= arm-none-eabi-
+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 ?= cortex_m0
+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/arm/cortex_m0/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 = link.lds
+
+# %jp{外部メモリ}%en{external memory}
+ifeq ($(MEMMAP),ext)
+LINK_SCRIPT = linkext.lds
+endif
+
+# %jp{内蔵RAM}%en{internal RAM}
+ifeq ($(MEMMAP),ram)
+LINK_SCRIPT = linkram.lds
+endif
+
+
+# %jp{パス設定}%en{add source directories}
+INC_DIRS += . ..
+SRC_DIRS += . ..
+
+
+# %jp{オプションフラグ}%en{option flags}
+AFLAGS = -mcpu=cortex-m0 -mthumb
+CFLAGS = -mcpu=cortex-m0 -mthumb
+LNFLAGS = -mcpu=cortex-m0 -mthumb -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)
+
+
+
+
+# --------------------------------------
+# %jp{ソースファイル}%en{source files}
+# --------------------------------------
+
+# %jp{アセンブラファイルの追加}%en{assembry sources}
+#ASRCS += ./vectors.S
+#ASRCS += ./crt0.S
+
+
+# %jp{C言語ファイルの追加}%en{C sources}
+CSRCS += ./kernel_vct.c
+CSRCS += ../kernel_cfg.c
+CSRCS += ../main.c
+CSRCS += ../sample.c
+CSRCS += ../ostimer.c
+CSRCS += ../uart.c
+
+
+
+
+# --------------------------------------
+# %jp{ルール定義}%en{rules}
+# --------------------------------------
+
+# %jp{ALL}%en{all}
+.PHONY : all
+all: kernel_make makeexe_all $(TARGET_EXE) $(TARGET_MOT) $(TARGET_HEX)
+
+# %jp{クリーン}%en{clean}
+.PHONY : clean
+clean: makeexe_clean
+ rm -f $(TARGET_EXE) $(TARGET_EXE) $(OBJS) ../kernel_cfg.c ../kernel_id.h kernel_vct.c
+
+# %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 kernel_vct.c: ../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}
+# --------------------------------------
+
+$(OBJS_DIR)/sample.$(EXT_OBJ) : ../kernel_id.h
+
+
+
+# end of file
+
--- /dev/null
+OUTPUT_ARCH(arm)
+ENTRY(_kernel_reset_handler)
+
+MEMORY
+{
+ vector : o = 0x00000000, l = 0x00001000
+ ro : o = 0x00001000, l = 0x00007000
+ rw : o = 0x10000000, l = 0x00002000
+}
+
+SECTIONS
+{
+ .vector :
+ {
+ ___vector = . ;
+ */kernel_vct.o(.data)
+ */kernel_vct.o(.rodata*)
+ FILL(0xff)
+ ___vector_end = . ;
+ } > vector
+ .text :
+ {
+ ___text = . ;
+ *(.text)
+ *(.strings)
+ *(.rodata*)
+ *(.glue*)
+ ___text_end = . ;
+ } > ro
+ .tors :
+ {
+ . = ALIGN(4);
+ ___ctors = . ;
+ *(.ctors)
+ ___ctors_end = . ;
+ ___dtors = . ;
+ *(.dtors)
+ ___dtors_end = . ;
+ } > ro
+ data : AT (ADDR(.tors) + SIZEOF(.tors))
+ {
+ ___data_rom = ADDR(.tors) + SIZEOF(.tors);
+ ___data = . ;
+ *(.data)
+ ___data_end = . ;
+ } > rw
+ .bss :
+ {
+ ___bss = . ;
+ *(.bss)
+ *(COMMON)
+ ___bss_end = . ;
+ } >rw
+}
+
--- /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"
+
+
+/** %jp{メイン関数} */
+int main()
+{
+ /* %jp{カーネルの動作開始} */
+ vsta_knl();
+
+ return 0;
+}
+
+/* dummy */
+void _sbrk(void)
+{
+}
+
+
+/* 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/
+ */
+
+
+#include "kernel.h"
+#include "ostimer.h"
+
+
+#define REG_SCSR ((volatile UW *)0xE000E010) /* SysTick Control and Status Register */
+#define REG_SRVR ((volatile UW *)0xE000E014) /* SysTick Reload Value Register */
+#define REG_SCUVR ((volatile UW *)0xE000E018) /* SysTick Current Value Register */
+#define REG_SCAVR ((volatile UW *)0xE000E01c) /* SysTick Calibration Value Register */
+
+
+/** %jp{OS用タイマ初期化ルーチン} */
+void OsTimer_Initialize(VP_INT exinf)
+{
+ /* %jp{タイマ動作開始} */
+ *REG_SRVR = 1000000;
+ *REG_SCUVR = 0;
+ *REG_SCSR = 0x00000007;
+
+ ena_int(15);
+}
+
+
+/** %jp{タイマ割込みハンドラ} */
+void OsTimer_Isr(void)
+{
+ /* %jp{割込み要因クリア} */
+ vclr_int(15);
+
+ /* %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);
+void OsTimer_Isr(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __ostimer_h__ */
+
+
+/* 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/
+ */
+
+#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{適当な時間待つ} */
+void rand_wait(void)
+{
+ static long x = 1;
+ int r;
+
+ /* 擬似乱数生成 */
+ wai_sem(SEMID_RAND);
+ x = x * 214013 + 2531011;
+ r = ((x >> 16) & 0xffff);
+ sig_sem(SEMID_RAND);
+
+ dly_tsk((r % 100) + 10);
+}
+
+
+/** %jp{状態表示} */
+void print_state(int num, char *text)
+{
+ wai_sem(SEMID_UART);
+
+ /* %jp{文字列生成} */
+ Uart_PutChar('0' + num);
+ Uart_PutChar(' ');
+ Uart_PutChar(':');
+ Uart_PutChar(' ');
+ Uart_PutString(text);
+
+ sig_sem(SEMID_UART);
+}
+
+
+/** %jp{サンプルタスク} */
+void Sample_Task(VP_INT exinf)
+{
+ int num;
+
+ num = (int)exinf;
+
+ /* %jp{いわゆる哲学者の食事の問題} */
+ for ( ; ; )
+ {
+ /* %jp{適当な時間考える} */
+ print_state(num, "thinking");
+ rand_wait();
+
+ /* %jp{左右のフォークを取るまでループ} */
+ for ( ; ; )
+ {
+ /* %jp{左から順に取る} */
+ wai_sem(LEFT(num));
+ if ( pol_sem(RIGHT(num)) == E_OK )
+ {
+ break; /* %jp{両方取れた} */
+ }
+ sig_sem(LEFT(num)); /* %jp{取れなければ離す} */
+
+ /* %jp{適当な時間待つ} */
+ print_state(num, "hungry");
+ rand_wait();
+
+ /* %jp{右から順に取る} */
+ wai_sem(RIGHT(num));
+ if ( pol_sem(LEFT(num)) == E_OK )
+ {
+ break; /* %jp{両方取れた} */
+ }
+ sig_sem(RIGHT(num)); /* %jp{取れなければ離す} */
+
+ /* %jp{適当な時間待つ} */
+ print_state(num, "hungry");
+ rand_wait();
+ }
+
+ /* %jp{適当な時間、食べる} */
+ print_state(num, "eating");
+ rand_wait();
+
+ /* %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-2006 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+/* %jp{カーネル独自の設定}%en{kernel} */
+KERNEL_HEP_MEM(256, NULL);
+KERNEL_SYS_STK(256, NULL);
+KERNEL_INT_STK(512, NULL);
+KERNEL_MAX_TSKID(5);
+KERNEL_MAX_SEMID(7);
+KERNEL_MAX_FLGID(0);
+KERNEL_MAX_MBXID(0);
+KERNEL_MAX_MPFID(0);
+KERNEL_MAX_MTXID(0);
+
+
+/* %jp{OSタイマの設定}%en{OS timer} */
+INCLUDE("\"ostimer.h\"");
+ATT_INI({TA_HLNG, 0, OsTimer_Initialize});
+DEF_INH(15, {TA_HLNG, OsTimer_Isr}); /* 15:SysTick */
+
+/* %jp{サンプル}%en{Sample program} */
+INCLUDE("\"sample.h\"");
+ATT_INI({TA_HLNG, 0, Sample_Initialize});
+CRE_TSK(TSKID_SAMPLE1, {TA_HLNG | TA_ACT, 1, Sample_Task, 2, 512, NULL});
+CRE_TSK(TSKID_SAMPLE2, {TA_HLNG | TA_ACT, 2, Sample_Task, 2, 512, NULL});
+CRE_TSK(TSKID_SAMPLE3, {TA_HLNG | TA_ACT, 3, Sample_Task, 2, 512, NULL});
+CRE_TSK(TSKID_SAMPLE4, {TA_HLNG | TA_ACT, 4, Sample_Task, 2, 512, NULL});
+CRE_TSK(TSKID_SAMPLE5, {TA_HLNG | TA_ACT, 5, Sample_Task, 2, 512, 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-2011 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+#include "kernel.h"
+
+
+/* %jp{UARTの初期化} */
+void Uart_Initialize(void)
+{
+}
+
+
+/* %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_PutHexWord(int i)
+{
+ Uart_PutHexByte((i >> 8) & 0xff);
+ Uart_PutHexByte((i >> 0) & 0xff);
+}
+
+
+
+/* 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_PutHexWord(int i);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __ostimer_h__ */
+
+
+/* end of file */
+++ /dev/null
-/* ------------------------------------------------------------------------ */
-/* Hyper Operating System V4 Advance */
-/* Sample program for ADuC7000 series */
-/* */
-/* Copyright (C) 1998-2007 by Project HOS */
-/* http://sourceforge.jp/projects/hos/ */
-/* ------------------------------------------------------------------------ */
-
-
- .extern __kernel_int_isp
- .extern ___data
- .extern ___data_end
- .extern ___bss
- .extern ___bss_end
- .extern main
-
- .global _reset_handler
- .global __main
-
-
- .text
-
-#define Mode_USR 0x10
-#define Mode_IRQ 0x12
-#define Mode_FIQ 0x11
-#define Mode_SVC 0x13
-#define Mode_UND 0x1b
-#define Mode_SYS 0x1f
-#define I_Bit 0x80
-#define F_Bit 0x40
-#define T_Bit 0x20
-
-
-/************************************************
- リセットハンドラ
-************************************************/
- .align 4
-_reset_handler:
- /* モード設定 */
- msr cpsr_c, #(Mode_SYS | F_Bit | I_Bit)
-
- /* スタック仮設定 */
- ldr r0, =_kernel_int_isp
- ldr sp, [r0]
-
-
- /* DATA領域のコピー */
- ldr r0, =___data_rom
- ldr r1, =___data
- ldr r2, =___data_end
-data_loop:
- cmp r1, r2
- ldrcc r3, [r0], #4
- strcc r3, [r1], #4
- bcc data_loop
-
-
- /* BSS領域の初期化 */
- ldr r0, =___bss
- ldr r1, =___bss_end
- mov r2, #0
-bss_loop:
- cmp r0, r1
- strcc r2, [r0], #4
- bcc bss_loop
-
-
- /* main関数の呼び出し */
- bl main
-end_loop:
- b end_loop
-
-
-__main:
- bx lr
-
-
-
- .end
-
-
-/* end of file */