3 * Toyohashi Open Platform for Embedded Real-Time Systems/
4 * Just Standard Profile Kernel
6 * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
7 * Toyohashi Univ. of Technology, JAPAN
9 * ¾åµÃøºî¸¢¼Ô¤Ï¡¤°Ê²¼¤Î (1)¡Á(4) ¤Î¾ò·ï¤«¡¤Free Software Foundation
10 * ¤Ë¤è¤Ã¤Æ¸øɽ¤µ¤ì¤Æ¤¤¤ë GNU General Public License ¤Î Version 2 ¤Ëµ
11 * ½Ò¤µ¤ì¤Æ¤¤¤ë¾ò·ï¤òËþ¤¿¤¹¾ì¹ç¤Ë¸Â¤ê¡¤ËÜ¥½¥Õ¥È¥¦¥§¥¢¡ÊËÜ¥½¥Õ¥È¥¦¥§¥¢
12 * ¤ò²þÊѤ·¤¿¤â¤Î¤ò´Þ¤à¡¥°Ê²¼Æ±¤¸¡Ë¤ò»ÈÍÑ¡¦Ê£À½¡¦²þÊÑ¡¦ºÆÇÛÉۡʰʲ¼¡¤
13 * ÍøÍѤȸƤ֡ˤ¹¤ë¤³¤È¤ò̵½þ¤ÇµöÂú¤¹¤ë¡¥
14 * (1) ËÜ¥½¥Õ¥È¥¦¥§¥¢¤ò¥½¡¼¥¹¥³¡¼¥É¤Î·Á¤ÇÍøÍѤ¹¤ë¾ì¹ç¤Ë¤Ï¡¤¾åµ¤ÎÃøºî
15 * ¸¢É½¼¨¡¤¤³¤ÎÍøÍѾò·ï¤ª¤è¤Ó²¼µ¤Î̵Êݾڵ¬Ä꤬¡¤¤½¤Î¤Þ¤Þ¤Î·Á¤Ç¥½¡¼
16 * ¥¹¥³¡¼¥ÉÃæ¤Ë´Þ¤Þ¤ì¤Æ¤¤¤ë¤³¤È¡¥
17 * (2) ËÜ¥½¥Õ¥È¥¦¥§¥¢¤ò¡¤¥é¥¤¥Ö¥é¥ê·Á¼°¤Ê¤É¡¤Â¾¤Î¥½¥Õ¥È¥¦¥§¥¢³«È¯¤Ë»È
18 * ÍѤǤ¤ë·Á¤ÇºÆÇÛÉÛ¤¹¤ë¾ì¹ç¤Ë¤Ï¡¤ºÆÇÛÉÛ¤Ëȼ¤¦¥É¥¥å¥á¥ó¥È¡ÊÍøÍÑ
19 * ¼Ô¥Þ¥Ë¥å¥¢¥ë¤Ê¤É¡Ë¤Ë¡¤¾åµ¤ÎÃøºî¸¢É½¼¨¡¤¤³¤ÎÍøÍѾò·ï¤ª¤è¤Ó²¼µ
20 * ¤Î̵Êݾڵ¬Äê¤ò·ÇºÜ¤¹¤ë¤³¤È¡¥
21 * (3) ËÜ¥½¥Õ¥È¥¦¥§¥¢¤ò¡¤µ¡´ï¤ËÁȤ߹þ¤à¤Ê¤É¡¤Â¾¤Î¥½¥Õ¥È¥¦¥§¥¢³«È¯¤Ë»È
22 * ÍѤǤ¤Ê¤¤·Á¤ÇºÆÇÛÉÛ¤¹¤ë¾ì¹ç¤Ë¤Ï¡¤¼¡¤Î¤¤¤º¤ì¤«¤Î¾ò·ï¤òËþ¤¿¤¹¤³
24 * (a) ºÆÇÛÉÛ¤Ëȼ¤¦¥É¥¥å¥á¥ó¥È¡ÊÍøÍѼԥޥ˥奢¥ë¤Ê¤É¡Ë¤Ë¡¤¾åµ¤ÎÃø
25 * ºî¸¢É½¼¨¡¤¤³¤ÎÍøÍѾò·ï¤ª¤è¤Ó²¼µ¤Î̵Êݾڵ¬Äê¤ò·ÇºÜ¤¹¤ë¤³¤È¡¥
26 * (b) ºÆÇÛÉۤηÁÂÖ¤ò¡¤Ê̤ËÄê¤á¤ëÊýË¡¤Ë¤è¤Ã¤Æ¡¤TOPPERS¥×¥í¥¸¥§¥¯¥È¤Ë
28 * (4) ËÜ¥½¥Õ¥È¥¦¥§¥¢¤ÎÍøÍѤˤè¤êľÀÜŪ¤Þ¤¿¤Ï´ÖÀÜŪ¤ËÀ¸¤¸¤ë¤¤¤«¤Ê¤ë»
29 * ³²¤«¤é¤â¡¤¾åµÃøºî¸¢¼Ô¤ª¤è¤ÓTOPPERS¥×¥í¥¸¥§¥¯¥È¤òÌÈÀÕ¤¹¤ë¤³¤È¡¥
31 * ËÜ¥½¥Õ¥È¥¦¥§¥¢¤Ï¡¤ÌµÊݾڤÇÄ󶡤µ¤ì¤Æ¤¤¤ë¤â¤Î¤Ç¤¢¤ë¡¥¾åµÃøºî¸¢¼Ô¤ª
32 * ¤è¤ÓTOPPERS¥×¥í¥¸¥§¥¯¥È¤Ï¡¤ËÜ¥½¥Õ¥È¥¦¥§¥¢¤Ë´Ø¤·¤Æ¡¤¤½¤ÎŬÍѲÄǽÀ¤â
33 * ´Þ¤á¤Æ¡¤¤¤¤«¤Ê¤ëÊݾڤâ¹Ô¤ï¤Ê¤¤¡¥¤Þ¤¿¡¤ËÜ¥½¥Õ¥È¥¦¥§¥¢¤ÎÍøÍѤˤè¤êľ
34 * ÀÜŪ¤Þ¤¿¤Ï´ÖÀÜŪ¤ËÀ¸¤¸¤¿¤¤¤«¤Ê¤ë»³²¤Ë´Ø¤·¤Æ¤â¡¤¤½¤ÎÀÕǤ¤òÉé¤ï¤Ê¤¤¡¥
36 * @(#) $Id: upd72001.c,v 1.4 2003/12/13 06:21:49 hiro Exp $
40 * ¦ÌPD72001ÍÑ ´Ê°×SIO¥É¥é¥¤¥Ð
43 #include <s_services.h>
47 * ¥Ç¥Ð¥¤¥¹¥ì¥¸¥¹¥¿¤Î¥¢¥¯¥»¥¹´Ö³Ö»þ´Ö¡Ênsecñ°Ì¡Ë
49 * 200¤È¤¤¤¦Ãͤˤ¢¤Þ¤êº¬µò¤Ï¤Ê¤¤¡¥
51 #define UPD72001_DELAY 200
54 * ¦ÌPD72001¤Î¥ì¥¸¥¹¥¿¤ÎÈÖ¹æ
56 #define UPD72001_CR0 0x00u /* ¥³¥ó¥È¥í¡¼¥ë¥ì¥¸¥¹¥¿ */
57 #define UPD72001_CR1 0x01u
58 #define UPD72001_CR2 0x02u
59 #define UPD72001_CR3 0x03u
60 #define UPD72001_CR4 0x04u
61 #define UPD72001_CR5 0x05u
62 #define UPD72001_CR10 0x0au
63 #define UPD72001_CR12 0x0cu
64 #define UPD72001_CR14 0x0eu
65 #define UPD72001_CR15 0x0fu
67 #define UPD72001_SR0 0x00u /* ¥¹¥Æ¡¼¥¿¥¹¥ì¥¸¥¹¥¿ */
70 * ¥³¥ó¥È¥í¡¼¥ë¥ì¥¸¥¹¥¿¤ÎÀßÄêÃÍ
72 #define CR_RESET 0x18u /* ¥Ý¡¼¥È¥ê¥»¥Ã¥È¥³¥Þ¥ó¥É */
74 #define CR0_EOI 0x38u /* EOI¡ÊEnd of Interrupt¡Ë*/
76 #define CR1_DOWN 0x00u /* Á´³ä¹þ¤ß¤ò¶Ø»ß */
77 #define CR1_RECV 0x10u /* ¼õ¿®³ä¹þ¤ßµö²Ä¥Ó¥Ã¥È */
78 #define CR1_SEND 0x02u /* Á÷¿®³ä¹þ¤ßµö²Ä¥Ó¥Ã¥È */
80 #define CR3_DEF 0xc1u /* ¥Ç¡¼¥¿ 8bit¡¤¼õ¿®¥¤¥Í¡¼¥Ö¥ë */
81 #define CR4_DEF 0x44u /* ¥¹¥È¥Ã¥×¥Ó¥Ã¥È 1bit¡¤¥Ñ¥ê¥Æ¥£¤Ê¤· */
82 #define CR5_DEF 0xeau /* ¥Ç¡¼¥¿ 8bit¡¤Á÷¿®¥¤¥Í¡¼¥Ö¥ë */
84 #define CR10_DEF 0x00u /* NRZ */
85 #define CR14_DEF 0x07u /* ¥Ü¡¼¥ì¡¼¥È¥¸¥§¥Í¥ì¡¼¥¿¥¤¥Í¡¼¥Ö¥ë */
86 #define CR15_DEF 0x56u /* ¥Ü¡¼¥ì¡¼¥È¥¸¥§¥Í¥ì¡¼¥¿»ÈÍÑ */
88 #define SR0_RECV 0x01u /* ¼õ¿®ÄÌÃÎ¥Ó¥Ã¥È */
89 #define SR0_SEND 0x04u /* Á÷¿®²Äǽ¥Ó¥Ã¥È */
92 * ¥·¥ê¥¢¥ëI/O¥Ý¡¼¥È½é´ü²½¥Ö¥í¥Ã¥¯¤ÎÄêµÁ
94 typedef struct sio_port_initialization_block {
95 VP data; /* ¥Ç¡¼¥¿¥ì¥¸¥¹¥¿¤ÎÈÖÃÏ */
96 VP ctrl; /* ¥³¥ó¥È¥í¡¼¥ë¥ì¥¸¥¹¥¿¤ÎÈÖÃÏ */
98 UB cr3_def; /* CR3¤ÎÀßÄêÃ͡ʼõ¿®¥Ó¥Ã¥È¿ô¡Ë*/
99 UB cr4_def; /* CR4¤ÎÀßÄêÃÍ¡Ê¥¹¥È¥Ã¥×¥Ó¥Ã¥È¡¤¥Ñ¥ê¥Æ¥£¡Ë*/
100 UB cr5_def; /* CR5¤ÎÀßÄêÃÍ¡ÊÁ÷¿®¥Ó¥Ã¥È¿ô¡Ë*/
101 UB brg1_def; /* ¥Ü¡¼¥ì¡¼¥È¾å°Ì¤ÎÀßÄêÃÍ */
102 UB brg2_def; /* ¥Ü¡¼¥ì¡¼¥È²¼°Ì¤ÎÀßÄêÃÍ */
106 * ¥·¥ê¥¢¥ëI/O¥Ý¡¼¥È´ÉÍý¥Ö¥í¥Ã¥¯¤ÎÄêµÁ
108 struct sio_port_control_block {
109 const SIOPINIB *siopinib; /* ¥·¥ê¥¢¥ëI/O¥Ý¡¼¥È½é´ü²½¥Ö¥í¥Ã¥¯ */
110 VP_INT exinf; /* ³ÈÄ¥¾ðÊó */
111 BOOL openflag; /* ¥ª¡¼¥×¥óºÑ¤ß¥Õ¥é¥° */
112 UB cr1; /* CR1¤ÎÀßÄêÃ͡ʳä¹þ¤ßµö²Ä¡Ë*/
113 BOOL getready; /* ʸ»ú¤ò¼õ¿®¤·¤¿¾õÂÖ */
114 BOOL putready; /* ʸ»ú¤òÁ÷¿®¤Ç¤¤ë¾õÂÖ */
118 * ¥·¥ê¥¢¥ëI/O¥Ý¡¼¥È½é´ü²½¥Ö¥í¥Ã¥¯
120 * ID = 1 ¤ò¥Ý¡¼¥ÈB¡¤ID = 2 ¤ò¥Ý¡¼¥ÈA¤ËÂбþ¤µ¤»¤Æ¤¤¤ë¡¥
122 const SIOPINIB siopinib_table[TNUM_SIOP] = {
123 { (VP) TADR_UPD72001_DATAB, (VP) TADR_UPD72001_CTRLB,
124 CR3_DEF, CR4_DEF, CR5_DEF, BRG1_DEF, BRG2_DEF },
126 { (VP) TADR_UPD72001_DATAA, (VP) TADR_UPD72001_CTRLA,
127 CR3_DEF, CR4_DEF, CR5_DEF, BRG1_DEF, BRG2_DEF },
128 #endif /* TNUM_SIOP >= 2 */
132 * ¥·¥ê¥¢¥ëI/O¥Ý¡¼¥È´ÉÍý¥Ö¥í¥Ã¥¯¤Î¥¨¥ê¥¢
134 SIOPCB siopcb_table[TNUM_SIOP];
137 * ¥·¥ê¥¢¥ëI/O¥Ý¡¼¥ÈID¤«¤é´ÉÍý¥Ö¥í¥Ã¥¯¤ò¼è¤ê½Ð¤¹¤¿¤á¤Î¥Þ¥¯¥í
139 #define INDEX_SIOP(siopid) ((UINT)((siopid) - 1))
140 #define get_siopcb(siopid) (&(siopcb_table[INDEX_SIOP(siopid)]))
143 * ¥Ç¥Ð¥¤¥¹¥ì¥¸¥¹¥¿¤Ø¤Î¥¢¥¯¥»¥¹´Ø¿ô
146 upd72001_read_reg(VP addr)
150 val = (UB) upd72001_reb_reg(addr);
151 sil_dly_nse(UPD72001_DELAY);
156 upd72001_write_reg(VP addr, UB val)
158 upd72001_wrb_reg(addr, (VB) val);
159 sil_dly_nse(UPD72001_DELAY);
163 upd72001_read_ctrl(VP addr, UB reg)
165 upd72001_write_reg(addr, reg);
166 return(upd72001_read_reg(addr));
170 upd72001_write_ctrl(VP addr, UB reg, UB val)
172 upd72001_write_reg(addr, reg);
173 upd72001_write_reg(addr, val);
177 upd72001_write_brg(VP addr, UB reg, UB val, UB brg2, UB brg1)
179 upd72001_write_reg(addr, reg);
180 upd72001_write_reg(addr, val);
181 upd72001_write_reg(addr, brg2);
182 upd72001_write_reg(addr, brg1);
183 (void) upd72001_read_reg(addr); /* ¥À¥ß¡¼¥ê¡¼¥É */
187 * ¾õÂÖ¤ÎÆɽФ·¡ÊSR0¤ÎÆɽФ·¡Ë
189 * ¦ÌPD72001¤Ï¡¤¾õÂÖ¡ÊSR0¡Ë¤ò°ìÅÙÆɤà¤È¼õ¿®ÄÌÃΥӥåȤ¬Íî¤Á¤Æ¤·¤Þ¤¦¤¿
190 * ¤á¡¤¾õÂÖ¤òÆɤ߽Ф¹´Ø¿ô¤òÀߤ±¡¤¥·¥ê¥¢¥ëI/O¥Ý¡¼¥È´ÉÍý¥Ö¥í¥Ã¥¯Ãæ¤Î
191 * getready ¤Ë¼õ¿®ÄÌÃξõÂÖ¡¤putready ¤ËÁ÷¿®²Äǽ¾õÂÖ¤òÊݸ¤·¤Æ¤¤¤ë¡ÊÁ÷
192 * ¿®²Äǽ¾õÂÖ¤ÎÊݸ¤ÏÉÔÍפ«¤â¤·¤ì¤Ê¤¤¡Ë¡¥
193 * ¾õÂ֥쥸¥¹¥¿¤òÆɤó¤Ç¤â¼õ¿®ÄÌÃΥӥåȤ¬Íî¤Á¤Ê¤¤¥Ç¥Ð¥¤¥¹¡Ê¤³¤Á¤é¤¬Éá
194 * Ä̤Ȼפï¤ì¤ë¡Ë¤Ç¤Ï¡¤¤³¤Î´Ø¿ô¤ÏɬÍפʤ¤¡¥
197 upd72001_get_stat(SIOPCB *siopcb)
201 sr0 = upd72001_read_ctrl(siopcb->siopinib->ctrl, UPD72001_SR0);
202 if ((sr0 & SR0_RECV) != 0) {
203 siopcb->getready = TRUE;
205 if ((sr0 & SR0_SEND) != 0) {
206 siopcb->putready = TRUE;
211 * ʸ»ú¤ò¼õ¿®¤Ç¤¤ë¤«¡©
214 upd72001_getready(SIOPCB *siopcb)
216 upd72001_get_stat(siopcb);
217 return(siopcb->getready);
221 * ʸ»ú¤òÁ÷¿®¤Ç¤¤ë¤«¡©
224 upd72001_putready(SIOPCB *siopcb)
226 upd72001_get_stat(siopcb);
227 return(siopcb->putready);
231 * ¼õ¿®¤·¤¿Ê¸»ú¤Î¼è½Ð¤·
234 upd72001_getchar(SIOPCB *siopcb)
236 siopcb->getready = FALSE;
237 return((char) upd72001_read_reg(siopcb->siopinib->data));
241 * Á÷¿®¤¹¤ëʸ»ú¤Î½ñ¹þ¤ß
244 upd72001_putchar(SIOPCB *siopcb, char c)
246 siopcb->putready = FALSE;
247 upd72001_write_reg(siopcb->siopinib->data, (UB) c);
251 * EOI¡ÊEnd Of Interrupt¡Ëȯ¹Ô
256 upd72001_write_ctrl((VP) TADR_UPD72001_CTRLA, UPD72001_CR0, CR0_EOI);
260 * SIO¥É¥é¥¤¥Ð¤Î½é´ü²½¥ë¡¼¥Á¥ó
263 upd72001_initialize()
269 * ¥·¥ê¥¢¥ëI/O¥Ý¡¼¥È´ÉÍý¥Ö¥í¥Ã¥¯¤Î½é´ü²½
271 for (siopcb = siopcb_table, i = 0; i < TNUM_SIOP; siopcb++, i++) {
272 siopcb->siopinib = &(siopinib_table[i]);
273 siopcb->openflag = FALSE;
278 * ¥ª¡¼¥×¥ó¤·¤Æ¤¤¤ë¥Ý¡¼¥È¤¬¤¢¤ë¤«¡©
281 upd72001_openflag(void)
284 return(siopcb_table[0].openflag);
285 #else /* TNUM_SIOP < 2 */
286 return(siopcb_table[0].openflag || siopcb_table[1].openflag);
287 #endif /* TNUM_SIOP < 2 */
291 * ¥·¥ê¥¢¥ëI/O¥Ý¡¼¥È¤Î¥ª¡¼¥×¥ó
294 upd72001_opn_por(ID siopid, VP_INT exinf)
297 const SIOPINIB *siopinib;
299 siopcb = get_siopcb(siopid);
300 siopinib = siopcb->siopinib;
302 upd72001_write_reg(siopinib->ctrl, CR_RESET);
303 if (!upd72001_openflag()) {
304 upd72001_write_ctrl((VP) TADR_UPD72001_CTRLA,
306 upd72001_write_ctrl((VP) TADR_UPD72001_CTRLB,
309 siopcb->cr1 = CR1_DOWN;
310 upd72001_write_ctrl(siopinib->ctrl, UPD72001_CR1, siopcb->cr1);
311 upd72001_write_ctrl(siopinib->ctrl, UPD72001_CR4, siopinib->cr4_def);
312 upd72001_write_brg(siopinib->ctrl, UPD72001_CR12,
313 0x01, siopinib->brg2_def, siopinib->brg1_def);
314 upd72001_write_brg(siopinib->ctrl, UPD72001_CR12,
315 0x02, siopinib->brg2_def, siopinib->brg1_def);
316 upd72001_write_ctrl(siopinib->ctrl, UPD72001_CR15, CR15_DEF);
317 upd72001_write_ctrl(siopinib->ctrl, UPD72001_CR14, CR14_DEF);
318 upd72001_write_ctrl(siopinib->ctrl, UPD72001_CR10, CR10_DEF);
319 upd72001_write_ctrl(siopinib->ctrl, UPD72001_CR3, siopinib->cr3_def);
320 upd72001_write_ctrl(siopinib->ctrl, UPD72001_CR5, siopinib->cr5_def);
321 siopcb->exinf = exinf;
322 siopcb->getready = siopcb->putready = FALSE;
323 siopcb->openflag = TRUE;
328 * ¥·¥ê¥¢¥ëI/O¥Ý¡¼¥È¤Î¥¯¥í¡¼¥º
331 upd72001_cls_por(SIOPCB *siopcb)
333 upd72001_write_ctrl(siopcb->siopinib->ctrl, UPD72001_CR1, CR1_DOWN);
334 siopcb->openflag = FALSE;
338 * ¥·¥ê¥¢¥ëI/O¥Ý¡¼¥È¤Ø¤Îʸ»úÁ÷¿®
341 upd72001_snd_chr(SIOPCB *siopcb, char c)
343 if (upd72001_putready(siopcb)) {
344 upd72001_putchar(siopcb, c);
351 * ¥·¥ê¥¢¥ëI/O¥Ý¡¼¥È¤«¤é¤Îʸ»ú¼õ¿®
354 upd72001_rcv_chr(SIOPCB *siopcb)
356 if (upd72001_getready(siopcb)) {
357 return((INT)(UB) upd72001_getchar(siopcb));
363 * ¥·¥ê¥¢¥ëI/O¥Ý¡¼¥È¤«¤é¤Î¥³¡¼¥ë¥Ð¥Ã¥¯¤Îµö²Ä
366 upd72001_ena_cbr(SIOPCB *siopcb, UINT cbrtn)
378 siopcb->cr1 |= cr1_bit;
379 upd72001_write_ctrl(siopcb->siopinib->ctrl, UPD72001_CR1, siopcb->cr1);
383 * ¥·¥ê¥¢¥ëI/O¥Ý¡¼¥È¤«¤é¤Î¥³¡¼¥ë¥Ð¥Ã¥¯¤Î¶Ø»ß
386 upd72001_dis_cbr(SIOPCB *siopcb, UINT cbrtn)
398 siopcb->cr1 &= ~cr1_bit;
399 upd72001_write_ctrl(siopcb->siopinib->ctrl, UPD72001_CR1, siopcb->cr1);
403 * ¥·¥ê¥¢¥ëI/O¥Ý¡¼¥È¤ËÂФ¹¤ë³ä¹þ¤ß½èÍý
406 upd72001_isr_siop(SIOPCB *siopcb)
408 if ((siopcb->cr1 & CR1_RECV) != 0 && upd72001_getready(siopcb)) {
410 * ¼õ¿®ÄÌÃÎ¥³¡¼¥ë¥Ð¥Ã¥¯¥ë¡¼¥Á¥ó¤ò¸Æ¤Ó½Ð¤¹¡¥
412 upd72001_ierdy_rcv(siopcb->exinf);
414 if ((siopcb->cr1 & CR1_SEND) != 0 && upd72001_putready(siopcb)) {
416 * Á÷¿®²Äǽ¥³¡¼¥ë¥Ð¥Ã¥¯¥ë¡¼¥Á¥ó¤ò¸Æ¤Ó½Ð¤¹¡¥
418 upd72001_ierdy_snd(siopcb->exinf);
423 * SIO¤Î³ä¹þ¤ß¥µ¡¼¥Ó¥¹¥ë¡¼¥Á¥ó
428 if (siopcb_table[0].openflag) {
429 upd72001_isr_siop(&(siopcb_table[0]));
432 if (siopcb_table[1].openflag) {
433 upd72001_isr_siop(&(siopcb_table[1]));
435 #endif /* TNUM_SIOP >= 2 */