• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

HOS-V4 Advance の開発リポジトリ


Commit MetaInfo

Revision00db3cf77d5b22cb9a51acd74536cadbbd75b7c6 (tree)
Zeit2011-06-29 01:04:43
Autorryuz <ryuz@user...>
Commiterryuz

Log Message

add Simple Microblaze Microcontroler sample

Ändern Zusammenfassung

Diff

--- /dev/null
+++ b/sample/mb/smm/gcc/crt0.S
@@ -0,0 +1,69 @@
1+/* ------------------------------------------------------------------------ */
2+/* Hyper Operating System V4 Advance */
3+/* Sample program for MicroBlaze */
4+/* */
5+/* Copyright (C) 1998-2011 by Project HOS */
6+/* http://sourceforge.jp/projects/hos/ */
7+/* ------------------------------------------------------------------------ */
8+
9+
10+ .extern _kernel_int_isp
11+ .extern ___data
12+ .extern ___data_end
13+ .extern ___bss
14+ .extern ___bss_end
15+ .extern main
16+
17+ .global _reset_handler
18+
19+ .text
20+
21+
22+
23+/************************************************
24+ リセットハンドラ
25+************************************************/
26+ .align 2
27+_reset_handler:
28+ /* スタック設定 */
29+ lwi r1, r0, _kernel_int_isp
30+
31+ addik r3, r0, ___data
32+ addik r4, r0, ___data_end
33+ addik r5, r0, ___data_ro
34+
35+ /* DATA領域のコピー */
36+ cmpu r18, r4, r3
37+ bgei r18, data_loop_end
38+data_loop:
39+ lwi r6, r5, 0
40+ swi r6, r3, 0
41+ addik r3, r3, 4
42+ cmpu r18, r4, r3
43+ bltid r18, data_loop
44+ addik r5, r5, 4
45+data_loop_end:
46+
47+ /* BSS領域の初期化 */
48+ addik r3, r0, ___bss
49+ addik r4, r0, ___bss_end
50+ cmpu r18,r4, r3
51+ bgei r18, bss_loop_end
52+bss_loop:
53+ swi r0, r3, 0
54+ addik r3, r3, 4
55+ cmpu r18, r4, r3
56+ blti r18, bss_loop
57+bss_loop_end:
58+
59+
60+ /* main関数の呼び出し */
61+ brlid r15, main
62+ nop
63+
64+exit_loop:
65+ bri exit_loop
66+
67+
68+
69+/* end of file */
--- /dev/null
+++ b/sample/mb/smm/gcc/link.lds
@@ -0,0 +1,62 @@
1+ENTRY(_reset_handler)
2+
3+MEMORY
4+{
5+ ro : o = 0x00000100, l = 0x00003f00
6+ rw : o = 0x00004000, l = 0x00004000
7+}
8+
9+SECTIONS
10+{
11+ .vectors.reset 0x00000000 :
12+ {
13+ *(.vectors.reset)
14+ }
15+ .vectors.sw_exception 0x00000008 :
16+ {
17+ *(.vectors.sw_exception)
18+ }
19+ .vectors.interrupt 0x00000010 :
20+ {
21+ *(.vectors.interrupt)
22+ }
23+ .vectors.hw_exception 0x00000020 :
24+ {
25+ *(.vectors.hw_exception)
26+ }
27+
28+ .text :
29+ {
30+ ___text = . ;
31+ *(.text)
32+ *(.strings)
33+ *(.rodata*)
34+ *(.glue*)
35+ ___text_end = . ;
36+ } > ro
37+ .tors :
38+ {
39+ . = ALIGN(4);
40+ ___ctors = . ;
41+ *(.ctors)
42+ ___ctors_end = . ;
43+ ___dtors = . ;
44+ *(.dtors)
45+ ___dtors_end = . ;
46+ } > ro
47+ data : AT (ADDR(.tors) + SIZEOF(.tors))
48+ {
49+ ___data_ro = ADDR(.tors) + SIZEOF(.tors);
50+ ___data = . ;
51+ *(.data)
52+ ___data_end = . ;
53+ } > rw
54+ .bss :
55+ {
56+ ___bss = . ;
57+ *(.bss)
58+ *(COMMON)
59+ ___bss_end = . ;
60+ } >rw
61+}
62+
--- /dev/null
+++ b/sample/mb/smm/gcc/vectors.S
@@ -0,0 +1,38 @@
1+/* ------------------------------------------------------------------------ */
2+/* Hyper Operating System V4 サンプルプログラム */
3+/* ベクタテーブル */
4+/* */
5+/* Copyright (C) 1998-2011 by Project HOS */
6+/* http://sourceforge.jp/projects/hos/ */
7+/* ------------------------------------------------------------------------ */
8+
9+
10+ /* --- 外部定数宣言 */
11+ .global _reset_handler
12+ .global _kernel_exc_hdr
13+ .global _kernel_int_hdr
14+ .global _kernel_brk_hdr
15+ .global _kernel_hwe_hdr
16+
17+
18+ .align 2
19+
20+/* --------------------------------------- */
21+/* ベクタ定義 */
22+/* --------------------------------------- */
23+
24+ .section .vectors.reset, "ax"
25+ brai _reset_handler
26+
27+ .section .vectors.sw_exception, "ax"
28+ bri _kernel_exc_hdr
29+
30+ .section .vectors.interrupt, "ax"
31+ bri _kernel_int_hdr
32+
33+ .section .vectors.hw_exception, "ax"
34+ bri _kernel_hwe_hdr
35+
36+
37+
38+/* end of file */
--- /dev/null
+++ b/sample/mb/smm/main.c
@@ -0,0 +1,28 @@
1+/**
2+ * Sample program for Hyper Operating System V4 Advance
3+ *
4+ * @file main.c
5+ * @brief %jp{メイン関数}%en{main}
6+ *
7+ * Copyright (C) 1998-2006 by Project HOS
8+ * http://sourceforge.jp/projects/hos/
9+ */
10+
11+
12+#include "kernel.h"
13+#include "uart.h"
14+
15+
16+
17+/** %jp{メイン関数} */
18+int main()
19+{
20+ /* %jp{カーネルの動作開始} */
21+ vsta_knl();
22+
23+ return 0;
24+}
25+
26+
27+
28+/* end of file */
--- /dev/null
+++ b/sample/mb/smm/ostimer.c
@@ -0,0 +1,64 @@
1+/**
2+ * Sample program for Hyper Operating System V4 Advance
3+ *
4+ * @file ostimer.c
5+ * @brief %jp{OSタイマ}%en{OS timer}
6+ *
7+ * Copyright (C) 1998-2008 by Project HOS
8+ * http://sourceforge.jp/projects/hos/
9+ */
10+
11+
12+#include "kernel.h"
13+#include "ostimer.h"
14+
15+
16+#define INTNO_TIMER 0
17+
18+#define REG_TIMER_BASE 0x41c00000
19+#define REG_TIMER_TCSR0 ((volatile unsigned long *)(REG_TIMER_BASE + 0x00))
20+#define REG_TIMER_TLR0 ((volatile unsigned long *)(REG_TIMER_BASE + 0x04))
21+#define REG_TIMER_TCR0 ((volatile unsigned long *)(REG_TIMER_BASE + 0x08))
22+#define REG_TIMER_TCSR1 ((volatile unsigned long *)(REG_TIMER_BASE + 0x10))
23+#define REG_TIMER_TLR1 ((volatile unsigned long *)(REG_TIMER_BASE + 0x14))
24+#define REG_TIMER_TCR1 ((volatile unsigned long *)(REG_TIMER_BASE + 0x18))
25+
26+
27+static void OsTimer_Isr(VP_INT exinf); /**< %jp{タイマ割込みサービスルーチン} */
28+
29+
30+/** %jp{OS用タイマ初期化ルーチン} */
31+void OsTimer_Initialize(VP_INT exinf)
32+{
33+ T_CISR cisr;
34+
35+ /* %jp{割込みサービスルーチン生成} */
36+ cisr.isratr = TA_HLNG;
37+ cisr.exinf = 0;
38+ cisr.intno = INTNO_TIMER;
39+ cisr.isr = (FP)OsTimer_Isr;
40+ acre_isr(&cisr);
41+
42+ /* 開始 */
43+ *REG_TIMER_TLR0 = 100000 - 1; /* 1ms 100MHz */
44+ *REG_TIMER_TCSR0 = 0x0132; /* clear int, load counter */
45+ *REG_TIMER_TCSR0 = 0x00d2; /* start */
46+
47+ /* 割込み許可 */
48+ ena_int(INTNO_TIMER);
49+}
50+
51+
52+/** %jp{タイマ割込みハンドラ} */
53+void OsTimer_Isr(VP_INT exinf)
54+{
55+ *REG_TIMER_TCSR0 |= 0x0100; /* clear int */
56+ vclr_int(INTNO_TIMER);
57+
58+ /* %jp{タイムティック供給} */
59+ isig_tim();
60+}
61+
62+
63+
64+/* end of file */
--- /dev/null
+++ b/sample/mb/smm/ostimer.h
@@ -0,0 +1,31 @@
1+/**
2+ * Sample program for Hyper Operating System V4 Advance
3+ *
4+ * @file ostimer.c
5+ * @brief %jp{OSタイマ}%en{OS timer}
6+ *
7+ * Copyright (C) 1998-2006 by Project HOS
8+ * http://sourceforge.jp/projects/hos/
9+ */
10+
11+
12+#ifndef __ostimer_h__
13+#define __ostimer_h__
14+
15+
16+#ifdef __cplusplus
17+extern "C" {
18+#endif
19+
20+/** %jp{OS用タイマ初期化ルーチン} */
21+void OsTimer_Initialize(VP_INT exinf);
22+
23+#ifdef __cplusplus
24+}
25+#endif
26+
27+
28+#endif /* __ostimer_h__ */
29+
30+
31+/* end of file */
--- /dev/null
+++ b/sample/mb/smm/readme.txt
@@ -0,0 +1,46 @@
1+==============================================================================
2+ Hyper Operating System V4 Advance
3+ 用サンプル
4+
5+ Copyright (C) 2008-2011 by Project HOS
6+==============================================================================
7+
8+
9+<概要>
10+ お題は例によって、「哲学者の食事の問題」です。
11+ 5つのタスクを哲学者、5つのセマフォをフォークに見立てて、
12+動作します。
13+
14+ 哲学者はランダムな時間考え事をするとおもむろに両サイドの
15+フォークを取って食事を始めます。しかし左右どちらかの哲学者が
16+すでにフォークを使って食事をしていると、フォークが使えず
17+空腹状態になります。
18+
19+
20+<環境>
21+ XILINX EDK12
22+
23+<使い方>
24+ GNU make が利用できる環境で
25+
26+ gcc の場合: hos-v4a/sample/mb/mb_v8/gcc
27+
28+ に移動して、gmake
29+
30+ と打ち込みます。
31+
32+ 出来上がった、sample.bin をROMに配置して合成することで動作します。
33+
34+ 5人の哲学者がそれぞれ、考えたり、お腹を空かせたり、食事したりする様子が
35+シリアルに表示されれば成功です。
36+
37+<備考>
38+ gmake MEMMAP=ram
39+
40+ としすると、RAMを0番地に配置したモデルで sample_ram.bin を生成します。
41+ ROM化せずにRAMをマッピングしてデバッグする場合にご利用ください。
42+
43+
44+==============================================================================
45+ end of file
46+==============================================================================
--- /dev/null
+++ b/sample/mb/smm/sample.c
@@ -0,0 +1,130 @@
1+/**
2+ * Sample program for Hyper Operating System V4 Advance
3+ *
4+ * @file sample.c
5+ * @brief %jp{サンプルプログラム}%en{Sample program}
6+ *
7+ * Copyright (C) 1998-2009 by Project HOS
8+ * http://sourceforge.jp/projects/hos/
9+ */
10+
11+
12+#include <stdlib.h>
13+#include <string.h>
14+#include "kernel.h"
15+#include "kernel_id.h"
16+#include "uart.h"
17+
18+
19+#define LEFT(num) ((num) <= 1 ? 5 : (num) - 1)
20+#define RIGHT(num) ((num) >= 5 ? 1 : (num) + 1)
21+
22+
23+/** %jp{初期化ハンドラ} */
24+void Sample_Initialize(VP_INT exinf)
25+{
26+ /* %jp{UART初期化} */
27+ Uart_Initialize();
28+
29+ /* %jp{タスク起動} */
30+ act_tsk(TSKID_SAMPLE1);
31+ act_tsk(TSKID_SAMPLE2);
32+ act_tsk(TSKID_SAMPLE3);
33+ act_tsk(TSKID_SAMPLE4);
34+ act_tsk(TSKID_SAMPLE5);
35+}
36+
37+
38+/** %jp{適当な時間待つ} */
39+void Sample_RandWait(void)
40+{
41+ static unsigned long seed = 12345;
42+ unsigned long r;
43+
44+ wai_sem(SEMID_RAND);
45+ seed = seed * 22695477UL + 1;
46+ r = seed;
47+ sig_sem(SEMID_RAND);
48+
49+ dly_tsk((r % 1000) + 100);
50+}
51+
52+
53+/** %jp{状態表示} */
54+void Sample_PrintSatet(int num, const char *text)
55+{
56+ int i;
57+
58+ wai_sem(SEMID_UART);
59+
60+ /* %jp{文字列出力} */
61+ Uart_PutChar('0' + num);
62+ Uart_PutChar(' ');
63+ Uart_PutChar(':');
64+ Uart_PutChar(' ');
65+ for ( i = 0; text[i] != '\0'; i++ )
66+ {
67+ Uart_PutChar(text[i]);
68+ }
69+ Uart_PutChar('\r');
70+ Uart_PutChar('\n');
71+
72+ sig_sem(SEMID_UART);
73+}
74+
75+
76+
77+/** %jp{サンプルタスク} */
78+void Sample_Task(VP_INT exinf)
79+{
80+ int num;
81+
82+ num = (int)exinf;
83+
84+ /* %jp{いわゆる哲学者の食事の問題} */
85+ for ( ; ; )
86+ {
87+ /* %jp{適当な時間考える} */
88+ Sample_PrintSatet(num, "thinking");
89+ Sample_RandWait();
90+
91+ /* %jp{左右のフォークを取るまでループ} */
92+ for ( ; ; )
93+ {
94+ /* %jp{左から順に取る} */
95+ wai_sem(LEFT(num));
96+ if ( pol_sem(RIGHT(num)) == E_OK )
97+ {
98+ break; /* %jp{両方取れた} */
99+ }
100+ sig_sem(LEFT(num)); /* %jp{取れなければ離す} */
101+
102+ /* %jp{適当な時間待つ} */
103+ Sample_PrintSatet(num, "hungry");
104+ Sample_RandWait();
105+
106+ /* %jp{右から順に取る} */
107+ wai_sem(RIGHT(num));
108+ if ( pol_sem(LEFT(num)) == E_OK )
109+ {
110+ break; /* %jp{両方取れた} */
111+ }
112+ sig_sem(RIGHT(num)); /* %jp{取れなければ離す} */
113+
114+ /* %jp{適当な時間待つ} */
115+ Sample_PrintSatet(num, "hungry");
116+ Sample_RandWait();
117+ }
118+
119+ /* %jp{適当な時間、食べる} */
120+ Sample_PrintSatet(num, "eating");
121+ Sample_RandWait();
122+
123+ /* %jp{フォークを置く} */
124+ sig_sem(LEFT(num));
125+ sig_sem(RIGHT(num));
126+ }
127+}
128+
129+
130+/* end of file */
--- /dev/null
+++ b/sample/mb/smm/sample.h
@@ -0,0 +1,33 @@
1+/**
2+ * Sample program for Hyper Operating System V4 Advance
3+ *
4+ * @file sample.c
5+ * @brief %jp{サンプルプログラム}%en{Sample program}
6+ *
7+ * Copyright (C) 1998-2006 by Project HOS
8+ * http://sourceforge.jp/projects/hos/
9+ */
10+
11+
12+
13+#ifndef __sample_h__
14+#define __sample_h__
15+
16+
17+#ifdef __cplusplus
18+extern "C" {
19+#endif
20+
21+void Sample_Initialize(VP_INT exinf);
22+void Sample_Task(VP_INT exinf);
23+void Sample_Print(VP_INT exinf);
24+
25+#ifdef __cplusplus
26+}
27+#endif
28+
29+
30+#endif /* __sample_h__ */
31+
32+
33+/* end of file */
--- /dev/null
+++ b/sample/mb/smm/system.cfg
@@ -0,0 +1,47 @@
1+/**
2+ * Sample program for Hyper Operating System V4 Advance
3+ *
4+ * @file system.cfg
5+ * @brief %jp{サンプルのコンフィギュレーション}
6+ *
7+ * Copyright (C) 1998-2009 by Project HOS
8+ * http://sourceforge.jp/projects/hos/
9+ */
10+
11+
12+/* %jp{カーネル独自の設定}%en{kernel} */
13++KERNEL_IRC_REGBASE(0x41200000);
14+KERNEL_HEP_MEM(512, NULL);
15+KERNEL_SYS_STK(512, NULL);
16+KERNEL_INT_STK(512, NULL);
17+KERNEL_MAX_TSKID(6);
18+KERNEL_MAX_SEMID(7);
19+KERNEL_MAX_FLGID(0);
20+KERNEL_MAX_MBXID(0);
21+KERNEL_MAX_MPFID(0);
22+KERNEL_MAX_MTXID(1);
23+KERNEL_MAX_ISRID(2);
24+
25+
26+/* %jp{OSタイマの設定}%en{OS timer} */
27+INCLUDE("\"ostimer.h\"");
28+ATT_INI({TA_HLNG, 0, OsTimer_Initialize});
29+
30+/* %jp{サンプル}%en{Sample program} */
31+INCLUDE("\"sample.h\"");
32+ATT_INI({TA_HLNG, 0, Sample_Initialize});
33+CRE_TSK(TSKID_SAMPLE1, {TA_HLNG, 1, Sample_Task, 2, 512, NULL});
34+CRE_TSK(TSKID_SAMPLE2, {TA_HLNG, 2, Sample_Task, 2, 512, NULL});
35+CRE_TSK(TSKID_SAMPLE3, {TA_HLNG, 3, Sample_Task, 2, 512, NULL});
36+CRE_TSK(TSKID_SAMPLE4, {TA_HLNG, 4, Sample_Task, 2, 512, NULL});
37+CRE_TSK(TSKID_SAMPLE5, {TA_HLNG, 5, Sample_Task, 2, 512, NULL});
38+CRE_SEM(1, {TA_TFIFO, 1, 1});
39+CRE_SEM(2, {TA_TFIFO, 1, 1});
40+CRE_SEM(3, {TA_TFIFO, 1, 1});
41+CRE_SEM(4, {TA_TFIFO, 1, 1});
42+CRE_SEM(5, {TA_TFIFO, 1, 1});
43+CRE_SEM(SEMID_RAND, {TA_TFIFO, 1, 1});
44+CRE_SEM(SEMID_UART, {TA_TFIFO, 1, 1});
45+
46+
47+/* end of file */
--- /dev/null
+++ b/sample/mb/smm/uart.c
@@ -0,0 +1,110 @@
1+/**
2+ * Sample program for Hyper Operating System V4 Advance
3+ *
4+ * @file uart.c
5+ * @brief %jp{UARTへの出力}%en{UART device driver}
6+ *
7+ * Copyright (C) 1998-2006 by Project HOS
8+ * http://sourceforge.jp/projects/hos/
9+ */
10+
11+
12+#include "kernel.h"
13+
14+
15+#define REG_UART_BASE 0x80000000
16+#define REG_UART_RBR ((volatile unsigned long *)(REG_UART_BASE + 0x1000))
17+#define REG_UART_THR ((volatile unsigned long *)(REG_UART_BASE + 0x1000))
18+#define REG_UART_IER ((volatile unsigned long *)(REG_UART_BASE + 0x1004))
19+#define REG_UART_IIR ((volatile unsigned long *)(REG_UART_BASE + 0x1008))
20+#define REG_UART_LCR ((volatile unsigned long *)(REG_UART_BASE + 0x100c))
21+#define REG_UART_MCR ((volatile unsigned long *)(REG_UART_BASE + 0x1010))
22+#define REG_UART_LSR ((volatile unsigned long *)(REG_UART_BASE + 0x1014))
23+#define REG_UART_MSR ((volatile unsigned long *)(REG_UART_BASE + 0x1018))
24+#define REG_UART_SCR ((volatile unsigned long *)(REG_UART_BASE + 0x101c))
25+#define REG_UART_DLL ((volatile unsigned long *)(REG_UART_BASE + 0x1000))
26+#define REG_UART_DLM ((volatile unsigned long *)(REG_UART_BASE + 0x1004))
27+
28+
29+/* %jp{UARTの初期化} */
30+void Uart_Initialize(void)
31+{
32+ *REG_UART_IER = 0x00;
33+ *REG_UART_LCR = 0x03;
34+ *REG_UART_MCR = 0x03;
35+ *REG_UART_LCR |= 0x80;
36+ *REG_UART_DLL = 80; /* 50000000 / 38400 / 16 - 1 */
37+ *REG_UART_DLM = 0x00;
38+ *REG_UART_LCR &= 0x7f;
39+}
40+
41+
42+/* %jp{1文字入力} */
43+char Uart_GetChar(void)
44+{
45+ return 0;
46+}
47+
48+
49+/* %jp{1文字出力} */
50+void Uart_PutChar(int c)
51+{
52+ while ( !(*REG_UART_LSR & 0x20) )
53+ ;
54+
55+ *REG_UART_THR = c;
56+}
57+
58+
59+/* %jp{文字列出力} */
60+void Uart_PutString(const char *text)
61+{
62+ while ( *text != '\0' )
63+ {
64+ if ( *text == '\n' )
65+ {
66+ Uart_PutChar('\r');
67+ Uart_PutChar('\n');
68+ }
69+ else
70+ {
71+ Uart_PutChar(*text);
72+ }
73+
74+ text++;
75+ }
76+}
77+
78+
79+char Uart_hex2asc(int a)
80+{
81+ if ( a < 10 )
82+ {
83+ return '0' + a;
84+ }
85+ return 'a' + a - 10;
86+}
87+
88+
89+void Uart_PutHexByte(char c)
90+{
91+ Uart_PutChar(Uart_hex2asc((c >> 4) & 0xf));
92+ Uart_PutChar(Uart_hex2asc((c >> 0) & 0xf));
93+}
94+
95+
96+void Uart_PutHexHalfWord(unsigned short h)
97+{
98+ Uart_PutHexByte((h >> 8) & 0xff);
99+ Uart_PutHexByte((h >> 0) & 0xff);
100+}
101+
102+void Uart_PutHexWord(unsigned long w)
103+{
104+ Uart_PutHexHalfWord((w >> 16) & 0xffff);
105+ Uart_PutHexHalfWord((w >> 0) & 0xffff);
106+}
107+
108+
109+
110+/* end of file */
--- /dev/null
+++ b/sample/mb/smm/uart.h
@@ -0,0 +1,37 @@
1+/**
2+ * Sample program for Hyper Operating System V4 Advance
3+ *
4+ * @file uart.h
5+ * @brief %jp{UARTへの出力}%en{UART device driver}
6+ *
7+ * Copyright (C) 1998-2006 by Project HOS
8+ * http://sourceforge.jp/projects/hos/
9+ */
10+
11+
12+#ifndef __ostimer_h__
13+#define __ostimer_h__
14+
15+
16+#ifdef __cplusplus
17+extern "C" {
18+#endif
19+
20+void Uart_Initialize(void); /* %jp{UART の初期化} */
21+void Uart_PutChar(int c); /* %jp{1文字出力} */
22+void Uart_PutString(const char *text); /* %jp{文字列出力} */
23+
24+void Uart_PutHexByte(char c);
25+void Uart_PutHexHalfWord(unsigned short h);
26+void Uart_PutHexWord(unsigned long w);
27+
28+
29+#ifdef __cplusplus
30+}
31+#endif
32+
33+
34+#endif /* __ostimer_h__ */
35+
36+
37+/* end of file */