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{\tgEF
|
---|
10 | * Ai{\tgEFAðüϵ½àÌðÜÞDȺ¯¶jðgpE¡»Eü
|
---|
11 | * ÏEÄzziȺCpÆÄÔj·é±Æð³Åø·éD
|
---|
12 | * (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì
|
---|
13 | * \¦C±Ìpð¨æѺL̳ÛØKèªC»ÌÜÜÌ`Å\[
|
---|
14 | * XR[hÉÜÜêÄ¢é±ÆD
|
---|
15 | * (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJÉg
|
---|
16 | * pÅ«é`ÅÄzz·éêÉÍCÄzzɺ¤hL
|
---|
17 | gip
|
---|
18 | * Ò}j
|
---|
19 | AÈÇjÉCãLÌì \¦C±Ìpð¨æѺL
|
---|
20 | * ̳ÛØKèðfÚ·é±ÆD
|
---|
21 | * (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJÉg
|
---|
22 | * pÅ«È¢`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·±
|
---|
23 | * ÆD
|
---|
24 | * (a) Äzzɺ¤hL
|
---|
25 | gipÒ}j
|
---|
26 | AÈÇjÉCãLÌ
|
---|
27 | * ì \¦C±Ìpð¨æѺL̳ÛØKèðfÚ·é±ÆD
|
---|
28 | * (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ
|
---|
29 | * ñ·é±ÆD
|
---|
30 | * (4) {\tgEFAÌpÉæè¼ÚIܽÍÔÚIɶ¶é¢©Èé¹
|
---|
31 | * Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD
|
---|
32 | * ܽC{\tgEFAÌ[UܽÍGh[U©çÌ¢©Èé
|
---|
33 | * RÉîÿ©çàCãLì Ò¨æÑTOPPERSvWFNgð
|
---|
34 | * ÆÓ·é±ÆD
|
---|
35 | *
|
---|
36 | * {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨
|
---|
37 | * æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI
|
---|
38 | * ÉηéK«àÜßÄC¢©ÈéÛØàsíÈ¢DܽC{\tgEF
|
---|
39 | * AÌpÉæè¼ÚIܽÍÔÚIɶ¶½¢©Èé¹QÉÖµÄàC»
|
---|
40 | * ÌÓCðíÈ¢D
|
---|
41 | *
|
---|
42 | */
|
---|
43 |
|
---|
44 | /*
|
---|
45 | * VAhCoiFS K70pj
|
---|
46 | */
|
---|
47 |
|
---|
48 | #include <kernel.h>
|
---|
49 | #include <sil.h>
|
---|
50 | #include "target_serial.h"
|
---|
51 | #include "target_syssvc.h"
|
---|
52 |
|
---|
53 | /*
|
---|
54 | * WX^Ýè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 | * UARTWX^è`
|
---|
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 | * VAI/O|[gÇubNGA
|
---|
90 | */
|
---|
91 | SIOPCB siopcb_table[TNUM_PORT];
|
---|
92 |
|
---|
93 | static const uint32_t sioreg_table[TNUM_PORT] = {
|
---|
94 | UART2_BASE,
|
---|
95 | };
|
---|
96 |
|
---|
97 | #pragma inline
|
---|
98 | bool_t sio_putready(SIOPCB* siopcb)
|
---|
99 | {
|
---|
100 | return (sil_reb_mem((void*)UART_S1(siopcb->reg)) & S1_TC) != 0;
|
---|
101 | }
|
---|
102 |
|
---|
103 | #pragma inline
|
---|
104 | bool_t sio_getready(SIOPCB* siopcb)
|
---|
105 | {
|
---|
106 | return (sil_reb_mem((void*)UART_S1(siopcb->reg)) & S1_RDRF) != 0;
|
---|
107 | }
|
---|
108 |
|
---|
109 | /*
|
---|
110 | * ^[QbgÌVAú»
|
---|
111 | */
|
---|
112 | void 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 | * ^[QbgÌVAI¹
|
---|
143 | */
|
---|
144 | void 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 | */
|
---|
155 | void 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 | * VAI[v
|
---|
168 | */
|
---|
169 | SIOPCB *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 | * VAN[Y
|
---|
187 | */
|
---|
188 | void sio_cls_por(SIOPCB *p_siopcb)
|
---|
189 | {
|
---|
190 | target_uart_term(PORT2SIOPID(p_siopcb->port));
|
---|
191 | }
|
---|
192 |
|
---|
193 | /*
|
---|
194 | * Ýnh
|
---|
195 | */
|
---|
196 | void 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 | */
|
---|
211 | bool_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 | */
|
---|
230 | int_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[obNÌÂ
|
---|
243 | */
|
---|
244 | void 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[obNÌÖ~
|
---|
260 | */
|
---|
261 | void 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 | */
|
---|
278 | void 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 | }
|
---|