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) 2010 by Meika Sugimoto
|
---|
9 | * Copyright (C) 2011-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 | * VAhCoiQB-R5F100LEpj
|
---|
49 | */
|
---|
50 | #pragma sfr
|
---|
51 | #pragma NOP
|
---|
52 |
|
---|
53 | #include <kernel.h>
|
---|
54 | #include "target_serial.h"
|
---|
55 | #include "target_syssvc.h"
|
---|
56 |
|
---|
57 | /*
|
---|
58 | * VAI/O|[gÇubNGA
|
---|
59 | */
|
---|
60 | static SIOPCB siopcb_table[TNUM_SIOP];
|
---|
61 |
|
---|
62 |
|
---|
63 | /*
|
---|
64 | * WX^Ýèl
|
---|
65 | */
|
---|
66 | #define PORT2SIOPID(x) ((x) + 1)
|
---|
67 | #define INDEX_PORT(x) ((x) - 1)
|
---|
68 | #define GET_SIOPCB(x) (&siopcb_table[INDEX_PORT(x)])
|
---|
69 |
|
---|
70 | extern void x_clear_int(INTNO intno);
|
---|
71 |
|
---|
72 | /*
|
---|
73 | * áxVAú»
|
---|
74 | */
|
---|
75 | void target_sau_init(ID siopid)
|
---|
76 | {
|
---|
77 | /* ú»ÏÝÌêÍ·®É^[ */
|
---|
78 | if(PER0 & TBIT_PER0_SAU0EN) {
|
---|
79 | return;
|
---|
80 | }
|
---|
81 |
|
---|
82 | /* NbNÂ */
|
---|
83 | PER0 |= TBIT_PER0_SAU0EN;
|
---|
84 |
|
---|
85 | // µÒÂ
|
---|
86 | NOP();
|
---|
87 | NOP();
|
---|
88 | NOP();
|
---|
89 |
|
---|
90 | // CKm0 ðIðDügÍ fclk/8 (=2.5MHz)
|
---|
91 | SPS0 = UINT16_C(0x0033);
|
---|
92 |
|
---|
93 | // jbg0C`l{0,1} Ì®ìâ~
|
---|
94 | ST0 |= UINT16_C(0x0003);
|
---|
95 |
|
---|
96 | // [hÝè
|
---|
97 | // ®ìNbNFSPS0WX^ÅÝèµ½®ìNbN̤¿CCK00 Ìûðg¤
|
---|
98 | // ]NbNFCKS00, CKS01 rbgÅwèµ½®ìNbN(ÂÜèCK00)̪üNbN
|
---|
99 | // X^[ggKvöFM-->\tgEFAgKÌÝ, óM-->RxD0[q
|
---|
100 | // §ºèðX^[grbgƵÄo
|
---|
101 | // UART[hCèÝÍ]®¹Ý
|
---|
102 | SMR00 = UINT16_C(0x0022);
|
---|
103 | SMR01 = UINT16_C(0x0122);
|
---|
104 |
|
---|
105 | // `l0: MÌÝÂC`l1: óMÌÝÂ
|
---|
106 | // G[ÝINTSREx̶ðÖ~
|
---|
107 | // peBȵCLSBt@[XgC1XgbvrbgC8rbgf[^·
|
---|
108 | SCR00 = UINT16_C(0x8097);
|
---|
109 | SCR01 = UINT16_C(0x4097);
|
---|
110 |
|
---|
111 | // [rbg15:9] = 0x40 --> 64
|
---|
112 | // VAÖÌNbNÍ 2.5MHz(=20/8)
|
---|
113 | // ªüäÍ (64+1)*2 = 130
|
---|
114 | // 2.5[MHz]/130 = 19.23[kHz]
|
---|
115 | SDR00 = UINT16_C(0x8000);
|
---|
116 | SDR01 = UINT16_C(0x8000);
|
---|
117 |
|
---|
118 | // óM|[gÌmCYtB^ON
|
---|
119 | NFEN0 |= UINT8_C(0x01);
|
---|
120 |
|
---|
121 | // G[tOÌNA(óM¤Ì`l1ÌÝ)
|
---|
122 | SIR01 |= UINT16_C(0x0007);
|
---|
123 |
|
---|
124 | // VAf[^oÍlð`l0ÌÝ1Æ·éD
|
---|
125 | SO0 |= UINT16_C(0x0001);
|
---|
126 |
|
---|
127 | // ÊMf[^ͽ]¹¸»ÌÜÜoÍ
|
---|
128 | SOL0 = UINT16_C(0x0000);
|
---|
129 |
|
---|
130 | /*
|
---|
131 | * VA`l0Jn
|
---|
132 | */
|
---|
133 | // VAoÍÂ
|
---|
134 | SOE0 |= UINT16_C(0x0001);
|
---|
135 |
|
---|
136 | // `l{0,1}ÌJn
|
---|
137 | SS0 |= UINT16_C(0x0003);
|
---|
138 | }
|
---|
139 |
|
---|
140 | /*
|
---|
141 | * SIOú»
|
---|
142 | */
|
---|
143 | void sio_initialize(intptr_t exinf)
|
---|
144 | {
|
---|
145 | }
|
---|
146 |
|
---|
147 | /*
|
---|
148 | * VAI[v
|
---|
149 | */
|
---|
150 | SIOPCB *sio_opn_por(ID siopid, intptr_t exinf)
|
---|
151 | {
|
---|
152 | int_t i;
|
---|
153 | SIOPCB* p_siopcb;
|
---|
154 |
|
---|
155 | if (siopid > TNUM_PORT) {
|
---|
156 | return NULL;
|
---|
157 | }
|
---|
158 |
|
---|
159 | p_siopcb = GET_SIOPCB(siopid);
|
---|
160 | p_siopcb->enacb &= ~TBIT_ENACB_SND;
|
---|
161 | p_siopcb->enacb &= ~TBIT_ENACB_RCV;
|
---|
162 | p_siopcb->exinf = exinf;
|
---|
163 |
|
---|
164 | // ÝÌ}XN
|
---|
165 | dis_int(INTNO_INTST0);
|
---|
166 | dis_int(INTNO_INTSR0);
|
---|
167 | // ÝvNA
|
---|
168 | x_clear_int(INTNO_INTST0);
|
---|
169 | x_clear_int(INTNO_INTSR0);
|
---|
170 |
|
---|
171 | // n[hEFAÌú»
|
---|
172 | target_sau_init(siopid);
|
---|
173 |
|
---|
174 | return p_siopcb;
|
---|
175 | }
|
---|
176 |
|
---|
177 | /*
|
---|
178 | * VAN[Y
|
---|
179 | */
|
---|
180 | void sio_cls_por(SIOPCB *p_siopcb)
|
---|
181 | {
|
---|
182 | /* óMÖ~ */
|
---|
183 |
|
---|
184 | // `l{0,1}Ìâ~
|
---|
185 | ST0 |= UINT16_C(0x0003);
|
---|
186 |
|
---|
187 | /* VAW
|
---|
188 | [ð³øÉ·é */
|
---|
189 | PER0 &= ~TBIT_PER0_SAU0EN;
|
---|
190 | }
|
---|
191 |
|
---|
192 |
|
---|
193 | /*
|
---|
194 | * 1¶M
|
---|
195 | */
|
---|
196 | bool_t
|
---|
197 | sio_snd_chr(SIOPCB *p_siopcb, char c)
|
---|
198 | {
|
---|
199 | // Mobt@ªóÈçÎC1¶M
|
---|
200 | if((SSR00L & TBIT_SSRmnL_TSF) == UINT16_C(0)) {
|
---|
201 | SDR00 = (uint16_t)c;
|
---|
202 |
|
---|
203 | return true;
|
---|
204 | }
|
---|
205 |
|
---|
206 | return false;
|
---|
207 | }
|
---|
208 |
|
---|
209 | /*
|
---|
210 | * 1¶óM
|
---|
211 | */
|
---|
212 | int_t
|
---|
213 | sio_rcv_chr(SIOPCB *p_siopcb)
|
---|
214 | {
|
---|
215 | int_t c = -1;
|
---|
216 |
|
---|
217 | // óMobt@Éf[^ª êÎC1¶óM
|
---|
218 | if((SSR01L & TBIT_SSRmnL_BFF) != 0) {
|
---|
219 | c = (int_t)SDR01;
|
---|
220 | }
|
---|
221 |
|
---|
222 | return c;
|
---|
223 | }
|
---|
224 |
|
---|
225 | /*
|
---|
226 | * R[obNÌÂ
|
---|
227 | */
|
---|
228 | void
|
---|
229 | sio_ena_cbr(SIOPCB *p_siopcb, uint_t cbrtn)
|
---|
230 | {
|
---|
231 | switch (cbrtn) {
|
---|
232 | case SIO_RDY_SND:
|
---|
233 | p_siopcb->enacb |= TBIT_ENACB_SND;
|
---|
234 | x_clear_int(INTNO_INTST0);
|
---|
235 | ena_int(INTNO_INTST0);
|
---|
236 | break;
|
---|
237 | case SIO_RDY_RCV:
|
---|
238 | p_siopcb->enacb |= TBIT_ENACB_RCV;
|
---|
239 | x_clear_int(INTNO_INTSR0);
|
---|
240 | ena_int(INTNO_INTSR0);
|
---|
241 | break;
|
---|
242 | default:
|
---|
243 | break;
|
---|
244 | }
|
---|
245 | }
|
---|
246 |
|
---|
247 | /*
|
---|
248 | * R[obNÌÖ~
|
---|
249 | */
|
---|
250 | void
|
---|
251 | sio_dis_cbr(SIOPCB *p_siopcb, uint_t cbrtn)
|
---|
252 | {
|
---|
253 | switch (cbrtn) {
|
---|
254 | case SIO_RDY_SND:
|
---|
255 | p_siopcb->enacb &= ~TBIT_ENACB_SND;
|
---|
256 | dis_int(INTNO_INTST0);
|
---|
257 | x_clear_int(INTNO_INTST0);
|
---|
258 | break;
|
---|
259 | case SIO_RDY_RCV:
|
---|
260 | p_siopcb->enacb &= ~TBIT_ENACB_RCV;
|
---|
261 | dis_int(INTNO_INTSR0);
|
---|
262 | x_clear_int(INTNO_INTSR0);
|
---|
263 | break;
|
---|
264 | default:
|
---|
265 | break;
|
---|
266 | }
|
---|
267 | }
|
---|
268 |
|
---|
269 |
|
---|
270 | /*
|
---|
271 | * ÝT[rX[`
|
---|
272 | */
|
---|
273 |
|
---|
274 | /*
|
---|
275 | * óMÝ
|
---|
276 | */
|
---|
277 | void
|
---|
278 | sio_isr_rcv(intptr_t portid)
|
---|
279 | {
|
---|
280 | SIOPCB *p_siopcb = GET_SIOPCB((ID)portid);
|
---|
281 |
|
---|
282 | if((p_siopcb->enacb & TBIT_ENACB_RCV) != 0) {
|
---|
283 | /*
|
---|
284 | * óMÊmR[obN[`ðÄÑo·D
|
---|
285 | */
|
---|
286 | sio_irdy_rcv(p_siopcb->exinf);
|
---|
287 | }
|
---|
288 | }
|
---|
289 |
|
---|
290 | /*
|
---|
291 | * MÝ
|
---|
292 | */
|
---|
293 | void
|
---|
294 | sio_isr_snd(intptr_t portid)
|
---|
295 | {
|
---|
296 | SIOPCB *p_siopcb = GET_SIOPCB((ID)portid);
|
---|
297 |
|
---|
298 | if((p_siopcb->enacb & TBIT_ENACB_SND) != 0) {
|
---|
299 | /*
|
---|
300 | * MÊmR[obN[`ðÄÑo·D
|
---|
301 | */
|
---|
302 | sio_irdy_snd(p_siopcb->exinf);
|
---|
303 | }
|
---|
304 | }
|
---|
305 |
|
---|
306 | /*
|
---|
307 | * 1¶oÍi|[OÅÌoÍj
|
---|
308 | */
|
---|
309 | void
|
---|
310 | sio_pol_snd_chr(char c, ID siopid)
|
---|
311 | {
|
---|
312 | /* Mobt@ªóÉÈéÜÅÒÂ(LÀÔàÌð¬§ð¼è) */
|
---|
313 | while((SSR00L & TBIT_SSRmnL_TSF) != 0){}
|
---|
314 |
|
---|
315 | // 1¶M
|
---|
316 | SDR00 = (uint16_t)c;
|
---|
317 | }
|
---|