source: anotherchoice/tags/jsp-1.4.4-full-UTF8/config/m32r/m3a_2131/hw_serial.c@ 26

Last change on this file since 26 was 26, checked in by ykominami, 12 years ago

initial

File size: 6.0 KB
Line 
1/*
2 * TOPPERS/JSP Kernel
3 * Toyohashi Open Platform for Embedded Real-Time Systems/
4 * Just Standard Profile Kernel
5 *
6 * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
7 * Toyohashi Univ. of Technology, JAPAN
8 *
9 * 上記著作権者
10は,以下の (1)〜(4) の条件か,Free Software Foundation
11 * によってå…
12¬è¡¨ã•ã‚Œã¦ã„ã‚‹ GNU General Public License の Version 2 に記
13 * 述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
14 * を改変したものを含む.以下同じ)を使用・複製・改変・再é…
15å¸ƒï¼ˆä»¥ä¸‹ï¼Œ
16 * 利用と呼ぶ)することを無償で許諾する.
17 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
18 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
19 * スコード中に含まれていること.
20 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
21 * 用できる形で再é…
22å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œå†é…
23å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨
24 * 者
25マニュアルなど)に,上記の著作権表示,この利用条件および下記
26 * の無保証規定を掲載すること.
27 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
28 * 用できない形で再é…
29å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œæ¬¡ã®ã„ずれかの条件を満たすこ
30 * と.
31 * (a) 再é…
32å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨è€…
33マニュアルなど)に,上記の著
34 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
35 * (b) 再é…
36å¸ƒã®å½¢æ…
37‹ã‚’,別に定める方法によって,TOPPERSプロジェクトに
38 * 報告すること.
39 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
40 * 害からも,上記著作権者
41およびTOPPERSプロジェクトをå…
42è²¬ã™ã‚‹ã“と.
43 *
44 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者
45お
46 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
47 * 含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
48 * 接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
49 *
50 * @(#) $Id: hw_serial.c,v 1.1 2007/05/30 08:38:51 honda Exp $
51 */
52
53/*
54 * シリアルI/Oデバイス(SIO)ドライバ(M32102内
55蔵非同期シリアル用)
56 */
57
58#include <sil.h>
59#include <hw_serial.h>
60
61#include <cpu_rename.h>
62#include <sys_rename.h>
63
64SIOPCB siopcb_table[TNUM_PORT];
65
66extern FP InterruptHandlerEntry[];
67
68/*
69 * 作業用関数
70 */
71#define ID_PORT(x) ((x) + 1)
72#define INDEX_PORT(x) ((x) - 1)
73#define GET_SIOPCB(x) (&siopcb_table[INDEX_PORT(x)])
74
75/*
76 * シリアルポートの初期化
77 */
78void
79sio_initialize(void)
80{
81 int i;
82
83 for(i=0;i<TNUM_PORT;i++)
84 {
85 siopcb_table[i].flags = SIO_TYP_M32RUART;
86 siopcb_table[i].port = i;
87 siopcb_table[i].exinf = 0;
88
89 InterruptHandlerEntry[INT_SIO0RCV + (siopcb_table[i].port * 2) - 1] = sio_handler_in;
90 InterruptHandlerEntry[INT_SIO0XMT + (siopcb_table[i].port * 2) - 1] = sio_handler_out;
91 }
92}
93
94/*
95 * シリアルI/Oポートのオープン
96 */
97SIOPCB *
98sio_opn_por(ID siopid, VP_INT exinf)
99{
100 SIOPCB * siopcb = GET_SIOPCB(siopid);
101
102 siopcb->exinf = exinf;
103
104 switch(SIO_TYP(siopcb->flags)) {
105 case SIO_TYP_M32RUART:
106
107 /* UART初期化 */
108 sil_wrb_mem((void *)(SIOCR(siopcb->port)+3), 0);
109
110 /* ポートを開く(UART0) */
111 sil_wrb_mem((void *)PDATA(5), 0);
112 sil_wrb_mem((void *)PDIR(5), 0x80);
113
114 /* UART, Non-parity, 1 stop-bit */
115 sil_wrb_mem((void *)(SIOMOD0(siopcb->port)+3), 0);
116
117 /* 8bit, internal clock */
118 sil_wrh_mem((void *)(SIOMOD1(siopcb->port)+2), 0x0800);
119
120 /* M32R(32102) - f(BLK)=16MHzで115200bps */
121 sil_wrh_mem((void *)(SIOBAUR(siopcb->port)+2), SERIAL_CLKDIV);
122 sil_wrb_mem((void *)(SIORBAUR(siopcb->port)+3), SERIAL_CLKCMP);
123
124 /* 送受信割込み発生許可 */
125 sil_wrh_mem((void *)(SIOTRCR(siopcb->port)+2), 0x0006);
126
127 /* ステータスクリア, 送受信動作開始 */
128 sil_wrb_mem((void *)(SIOCR(siopcb->port)+2), 0x3);
129 sil_wrb_mem((void *)(SIOCR(siopcb->port)+3), 0x3);
130
131 /* 受信割込み受付許可 */
132 sil_wrh_mem((void *)(ICUCR(SIO,siopcb->port)+2), 0x1000);
133 sil_wrh_mem((void *)(ICUCR(SIO,siopcb->port)+6), 0x1000);
134
135 /* TxD,RxDピン有効(UART0) */
136 sil_wrh_mem((void *)PMOD(5), 0x5500);
137
138 break;
139 }
140
141 return siopcb;
142}
143
144/*
145 * シリアルI/Oポートのクローズ
146 */
147void
148sio_cls_por(SIOPCB *siopcb)
149{
150 switch(SIO_TYP(siopcb->flags))
151 {
152 case SIO_TYP_M32RUART:
153 /* 送受信動作を禁止する */
154 sil_wrb_mem((void *)(SIOCR(siopcb->port)+3), 0);
155 break;
156 }
157}
158
159/*
160 * シリアルI/Oポートからの文字受信
161 */
162INT sio_rcv_chr(SIOPCB * siopcb)
163{
164 switch(SIO_TYP(siopcb->flags))
165 {
166 case SIO_TYP_M32RUART:
167 return sil_reb_mem((void *)(SIORXB(siopcb->port)+3));
168 }
169
170 return -1;
171}
172
173
174/*
175 * 文字を受信したかをチェック
176 */
177
178inline BOOL
179hw_port_getready(SIOPCB *p)
180{
181 switch(SIO_TYP(p->flags))
182 {
183 case SIO_TYP_M32RUART:
184 return (sil_reb_mem((void *)(SIOSTS(p->port)+3)) & 0x4) != 0 ? TRUE : FALSE;
185 }
186 return FALSE;
187}
188
189/*
190 * シリアルI/Oポートからのコールバック許可
191 */
192void sio_ena_cbr(SIOPCB * siopcb, UINT cbrtn)
193{}
194
195/*
196 * シリアルI/Oポートからのコールバック禁止
197 */
198void sio_dis_cbr(SIOPCB * siopcb, UINT cbrtn)
199{}
200
201void sio_handler_in(void)
202{
203 int port;
204
205 for(port = 0; port < TNUM_PORT; ++ port)
206 {
207 if( hw_port_getready(&siopcb_table[port]) == TRUE )
208 sio_ierdy_rcv(GET_SIOPCB(ID_PORT(port))->exinf);
209 }
210}
211
212void sio_handler_out(void)
213{
214 int port;
215
216 for(port = 0; port < TNUM_PORT; ++ port)
217 {
218 if((siopcb_table[port].flags & SIO_STS_SENDING) != 0)
219 {
220 /* 送信ステータス初期化 */
221 sil_wrb_mem((void *)(SIOCR(port)+2), 0x1);
222 siopcb_table[port].flags &= ~SIO_STS_SENDING;
223
224 sio_ierdy_snd(GET_SIOPCB(ID_PORT(port))->exinf);
225 }
226 }
227}
Note: See TracBrowser for help on using the repository browser.