source: ssp_rpi3/trunk/arch/arm64_gcc/common/core_timer.c@ 384

Last change on this file since 384 was 384, checked in by nmir-saito, 5 years ago

add target dependent files of ssp for rpi3

  • Property svn:keywords set to Id
File size: 5.0 KB
Line 
1/*
2 * TOPPERS/SSP Kernel
3 * Smallest Set Profile Kernel
4 *
5 * Copyright (C) 2013-2015 by Embedded and Real-Time Systems Laboratory
6 * Graduate School of Information Science, Nagoya Univ., JAPAN
7 * Copyright (C) 2018,2019 by Naoki Saito
8 * Nagoya Municipal Industrial Research Institute, JAPAN
9 *
10 * 上記著作権者
11は,以下の(1)〜(4)の条件を満たす場合に限り,本ソフトウェ
12 * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
13 * 変・再é…
14å¸ƒï¼ˆä»¥ä¸‹ï¼Œåˆ©ç”¨ã¨å‘¼ã¶ï¼‰ã™ã‚‹ã“とを無償で許諾する.
15 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
16 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
17 * スコード中に含まれていること.
18 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
19 * 用できる形で再é…
20å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œå†é…
21å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨
22 * 者
23マニュアルなど)に,上記の著作権表示,この利用条件および下記
24 * の無保証規定を掲載すること.
25 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
26 * 用できない形で再é…
27å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œæ¬¡ã®ã„ずれかの条件を満たすこ
28 * と.
29 * (a) 再é…
30å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨è€…
31マニュアルなど)に,上記の著
32 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
33 * (b) 再é…
34å¸ƒã®å½¢æ…
35‹ã‚’,別に定める方法によって,TOPPERSプロジェクトに
36 * 報告すること.
37 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
38 * 害からも,上記著作権者
39およびTOPPERSプロジェクトをå…
40è²¬ã™ã‚‹ã“と.
41 * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
42 * 由に基づく請求からも,上記著作権者
43およびTOPPERSプロジェクトを
44 * å…
45è²¬ã™ã‚‹ã“と.
46 *
47 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者
48お
49 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
50 * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
51 * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
52 * の責任を負わない.
53 *
54 * $Id: core_timer.c 384 2019-04-16 11:01:09Z nmir-saito $
55 */
56
57/*
58 * タイマドライバ(Generic Timer)
59 */
60#include "kernel_impl.h"
61#include "time_event.h"
62#include "target_timer.h"
63
64/*
65 * タイマの周波数(単位: kHz)
66 */
67static uint32_t timer_clock;
68
69/*
70 * タイマの設定値(比較対象とする値)
71 */
72static uint64_t timer_cval;
73
74/*
75 * タイマの開始
76 */
77Inline void
78target_timer_start(void)
79{
80 uint32_t cntp_ctl;
81
82 cntp_ctl = clock_read_ctrl();
83 cntp_ctl |= ((uint32_t)CNTP_CTL_ENABLE);
84 clock_write_ctrl(cntp_ctl);
85}
86
87/*
88 * タイマの停止
89 */
90Inline void
91target_timer_stop(void)
92{
93 uint32_t cntp_ctl;
94 cntp_ctl = clock_read_ctrl();
95 cntp_ctl &= ~CNTP_CTL_ENABLE;
96 clock_write_ctrl(cntp_ctl);
97}
98
99/*
100 * タイマの起動処理
101 */
102void
103target_timer_initialize(intptr_t exinf)
104{
105 uint32_t cyc;
106 uint32_t timer_clock_hz;
107
108 /*
109 * タイマの停止
110 */
111 target_timer_stop();
112
113 /*
114 * プリスケーラ(=2^31 --> divider=1)
115 */
116 sil_wrw_mem((uint32_t *)(0x40000008), 0x80000000);
117
118 timer_clock_hz = get_timer_freq(); // 19.2MHz
119 timer_clock = timer_clock_hz / 1000;
120
121 /*
122 * 1ティックのクロック数
123 */
124 cyc = (timer_clock * (TIC_NUME) / (TIC_DENO));
125
126 /*
127 * タイマの開始
128 */
129 clock_write_tval((uint32_t)cyc);
130 target_timer_start();
131
132 /*
133 * タイマの設定値
134 */
135 timer_cval = clock_read_cval();
136}
137
138/*
139 * タイマの停止処理
140 */
141void
142target_timer_terminate(intptr_t exinf)
143{
144 /*
145 * タイマの停止
146 */
147 clock_write_ctrl((uint32_t)0);
148}
149
150/*
151 * タイマ割込みハンドラ
152 */
153void
154target_timer_handler(void)
155{
156 uint32_t cyc;
157 uint64_t pct;
158
159 /*
160 * タイマの停止
161 */
162 target_timer_stop();
163
164 /*
165 * 1ティックのクロック数
166 */
167 cyc = (timer_clock * (TIC_NUME) / (TIC_DENO));
168
169 /*
170 * タイマの設定値
171 */
172 timer_cval = timer_cval + (uint64_t)cyc;
173
174
175 // カウンタから読み出し
176 pct = clock_read_counter();
177
178 while (timer_cval > pct + cyc) {
179 timer_cval = timer_cval - (uint64_t)cyc;
180 }
181 while (timer_cval < pct) {
182 timer_cval = timer_cval + (uint64_t)cyc;
183 }
184
185 /*
186 * タイマの設定
187 */
188 clock_write_cval((uint64_t)timer_cval);
189
190 /*
191 * タイマの開始
192 */
193 target_timer_start();
194
195 i_begin_int(INTNO_TIMER);
196 signal_time(); /* タイムティックの供給 */
197 i_end_int(INTNO_TIMER);
198}
Note: See TracBrowser for help on using the repository browser.