source: azure_iot_hub/trunk/asp3_dcre/target/gr_citrus_gcc/target_timer.c@ 388

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

Azure IoT Hub Device C SDK を使ったサンプルの追加

  • 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.7 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 388 2019-05-22 11:25:18Z coas-nagasima $
61 */
62
63/*
64 * タイマドライバ(GR-CITRUS用)
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#ifdef _MSC_VER
423 // シミュレーションではタイマーが戻らないよう調整
424 if (time < current_hrtcnt)
425 time = current_hrtcnt + ((HRTCNT)local_cnt / USEC_CONVERT_VALUE);
426#endif
427 return time;
428}
429
430/*
431 * オーバランタイマドライバ
432 */
433#ifdef TOPPERS_SUPPORT_OVRHDR
434
435/*
436 * オーバランタイマの初期化処理
437 */
438void
439target_ovrtimer_initialize(intptr_t exinf)
440{
441 /*
442 * モジュールストップ機能の設定 CMTユニット1 解除
443 */
444 sil_wrh_mem(SYSTEM_PRCR_ADDR, 0xA502); /* 書込み許可 */
445 sil_wrw_mem(SYSTEM_MSTPCRA_ADDR,
446 sil_rew_mem(SYSTEM_MSTPCRA_ADDR) & ~SYSTEM_MSTPCRA_MSTPA14_BIT);
447 sil_wrh_mem(SYSTEM_PRCR_ADDR, 0xA500); /* 書込み禁止 */
448
449 /*
450 * タイマ停止 CMT2
451 */
452 sil_wrh_mem(CMT_CMSTR1_ADDR,
453 sil_reh_mem(CMT_CMSTR1_ADDR) & ~CMT_CMSTR1_STR2_BIT);
454
455 /*
456 * カウントアップに用いられるクロック設定 CMT2
457 * PCLK/8を選択
458 */
459 sil_wrh_mem(CMT2_CMCR_ADDR, CMT_PCLK_DIV_8);
460
461 /*
462 * コンペアマッチタイマカウンタ設定 CMT2
463 */
464 sil_wrh_mem(CMT2_CMCNT_ADDR, 0U);
465
466 /*
467 * コンペアマッチタイマ周期設定 CMT2
468 */
469 sil_wrh_mem(CMT2_CMCOR_ADDR, 0U);
470
471 /*
472 * コンペアマッチタイマ割り込み要求å…
473ˆè¨­å®šãƒ¬ã‚¸ã‚¹ã‚¿ï¼ˆ30)
474 */
475 sil_wrb_mem(ICU_ISELR030_ADDR, ICU_ISEL_CPU);
476
477 /*
478 * タイマ動作開始前の割込み要求をクリア
479 */
480 target_ovrtimer_int_clear();
481}
482
483void
484target_ovrtimer_start(PRCTIM ovrtim)
485{
486 uint32_t current_timer_count_work;
487 uint32_t total_timer_count;
488
489 /*
490 * 時間 -> タイマカウンタ 変換
491 */
492 total_timer_count = ovrtim * USEC_CONVERT_VALUE;
493 timer_ovr_upper_set_count = total_timer_count / CMCOR_PERIOD;
494 timer_ovr_lower_set_count = total_timer_count % CMCOR_PERIOD;
495
496 /*
497 * 高分解能上位タイマカウンタ現在値で調整
498 */
499 timer_ovr_ovrtim_backup = ovrtim;
500 timer_ovr_hrt_backup = target_hrt_get_current();
501 current_timer_count_work = timer_ovr_lower_set_count + sil_reh_mem(CMT1_CMCNT_ADDR);
502 if(current_timer_count_work >= CMCOR_PERIOD) {
503 timer_ovr_upper_set_count++;
504 timer_ovr_lower_set_count = current_timer_count_work - CMCOR_PERIOD;
505 }
506
507 /*
508 * オーバランタイマ動作中フラグ
509 */
510 timer_ovr_running_flg = true;
511
512 /*
513 * 下位タイマ設定
514 */
515 if(timer_ovr_upper_set_count == 0) {
516 if(timer_ovr_lower_set_count == 0) {
517 target_ovrtimer_raise_event();
518 }
519 else {
520 /*
521 * コンペアマッチタイマカウンタクリア CMT2
522 */
523 sil_wrh_mem(CMT2_CMCNT_ADDR, 0U);
524
525 /*
526 * コンペアマッチタイマ周期設定 CMT2
527 */
528 sil_wrh_mem(CMT2_CMCOR_ADDR, timer_ovr_lower_set_count);
529
530 /*
531 * タイマ動作開始前の割込み要求をクリア
532 */
533 target_ovrtimer_int_clear();
534
535 /*
536 * コンペアマッチタイマ割り込みを許可 CMT2
537 */
538 sil_wrh_mem(CMT2_CMCR_ADDR,
539 sil_reh_mem(CMT2_CMCR_ADDR) | CMT2_CMCR_CMIE_BIT);
540
541 /*
542 * タイマ動作開始 CMT2
543 */
544 sil_wrh_mem(CMT_CMSTR1_ADDR,
545 sil_reh_mem(CMT_CMSTR1_ADDR) | CMT_CMSTR1_STR2_BIT);
546 }
547 }
548}
549
550/*
551 * オーバランタイマの停止処理
552 */
553void
554target_ovrtimer_terminate(intptr_t exinf)
555{
556 /*
557 * タイマ停止
558 */
559 sil_wrh_mem(CMT_CMSTR1_ADDR,
560 sil_reh_mem(CMT_CMSTR1_ADDR) & ~CMT_CMSTR1_STR2_BIT);
561
562 /*
563 * タイマ割り込み禁止
564 */
565 sil_wrh_mem(CMT2_CMCR_ADDR,
566 sil_reh_mem(CMT2_CMCR_ADDR) & ~CMT2_CMCR_CMIE_BIT);
567
568 /*
569 * タイマ割込み要求をクリア
570 */
571 target_ovrtimer_int_clear();
572
573 /*
574 * オーバランタイマ動作中フラグ
575 */
576 timer_ovr_running_flg = false;
577
578 /*
579 * モジュールストップ機能の設定 CMTユニット0 停止
580 */
581 sil_wrh_mem(SYSTEM_PRCR_ADDR, 0xA502); /* 書込み許可 */
582 sil_wrw_mem(SYSTEM_MSTPCRA_ADDR,
583 sil_rew_mem(SYSTEM_MSTPCRA_ADDR) | SYSTEM_MSTPCRA_MSTPA14_BIT);
584 sil_wrh_mem(SYSTEM_PRCR_ADDR, 0xA500); /* 書込み禁止 */
585}
586
587/*
588 * オーバランタイマの停止
589 */
590PRCTIM
591target_ovrtimer_stop(uint_t int_num)
592{
593 uint32_t cnt;
594
595 /*
596 * タイマ停止
597 */
598 sil_wrh_mem(CMT_CMSTR1_ADDR,
599 sil_reh_mem(CMT_CMSTR1_ADDR) & ~CMT_CMSTR1_STR2_BIT);
600
601 /*
602 * オーバランタイマ動作中フラグ
603 */
604 timer_ovr_running_flg = false;
605
606 if(int_num == INTNO_TIMER2) {
607 /*
608 * オーバラン割込みの場合
609 */
610 target_ovrtimer_int_clear();
611 return(0U);
612 }
613 else {
614 HRTCNT timer_ovr_hrt_current = target_hrt_get_current();
615 if((timer_ovr_hrt_current < timer_ovr_hrt_backup) && (int_num == INTNO_OVR_BASE_TIMER)) {
616 timer_ovr_hrt_current += (CMCOR_PERIOD / USEC_CONVERT_VALUE);
617 }
618
619 cnt = timer_ovr_ovrtim_backup - (timer_ovr_hrt_current - timer_ovr_hrt_backup);
620 if(timer_ovr_hrt_current < timer_ovr_hrt_backup) {
621 cnt += TCYC_HRTCNT;
622 }
623
624 if(cnt > timer_ovr_ovrtim_backup) { /* 設定時間を過ぎた */
625 cnt = 0;
626 }
627 return (PRCTIM)cnt;
628 }
629}
630
631/*
632 * オーバランタイマの現在値の読出し
633 */
634PRCTIM
635target_ovrtimer_get_current(void)
636{
637 uint32_t cnt;
638
639 if (probe_int(INTNO_TIMER2)) {
640 /*
641 * 割込み要求が発生している場合
642 */
643 return(0U);
644 }
645 else {
646 HRTCNT timer_ovr_hrt_current = target_hrt_get_current();
647 cnt = timer_ovr_ovrtim_backup - (timer_ovr_hrt_current - timer_ovr_hrt_backup);
648 if(timer_ovr_hrt_current < timer_ovr_hrt_backup) {
649 cnt += TCYC_HRTCNT;
650 }
651
652 if(cnt > timer_ovr_ovrtim_backup) { /* 設定時間を過ぎた */
653 cnt = 0;
654 }
655 return (PRCTIM)cnt;
656 }
657}
658
659/*
660 * 高分解能タイマ割込みの要求
661 */
662void
663target_ovrtimer_raise_event(void)
664{
665 /*
666 * オーバラン下位タイマ強制割り込み起動
667 * 注意:停止するまで割り込みが繰り返し発生する
668 */
669 sil_wrh_mem(CMT2_CMCNT_ADDR, 0U); /* カウンタ初期化 */
670 clear_int(INTNO_TIMER2); /* 要求クリア */
671 sil_wrh_mem(CMT2_CMCOR_ADDR, 0U); /* マッチ周期設定 */
672 sil_wrh_mem(CMT2_CMCR_ADDR, /* 割り込み許可 */
673 sil_reh_mem(CMT2_CMCR_ADDR) | CMT2_CMCR_CMIE_BIT);
674 sil_wrh_mem(CMT_CMSTR1_ADDR, /* タイマ起動 */
675 sil_reh_mem(CMT_CMSTR1_ADDR) | CMT_CMSTR1_STR2_BIT);
676}
677
678/*
679 * オーバランタイマ割込みハンドラ
680 *
681 * このルーチンに来るまでに,target_ovrtimer_stopが呼ばれているため,
682 * OSタイマを停止する必
683要はない.
684 */
685void
686target_ovrtimer_handler(void)
687{
688 /*
689 * タイマ割り込み禁止
690 */
691 sil_wrh_mem(CMT2_CMCR_ADDR,
692 sil_reh_mem(CMT2_CMCR_ADDR) & ~CMT2_CMCR_CMIE_BIT);
693
694 /*
695 * 上下位タイマカウンタクリア
696 */
697 timer_ovr_upper_set_count = 0;
698 timer_ovr_lower_set_count = 0;
699
700 call_ovrhdr(); /* オーバランハンドラの起動処理 */
701}
702
703#endif /* TOPPERS_SUPPORT_OVRHDR */
Note: See TracBrowser for help on using the repository browser.