source: asp_ewarm/asp-1.7.0/target/fs_k70f120m_EWARM2/target_serial.c@ 61

Last change on this file since 61 was 61, checked in by ertl-honda, 11 years ago

ASP for EWARM のコミット.

File size: 6.4 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) 2007 by Embedded and Real-Time Systems Laboratory
7 * Graduate School of Information Science, Nagoya Univ., JAPAN
8 *
9 * ã‹L’˜ìŒ ŽÒ‚́CˆÈ‰º‚Ì(1)`(4)‚ÌðŒ‚ð–ž‚½‚·ê‡‚ÉŒÀ‚èC–{ƒ\ƒtƒgƒEƒF
10 * ƒAi–{ƒ\ƒtƒgƒEƒFƒA‚ð‰ü•Ï‚µ‚½‚à‚Ì‚ðŠÜ‚ށDˆÈ‰º“¯‚¶j‚ðŽg—pE•¡»E‰ü
11 * •ÏEÄ”z•ziˆÈ‰ºC—˜—p‚ƌĂԁj‚·‚邱‚Ƃ𖳏ž‚Å‹–‘ø‚·‚éD
12 * (1) –{ƒ\ƒtƒgƒEƒFƒA‚ðƒ\[ƒXƒR[ƒh‚ÌŒ`‚Å—˜—p‚·‚éê‡‚ɂ́Cã‹L‚Ì’˜ì
13 * Œ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’肪C‚»‚Ì‚Ü‚Ü‚ÌŒ`‚Ń\[
14 * ƒXƒR[ƒh’†‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚邱‚ƁD
15 * (2) –{ƒ\ƒtƒgƒEƒFƒA‚ðCƒ‰ƒCƒuƒ‰ƒŠŒ`Ž®‚ȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
16 * —p‚Å‚«‚éŒ`‚ōĔz•z‚·‚éê‡‚ɂ́CÄ”z•z‚É”º‚¤ƒhƒLƒ…
17ƒƒ“ƒgi—˜—p
18 * ŽÒƒ}ƒjƒ…
19ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L
20 * ‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
21 * (3) –{ƒ\ƒtƒgƒEƒFƒA‚ðC‹@Ší‚É‘g‚ݍž‚ނȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
22 * —p‚Å‚«‚È‚¢Œ`‚ōĔz•z‚·‚éê‡‚ɂ́CŽŸ‚Ì‚¢‚¸‚ê‚©‚ÌðŒ‚ð–ž‚½‚·‚±
23 * ‚ƁD
24 * (a) Ä”z•z‚É”º‚¤ƒhƒLƒ…
25ƒƒ“ƒgi—˜—pŽÒƒ}ƒjƒ…
26ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜
27 * ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
28 * (b) Ä”z•z‚ÌŒ`‘Ô‚ðC•Ê‚É’è‚ß‚é•û–@‚É‚æ‚Á‚āCTOPPERSƒvƒƒWƒFƒNƒg‚É
29 * •ñ‚·‚邱‚ƁD
30 * (4) –{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚é‚¢‚©‚Ȃ鑹
31 * ŠQ‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD
32 * ‚Ü‚½C–{ƒ\ƒtƒgƒEƒFƒA‚̃†[ƒU‚Ü‚½‚̓Gƒ“ƒhƒ†[ƒU‚©‚ç‚Ì‚¢‚©‚Ȃ闝
33 * —R‚ÉŠî‚­¿‹‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð
34 * –Ɛӂ·‚邱‚ƁD
35 *
36 * –{ƒ\ƒtƒgƒEƒFƒA‚́C–³•ÛØ‚Å’ñ‹Ÿ‚³‚ê‚Ä‚¢‚é‚à‚Ì‚Å‚ ‚éDã‹L’˜ìŒ ŽÒ‚¨
37 * ‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚́C–{ƒ\ƒtƒgƒEƒFƒA‚ÉŠÖ‚µ‚āC“Á’è‚ÌŽg—p–Ú“I
38 * ‚ɑ΂·‚é“K‡«‚àŠÜ‚߂āC‚¢‚©‚È‚é•ÛØ‚às‚í‚È‚¢D‚Ü‚½C–{ƒ\ƒtƒgƒEƒF
39 * ƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚½‚¢‚©‚Ȃ鑹ŠQ‚ÉŠÖ‚µ‚Ä‚àC‚»
40 * ‚̐ӔC‚𕉂í‚È‚¢D
41 *
42 */
43
44/*
45 * ƒVƒŠƒAƒ‹ƒhƒ‰ƒCƒoiFS K70—pj
46 */
47
48#include <kernel.h>
49#include <sil.h>
50#include "target_serial.h"
51#include "target_syssvc.h"
52
53/*
54 * ƒŒƒWƒXƒ^Ý’è’l
55 */
56#define PORT2SIOPID(x) ((x) + 1)
57#define INDEX_PORT(x) ((x) - 1)
58#define GET_SIOPCB(x) (&siopcb_table[INDEX_PORT(x)])
59
60/*
61 * UARTƒŒƒWƒXƒ^’è‹`
62 */
63#define UART_BDH(x) (x)
64#define UART_BDL(x) (x + 0x01)
65#define UART_C1(x) (x + 0x02)
66#define UART_C2(x) (x + 0x03)
67#define UART_S1(x) (x + 0x04)
68#define UART_C3(x) (x + 0x06)
69#define UART_D(x) (x + 0x07)
70#define UART_C4(x) (x + 0x0A)
71
72#define S1_TDRE (0x80)
73#define S1_TC (0x40)
74#define S1_RDRF (0x20)
75#define S1_OR (0x08)
76#define S1_FE (0x02)
77#define S1_PE (0x01)
78#define C2_TIE (0x80)
79#define C2_TCIE (0x40)
80#define C2_RIE (0x20)
81#define C2_TE (0x08)
82#define C2_RE (0x04)
83#define C3_ORIE (0x08)
84#define C3_NEIE (0x04)
85#define C3_FEIE (0x02)
86#define C3_PEIE (0x01)
87
88/*
89 * ƒVƒŠƒAƒ‹I/Oƒ|[ƒgŠÇ—ƒuƒƒbƒNƒGƒŠƒA
90 */
91SIOPCB siopcb_table[TNUM_PORT];
92
93static const uint32_t sioreg_table[TNUM_PORT] = {
94 UART2_BASE,
95};
96
97#pragma inline
98bool_t sio_putready(SIOPCB* siopcb)
99{
100 return (sil_reb_mem((void*)UART_S1(siopcb->reg)) & S1_TC) != 0;
101}
102
103#pragma inline
104bool_t sio_getready(SIOPCB* siopcb)
105{
106 return (sil_reb_mem((void*)UART_S1(siopcb->reg)) & S1_RDRF) != 0;
107}
108
109/*
110 * ƒ^[ƒQƒbƒg‚̃VƒŠƒAƒ‹‰Šú‰»
111 */
112void target_uart_init(ID siopid)
113{
114 uint32_t tmp, brfa;
115 uint32_t reg = sioreg_table[INDEX_PORT(siopid)];
116 uint32_t src_clock;
117
118 /* UART‚Ì–³Œø‰» */
119 sil_andb((void*)UART_C2(reg), ~(C2_TE|C2_RE));
120
121 /* 1STOP BIT, 1START BIT, 8DATA bits, Parity‚È‚µ */
122 sil_wrb_mem((void*)UART_C1(reg), 0);
123
124 /* fck=60MHz */
125 src_clock = BUS_CLOCK;
126
127 tmp = src_clock / (BPS_SETTING * 16);
128 sil_wrb_mem( (void*)UART2_BDH, (sil_reb_mem( (void*)UART2_BDH ) & ~(0x1F)) | ((tmp & 0x1F00) >> 8) );
129 sil_wrb_mem( (void*)UART2_BDL, (char_t)(tmp & 0xFF) );
130
131 brfa = (((src_clock / 1000 * 32000) / (BPS_SETTING * 16)) - (tmp * 32) );
132 sil_wrb_mem( (void*)UART2_C4, (sil_reb_mem( (void*)UART2_C4 ) & ~(0x1F)) | (brfa & 0x1F) );
133
134 /* ƒGƒ‰[Š„ž‚Ý‚Ì—LŒø‰» */
135 sil_orb((void*)UART_C3(reg), (C3_ORIE|C3_NEIE|C3_FEIE|C3_PEIE));
136
137 /* ‘—ŽóM‚Ì—LŒø‰» */
138 sil_orb( (void*)UART2_C2, (C2_RIE|C2_TE|C2_RE) );
139}
140
141/*
142 * ƒ^[ƒQƒbƒg‚̃VƒŠƒAƒ‹I—¹
143 */
144void target_uart_term(ID siopid)
145{
146 uint32_t reg = sioreg_table[INDEX_PORT(siopid)];
147
148 /* UART‚Ì–³Œø‰» */
149 sil_andb((void*)UART_C2(reg), ~(C2_TE|C2_RE));
150}
151
152/*
153 * SIO‰Šú‰»
154 */
155void sio_initialize(intptr_t exinf)
156{
157 int i;
158
159 for (i = 0; i < TNUM_PORT; i++) {
160 siopcb_table[i].port = i;
161 siopcb_table[i].reg = sioreg_table[i];
162 siopcb_table[i].exinf = 0;
163 }
164}
165
166/*
167 * ƒVƒŠƒAƒ‹ƒI[ƒvƒ“
168 */
169SIOPCB *sio_opn_por(ID siopid, intptr_t exinf)
170{
171 SIOPCB* siopcb;
172
173 if (siopid > TNUM_PORT) {
174 return NULL;
175 }
176
177 siopcb = GET_SIOPCB(siopid);
178 siopcb->exinf = exinf;
179
180 target_uart_init(siopid);
181
182 return siopcb;
183}
184
185/*
186 * ƒVƒŠƒAƒ‹ƒNƒ[ƒY
187 */
188void sio_cls_por(SIOPCB *p_siopcb)
189{
190 target_uart_term(PORT2SIOPID(p_siopcb->port));
191}
192
193/*
194 * Š„ž‚݃nƒ“ƒhƒ‰
195 */
196void sio_isr(intptr_t exinf)
197{
198 SIOPCB* siopcb = GET_SIOPCB(exinf);
199
200 if (sio_putready(siopcb)) {
201 sio_irdy_snd(siopcb->exinf);
202 }
203 if (sio_getready(siopcb)) {
204 sio_irdy_rcv(siopcb->exinf);
205 }
206}
207
208/*
209 * 1•¶Žš‘—M
210 */
211bool_t sio_snd_chr(SIOPCB *siopcb, char c)
212{
213 bool_t stat;
214
215 if (sio_putready(siopcb)) {
216 sil_wrb_mem((void*)UART_D(siopcb->reg), c);
217 stat = true;
218 }
219 else
220 {
221 stat = false;
222 }
223
224 return stat;
225}
226
227/*
228 * 1•¶ŽšŽóM
229 */
230int_t sio_rcv_chr(SIOPCB *siopcb)
231{
232 int_t c = -1;
233
234 if (sio_getready(siopcb)) {
235 c = sil_reb_mem((void*)UART_D(siopcb->reg));
236 }
237
238 return c;
239}
240
241/*
242 * ƒR[ƒ‹ƒoƒbƒN‚Ì‹–‰Â
243 */
244void sio_ena_cbr(SIOPCB *siopcb, uint_t cbrtn)
245{
246 switch (cbrtn) {
247 case SIO_RDY_SND:
248 sil_orb((void*)UART_C2(siopcb->reg), C2_TCIE);
249 break;
250 case SIO_RDY_RCV:
251 sil_orb((void*)UART_C2(siopcb->reg), C2_RIE);
252 break;
253 default:
254 break;
255 }
256}
257
258/*
259 * ƒR[ƒ‹ƒoƒbƒN‚Ì‹ÖŽ~
260 */
261void sio_dis_cbr(SIOPCB *siopcb, uint_t cbrtn)
262{
263 switch (cbrtn) {
264 case SIO_RDY_SND:
265 sil_andb((void*)UART_C2(siopcb->reg), ~C2_TCIE);
266 break;
267 case SIO_RDY_RCV:
268 sil_andb((void*)UART_C2(siopcb->reg), ~C2_RIE);
269 break;
270 default:
271 break;
272 }
273}
274
275/*
276 * 1•¶Žšo—́iƒ|[ƒŠƒ“ƒO‚ł̏o—́j
277 */
278void sio_pol_snd_chr(char_t c, ID siopid)
279{
280 uint32_t reg = sioreg_table[INDEX_PORT(siopid)];
281
282 sil_wrb_mem((void*)UART_D(reg), c);
283
284 while ((sil_reb_mem((void*)UART_S1(reg)) & S1_TC) == 0) ;
285}
Note: See TracBrowser for help on using the repository browser.