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

Last change on this file since 164 was 164, checked in by coas-nagasima, 7 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-chdr
File size: 5.0 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.h 164 2016-03-07 11:33:50Z coas-nagasima $
49 */
50
51/*
52 * ƒ^ƒCƒ}ƒhƒ‰ƒCƒoiGR-SAKURA—pj
53 */
54
55#ifndef TOPPERS_TARGET_TIMER_H
56#define TOPPERS_TARGET_TIMER_H
57
58#include <sil.h>
59#include "grsakura.h"
60#include "target_syssvc.h"
61
62/*
63 * ƒ^ƒCƒ}Š„ž‚݃nƒ“ƒhƒ‰“o˜^‚Ì‚½‚߂̒萔
64 */
65#define INHNO_TIMER INT_CMT0_CMI /* Š„ž‚݃nƒ“ƒhƒ‰”ԍ† */
66#define INTNO_TIMER INT_CMT0_CMI /* Š„ž‚ݔԍ† */
67#define INTPRI_TIMER -5 /* Š„ž‚Ý—Dæ“x */
68#define INTATR_TIMER (TA_ENAINT | TA_EDGE) /* Š„ž‚Ý‘®« */
69
70#ifndef TOPPERS_MACRO_ONLY
71
72/*
73 * ƒ^ƒCƒ}’l‚Ì“à•”•\Œ»‚ÌŒ^
74 */
75typedef uint16_t CLOCK;
76
77/*
78 * ƒ^ƒCƒ}’l‚Ì“à•”•\Œ»‚ƃ~ƒŠ•b’PˆÊ‚Æ‚Ì•ÏŠ·
79 *
80 * 1ms‚̃^ƒCƒ}[Š„‚荞‚Ý‚ðŽg—p‚·‚é‚Ì‚Å‚»‚̃NƒƒbƒN‚ð’è‹`‚·‚éD
81 */
82#define TIMER_CLOCK (FREQ_PCLK / 8U) /* PCLK/Å’ᕪŽü”ä8 = 6MHz */
83#define TO_CLOCK(nume, deno) ((CLOCK)(TIMER_CLOCK * (nume) / (deno)))
84#define TO_USEC(clock) ((SYSUTM)((clock) * 1000U / TIMER_CLOCK))
85
86/*
87 * Ý’è‚Å‚«‚éÅ‘å‚̃^ƒCƒ}ŽüŠúi’PˆÊ‚Í“à•”•\Œ»j
88 */
89#define MAX_CLOCK ((CLOCK) 0xFFFFU)
90
91/*
92 * «”\•]‰¿—pƒVƒXƒeƒ€Žž‚ðŽæ‚èo‚·Û‚̏ˆ—ŽžŠÔ‚ÌŒ©Ï‚è’li’PˆÊ‚Í“à•”•\Œ»j
93 */
94#define GET_TOLERANCE (100U) /* ˆ—’x‚ê‚ÌŒ©Ï‚è’li’PˆÊ‚Í“à•”•\Œ»j*/
95#define BEFORE_IREQ(clock) \
96 ((clock) >= (TO_CLOCK(TIC_NUME, TIC_DENO) - GET_TOLERANCE))
97
98/*
99 * ƒRƒ“ƒyƒAƒ}ƒbƒ`ƒ^ƒCƒ}ƒRƒ“ƒgƒ[ƒ‹ƒŒƒWƒXƒ^‚̐ݒè’l
100 */
101/*
102 * ƒNƒƒbƒN‘I‘ðƒrƒbƒg
103 *
104 * bit7‚Í—\–ñ—̈æ‚Å‚ ‚è, ‘ž‚Ý‚Í1ŒÅ’è
105 */
106#define CMT_PCLK_DIV_8 (0x0080U)
107#define CMT_PCLK_DIV_32 (0x0081U)
108#define CMT_PCLK_DIV_128 (0x0082U)
109#define CMT_PCLK_DIV_512 (0x0083U)
110
111/*
112 * ƒRƒ“ƒyƒAƒ}ƒbƒ`ƒ^ƒCƒ}ƒRƒ“ƒXƒ^ƒ“ƒgƒŒƒWƒXƒ^iCMCORj
113 *
114 * ƒRƒ“ƒyƒAƒ}ƒbƒ`ŽüŠú‚ð1ms‚Æ‚·‚éD
115 * Žü•Óƒ‚ƒWƒ…
116[ƒ‹ƒNƒƒbƒNiPCLKj48MHz‚ð8•ªŽü‚·‚é‚̂ŁC
117 * 1ŽüŠú‚ ‚½‚è166.7nsec‚Æ‚È‚èC6000ŽüŠú‚Å1msiƒ^ƒCƒ€ƒeƒBƒbƒN‚ÌŽüŠúj‚Æ‚·‚éD
118 */
119#define CMCOR_PERIOD (TIMER_CLOCK)
120
121/*
122 * ƒRƒ“ƒyƒAƒ}ƒbƒ`ƒ^ƒCƒ}Š„‚荞‚Ý—v‹æÝ’背ƒWƒXƒ^iiISELRijii= Š„‚荞‚݃xƒNƒ^”ԍ†j
123 */
124#define ICU_ISEL_CPU (0x00U)
125
126
127
128
129/*
130 * ƒ^ƒCƒ}‚Ì‹N“®ˆ—
131 *
132 * ƒ^ƒCƒ}‚ð‰Šú‰»‚µCŽüŠú“I‚ȃ^ƒCƒ}Š„ž‚Ý—v‹‚𔭐¶‚³‚¹‚éD
133 */
134extern void target_timer_initialize(intptr_t exinf);
135
136/*
137 * ƒ^ƒCƒ}‚Ì’âŽ~ˆ—
138 *
139 * ƒ^ƒCƒ}‚Ì“®ì‚ð’âŽ~‚³‚¹‚éD
140 */
141extern void target_timer_terminate(intptr_t exinf);
142
143/*
144 * ƒ^ƒCƒ}ƒŒƒWƒXƒ^’l‚̓ǂݏo‚µ
145 */
146Inline uint16_t rx630_cmt_getcount(void)
147{
148 return sil_reh_mem((uint16_t *)CMT0_CMCNT_ADDR);
149}
150
151/*
152 * ƒ^ƒCƒ}ƒŒƒWƒXƒ^’l‚̏‘‚«ž‚Ý
153 */
154Inline void rx630_cmt_setcount(uint16_t count)
155{
156 sil_wrh_mem((uint16_t *)CMT0_CMCNT_ADDR, count);
157}
158
159/*
160 * ƒ^ƒCƒ}‚ÌŒ»Ý’l‚̓Ǐo‚µ
161 */
162Inline CLOCK
163target_timer_get_current(void)
164{
165 /* ƒAƒbƒvƒJƒEƒ“ƒg‚Ì‚½‚߃^ƒCƒ}ƒŒƒWƒXƒ^’l‚ð‚»‚Ì‚Ü‚Ü•Ô‚· */
166 return (rx630_cmt_getcount());
167}
168
169/*
170 * ƒ^ƒCƒ}Š„ž‚Ý—v‹‚̃`ƒFƒbƒN
171 */
172Inline bool_t
173target_timer_probe_int(void)
174{
175 return(x_probe_int(INTNO_TIMER));
176}
177
178/*
179 * ƒ^ƒCƒ}Š„ž‚݃nƒ“ƒhƒ‰
180 */
181extern void target_timer_handler(void);
182
183#endif /* TOPPERS_MACRO_ONLY */
184#endif /* TOPPERS_TARGET_TIMER_H */
Note: See TracBrowser for help on using the repository browser.