1 | /*
|
---|
2 | * TOPPERS/SSP 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 | * Copyright (C) 2012 by Meika Sugimoto
|
---|
9 | * Copyright (C) 2015 by Naoki Saito
|
---|
10 | * Nagoya Municipal Industrial Research Institute, JAPAN
|
---|
11 | *
|
---|
12 | * ãLì ÒÍCȺÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF
|
---|
13 | * Ai{\tgEFAðüϵ½àÌðÜÞDȺ¯¶jðgpE¡»Eü
|
---|
14 | * ÏEÄzziȺCpÆÄÔj·é±Æð³Åø·éD
|
---|
15 | * (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì
|
---|
16 | * \¦C±Ìpð¨æÑºLÌ³ÛØKèªC»ÌÜÜÌ`Å\[
|
---|
17 | * XR[hÉÜÜêĢ鱯D
|
---|
18 | * (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJÉg
|
---|
19 | * pÅ«é`ÅÄzz·éêÉÍCÄzzɺ¤hL
|
---|
20 | gip
|
---|
21 | * Ò}j
|
---|
22 | AÈÇjÉCãLÌì \¦C±Ìpð¨æÑºL
|
---|
23 | * Ì³ÛØKèðfÚ·é±ÆD
|
---|
24 | * (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJÉg
|
---|
25 | * pūȢ`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·±
|
---|
26 | * ÆD
|
---|
27 | * (a) Äzzɺ¤hL
|
---|
28 | gipÒ}j
|
---|
29 | AÈÇjÉCãLÌ
|
---|
30 | * ì \¦C±Ìpð¨æÑºLÌ³ÛØKèðfÚ·é±ÆD
|
---|
31 | * (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ
|
---|
32 | * ñ·é±ÆD
|
---|
33 | * (4) {\tgEFAÌpÉæè¼ÚIܽÍÔÚIɶ¶é¢©Èé¹
|
---|
34 | * Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD
|
---|
35 | * ܽC{\tgEFAÌ[UܽÍGh[U©çÌ¢©Èé
|
---|
36 | * RÉîÿ©çàCãLì Ò¨æÑTOPPERSvWFNgð
|
---|
37 | * ÆÓ·é±ÆD
|
---|
38 | *
|
---|
39 | * {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨
|
---|
40 | * æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI
|
---|
41 | * ÉηéK«àÜßÄC¢©ÈéÛØàsíÈ¢DܽC{\tgEF
|
---|
42 | * AÌpÉæè¼ÚIܽÍÔÚIɶ¶½¢©Èé¹QÉÖµÄàC»
|
---|
43 | * ÌÓCðíÈ¢D
|
---|
44 | *
|
---|
45 | */
|
---|
46 |
|
---|
47 | /*
|
---|
48 | * VAhCoiCQ-FRM-FM3pj
|
---|
49 | */
|
---|
50 |
|
---|
51 | #include <sil.h>
|
---|
52 | #include "kernel_int.h"
|
---|
53 | #include "target_serial.h"
|
---|
54 | #include "target_syssvc.h"
|
---|
55 |
|
---|
56 | /*
|
---|
57 | * WX^Ýèl
|
---|
58 | */
|
---|
59 | #define PORT2SIOPID(x) ((x) + 1)
|
---|
60 | #define INDEX_PORT(x) ((x) - 1)
|
---|
61 | #define GET_SIOPCB(x) (&siopcb_table[INDEX_PORT(x)])
|
---|
62 |
|
---|
63 | /*
|
---|
64 | * USARTWX^è`
|
---|
65 | * #define MFS_SMR(ch) (MFS_BASEADDR((ch)) + 0x00)
|
---|
66 | * #define MFS_SCR(ch) (MFS_BASEADDR((ch)) + 0x01)
|
---|
67 | * #define MFS_ESCR(ch) (MFS_BASEADDR((ch)) + 0x04)
|
---|
68 | * #define MFS_SSR(ch) (MFS_BASEADDR((ch)) + 0x05)
|
---|
69 | * #define MFS_RDRTDR(ch) (MFS_BASEADDR((ch)) + 0x08)
|
---|
70 | * #define MFS_BGR0(ch) (MFS_BASEADDR((ch)) + 0x0B)
|
---|
71 | * #define MFS_BGR1(ch) (MFS_BASEADDR((ch)) + 0x0C)
|
---|
72 | *
|
---|
73 | */
|
---|
74 |
|
---|
75 | /*
|
---|
76 | * rbgèÄÍoCgANZXpÉLqµÄ¢é
|
---|
77 | */
|
---|
78 |
|
---|
79 | /* SCR */
|
---|
80 | #define SCR_UPCL (1U << 7)
|
---|
81 | #define SCR_RIE (1U << 4)
|
---|
82 | #define SCR_TIE (1U << 3)
|
---|
83 | #define SCR_TEIE (1U << 2)
|
---|
84 | #define SCR_RXE (1U << 1)
|
---|
85 | #define SCR_TXE (1U << 0)
|
---|
86 |
|
---|
87 | /* SMR */
|
---|
88 | #define SMR_MODE_ASYNC_NORMAL (0U << 5)
|
---|
89 | #define SMR_MODE_ASYNC_MULTI (1U << 5)
|
---|
90 | #define SMR_MODE_CLKSYNC (2U << 5)
|
---|
91 | #define SMR_MODE_LIN (3U << 5)
|
---|
92 | #define SMR_MODE_I2C (4U << 5)
|
---|
93 |
|
---|
94 | #define SMR_WAKEUP (1U << 4)
|
---|
95 |
|
---|
96 | #define SMR_SBL_1OR3 (0U << 3) /* ESCR.ESBL = 0Å1 */
|
---|
97 | #define SMR_SBL_2OR4 (1U << 3) /* ESCR.ESBL = 0Å2 */
|
---|
98 |
|
---|
99 | #define SMR_BDS_LSBFIRST (0U << 2)
|
---|
100 | #define SMR_BDS_MSBFIRST (1U << 2)
|
---|
101 |
|
---|
102 | #define SMR_SOE_DISABLE (0U << 0)
|
---|
103 | #define SMR_SOE_ENABLE (1U << 0)
|
---|
104 |
|
---|
105 | /* SSR */
|
---|
106 | #define SSR_REC (1U << 7)
|
---|
107 | #define SSR_PE (1U << 5)
|
---|
108 | #define SSR_FRE (1U << 4)
|
---|
109 | #define SSR_ORE (1U << 3)
|
---|
110 | #define SSR_RDRF (1U << 2)
|
---|
111 | #define SSR_TDRE (1U << 1)
|
---|
112 | #define SSR_TBI (1U << 0)
|
---|
113 |
|
---|
114 | /* ESCR */
|
---|
115 | #define ESCR_FLWEN_ENABLE (1U << 7)
|
---|
116 | #define ESCR_FLWEN_DISABLE (0U << 7)
|
---|
117 | #define ESCR_ESBL (1U << 6)
|
---|
118 | #define ESCR_INV_NRZ (0U << 5)
|
---|
119 | #define ESCR_INV_INVNRZ (1U << 5)
|
---|
120 | #define ESCR_PEN (1U << 4)
|
---|
121 | #define ESCR_PEN_DISABLE (0U << 4)
|
---|
122 | #define ESCR_PEN_ENABLE (1U << 4)
|
---|
123 | #define ESCR_P_EVEN (0U << 3)
|
---|
124 | #define ESCR_P_ODD (1U << 3)
|
---|
125 | #define ESCR_DATALEN_8 (0U << 0)
|
---|
126 | #define ESCR_DATALEN_5 (1U << 0)
|
---|
127 | #define ESCR_DATALEN_6 (2U << 0)
|
---|
128 | #define ESCR_DATALEN_7 (3U << 0)
|
---|
129 | #define ESCR_DATALEN_9 (4U << 0)
|
---|
130 |
|
---|
131 |
|
---|
132 | /*
|
---|
133 | * VAI/O|[gÇubNGA
|
---|
134 | */
|
---|
135 | SIOPCB siopcb_table[TNUM_PORT];
|
---|
136 |
|
---|
137 | static const uint32_t sioreg_table[TNUM_PORT] = {
|
---|
138 | MFS_BASEADDR(0),
|
---|
139 | #if (TNUM_PORT >= 2)
|
---|
140 | MFS_BASEADDR(4)
|
---|
141 | #endif
|
---|
142 | };
|
---|
143 |
|
---|
144 | Inline bool_t sio_putready(SIOPCB* siopcb)
|
---|
145 | {
|
---|
146 | return ((sil_reb_mem((void*)MFS_SSR(siopcb->port)) & SSR_TDRE) != 0);
|
---|
147 | }
|
---|
148 |
|
---|
149 | Inline bool_t sio_getready(SIOPCB* siopcb)
|
---|
150 | {
|
---|
151 | return ((sil_reb_mem((void*)MFS_SSR(siopcb->port)) & SSR_RDRF) != 0);
|
---|
152 | }
|
---|
153 |
|
---|
154 | /*
|
---|
155 | * áxoÍÌú»
|
---|
156 | */
|
---|
157 |
|
---|
158 | void target_low_output_init(ID siopid)
|
---|
159 | {
|
---|
160 | uint32_t ch = INDEX_PORT(siopid);
|
---|
161 |
|
---|
162 | /* ú»ÏÝÌêÍ·®É^[ */
|
---|
163 | if((sil_reb_mem((void*)MFS_SCR(ch)) & (SCR_TXE | SCR_RXE)) != 0)
|
---|
164 | {
|
---|
165 | return ;
|
---|
166 | }
|
---|
167 |
|
---|
168 | /* USART̳ø»CZbg */
|
---|
169 | sil_wrb_mem((void *)MFS_SCR(ch) , SCR_UPCL);
|
---|
170 | sil_wrb_mem((void *)MFS_SCR(ch) , 0x0);
|
---|
171 |
|
---|
172 | /* ÊM[hÝè */
|
---|
173 | sil_wrb_mem((void *)MFS_SMR(ch) ,
|
---|
174 | (SMR_MODE_ASYNC_NORMAL | SMR_SBL_1OR3 | SMR_BDS_LSBFIRST | SMR_SOE_DISABLE));
|
---|
175 | sil_wrb_mem((void *)MFS_ESCR(ch) ,
|
---|
176 | (ESCR_FLWEN_DISABLE | ESCR_INV_NRZ | ESCR_PEN_DISABLE | ESCR_DATALEN_8));
|
---|
177 | /* ÊM¬xÝè */
|
---|
178 | sil_wrh_mem((void *)MFS_BGR0(ch) , BPS_SETTING); /* n[t[hANZX·é */
|
---|
179 | /* FIFO³ø» */
|
---|
180 | sil_wrb_mem((void *)MFS_FCR0(ch) , 0x00);
|
---|
181 | sil_wrb_mem((void *)MFS_FCR1(ch) , 0x00);
|
---|
182 |
|
---|
183 | /* USARTÌLø» */
|
---|
184 | sil_orb((void *)MFS_SMR(ch) , SMR_SOE_ENABLE);
|
---|
185 | sil_orb((void*)MFS_SCR(ch) , (SCR_TXE | SCR_RXE));
|
---|
186 | }
|
---|
187 |
|
---|
188 | /*
|
---|
189 | * ^[QbgÌVAú»
|
---|
190 | */
|
---|
191 | void target_usart_init(ID siopid)
|
---|
192 | {
|
---|
193 | target_low_output_init(siopid);
|
---|
194 |
|
---|
195 | /* ÝÂ */
|
---|
196 | x_clear_int(INTNO_SIO_TX);
|
---|
197 | x_clear_int(INTNO_SIO_RX);
|
---|
198 | /* ÝÖ~ */
|
---|
199 | (void)ena_int(INTNO_SIO_TX);
|
---|
200 | (void)ena_int(INTNO_SIO_RX);
|
---|
201 | }
|
---|
202 |
|
---|
203 | /*
|
---|
204 | * ^[QbgÌVAI¹
|
---|
205 | */
|
---|
206 | void target_usart_term(ID siopid)
|
---|
207 | {
|
---|
208 | /* ÝÖ~ */
|
---|
209 | (void)dis_int(INTNO_SIO_TX);
|
---|
210 | (void)dis_int(INTNO_SIO_RX);
|
---|
211 |
|
---|
212 | /* USART̳ø» */
|
---|
213 | sil_andb((void*)MFS_SCR(INDEX_PORT(siopid)) , (SCR_TXE | SCR_RIE));
|
---|
214 | }
|
---|
215 |
|
---|
216 | /*
|
---|
217 | * SIOú»
|
---|
218 | */
|
---|
219 | void sio_initialize(intptr_t exinf)
|
---|
220 | {
|
---|
221 | int i;
|
---|
222 |
|
---|
223 | for (i = 0; i < TNUM_PORT; i++) {
|
---|
224 | siopcb_table[i].port = i;
|
---|
225 | siopcb_table[i].reg = sioreg_table[i];
|
---|
226 | siopcb_table[i].exinf = 0;
|
---|
227 | }
|
---|
228 | }
|
---|
229 |
|
---|
230 | /*
|
---|
231 | * VAI[v
|
---|
232 | */
|
---|
233 | SIOPCB *sio_opn_por(ID siopid, intptr_t exinf)
|
---|
234 | {
|
---|
235 | SIOPCB* siopcb;
|
---|
236 |
|
---|
237 | if (siopid > TNUM_PORT) {
|
---|
238 | return NULL;
|
---|
239 | }
|
---|
240 |
|
---|
241 | siopcb = GET_SIOPCB(siopid);
|
---|
242 | siopcb->exinf = exinf;
|
---|
243 |
|
---|
244 | target_usart_init(siopid);
|
---|
245 |
|
---|
246 | return siopcb;
|
---|
247 | }
|
---|
248 |
|
---|
249 | /*
|
---|
250 | * VAN[Y
|
---|
251 | */
|
---|
252 | void sio_cls_por(SIOPCB *p_siopcb)
|
---|
253 | {
|
---|
254 | target_usart_term(p_siopcb->port);
|
---|
255 | }
|
---|
256 |
|
---|
257 | /*
|
---|
258 | * Ýnh
|
---|
259 | */
|
---|
260 | void sio_isr_tx(intptr_t exinf)
|
---|
261 | {
|
---|
262 | SIOPCB* siopcb = GET_SIOPCB(exinf);
|
---|
263 |
|
---|
264 | if (sio_putready(siopcb)) {
|
---|
265 | sio_irdy_snd(siopcb->exinf);
|
---|
266 | }
|
---|
267 | }
|
---|
268 |
|
---|
269 | void sio_isr_rx(intptr_t exinf)
|
---|
270 | {
|
---|
271 | SIOPCB* siopcb = GET_SIOPCB(exinf);
|
---|
272 |
|
---|
273 | if (sio_getready(siopcb)) {
|
---|
274 | sio_irdy_rcv(siopcb->exinf);
|
---|
275 | }
|
---|
276 | }
|
---|
277 |
|
---|
278 | /*
|
---|
279 | * 1¶M
|
---|
280 | */
|
---|
281 | bool_t sio_snd_chr(SIOPCB *siopcb, char c)
|
---|
282 | {
|
---|
283 | bool_t ret = false;
|
---|
284 |
|
---|
285 | if (sio_putready(siopcb)) {
|
---|
286 | sil_wrb_mem((void*)MFS_RDRTDR(siopcb->port), c);
|
---|
287 |
|
---|
288 | ret = true;
|
---|
289 | }
|
---|
290 |
|
---|
291 | return ret;
|
---|
292 | }
|
---|
293 |
|
---|
294 | /*
|
---|
295 | * 1¶óM
|
---|
296 | */
|
---|
297 | int_t sio_rcv_chr(SIOPCB *siopcb)
|
---|
298 | {
|
---|
299 | int_t c = -1;
|
---|
300 |
|
---|
301 | if (sio_getready(siopcb)) {
|
---|
302 | c = (int)sil_reb_mem((void*)MFS_RDRTDR(siopcb->port));
|
---|
303 | }
|
---|
304 |
|
---|
305 | return c;
|
---|
306 | }
|
---|
307 |
|
---|
308 | /*
|
---|
309 | * R[obNÌÂ
|
---|
310 | */
|
---|
311 | void sio_ena_cbr(SIOPCB *siopcb, uint_t cbrtn)
|
---|
312 | {
|
---|
313 | switch (cbrtn) {
|
---|
314 | case SIO_RDY_SND:
|
---|
315 | sil_orb((void*)MFS_SCR(siopcb->port), SCR_TIE);
|
---|
316 | break;
|
---|
317 | case SIO_RDY_RCV:
|
---|
318 | sil_orb((void*)MFS_SCR(siopcb->port), SCR_RIE);
|
---|
319 | break;
|
---|
320 | default:
|
---|
321 | break;
|
---|
322 | }
|
---|
323 | }
|
---|
324 |
|
---|
325 | /*
|
---|
326 | * R[obNÌÖ~
|
---|
327 | */
|
---|
328 | void sio_dis_cbr(SIOPCB *siopcb, uint_t cbrtn)
|
---|
329 | {
|
---|
330 | switch (cbrtn) {
|
---|
331 | case SIO_RDY_SND:
|
---|
332 | sil_andb((void*)MFS_SCR(siopcb->port), ~SCR_TIE);
|
---|
333 | break;
|
---|
334 | case SIO_RDY_RCV:
|
---|
335 | sil_andb((void*)MFS_SCR(siopcb->port), ~SCR_RIE);
|
---|
336 | break;
|
---|
337 | default:
|
---|
338 | break;
|
---|
339 | }
|
---|
340 | }
|
---|
341 |
|
---|
342 | /*
|
---|
343 | * 1¶oÍi|[OÅÌoÍj
|
---|
344 | */
|
---|
345 | void sio_pol_snd_chr(char c, ID siopid)
|
---|
346 | {
|
---|
347 | sil_wrb_mem((void*)MFS_RDRTDR(INDEX_PORT(siopid)), (int)c);
|
---|
348 |
|
---|
349 | while ((sil_reb_mem((void*)MFS_SSR(INDEX_PORT(siopid))) & SSR_TDRE) == 0U)
|
---|
350 | ;
|
---|
351 | }
|
---|