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

Last change on this file since 363 was 363, checked in by ykominami, 5 years ago

add tags/jsp-1.4.4-full-UTF8

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