source: UsbWattMeter/trunk/asp_dcre/target/grsakura_ccrx/target_timer.c@ 164

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

TOPPERS/ECNLサンプルアプリ「USB充電器電力計」を追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc
File size: 4.1 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 *
15 * ã‹L’˜ìŒ ŽÒ‚́CˆÈ‰º‚Ì(1)`(4)‚ÌðŒ‚ð–ž‚½‚·ê‡‚ÉŒÀ‚èC–{ƒ\ƒtƒgƒEƒF
16 * ƒAi–{ƒ\ƒtƒgƒEƒFƒA‚ð‰ü•Ï‚µ‚½‚à‚Ì‚ðŠÜ‚ށDˆÈ‰º“¯‚¶j‚ðŽg—pE•¡»E‰ü
17 * •ÏEÄ”z•ziˆÈ‰ºC—˜—p‚ƌĂԁj‚·‚邱‚Ƃ𖳏ž‚Å‹–‘ø‚·‚éD
18 * (1) –{ƒ\ƒtƒgƒEƒFƒA‚ðƒ\[ƒXƒR[ƒh‚ÌŒ`‚Å—˜—p‚·‚éê‡‚ɂ́Cã‹L‚Ì’˜ì
19 * Œ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’肪C‚»‚Ì‚Ü‚Ü‚ÌŒ`‚Ń\[
20 * ƒXƒR[ƒh’†‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚邱‚ƁD
21 * (2) –{ƒ\ƒtƒgƒEƒFƒA‚ðCƒ‰ƒCƒuƒ‰ƒŠŒ`Ž®‚ȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
22 * —p‚Å‚«‚éŒ`‚ōĔz•z‚·‚éê‡‚ɂ́CÄ”z•z‚É”º‚¤ƒhƒLƒ…
23ƒƒ“ƒgi—˜—p
24 * ŽÒƒ}ƒjƒ…
25ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L
26 * ‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
27 * (3) –{ƒ\ƒtƒgƒEƒFƒA‚ðC‹@Ší‚É‘g‚ݍž‚ނȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
28 * —p‚Å‚«‚È‚¢Œ`‚ōĔz•z‚·‚éê‡‚ɂ́CŽŸ‚Ì‚¢‚¸‚ê‚©‚ÌðŒ‚ð–ž‚½‚·‚±
29 * ‚ƁD
30 * (a) Ä”z•z‚É”º‚¤ƒhƒLƒ…
31ƒƒ“ƒgi—˜—pŽÒƒ}ƒjƒ…
32ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜
33 * ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
34 * (b) Ä”z•z‚ÌŒ`‘Ô‚ðC•Ê‚É’è‚ß‚é•û–@‚É‚æ‚Á‚āCTOPPERSƒvƒƒWƒFƒNƒg‚É
35 * •ñ‚·‚邱‚ƁD
36 * (4) –{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚é‚¢‚©‚Ȃ鑹
37 * ŠQ‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD
38 * ‚Ü‚½C–{ƒ\ƒtƒgƒEƒFƒA‚̃†[ƒU‚Ü‚½‚̓Gƒ“ƒhƒ†[ƒU‚©‚ç‚Ì‚¢‚©‚Ȃ闝
39 * —R‚ÉŠî‚­¿‹‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð
40 * –Ɛӂ·‚邱‚ƁD
41 *
42 * –{ƒ\ƒtƒgƒEƒFƒA‚́C–³•ÛØ‚Å’ñ‹Ÿ‚³‚ê‚Ä‚¢‚é‚à‚Ì‚Å‚ ‚éDã‹L’˜ìŒ ŽÒ‚¨
43 * ‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚́C–{ƒ\ƒtƒgƒEƒFƒA‚ÉŠÖ‚µ‚āC“Á’è‚ÌŽg—p–Ú“I
44 * ‚ɑ΂·‚é“K‡«‚àŠÜ‚߂āC‚¢‚©‚È‚é•ÛØ‚às‚í‚È‚¢D‚Ü‚½C–{ƒ\ƒtƒgƒEƒF
45 * ƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚½‚¢‚©‚Ȃ鑹ŠQ‚ÉŠÖ‚µ‚Ä‚àC‚»
46 * ‚̐ӔC‚𕉂í‚È‚¢D
47 *
48 * @(#) $Id: target_timer.c 164 2016-03-07 11:33:50Z coas-nagasima $
49 */
50
51/*
52 * ƒ^ƒCƒ}ƒhƒ‰ƒCƒoiGR-SAKURA—pj
53 */
54
55#include "kernel_impl.h"
56#include "time_event.h"
57#include <sil.h>
58#include "target_timer.h"
59
60/*
61 * ƒ^ƒCƒ}‚̏‰Šú‰»ˆ—
62 */
63void
64target_timer_initialize(intptr_t exinf)
65{
66 /*
67 * ƒ‚ƒWƒ…
68[ƒ‹ƒXƒgƒbƒv‹@”\‚̐ݒè
69 */
70 sil_wrh_mem((uint16_t *)SYSTEM_PRCR_ADDR, (uint16_t)0xA502); /* ‘ž‚Ý‹–‰Â */
71 sil_wrw_mem((uint32_t *)SYSTEM_MSTPCRA_ADDR,
72 sil_rew_mem((uint32_t *)SYSTEM_MSTPCRA_ADDR) & ~SYSTEM_MSTPCRA_MSTPA15_BIT); /* CMT0 */
73 sil_wrh_mem((uint16_t *)SYSTEM_PRCR_ADDR, (uint16_t)0xA500); /* ‘ž‚Ý‹ÖŽ~ */
74
75 /*
76 * ƒ^ƒCƒ}’âŽ~
77 */
78 sil_wrh_mem((uint16_t *)CMT_CMSTR0_ADDR,
79 sil_reh_mem((uint16_t *)CMT_CMSTR0_ADDR) & ~CMT_CMSTR0_STR0_BIT);
80
81 /*
82 * ƒJƒEƒ“ƒgƒAƒbƒv‚É—p‚¢‚ç‚ê‚éƒNƒƒbƒNÝ’è
83 * PCLK/32‚ð‘I‘ð
84 */
85 sil_wrh_mem((uint16_t *)CMT0_CMCR_ADDR, CMT_PCLK_DIV_8);
86
87 /*
88 * ƒRƒ“ƒyƒAƒ}ƒbƒ`ƒ^ƒCƒ}ƒJƒEƒ“ƒ^Ý’è
89 */
90 sil_wrh_mem((uint16_t *)CMT0_CMCNT_ADDR, 0U);
91
92 /*
93 * ƒRƒ“ƒyƒAƒ}ƒbƒ`ƒ^ƒCƒ}ŽüŠúÝ’è
94 */
95 sil_wrh_mem((uint16_t *)CMT0_CMCOR_ADDR, CMCOR_PERIOD);
96
97 /*
98 * ƒRƒ“ƒyƒAƒ}ƒbƒ`ƒ^ƒCƒ}Š„‚荞‚Ý—v‹æÝ’背ƒWƒXƒ^iISELR28j
99 */
100 sil_wrb_mem((uint8_t *)ICU_ISELR028_ADDR, ICU_ISEL_CPU);
101
102 /*
103 * ƒ^ƒCƒ}“®ìŠJŽn‘O‚ÌŠ„ž‚Ý—v‹‚ðƒNƒŠƒA
104 */
105 x_clear_int(INTNO_TIMER);
106
107 /*
108 * ƒRƒ“ƒyƒAƒ}ƒbƒ`ƒ^ƒCƒ}Š„‚荞‚Ý‚ð‹–‰Â
109 */
110 sil_wrh_mem((uint16_t *)CMT0_CMCR_ADDR,
111 sil_reh_mem((uint16_t *)CMT0_CMCR_ADDR) | CMT0_CMCR_CMIE_BIT);
112
113 /*
114 * ƒ^ƒCƒ}“®ìŠJŽn
115 */
116 sil_wrh_mem((uint16_t *)CMT_CMSTR0_ADDR,
117 sil_reh_mem((uint16_t *)CMT_CMSTR0_ADDR) | CMT_CMSTR0_STR0_BIT);
118}
119
120/*
121 * ƒ^ƒCƒ}‚Ì’âŽ~ˆ—
122 */
123void
124target_timer_terminate(intptr_t exinf)
125{
126 /*
127 * ƒ^ƒCƒ}’âŽ~
128 */
129 sil_wrh_mem((uint16_t *)CMT_CMSTR0_ADDR,
130 sil_reh_mem((uint16_t *)CMT_CMSTR0_ADDR) & ~CMT_CMSTR0_STR0_BIT);
131}
132
133/*
134 * ƒ^ƒCƒ}Š„ž‚݃nƒ“ƒhƒ‰
135 */
136void target_timer_handler(void)
137{
138 i_begin_int(INTNO_TIMER);
139
140 signal_time(); /* ƒ^ƒCƒ€ƒeƒBƒbƒN‚Ì‹Ÿ‹‹ */
141
142 i_end_int(INTNO_TIMER);
143}
Note: See TracBrowser for help on using the repository browser.