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) 2006-2008 by Embedded and Real-Time Systems Laboratory
|
---|
9 | * Graduate School of Information Science, Nagoya Univ., JAPAN
|
---|
10 | *
|
---|
11 | * ãLì ÒÍCȺÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF
|
---|
12 | * Ai{\tgEFAðüϵ½àÌðÜÞDȺ¯¶jðgpE¡»Eü
|
---|
13 | * ÏEÄzziȺCpÆÄÔj·é±Æð³Åø·éD
|
---|
14 | * (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì
|
---|
15 | * \¦C±Ìpð¨æѺL̳ÛØKèªC»ÌÜÜÌ`Å\[
|
---|
16 | * XR[hÉÜÜêÄ¢é±ÆD
|
---|
17 | * (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJÉg
|
---|
18 | * pÅ«é`ÅÄzz·éêÉÍCÄzzɺ¤hL
|
---|
19 | gip
|
---|
20 | * Ò}j
|
---|
21 | AÈÇjÉCãLÌì \¦C±Ìpð¨æѺL
|
---|
22 | * ̳ÛØKèðfÚ·é±ÆD
|
---|
23 | * (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJÉg
|
---|
24 | * pÅ«È¢`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·±
|
---|
25 | * ÆD
|
---|
26 | * (a) Äzzɺ¤hL
|
---|
27 | gipÒ}j
|
---|
28 | AÈÇjÉCãLÌ
|
---|
29 | * ì \¦C±Ìpð¨æѺL̳ÛØKèðfÚ·é±ÆD
|
---|
30 | * (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ
|
---|
31 | * ñ·é±ÆD
|
---|
32 | * (4) {\tgEFAÌpÉæè¼ÚIܽÍÔÚIɶ¶é¢©Èé¹
|
---|
33 | * Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD
|
---|
34 | * ܽC{\tgEFAÌ[UܽÍGh[U©çÌ¢©Èé
|
---|
35 | * RÉîÿ©çàCãLì Ò¨æÑTOPPERSvWFNgð
|
---|
36 | * ÆÓ·é±ÆD
|
---|
37 | *
|
---|
38 | * {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨
|
---|
39 | * æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI
|
---|
40 | * ÉηéK«àÜßÄC¢©ÈéÛØàsíÈ¢DܽC{\tgEF
|
---|
41 | * AÌpÉæè¼ÚIܽÍÔÚIɶ¶½¢©Èé¹QÉÖµÄàC»
|
---|
42 | * ÌÓCðíÈ¢D
|
---|
43 | *
|
---|
44 | * @(#) $Id: upd72001.c 873 2008-04-11 10:32:26Z hiro $
|
---|
45 | */
|
---|
46 |
|
---|
47 | /*
|
---|
48 | * ÊPD72001p ÈÕSIOhCo
|
---|
49 | */
|
---|
50 |
|
---|
51 | #include <sil.h>
|
---|
52 | #include "target_syssvc.h"
|
---|
53 | #include "upd72001.h"
|
---|
54 |
|
---|
55 | /*
|
---|
56 | * foCXWX^ÌANZXÔuÔinsecPÊj
|
---|
57 | *
|
---|
58 | * 200Æ¢¤lÉ ÜèªÍÈ¢D
|
---|
59 | */
|
---|
60 | #define UPD72001_DELAY 200U
|
---|
61 |
|
---|
62 | /*
|
---|
63 | * ÊPD72001ÌWX^ÌÔ
|
---|
64 | */
|
---|
65 | #define UPD72001_CR0 0x00U /* Rg[WX^ */
|
---|
66 | #define UPD72001_CR1 0x01U
|
---|
67 | #define UPD72001_CR2 0x02U
|
---|
68 | #define UPD72001_CR3 0x03U
|
---|
69 | #define UPD72001_CR4 0x04U
|
---|
70 | #define UPD72001_CR5 0x05U
|
---|
71 | #define UPD72001_CR10 0x0aU
|
---|
72 | #define UPD72001_CR12 0x0cU
|
---|
73 | #define UPD72001_CR14 0x0eU
|
---|
74 | #define UPD72001_CR15 0x0fU
|
---|
75 |
|
---|
76 | #define UPD72001_SR0 0x00U /* Xe[^XWX^ */
|
---|
77 |
|
---|
78 | /*
|
---|
79 | * Rg[WX^ÌÝèl
|
---|
80 | */
|
---|
81 | #define CR_RESET 0x18U /* |[gZbgR}h */
|
---|
82 |
|
---|
83 | #define CR0_EOI 0x38U /* EOIiEnd of Interruptj*/
|
---|
84 |
|
---|
85 | #define CR1_DOWN 0x00U /* SÝðÖ~ */
|
---|
86 | #define CR1_RECV 0x10U /* óMÝÂrbg */
|
---|
87 | #define CR1_SEND 0x02U /* MÝÂrbg */
|
---|
88 |
|
---|
89 | #define CR3_DEF 0xc1U /* f[^ 8bitCóMCl[u */
|
---|
90 | #define CR4_DEF 0x44U /* Xgbvrbg 1bitCpeBȵ */
|
---|
91 | #define CR5_DEF 0xeaU /* f[^ 8bitCMCl[u */
|
---|
92 |
|
---|
93 | #define CR10_DEF 0x00U /* NRZ */
|
---|
94 | #define CR14_DEF 0x07U /* {[[gWFl[^Cl[u */
|
---|
95 | #define CR15_DEF 0x56U /* {[[gWFl[^gp */
|
---|
96 |
|
---|
97 | #define SR0_RECV 0x01U /* óMÊmrbg */
|
---|
98 | #define SR0_SEND 0x04U /* MÂ\rbg */
|
---|
99 |
|
---|
100 | /*
|
---|
101 | * VAI/O|[gú»ubNÌè`
|
---|
102 | */
|
---|
103 | typedef struct sio_port_initialization_block {
|
---|
104 | void *data; /* f[^WX^ÌÔn */
|
---|
105 | void *ctrl; /* Rg[WX^ÌÔn */
|
---|
106 |
|
---|
107 | uint8_t cr3_def; /* CR3ÌÝèlióMrbgj*/
|
---|
108 | uint8_t cr4_def; /* CR4ÌÝèliXgbvrbgCpeBj*/
|
---|
109 | uint8_t cr5_def; /* CR5ÌÝèliMrbgj*/
|
---|
110 | uint8_t brg1_def; /* {[[gãÊÌÝèl */
|
---|
111 | uint8_t brg2_def; /* {[[gºÊÌÝèl */
|
---|
112 | } SIOPINIB;
|
---|
113 |
|
---|
114 | /*
|
---|
115 | * VAI/O|[gÇubNÌè`
|
---|
116 | */
|
---|
117 | struct sio_port_control_block {
|
---|
118 | const SIOPINIB *p_siopinib; /* VAI/O|[gú»ubN */
|
---|
119 | intptr_t exinf; /* g£îñ */
|
---|
120 | bool_t openflag; /* I[vÏÝtO */
|
---|
121 | uint8_t cr1; /* CR1ÌÝèliÝÂj*/
|
---|
122 | bool_t getready; /* ¶ðóMµ½óÔ */
|
---|
123 | bool_t putready; /* ¶ðMÅ«éóÔ */
|
---|
124 | };
|
---|
125 |
|
---|
126 | /*
|
---|
127 | * VAI/O|[gú»ubN
|
---|
128 | */
|
---|
129 | const SIOPINIB siopinib_table[TNUM_SIOP] = {
|
---|
130 | { (void *) TADR_UPD72001_DATAA, (void *) TADR_UPD72001_CTRLA,
|
---|
131 | CR3_DEF, CR4_DEF, CR5_DEF, BRG1_DEF, BRG2_DEF },
|
---|
132 | { (void *) TADR_UPD72001_DATAB, (void *) TADR_UPD72001_CTRLB,
|
---|
133 | CR3_DEF, CR4_DEF, CR5_DEF, BRG1_DEF, BRG2_DEF }
|
---|
134 | };
|
---|
135 |
|
---|
136 | /*
|
---|
137 | * VAI/O|[gÇubNÌGA
|
---|
138 | */
|
---|
139 | SIOPCB siopcb_table[TNUM_SIOP];
|
---|
140 |
|
---|
141 | /*
|
---|
142 | * VAI/O|[gID©çÇubNðæèo·½ßÌ}N
|
---|
143 | */
|
---|
144 | #define INDEX_SIOP(siopid) ((uint_t)((siopid) - 1))
|
---|
145 | #define get_siopcb(siopid) (&(siopcb_table[INDEX_SIOP(siopid)]))
|
---|
146 |
|
---|
147 | /*
|
---|
148 | * foCXWX^ÖÌANZXÖ
|
---|
149 | */
|
---|
150 | Inline uint8_t
|
---|
151 | upd72001_read_reg(void *addr)
|
---|
152 | {
|
---|
153 | uint8_t val;
|
---|
154 |
|
---|
155 | val = upd72001_reb_reg(addr);
|
---|
156 | sil_dly_nse(UPD72001_DELAY);
|
---|
157 | return(val);
|
---|
158 | }
|
---|
159 |
|
---|
160 | Inline void
|
---|
161 | upd72001_write_reg(void *addr, uint8_t val)
|
---|
162 | {
|
---|
163 | upd72001_wrb_reg(addr, val);
|
---|
164 | sil_dly_nse(UPD72001_DELAY);
|
---|
165 | }
|
---|
166 |
|
---|
167 | Inline uint8_t
|
---|
168 | upd72001_read_ctrl(void *addr, uint8_t reg)
|
---|
169 | {
|
---|
170 | upd72001_write_reg(addr, reg);
|
---|
171 | return(upd72001_read_reg(addr));
|
---|
172 | }
|
---|
173 |
|
---|
174 | Inline void
|
---|
175 | upd72001_write_ctrl(void *addr, uint8_t reg, uint8_t val)
|
---|
176 | {
|
---|
177 | upd72001_write_reg(addr, reg);
|
---|
178 | upd72001_write_reg(addr, val);
|
---|
179 | }
|
---|
180 |
|
---|
181 | Inline void
|
---|
182 | upd72001_write_brg(void *addr, uint8_t reg, uint8_t val,
|
---|
183 | uint8_t brg2, uint8_t brg1)
|
---|
184 | {
|
---|
185 | upd72001_write_reg(addr, reg);
|
---|
186 | upd72001_write_reg(addr, val);
|
---|
187 | upd72001_write_reg(addr, brg2);
|
---|
188 | upd72001_write_reg(addr, brg1);
|
---|
189 | (void) upd72001_read_reg(addr); /* _~[[h */
|
---|
190 | }
|
---|
191 |
|
---|
192 | /*
|
---|
193 | * óÔÌÇoµiSR0ÌÇoµj
|
---|
194 | *
|
---|
195 | * ÊPD72001ÍCóÔiSR0jðêxÇÞÆóMÊmrbgª¿ÄµÜ¤½
|
---|
196 | * ßCóÔðÇÝo·ÖðݯCVAI/O|[gÇubNÌ
|
---|
197 | * getreadyÉóMÊmóÔCputreadyÉMÂ\óÔðÛ¶µÄ¢éiM
|
---|
198 | * Â\óÔÌÛ¶Ísv©àµêÈ¢jD
|
---|
199 | * óÔWX^ðÇñÅàóMÊmrbgª¿È¢foCXi±¿çª
|
---|
200 | * ÊÆvíêéjÅÍC±ÌÖÍKvÈ¢D
|
---|
201 | */
|
---|
202 | static void
|
---|
203 | upd72001_get_stat(SIOPCB *p_siopcb)
|
---|
204 | {
|
---|
205 | uint8_t sr0;
|
---|
206 |
|
---|
207 | sr0 = upd72001_read_ctrl(p_siopcb->p_siopinib->ctrl, UPD72001_SR0);
|
---|
208 | if ((sr0 & SR0_RECV) != 0) {
|
---|
209 | p_siopcb->getready = true;
|
---|
210 | }
|
---|
211 | if ((sr0 & SR0_SEND) != 0) {
|
---|
212 | p_siopcb->putready = true;
|
---|
213 | }
|
---|
214 | }
|
---|
215 |
|
---|
216 | /*
|
---|
217 | * ¶ðóMÅ«é©H
|
---|
218 | */
|
---|
219 | Inline bool_t
|
---|
220 | upd72001_getready(SIOPCB *p_siopcb)
|
---|
221 | {
|
---|
222 | upd72001_get_stat(p_siopcb);
|
---|
223 | return(p_siopcb->getready);
|
---|
224 | }
|
---|
225 |
|
---|
226 | /*
|
---|
227 | * ¶ðMÅ«é©H
|
---|
228 | */
|
---|
229 | Inline bool_t
|
---|
230 | upd72001_putready(SIOPCB *p_siopcb)
|
---|
231 | {
|
---|
232 | upd72001_get_stat(p_siopcb);
|
---|
233 | return(p_siopcb->putready);
|
---|
234 | }
|
---|
235 |
|
---|
236 | /*
|
---|
237 | * óMµ½¶Ìæoµ
|
---|
238 | */
|
---|
239 | Inline char_t
|
---|
240 | upd72001_getchar(SIOPCB *p_siopcb)
|
---|
241 | {
|
---|
242 | p_siopcb->getready = false;
|
---|
243 | return((char_t) upd72001_read_reg(p_siopcb->p_siopinib->data));
|
---|
244 | }
|
---|
245 |
|
---|
246 | /*
|
---|
247 | * M·é¶ÌÝ
|
---|
248 | */
|
---|
249 | Inline void
|
---|
250 | upd72001_putchar(SIOPCB *p_siopcb, char_t c)
|
---|
251 | {
|
---|
252 | p_siopcb->putready = false;
|
---|
253 | upd72001_write_reg(p_siopcb->p_siopinib->data, (uint8_t) c);
|
---|
254 | }
|
---|
255 |
|
---|
256 | /*
|
---|
257 | * EOIiEnd Of Interruptjs
|
---|
258 | */
|
---|
259 | Inline void
|
---|
260 | upd72001_eoi(void)
|
---|
261 | {
|
---|
262 | upd72001_write_ctrl((void *) TADR_UPD72001_CTRLA, UPD72001_CR0, CR0_EOI);
|
---|
263 | }
|
---|
264 |
|
---|
265 | /*
|
---|
266 | * SIOhCoÌú»
|
---|
267 | */
|
---|
268 | void
|
---|
269 | upd72001_initialize(void)
|
---|
270 | {
|
---|
271 | SIOPCB *p_siopcb;
|
---|
272 | uint_t i;
|
---|
273 |
|
---|
274 | /*
|
---|
275 | * VAI/O|[gÇubNÌú»
|
---|
276 | */
|
---|
277 | for (p_siopcb = siopcb_table, i = 0; i < TNUM_SIOP; p_siopcb++, i++) {
|
---|
278 | p_siopcb->p_siopinib = &(siopinib_table[i]);
|
---|
279 | p_siopcb->openflag = false;
|
---|
280 | }
|
---|
281 | }
|
---|
282 |
|
---|
283 | /*
|
---|
284 | * I[vµÄ¢é|[gª é©H
|
---|
285 | */
|
---|
286 | bool_t
|
---|
287 | upd72001_openflag(void)
|
---|
288 | {
|
---|
289 | return(siopcb_table[0].openflag || siopcb_table[1].openflag);
|
---|
290 | }
|
---|
291 |
|
---|
292 | /*
|
---|
293 | * VAI/O|[gÌI[v
|
---|
294 | */
|
---|
295 | SIOPCB *
|
---|
296 | upd72001_opn_por(ID siopid, intptr_t exinf)
|
---|
297 | {
|
---|
298 | SIOPCB *p_siopcb;
|
---|
299 | const SIOPINIB *p_siopinib;
|
---|
300 |
|
---|
301 | p_siopcb = get_siopcb(siopid);
|
---|
302 | p_siopinib = p_siopcb->p_siopinib;
|
---|
303 |
|
---|
304 | upd72001_write_reg(p_siopinib->ctrl, CR_RESET);
|
---|
305 | if (!upd72001_openflag()) {
|
---|
306 | upd72001_write_ctrl((void *) TADR_UPD72001_CTRLA, UPD72001_CR2, 0x18);
|
---|
307 | upd72001_write_ctrl((void *) TADR_UPD72001_CTRLB, UPD72001_CR2, 0x00);
|
---|
308 | }
|
---|
309 | p_siopcb->cr1 = CR1_DOWN;
|
---|
310 | upd72001_write_ctrl(p_siopinib->ctrl, UPD72001_CR1, p_siopcb->cr1);
|
---|
311 | upd72001_write_ctrl(p_siopinib->ctrl, UPD72001_CR4, p_siopinib->cr4_def);
|
---|
312 | upd72001_write_brg(p_siopinib->ctrl, UPD72001_CR12, 0x01U,
|
---|
313 | p_siopinib->brg2_def, p_siopinib->brg1_def);
|
---|
314 | upd72001_write_brg(p_siopinib->ctrl, UPD72001_CR12, 0x02U,
|
---|
315 | p_siopinib->brg2_def, p_siopinib->brg1_def);
|
---|
316 | upd72001_write_ctrl(p_siopinib->ctrl, UPD72001_CR15, CR15_DEF);
|
---|
317 | upd72001_write_ctrl(p_siopinib->ctrl, UPD72001_CR14, CR14_DEF);
|
---|
318 | upd72001_write_ctrl(p_siopinib->ctrl, UPD72001_CR10, CR10_DEF);
|
---|
319 | upd72001_write_ctrl(p_siopinib->ctrl, UPD72001_CR3, p_siopinib->cr3_def);
|
---|
320 | upd72001_write_ctrl(p_siopinib->ctrl, UPD72001_CR5, p_siopinib->cr5_def);
|
---|
321 | p_siopcb->exinf = exinf;
|
---|
322 | p_siopcb->getready = p_siopcb->putready = false;
|
---|
323 | p_siopcb->openflag = true;
|
---|
324 | return(p_siopcb);
|
---|
325 | }
|
---|
326 |
|
---|
327 | /*
|
---|
328 | * VAI/O|[gÌN[Y
|
---|
329 | */
|
---|
330 | void
|
---|
331 | upd72001_cls_por(SIOPCB *p_siopcb)
|
---|
332 | {
|
---|
333 | upd72001_write_ctrl(p_siopcb->p_siopinib->ctrl, UPD72001_CR1, CR1_DOWN);
|
---|
334 | p_siopcb->openflag = false;
|
---|
335 | }
|
---|
336 |
|
---|
337 | /*
|
---|
338 | * VAI/O|[gÖ̶M
|
---|
339 | */
|
---|
340 | bool_t
|
---|
341 | upd72001_snd_chr(SIOPCB *p_siopcb, char_t c)
|
---|
342 | {
|
---|
343 | if (upd72001_putready(p_siopcb)) {
|
---|
344 | upd72001_putchar(p_siopcb, c);
|
---|
345 | return(true);
|
---|
346 | }
|
---|
347 | return(false);
|
---|
348 | }
|
---|
349 |
|
---|
350 | /*
|
---|
351 | * VAI/O|[g©ç̶óM
|
---|
352 | */
|
---|
353 | int_t
|
---|
354 | upd72001_rcv_chr(SIOPCB *p_siopcb)
|
---|
355 | {
|
---|
356 | if (upd72001_getready(p_siopcb)) {
|
---|
357 | return((int_t)(uint8_t) upd72001_getchar(p_siopcb));
|
---|
358 | }
|
---|
359 | return(-1);
|
---|
360 | }
|
---|
361 |
|
---|
362 | /*
|
---|
363 | * VAI/O|[g©çÌR[obNÌÂ
|
---|
364 | */
|
---|
365 | void
|
---|
366 | upd72001_ena_cbr(SIOPCB *p_siopcb, uint_t cbrtn)
|
---|
367 | {
|
---|
368 | uint8_t cr1_bit = 0;
|
---|
369 |
|
---|
370 | switch (cbrtn) {
|
---|
371 | case SIO_RDY_SND:
|
---|
372 | cr1_bit = CR1_SEND;
|
---|
373 | break;
|
---|
374 | case SIO_RDY_RCV:
|
---|
375 | cr1_bit = CR1_RECV;
|
---|
376 | break;
|
---|
377 | }
|
---|
378 | p_siopcb->cr1 |= cr1_bit;
|
---|
379 | upd72001_write_ctrl(p_siopcb->p_siopinib->ctrl,
|
---|
380 | UPD72001_CR1, p_siopcb->cr1);
|
---|
381 | }
|
---|
382 |
|
---|
383 | /*
|
---|
384 | * VAI/O|[g©çÌR[obNÌÖ~
|
---|
385 | */
|
---|
386 | void
|
---|
387 | upd72001_dis_cbr(SIOPCB *p_siopcb, uint_t cbrtn)
|
---|
388 | {
|
---|
389 | uint8_t cr1_bit = 0;
|
---|
390 |
|
---|
391 | switch (cbrtn) {
|
---|
392 | case SIO_RDY_SND:
|
---|
393 | cr1_bit = CR1_SEND;
|
---|
394 | break;
|
---|
395 | case SIO_RDY_RCV:
|
---|
396 | cr1_bit = CR1_RECV;
|
---|
397 | break;
|
---|
398 | }
|
---|
399 | p_siopcb->cr1 &= ~cr1_bit;
|
---|
400 | upd72001_write_ctrl(p_siopcb->p_siopinib->ctrl,
|
---|
401 | UPD72001_CR1, p_siopcb->cr1);
|
---|
402 | }
|
---|
403 |
|
---|
404 | /*
|
---|
405 | * VAI/O|[gÉηéÝ
|
---|
406 | */
|
---|
407 | static void
|
---|
408 | upd72001_isr_siop(SIOPCB *p_siopcb)
|
---|
409 | {
|
---|
410 | if ((p_siopcb->cr1 & CR1_RECV) != 0U && upd72001_getready(p_siopcb)) {
|
---|
411 | /*
|
---|
412 | * óMÊmR[obN[`ðÄÑo·D
|
---|
413 | */
|
---|
414 | upd72001_irdy_rcv(p_siopcb->exinf);
|
---|
415 | }
|
---|
416 | if ((p_siopcb->cr1 & CR1_SEND) != 0U && upd72001_putready(p_siopcb)) {
|
---|
417 | /*
|
---|
418 | * MÂ\R[obN[`ðÄÑo·D
|
---|
419 | */
|
---|
420 | upd72001_irdy_snd(p_siopcb->exinf);
|
---|
421 | }
|
---|
422 | }
|
---|
423 |
|
---|
424 | /*
|
---|
425 | * SIOÌÝT[rX[`
|
---|
426 | */
|
---|
427 | void
|
---|
428 | upd72001_isr(void)
|
---|
429 | {
|
---|
430 | if (siopcb_table[0].openflag) {
|
---|
431 | upd72001_isr_siop(&(siopcb_table[0]));
|
---|
432 | }
|
---|
433 | if (siopcb_table[1].openflag) {
|
---|
434 | upd72001_isr_siop(&(siopcb_table[1]));
|
---|
435 | }
|
---|
436 | upd72001_eoi();
|
---|
437 | }
|
---|