source: anotherchoice/tags/jsp-1.4.4-full-UTF8/config/lm32/ecp2/lm32.c

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

add tags/jsp-1.4.4-full-UTF8

  • Property svn:executable set to *
File size: 7.6 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: lm32.c,v 1.14 2007/07/27 11:28:44 honda Exp $
51 */
52
53#include <s_services.h>
54#include <lm32.h>
55
56const SIOPINIB siopinib_table[TNUM_SIOP] = {
57 {
58 (VP)UART1_RX_TX,
59 (VP)UART1_IER,
60 (VP)UART1_IIR,
61 (VP)UART1_LCR,
62 (VP)UART1_MCR,
63 (VP)UART1_LSR,
64 (VP)UART1_MSR,
65 (VP)UART1_DIV
66 }
67#if TNUM_SIOP >= 2
68 ,
69 {
70 (VP)UART2_RX_TX,
71 (VP)UART2_IER,
72 (VP)UART2_IIR,
73 (VP)UART2_LCR,
74 (VP)UART2_MCR,
75 (VP)UART2_LSR,
76 (VP)UART2_MSR,
77 (VP)UART2_DIV
78 }
79#endif /* TNUM_SIOP >= 2 */
80};
81
82SIOPCB siopcb_table[TNUM_SIOP];
83
84#define INDEX_SIOP(siopid) ((UINT)((siopid) - 1))
85#define get_siopcb(siopid) (&(siopcb_table[INDEX_SIOP(siopid)]))
86
87Inline BOOL
88uart_getready(SIOPCB *siopcb)
89{
90 return(sil_rew_mem((VP)(siopcb->siopinib->lsr)) & UART_LSR_RX_RDY_MASK);
91}
92
93Inline BOOL
94uart_putready(SIOPCB *siopcb)
95{
96 return(sil_rew_mem((VP)(siopcb->siopinib->lsr)) & UART_LSR_TX_RDY_MASK);
97}
98
99Inline UB
100uart_getchar(SIOPCB *siopcb)
101{
102 return(sil_rew_mem((VP)(siopcb->siopinib->rxtx)));
103}
104
105Inline void
106uart_putchar(SIOPCB *siopcb, UB c)
107{
108 sil_wrw_mem((VP)(siopcb->siopinib->rxtx), c);
109}
110
111Inline void
112uart_enable_send(SIOPCB *siopcb)
113{
114 const SIOPINIB *siopinib;
115 siopinib = siopcb->siopinib;
116 siopcb->ier_snapshot |= UART_IER_TX_INT_MASK;
117 sil_wrw_mem((VP)siopinib->ier, siopcb->ier_snapshot);
118}
119
120Inline void
121uart_disable_send(SIOPCB *siopcb)
122{
123 const SIOPINIB *siopinib;
124 siopinib = siopcb->siopinib;
125 siopcb->ier_snapshot &= (~UART_IER_TX_INT_MASK);
126 sil_wrw_mem((VP)siopinib->ier, siopcb->ier_snapshot);
127}
128
129Inline void
130uart_enable_rcv(SIOPCB *siopcb)
131{
132 const SIOPINIB *siopinib;
133 siopinib = siopcb->siopinib;
134 siopcb->ier_snapshot |= UART_IER_RX_INT_MASK;
135 sil_wrw_mem((VP)siopinib->ier, siopcb->ier_snapshot);
136}
137
138Inline void
139uart_disable_rcv(SIOPCB *siopcb)
140{
141 const SIOPINIB *siopinib;
142 siopinib = siopcb->siopinib;
143 siopcb->ier_snapshot &= (~UART_IER_RX_INT_MASK);
144 sil_wrw_mem((VP)siopinib->ier, siopcb->ier_snapshot);
145}
146
147void
148init_uart(void)
149{
150 volatile unsigned int divisor;
151 UW sr;
152
153 sil_wrw_mem((VP)UART1_IER, 0);
154
155 /* 8Data, 1Stop, No Parity*/
156 sil_wrw_mem((VP)UART1_LCR, 0x3);
157
158 /* 115200bps */
159 divisor = ((1048576.0 * (DEFAULT_UART_BAUDRATE/100)) / (MICO32_CPU_CLOCK_HZ/100)) + 0.5;
160 //divisor = 0x12e0;
161 sil_wrw_mem((VP)UART1_DIV, divisor);
162
163 sil_wrw_mem((VP)UART1_IER, UART_IER_RX_INT_MASK);
164}
165
166void
167uart_putc(char c)
168{
169 volatile unsigned int lsr;
170
171 while(1)
172 {
173 lsr = sil_rew_mem((VP)(UART1_LSR));
174 if(lsr & UART_LSR_TX_RDY_MASK)
175 {
176 sil_wrw_mem((VP)UART1_RX_TX, (VW)c);
177 return;
178 }
179 }
180}
181
182void
183uart_initialize()
184{
185 SIOPCB *siopcb;
186 UINT i;
187
188 for (siopcb = siopcb_table, i = 0; i < TNUM_SIOP; siopcb++, i++) {
189 siopcb->siopinib = &(siopinib_table[i]);
190 siopcb->openflag = FALSE;
191 siopcb->sendflag = FALSE;
192 }
193}
194
195BOOL
196uart_openflag(void)
197{
198 return(siopcb_table[0].openflag);
199}
200
201SIOPCB *
202uart_opn_por(ID siopid, VP_INT exinf)
203{
204 SIOPCB *siopcb;
205 const SIOPINIB *siopinib;
206 volatile unsigned int divisor;
207 UW sr;
208
209 siopcb = get_siopcb(siopid);
210 siopinib = siopcb->siopinib;
211
212 sil_wrw_mem((VP)siopinib->ier, 0);
213
214 /* 8Data, 1Stop, No Parity*/
215 sil_wrw_mem((VP)siopinib->lcr, 0x3);
216
217 /* 115200bps */
218 divisor = ((1048576.0 * (DEFAULT_UART_BAUDRATE/100)) / (MICO32_CPU_CLOCK_HZ/100)) + 0.5;
219 //divisor = 0x12e0;
220 sil_wrw_mem((VP)siopinib->div, divisor);
221
222 siopcb->ier_snapshot = UART_IER_RX_INT_MASK;
223 sil_wrw_mem((VP)siopinib->ier, siopcb->ier_snapshot);
224
225 Asm("rcsr %0, im" : "=r"(sr));
226 sr |= (1 << INHNO_SIO1);
227 Asm("wcsr im, %0" : : "r"(sr) );
228
229 siopcb->exinf = exinf;
230 siopcb->getready = siopcb->putready = FALSE;
231 siopcb->openflag = TRUE;
232
233 return(siopcb);
234}
235
236void
237uart_cls_por(SIOPCB *siopcb)
238{
239 const SIOPINIB *siopinib;
240 siopinib = siopcb->siopinib;
241 sil_wrw_mem((VP)siopinib->ier, 0);
242 siopcb->openflag = FALSE;
243}
244
245BOOL
246uart_snd_chr(SIOPCB *siopcb, char c)
247{
248 if (uart_putready(siopcb)){
249 uart_putchar(siopcb, c);
250 return(TRUE);
251 }
252 return(FALSE);
253}
254
255INT
256uart_rcv_chr(SIOPCB *siopcb)
257{
258 if (uart_getready(siopcb)) {
259 return((INT)(UB) uart_getchar(siopcb));
260 }
261 return(-1);
262}
263
264void
265uart_ena_cbr(SIOPCB *siopcb, UINT cbrtn)
266{
267 switch (cbrtn) {
268 case SIO_ERDY_SND:
269 uart_enable_send(siopcb);
270 break;
271 case SIO_ERDY_RCV:
272 uart_enable_rcv(siopcb);
273 break;
274 }
275}
276
277void
278uart_dis_cbr(SIOPCB *siopcb, UINT cbrtn)
279{
280 switch (cbrtn) {
281 case SIO_ERDY_SND:
282 uart_disable_send(siopcb);
283 break;
284 case SIO_ERDY_RCV:
285 uart_disable_rcv(siopcb);
286 break;
287 }
288}
289
290static void
291uart_isr_siop(SIOPCB *siopcb)
292{
293 volatile UW iir;
294
295 iir = sil_rew_mem((VP)(siopcb->siopinib->iir));
296
297 if (uart_getready(siopcb)) {
298 uart_ierdy_rcv(siopcb->exinf);
299 }
300 if (uart_putready(siopcb)) {
301 uart_ierdy_snd(siopcb->exinf);
302 }
303}
304
305void
306uart_isr0()
307{
308 uart_isr_siop(&(siopcb_table[0]));
309}
310
311#if TNUM_SIOP >= 2
312void
313uart_isr1()
314{
315 uart_isr_siop(&(siopcb_table[1]));
316}
317#endif
318
Note: See TracBrowser for help on using the repository browser.