source: anotherchoice/tags/jsp-1.4.4-full-UTF8/config/armv4/integrator/integrator.c@ 26

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

initial

File size: 9.3 KB
RevLine 
[26]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) 2003 by Advanced Data Controls, Corp
9 * Copyright (C) 2004 by Embedded and Real-Time Systems Laboratory
10 * Graduate School of Information Science, Nagoya Univ., JAPAN
11 *
12 * 上記著作権者
13は,以下の (1)〜(4) の条件か,Free Software Foundation
14 * によってå…
15¬è¡¨ã•ã‚Œã¦ã„ã‚‹ GNU General Public License の Version 2 に記
16 * 述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
17 * を改変したものを含む.以下同じ)を使用・複製・改変・再é…
18å¸ƒï¼ˆä»¥ä¸‹ï¼Œ
19 * 利用と呼ぶ)することを無償で許諾する.
20 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
21 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
22 * スコード中に含まれていること.
23 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
24 * 用できる形で再é…
25å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œå†é…
26å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨
27 * 者
28マニュアルなど)に,上記の著作権表示,この利用条件および下記
29 * の無保証規定を掲載すること.
30 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
31 * 用できない形で再é…
32å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œæ¬¡ã®ã„ずれかの条件を満たすこ
33 * と.
34 * (a) 再é…
35å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨è€…
36マニュアルなど)に,上記の著
37 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
38 * (b) 再é…
39å¸ƒã®å½¢æ…
40‹ã‚’,別に定める方法によって,TOPPERSプロジェクトに
41 * 報告すること.
42 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
43 * 害からも,上記著作権者
44およびTOPPERSプロジェクトをå…
45è²¬ã™ã‚‹ã“と.
46 *
47 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者
48お
49 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
50 * 含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
51 * 接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
52 *
53 * @(#) $Id: integrator.c,v 1.4 2004/05/27 07:32:22 honda Exp $
54 *
55 */
56
57/*
58 * Integrator 内
59部機能用ドライバ
60 */
61#include <s_services.h>
62#include <integrator.h>
63
64
65/*
66 * シリアルI/Oポート初期化ブロック
67 */
68const SIOPINIB siopinib_table[TNUM_SIOP] = {
69 {(VP)UART1_DR,(VP)UART1_CR,(VP)UART1_LCRL,
70 (VP)UART1_LCRM,(VP)UART1_LCRH,(VP)UART1_IIR,
71 (VP)UART1_FR,IRQ_UART1
72 }
73#if TNUM_SIOP >= 2
74 ,
75 {(VP)UART0_DR,(VP)UART0_CR,(VP)UART0_LCRL,
76 (VP)UART0_LCRM,(VP)UART0_LCRH,(VP)UART0_IIR,
77 (VP)UART0_FR,IRQ_UART0
78 }
79
80#endif /* TNUM_SIOP >= 2 */
81};
82
83
84/*
85 * シリアルI/Oポート管理ブロックのエリア
86 */
87SIOPCB siopcb_table[TNUM_SIOP];
88
89
90/*
91 * シリアルI/OポートIDから管理ブロックを取り出すためのマクロ
92 */
93#define INDEX_SIOP(siopid) ((UINT)((siopid) - 1))
94#define get_siopcb(siopid) (&(siopcb_table[INDEX_SIOP(siopid)]))
95
96
97/*
98 * 文字を受信したか?
99 */
100Inline BOOL
101uart_getready(SIOPCB *siopcb)
102{
103 return(((sil_rew_mem((VP)(siopcb->siopinib->flag_register)) & UFR_RXFE)==0));
104}
105
106/*
107 * 文字を送信できるか?
108 */
109Inline BOOL
110uart_putready(SIOPCB *siopcb)
111{
112 return((sil_rew_mem((VP)(siopcb->siopinib->flag_register)) & UFR_TXFF)==0);
113}
114
115/*
116 * 受信した文字の取り出し
117 */
118Inline UB
119uart_getchar(SIOPCB *siopcb)
120{
121 return(sil_rew_mem((VP)(siopcb->siopinib->uart_data)));
122}
123
124/*
125 * 送信する文字の書き込み
126 */
127Inline void
128uart_putchar(SIOPCB *siopcb, UB c)
129{
130 sil_wrw_mem((VP)(siopcb->siopinib->uart_data),c);
131}
132
133/*
134 * 送信割込み許可
135 */
136Inline void
137uart_enable_send(SIOPCB *siopcb)
138{
139 sil_wrw_mem((VP)(siopcb->siopinib->uart_control),
140 (sil_rew_mem((VP)(siopcb->siopinib->uart_control)) | UCR_TIE));
141}
142
143/*
144 * 送信割込み禁止
145 */
146Inline void
147uart_disable_send(SIOPCB *siopcb)
148{
149 sil_wrw_mem((VP)(siopcb->siopinib->uart_control),
150 (sil_rew_mem((VP)(siopcb->siopinib->uart_control)) & ~UCR_TIE));
151}
152
153
154/*
155 * 受信割込み許可
156 */
157Inline void
158uart_enable_rcv(SIOPCB *siopcb)
159{
160 sil_wrw_mem((VP)(siopcb->siopinib->uart_control),
161 (sil_rew_mem((VP)(siopcb->siopinib->uart_control)) | UCR_RIE));
162}
163
164/*
165 * 受信割込み禁止
166 */
167Inline void
168uart_disable_rcv(SIOPCB *siopcb)
169{
170 sil_wrw_mem((VP)(siopcb->siopinib->uart_control),
171 (sil_rew_mem((VP)(siopcb->siopinib->uart_control)) & ~UCR_RIE));
172}
173
174/*
175 * カーネル起動時のログ出力用の初期化
176 */
177void
178init_uart(void){
179 /* Disable Interrupt */
180 sil_wrw_mem((VP)UART1_CR, 0);
181 /* 115200bps */
182 sil_wrw_mem((VP)UART1_LCRL, ULCRL_115200);
183 sil_wrw_mem((VP)UART1_LCRM, ULCRM_115200);
184 /* 8Data, 1Stop, No Parity */
185 sil_wrw_mem((VP)UART1_LCRH, ULCRH_WLEN_8BIT);
186 /* Clear Error Flag */
187 sil_wrw_mem((VP)UART1_ECR,(URSR_OVERRUN|URSR_BREAK|URSR_PARITY|URSR_FRAMING));
188 /* Enabel UART0 */
189 sil_wrw_mem((VP)UART1_CR, UCR_UARTEN|UCR_RIE);
190}
191
192/*
193 * オンチップのUARTからのポーリング出力
194 */
195void
196uart_putc(char c)
197{
198 int i;
199
200 while((sil_rew_mem((VP)(UART1_FR)) & UFR_TXFF));
201
202 sil_wrw_mem((VP)UART1_DR,(VW)c);
203}
204
205
206/*
207 * SIOドライバの初期化ルーチン
208 * 1ポートしかないため,あまり意味はない
209 */
210void
211uart_initialize()
212{
213 SIOPCB *siopcb;
214 UINT i;
215
216 /*
217 * シリアルI/Oポート管理ブロックの初期化
218 */
219 for (siopcb = siopcb_table, i = 0; i < TNUM_SIOP; siopcb++, i++) {
220 siopcb->siopinib = &(siopinib_table[i]);
221 siopcb->openflag = FALSE;
222 siopcb->sendflag = FALSE;
223 }
224}
225
226/*
227 * オープンしているポートがあるか
228 */
229BOOL
230uart_openflag(void)
231{
232 return(siopcb_table[0].openflag);
233}
234
235/*
236 * シリアルI/Oポートのオープン
237 */
238SIOPCB *
239uart_opn_por(ID siopid, VP_INT exinf)
240{
241 int i;
242
243 SIOPCB *siopcb;
244 const SIOPINIB *siopinib;
245
246 siopcb = get_siopcb(siopid);
247 siopinib = siopcb->siopinib;
248
249 /* Disable Interrupt */
250 sil_wrw_mem((VP)siopinib->uart_control, 0);
251 /* 115200bps */
252 sil_wrw_mem((VP)siopinib->linectrl_lo, ULCRL_115200);
253 sil_wrw_mem((VP)siopinib->linectrl_mid, ULCRM_115200);
254
255 /* 8Data, 1Stop, No Parity */
256// sil_wrw_mem((VP)siopinib->linectrl_hi, ULCRH_WLEN_8BIT|ULCRH_FEN);
257 sil_wrw_mem((VP)siopinib->linectrl_hi, ULCRH_WLEN_8BIT);
258
259 /*
260 * Wait をå…
261¥ã‚Œãªã„と直後にbpsがおかしくなる.
262 */
263 for(i = 0; i < 1000; i++);
264
265 /*
266 * 割込み関連の設定
267 */
268 sil_wrw_mem((VP)siopinib->uart_control, UCR_UARTEN|UCR_RIE); /* Enable Interrupt */
269 sil_wrw_mem((VP)IRQ0_ENABLESET,siopinib->irq_bit);/*Enable interrupt register*/
270
271 siopcb->exinf = exinf;
272 siopcb->getready = siopcb->putready = FALSE;
273 siopcb->openflag = TRUE;
274
275 return(siopcb);
276}
277
278
279
280/*
281 * シリアルI/Oポートのクローズ
282 */
283void
284uart_cls_por(SIOPCB *siopcb)
285{
286 sil_wrw_mem((VP)(siopcb->siopinib->uart_control),
287 (sil_rew_mem((VP)(siopcb->siopinib->uart_control))&~UCR_UARTEN)); /* Disable Interrupt */
288
289 siopcb->openflag = FALSE;
290}
291
292/*
293 * シリアルI/Oポートへの文字送信
294 */
295BOOL
296uart_snd_chr(SIOPCB *siopcb, char c)
297{
298 if (uart_putready(siopcb)){
299 uart_putchar(siopcb, c);
300 return(TRUE);
301 }
302 return(FALSE);
303}
304
305/*
306 * シリアルI/Oポートからの文字受信
307 */
308INT
309uart_rcv_chr(SIOPCB *siopcb)
310{
311 if (uart_getready(siopcb)) {
312 return((INT)(UB) uart_getchar(siopcb));
313 }
314 return(-1);
315}
316
317/*
318 * シリアルI/Oポートからのコールバックの許可
319 */
320void
321uart_ena_cbr(SIOPCB *siopcb, UINT cbrtn)
322{
323 switch (cbrtn) {
324 case SIO_ERDY_SND:
325 uart_enable_send(siopcb);
326 break;
327 case SIO_ERDY_RCV:
328 uart_enable_rcv(siopcb);
329 break;
330 }
331}
332
333
334/*
335 * シリアルI/Oポートからのコールバックの禁止
336 */
337void
338uart_dis_cbr(SIOPCB *siopcb, UINT cbrtn)
339{
340 switch (cbrtn) {
341 case SIO_ERDY_SND:
342 uart_disable_send(siopcb);
343 break;
344 case SIO_ERDY_RCV:
345 uart_disable_rcv(siopcb);
346 break;
347 }
348}
349
350
351
352/*
353 * シリアルI/Oポートに対する割込み処理
354 */
355static void
356uart_isr_siop(SIOPCB *siopcb)
357{
358 if (uart_getready(siopcb)) {
359 /*
360 * 受信通知コールバックルーチンを呼び出す.
361 */
362 uart_ierdy_rcv(siopcb->exinf);
363 }
364 if (uart_putready(siopcb)) {
365 /*
366 * 送信可能コールバックルーチンを呼び出す.
367 */
368 uart_ierdy_snd(siopcb->exinf);
369 }
370}
371
372
373
374/*
375 * SIOの割込みサービスルーチン
376 */
377void
378uart_isr0()
379{
380 uart_isr_siop(&(siopcb_table[0]));
381}
382
383#if TNUM_SIOP >= 2
384void
385uart_isr1()
386{
387 uart_isr_siop(&(siopcb_table[1]));
388}
389#endif
Note: See TracBrowser for help on using the repository browser.