source: asp3_tinet_ecnl_rx/trunk/asp3_dcre/target/gr_sakura_gcc/target_timer.c@ 387

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

ファイルディスクリプタ処理を更新

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