OSDN Git Service

add Simple Microblaze Microcontroler sample
[hos/hos-v4a.git] / sample / mb / smm / ostimer.c
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 */