source: asp3_gr_sakura/trunk/target/gr_sakura_gcc/target_timer.c@ 317

Last change on this file since 317 was 317, checked in by coas-nagasima, 7 years ago

GR-SAKURA向けASP3を追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc
File size: 17.5 KB
Line 
1/*
2 * TOPPERS/ASP Kernel
3 * Toyohashi Open Platform for Embedded Real-Time Systems/
4 * Advanced Standard Profile Kernel
5 *
6 * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
7 * Toyohashi Univ. of Technology, JAPAN
8 * Copyright (C) 2003-2004 by Naoki Saito
9 * Nagoya Municipal Industrial Research Institute, JAPAN
10 * Copyright (C) 2003-2004 by Platform Development Center
11 * RICOH COMPANY,LTD. JAPAN
12 * Copyright (C) 2008-2010 by Witz Corporation, JAPAN
13 * Copyright (C) 2013 by Mitsuhiro Matsuura
14 * Copyright (C) 2017 by Cores Co., Ltd. Japan
15 *
16 * 上記著作権者
17は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
18 * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
19 * 変・再é…
20å¸ƒï¼ˆä»¥ä¸‹ï¼Œåˆ©ç”¨ã¨å‘¼ã¶ï¼‰ã™ã‚‹ã“とを無償で許諾する.
21 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
22 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
23 * スコード中に含まれていること.
24 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
25 * 用できる形で再é…
26å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œå†é…
27å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨
28 * 者
29マニュアルなど)に,上記の著作権表示,この利用条件および下記
30 * の無保証規定を掲載すること.
31 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
32 * 用できない形で再é…
33å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œæ¬¡ã®ã„ずれかの条件を満たすこ
34 * と.
35 * (a) 再é…
36å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨è€…
37マニュアルなど)に,上記の著
38 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
39 * (b) 再é…
40å¸ƒã®å½¢æ…
41‹ã‚’,別に定める方法によって,TOPPERSプロジェクトに
42 * 報告すること.
43 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
44 * 害からも,上記著作権者
45およびTOPPERSプロジェクトをå…
46è²¬ã™ã‚‹ã“と.
47 * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
48 * 由に基づく請求からも,上記著作権者
49およびTOPPERSプロジェクトを
50 * å…
51è²¬ã™ã‚‹ã“と.
52 *
53 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者
54お
55 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
56 * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
57 * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
58 * の責任を負わない.
59 *
60 * @(#) $Id: target_timer.c 317 2017-08-03 13:14:26Z coas-nagasima $
61 */
62
63/*
64 * タイマドライバ(GR-SAKURA用)
65 */
66
67#include "kernel_impl.h"
68#include "time_event.h"
69#include <sil.h>
70#include "target_timer.h"
71#ifdef TOPPERS_SUPPORT_OVRHDR
72#include "overrun.h"
73#endif /* TOPPERS_SUPPORT_OVRHDR */
74
75/*
76 * 上位タイマソフトカウンタ
77 */
78static uint16_t elapse_upper_timer = 0;
79
80/*
81 * 上下位タイマ設定カウンタ
82 */
83static uint16_t timer_upper_set_count = 0, timer_lower_set_count = 0;
84
85#ifdef TOPPERS_SUPPORT_OVRHDR
86
87/* オーバラン上下位タイマ設定カウンタ */
88static uint16_t timer_ovr_upper_set_count = 0, timer_ovr_lower_set_count = 0;
89
90/* オーバランタイマ実行中フラグ */
91static bool_t timer_ovr_running_flg = false;
92
93/* オーバランタイマ開始時HRTタイマ値 */
94static HRTCNT timer_ovr_hrt_backup;
95
96/* オーバランタイマ設定時間 */
97static PRCTIM timer_ovr_ovrtim_backup;
98
99/*
100 * オーバランタイマ割込み要求のクリア
101 */
102Inline void
103target_ovrtimer_int_clear()
104{
105 clear_int(INTNO_TIMER2);
106}
107
108#endif /* TOPPERS_SUPPORT_OVRHDR */
109
110/*
111 * タイマの初期化処理
112 */
113void
114target_timer_initialize(intptr_t exinf)
115{
116 /*
117 * モジュールストップ機能の設定 CMTユニット0 解除
118 */
119 sil_wrh_mem(SYSTEM_PRCR_ADDR, 0xA502); /* 書込み許可 */
120 sil_wrw_mem(SYSTEM_MSTPCRA_ADDR,
121 sil_rew_mem(SYSTEM_MSTPCRA_ADDR) & ~SYSTEM_MSTPCRA_MSTPA15_BIT);
122 sil_wrh_mem(SYSTEM_PRCR_ADDR, 0xA500); /* 書込み禁止 */
123
124 /*
125 * タイマ停止
126 */
127 sil_wrh_mem(CMT_CMSTR0_ADDR,
128 sil_reh_mem(CMT_CMSTR0_ADDR) & ~(CMT_CMSTR0_STR0_BIT | CMT_CMSTR0_STR1_BIT));
129
130 /*
131 * カウントアップに用いられるクロック設定
132 * PCLK/8を選択
133 */
134 sil_wrh_mem(CMT0_CMCR_ADDR, CMT_PCLK_DIV_8);
135 sil_wrh_mem(CMT1_CMCR_ADDR, CMT_PCLK_DIV_8);
136
137 /*
138 * コンペアマッチタイマカウンタ設定
139 */
140 sil_wrh_mem(CMT0_CMCNT_ADDR, 0U);
141 sil_wrh_mem(CMT1_CMCNT_ADDR, 0U);
142
143 /*
144 * コンペアマッチタイマ周期設定
145 */
146 sil_wrh_mem(CMT0_CMCOR_ADDR, 0); /* lower */
147 sil_wrh_mem(CMT1_CMCOR_ADDR, CMCOR_PERIOD - 1); /* upper */
148 elapse_upper_timer = 0;
149
150 /*
151 * コンペアマッチタイマ割り込み要求å…
152ˆè¨­å®šãƒ¬ã‚¸ã‚¹ã‚¿ï¼ˆ28,29)
153 */
154 sil_wrb_mem(ICU_ISELR028_ADDR, ICU_ISEL_CPU);
155 sil_wrb_mem(ICU_ISELR029_ADDR, ICU_ISEL_CPU);
156
157 /*
158 * タイマ動作開始前の割込み要求をクリア
159 */
160 clear_int(INTNO_TIMER0);
161 clear_int(INTNO_TIMER1);
162
163 /*
164 * コンペアマッチタイマ割り込みを許可
165 */
166// sil_wrh_mem(CMT0_CMCR_ADDR,
167// sil_reh_mem(CMT0_CMCR_ADDR) | CMT0_CMCR_CMIE_BIT); /* lower */
168 sil_wrh_mem(CMT1_CMCR_ADDR,
169 sil_reh_mem(CMT1_CMCR_ADDR) | CMT1_CMCR_CMIE_BIT); /* upper */
170
171 /*
172 * タイマ動作開始
173 */
174// sil_wrh_mem(CMT_CMSTR0_ADDR,
175// sil_reh_mem(CMT_CMSTR0_ADDR) | CMT_CMSTR0_STR0_BIT); /* lower */
176 sil_wrh_mem(CMT_CMSTR0_ADDR,
177 sil_reh_mem(CMT_CMSTR0_ADDR) | CMT_CMSTR0_STR1_BIT); /* upper */
178}
179
180/*
181 * タイマの停止処理
182 */
183void
184target_timer_terminate(intptr_t exinf)
185{
186 /*
187 * タイマ停止 lower, upper
188 */
189 sil_wrh_mem(CMT_CMSTR0_ADDR,
190 sil_reh_mem(CMT_CMSTR0_ADDR) & ~(CMT_CMSTR0_STR0_BIT | CMT_CMSTR0_STR1_BIT));
191
192 /*
193 * タイマ割り込み禁止 lower,upper
194 */
195 sil_wrh_mem(CMT0_CMCR_ADDR,
196 sil_reh_mem(CMT0_CMCR_ADDR) & ~CMT0_CMCR_CMIE_BIT);
197 sil_wrh_mem(CMT1_CMCR_ADDR,
198 sil_reh_mem(CMT1_CMCR_ADDR) & ~CMT1_CMCR_CMIE_BIT);
199
200 /*
201 * タイマ割込み要求をクリア
202 */
203 clear_int(INTNO_TIMER0);
204 clear_int(INTNO_TIMER1);
205
206 /*
207 * モジュールストップ機能の設定 CMTユニット0 停止
208 */
209 sil_wrh_mem(SYSTEM_PRCR_ADDR, 0xA502); /* 書込み許可 */
210 sil_wrw_mem(SYSTEM_MSTPCRA_ADDR,
211 sil_rew_mem(SYSTEM_MSTPCRA_ADDR) | SYSTEM_MSTPCRA_MSTPA15_BIT);
212 sil_wrh_mem(SYSTEM_PRCR_ADDR, 0xA500); /* 書込み禁止 */
213}
214
215/*
216 * 下位タイマ割込みハンドラ(CMT0)
217 */
218void target_lower_timer_handler(void)
219{
220 /*
221 * タイマ停止
222 */
223 sil_wrh_mem(CMT_CMSTR0_ADDR,
224 sil_reh_mem(CMT_CMSTR0_ADDR) & ~CMT_CMSTR0_STR0_BIT);
225
226 /*
227 * タイマ割り込み禁止
228 */
229 sil_wrh_mem(CMT0_CMCR_ADDR,
230 sil_reh_mem(CMT0_CMCR_ADDR) & ~CMT0_CMCR_CMIE_BIT);
231
232 /*
233 * 割り込み要因クリア
234 */
235 clear_int(INTNO_TIMER0);
236
237 /*
238 * カウント設定クリア
239 */
240 timer_lower_set_count = 0;
241
242 /*
243 * タイマ割り込み処理
244 */
245 signal_time();
246}
247
248/*
249 * 上位タイマ割込みハンドラ(CMT1)
250 */
251void target_upper_timer_handler(void)
252{
253 /*
254 * 上位タイマソフトカウンタ更新
255 */
256 elapse_upper_timer++;
257
258 /*
259 * 上位タイマ設定値更新
260 */
261 if(timer_upper_set_count > 0) {
262 timer_upper_set_count--;
263 }
264
265 /*
266 * 上位タイママッチ処理
267 */
268 if(timer_upper_set_count == 0){
269 if(timer_lower_set_count > 0){
270 /*
271 * 下位タイマ設定、開始
272 */
273 sil_wrh_mem(CMT0_CMCOR_ADDR, timer_lower_set_count);
274 clear_int(INTNO_TIMER0);
275 sil_wrh_mem(CMT0_CMCR_ADDR,
276 sil_reh_mem(CMT0_CMCR_ADDR) | CMT0_CMCR_CMIE_BIT);
277 sil_wrh_mem(CMT_CMSTR0_ADDR,
278 sil_reh_mem(CMT_CMSTR0_ADDR) | CMT_CMSTR0_STR0_BIT);
279 }
280 else{
281 /*
282 * 下位タイマ割り込み強制起動
283 */
284 target_hrt_raise_event();
285 }
286 }
287
288#ifdef TOPPERS_SUPPORT_OVRHDR
289 if(timer_ovr_running_flg == true) {
290 /*
291 * オーバラン上位タイマ設定値更新
292 */
293 if(timer_ovr_upper_set_count > 0) {
294 timer_ovr_upper_set_count--;
295 }
296
297 /*
298 * オーバラン上位タイママッチ処理
299 */
300 if(timer_ovr_upper_set_count == 0) {
301 if(timer_ovr_lower_set_count > 0){
302 /*
303 * オーバラン下位タイマ設定、開始
304 */
305 sil_wrh_mem(CMT2_CMCNT_ADDR, 0U);
306 sil_wrh_mem(CMT2_CMCOR_ADDR, timer_ovr_lower_set_count);
307 target_ovrtimer_int_clear();
308 sil_wrh_mem(CMT2_CMCR_ADDR,
309 sil_reh_mem(CMT2_CMCR_ADDR) | CMT2_CMCR_CMIE_BIT);
310 sil_wrh_mem(CMT_CMSTR1_ADDR,
311 sil_reh_mem(CMT_CMSTR1_ADDR) | CMT_CMSTR1_STR2_BIT);
312 }
313 else {
314 /*
315 * オーバラン下位タイマ割り込み強制起動
316 */
317 target_ovrtimer_raise_event();
318 }
319 }
320 }
321#endif /* TOPPERS_SUPPORT_OVRHDR */
322}
323
324/*
325 * 高分解能タイマへの割込みタイミングの設定
326 */
327void
328target_hrt_set_event(HRTCNT hrtcnt)
329{
330 uint32_t current_timer_count_work;
331 uint32_t total_timer_count;
332
333 /*
334 * 時間 -> タイマカウンタ 変換
335 */
336 total_timer_count = hrtcnt * USEC_CONVERT_VALUE;
337 timer_upper_set_count = total_timer_count / CMCOR_PERIOD;
338 timer_lower_set_count = total_timer_count % CMCOR_PERIOD;
339
340 /*
341 * 上位タイマカウンタ現在値で調整
342 */
343 current_timer_count_work = timer_lower_set_count + sil_reh_mem(CMT1_CMCNT_ADDR);
344 if(current_timer_count_work >= CMCOR_PERIOD) {
345 timer_upper_set_count++;
346 timer_lower_set_count = current_timer_count_work - CMCOR_PERIOD;
347 }
348
349 /*
350 * 下位タイマ設定
351 */
352 if(timer_upper_set_count == 0 && timer_lower_set_count > 0) {
353 /*
354 * コンペアマッチタイマカウンタ設定
355 */
356 sil_wrh_mem(CMT0_CMCNT_ADDR, 0U);
357
358 /*
359 * 割り込み要因クリア
360 */
361 clear_int(INTNO_TIMER0);
362
363 /*
364 * コンペアマッチタイマ周期設定
365 */
366 sil_wrh_mem(CMT0_CMCOR_ADDR, timer_lower_set_count);
367
368 /*
369 * タイマ割り込み許可
370 */
371 sil_wrh_mem(CMT0_CMCR_ADDR,
372 sil_reh_mem(CMT0_CMCR_ADDR) | CMT0_CMCR_CMIE_BIT);
373
374 /*
375 * タイマ開始
376 */
377 sil_wrh_mem(CMT_CMSTR0_ADDR,
378 sil_reh_mem(CMT_CMSTR0_ADDR) | CMT_CMSTR0_STR0_BIT);
379 }
380}
381
382/*
383 * 高分解能タイマ割込みの要求
384 */
385void
386target_hrt_raise_event(void)
387{
388 /*
389 * 下位タイマ強制割り込み起動
390 * 注意:停止するまで割り込みが繰り返し発生する
391 */
392 sil_wrh_mem(CMT0_CMCNT_ADDR, 0U); /* カウンタ初期化 */
393 clear_int(INTNO_TIMER0); /* 要求クリア */
394 sil_wrh_mem(CMT0_CMCOR_ADDR, 0U); /* マッチ周期設定 */
395 sil_wrh_mem(CMT0_CMCR_ADDR, /* 割り込み許可 */
396 sil_reh_mem(CMT0_CMCR_ADDR) | CMT0_CMCR_CMIE_BIT);
397 sil_wrh_mem(CMT_CMSTR0_ADDR, /* タイマ起動 */
398 sil_reh_mem(CMT_CMSTR0_ADDR) | CMT_CMSTR0_STR0_BIT);
399}
400
401/*
402 * 高分解能タイマの現在のカウント値の読出し 内
403部処理
404 */
405HRTCNT target_hrt_get_current_convert(void)
406{
407 uint16_t local_cnt, local_eut;
408 HRTCNT time;
409
410 local_eut = elapse_upper_timer;
411 local_cnt = sil_reh_mem(CMT1_CMCNT_ADDR);
412
413 /*
414 * 上位タイマ コンペアマッチチェック
415 */
416 if (probe_int(INTNO_TIMER1)) {
417 if(local_cnt < 0x8000)
418 local_eut += 1;
419 }
420
421 time = (((HRTCNT)local_eut * CMCOR_PERIOD) + (HRTCNT)local_cnt) / USEC_CONVERT_VALUE;
422
423 return time;
424}
425
426/*
427 * オーバランタイマドライバ
428 */
429#ifdef TOPPERS_SUPPORT_OVRHDR
430
431/*
432 * オーバランタイマの初期化処理
433 */
434void
435target_ovrtimer_initialize(intptr_t exinf)
436{
437 /*
438 * モジュールストップ機能の設定 CMTユニット1 解除
439 */
440 sil_wrh_mem(SYSTEM_PRCR_ADDR, 0xA502); /* 書込み許可 */
441 sil_wrw_mem(SYSTEM_MSTPCRA_ADDR,
442 sil_rew_mem(SYSTEM_MSTPCRA_ADDR) & ~SYSTEM_MSTPCRA_MSTPA14_BIT);
443 sil_wrh_mem(SYSTEM_PRCR_ADDR, 0xA500); /* 書込み禁止 */
444
445 /*
446 * タイマ停止 CMT2
447 */
448 sil_wrh_mem(CMT_CMSTR1_ADDR,
449 sil_reh_mem(CMT_CMSTR1_ADDR) & ~CMT_CMSTR1_STR2_BIT);
450
451 /*
452 * カウントアップに用いられるクロック設定 CMT2
453 * PCLK/8を選択
454 */
455 sil_wrh_mem(CMT2_CMCR_ADDR, CMT_PCLK_DIV_8);
456
457 /*
458 * コンペアマッチタイマカウンタ設定 CMT2
459 */
460 sil_wrh_mem(CMT2_CMCNT_ADDR, 0U);
461
462 /*
463 * コンペアマッチタイマ周期設定 CMT2
464 */
465 sil_wrh_mem(CMT2_CMCOR_ADDR, 0U);
466
467 /*
468 * コンペアマッチタイマ割り込み要求å…
469ˆè¨­å®šãƒ¬ã‚¸ã‚¹ã‚¿ï¼ˆ30)
470 */
471 sil_wrb_mem(ICU_ISELR030_ADDR, ICU_ISEL_CPU);
472
473 /*
474 * タイマ動作開始前の割込み要求をクリア
475 */
476 target_ovrtimer_int_clear();
477}
478
479void
480target_ovrtimer_start(PRCTIM ovrtim)
481{
482 uint32_t current_timer_count_work;
483 uint32_t total_timer_count;
484
485 /*
486 * 時間 -> タイマカウンタ 変換
487 */
488 total_timer_count = ovrtim * USEC_CONVERT_VALUE;
489 timer_ovr_upper_set_count = total_timer_count / CMCOR_PERIOD;
490 timer_ovr_lower_set_count = total_timer_count % CMCOR_PERIOD;
491
492 /*
493 * 高分解能上位タイマカウンタ現在値で調整
494 */
495 timer_ovr_ovrtim_backup = ovrtim;
496 timer_ovr_hrt_backup = target_hrt_get_current();
497 current_timer_count_work = timer_ovr_lower_set_count + sil_reh_mem(CMT1_CMCNT_ADDR);
498 if(current_timer_count_work >= CMCOR_PERIOD) {
499 timer_ovr_upper_set_count++;
500 timer_ovr_lower_set_count = current_timer_count_work - CMCOR_PERIOD;
501 }
502
503 /*
504 * オーバランタイマ動作中フラグ
505 */
506 timer_ovr_running_flg = true;
507
508 /*
509 * 下位タイマ設定
510 */
511 if(timer_ovr_upper_set_count == 0) {
512 if(timer_ovr_lower_set_count == 0) {
513 target_ovrtimer_raise_event();
514 }
515 else {
516 /*
517 * コンペアマッチタイマカウンタクリア CMT2
518 */
519 sil_wrh_mem(CMT2_CMCNT_ADDR, 0U);
520
521 /*
522 * コンペアマッチタイマ周期設定 CMT2
523 */
524 sil_wrh_mem(CMT2_CMCOR_ADDR, timer_ovr_lower_set_count);
525
526 /*
527 * タイマ動作開始前の割込み要求をクリア
528 */
529 target_ovrtimer_int_clear();
530
531 /*
532 * コンペアマッチタイマ割り込みを許可 CMT2
533 */
534 sil_wrh_mem(CMT2_CMCR_ADDR,
535 sil_reh_mem(CMT2_CMCR_ADDR) | CMT2_CMCR_CMIE_BIT);
536
537 /*
538 * タイマ動作開始 CMT2
539 */
540 sil_wrh_mem(CMT_CMSTR1_ADDR,
541 sil_reh_mem(CMT_CMSTR1_ADDR) | CMT_CMSTR1_STR2_BIT);
542 }
543 }
544}
545
546/*
547 * オーバランタイマの停止処理
548 */
549void
550target_ovrtimer_terminate(intptr_t exinf)
551{
552 /*
553 * タイマ停止
554 */
555 sil_wrh_mem(CMT_CMSTR1_ADDR,
556 sil_reh_mem(CMT_CMSTR1_ADDR) & ~CMT_CMSTR1_STR2_BIT);
557
558 /*
559 * タイマ割り込み禁止
560 */
561 sil_wrh_mem(CMT2_CMCR_ADDR,
562 sil_reh_mem(CMT2_CMCR_ADDR) & ~CMT2_CMCR_CMIE_BIT);
563
564 /*
565 * タイマ割込み要求をクリア
566 */
567 target_ovrtimer_int_clear();
568
569 /*
570 * オーバランタイマ動作中フラグ
571 */
572 timer_ovr_running_flg = false;
573
574 /*
575 * モジュールストップ機能の設定 CMTユニット0 停止
576 */
577 sil_wrh_mem(SYSTEM_PRCR_ADDR, 0xA502); /* 書込み許可 */
578 sil_wrw_mem(SYSTEM_MSTPCRA_ADDR,
579 sil_rew_mem(SYSTEM_MSTPCRA_ADDR) | SYSTEM_MSTPCRA_MSTPA14_BIT);
580 sil_wrh_mem(SYSTEM_PRCR_ADDR, 0xA500); /* 書込み禁止 */
581}
582
583/*
584 * オーバランタイマの停止
585 */
586PRCTIM
587target_ovrtimer_stop(uint_t int_num)
588{
589 uint32_t cnt;
590
591 /*
592 * タイマ停止
593 */
594 sil_wrh_mem(CMT_CMSTR1_ADDR,
595 sil_reh_mem(CMT_CMSTR1_ADDR) & ~CMT_CMSTR1_STR2_BIT);
596
597 /*
598 * オーバランタイマ動作中フラグ
599 */
600 timer_ovr_running_flg = false;
601
602 if(int_num == INTNO_TIMER2) {
603 /*
604 * オーバラン割込みの場合
605 */
606 target_ovrtimer_int_clear();
607 return(0U);
608 }
609 else {
610 HRTCNT timer_ovr_hrt_current = target_hrt_get_current();
611 if((timer_ovr_hrt_current < timer_ovr_hrt_backup) && (int_num == INTNO_OVR_BASE_TIMER)) {
612 timer_ovr_hrt_current += (CMCOR_PERIOD / USEC_CONVERT_VALUE);
613 }
614
615 cnt = timer_ovr_ovrtim_backup - (timer_ovr_hrt_current - timer_ovr_hrt_backup);
616 if(timer_ovr_hrt_current < timer_ovr_hrt_backup) {
617 cnt += TCYC_HRTCNT;
618 }
619
620 if(cnt > timer_ovr_ovrtim_backup) { /* 設定時間を過ぎた */
621 cnt = 0;
622 }
623 return (PRCTIM)cnt;
624 }
625}
626
627/*
628 * オーバランタイマの現在値の読出し
629 */
630PRCTIM
631target_ovrtimer_get_current(void)
632{
633 uint32_t cnt;
634
635 if (probe_int(INTNO_TIMER2)) {
636 /*
637 * 割込み要求が発生している場合
638 */
639 return(0U);
640 }
641 else {
642 HRTCNT timer_ovr_hrt_current = target_hrt_get_current();
643 cnt = timer_ovr_ovrtim_backup - (timer_ovr_hrt_current - timer_ovr_hrt_backup);
644 if(timer_ovr_hrt_current < timer_ovr_hrt_backup) {
645 cnt += TCYC_HRTCNT;
646 }
647
648 if(cnt > timer_ovr_ovrtim_backup) { /* 設定時間を過ぎた */
649 cnt = 0;
650 }
651 return (PRCTIM)cnt;
652 }
653}
654
655/*
656 * 高分解能タイマ割込みの要求
657 */
658void
659target_ovrtimer_raise_event(void)
660{
661 /*
662 * オーバラン下位タイマ強制割り込み起動
663 * 注意:停止するまで割り込みが繰り返し発生する
664 */
665 sil_wrh_mem(CMT2_CMCNT_ADDR, 0U); /* カウンタ初期化 */
666 clear_int(INTNO_TIMER2); /* 要求クリア */
667 sil_wrh_mem(CMT2_CMCOR_ADDR, 0U); /* マッチ周期設定 */
668 sil_wrh_mem(CMT2_CMCR_ADDR, /* 割り込み許可 */
669 sil_reh_mem(CMT2_CMCR_ADDR) | CMT2_CMCR_CMIE_BIT);
670 sil_wrh_mem(CMT_CMSTR1_ADDR, /* タイマ起動 */
671 sil_reh_mem(CMT_CMSTR1_ADDR) | CMT_CMSTR1_STR2_BIT);
672}
673
674/*
675 * オーバランタイマ割込みハンドラ
676 *
677 * このルーチンに来るまでに,target_ovrtimer_stopが呼ばれているため,
678 * OSタイマを停止する必
679要はない.
680 */
681void
682target_ovrtimer_handler(void)
683{
684 /*
685 * タイマ割り込み禁止
686 */
687 sil_wrh_mem(CMT2_CMCR_ADDR,
688 sil_reh_mem(CMT2_CMCR_ADDR) & ~CMT2_CMCR_CMIE_BIT);
689
690 /*
691 * 上下位タイマカウンタクリア
692 */
693 timer_ovr_upper_set_count = 0;
694 timer_ovr_lower_set_count = 0;
695
696 call_ovrhdr(); /* オーバランハンドラの起動処理 */
697}
698
699#endif /* TOPPERS_SUPPORT_OVRHDR */
Note: See TracBrowser for help on using the repository browser.