source: anotherchoice/tags/jsp-1.4.4-full-UTF8/pdic/simple_sio/st16c2550.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: 10.9 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: st16c2550.c,v 1.4 2005/11/12 15:00:43 honda Exp $
51 */
52
53/*
54 * ST16C2550 用 簡易SIOドライバ
55 */
56#include <s_services.h>
57#include <st16c2550.h>
58
59/*
60 * 各レジスタのオフセット
61 */
62#define ST16C_RHR 0x00 /* H LCR bit7=0 Read */
63#define ST16C_THR 0x00 /* H LCR bit7=0 Write */
64#define ST16C_DLL 0x00 /* H LCR bit7=1 */
65#define ST16C_IER 0x02 /* H LCR bit7=0 */
66#define ST16C_DLM 0x02 /* H LCR bit7=1 */
67#define ST16C_ISR 0x04 /* H Read */
68#define ST16C_FCR 0x04 /* H Write */
69#define ST16C_LCR 0x06 /* H */
70#define ST16C_MCR 0x08 /* H */
71#define ST16C_LSR 0x0a /* H Read */
72#define ST16C_MSR 0x0c /* H Read */
73#define ST16C_SPR 0x0e /* H */
74
75#define ISR_TX 0x02 /* 送信割り込み発生 */
76#define IER_TX 0x02 /* 送信割り込み許可 */
77#define ISR_RX 0x01 /* 受信割り込み発生 */
78#define IER_RX 0x01 /* 受信割り込み許可 */
79
80#define LCR_DL_MODE 0x80 /* Divisor Enable */
81#define LCR_VAL 0x03 /* 8bit,1stop,Noparity,No break */
82#define FCR_FIFO_DISABLE 0x00
83
84#define LSR_RX_DATA_READY 0x01
85#define LSR_TX_EMPTY 0x20
86
87#define MCR_INT_ENABLE 0x08
88
89/*
90 * 115200bpsに設定
91 * 4 = (7372800Hz)/(115200*16)
92 */
93#define DLM_VAL 0x00
94#define DLL_VAL 0x04
95
96
97
98
99/*
100 * シリアルI/Oポート初期化ブロック
101 */
102const SIOPINIB siopinib_table[TNUM_SIOP] = {
103 {ST16C_CHB, LCR_VAL, DLM_VAL, DLL_VAL, PINTER_PINT7E},
104#if TNUM_SIOP > 2
105 {ST16C_CHA, LCR_VAL, DLM_VAL, DLL_VAL, PINTER_PINT6E},
106#endif /* TNUM_SIOP > 2 */
107};
108
109/*
110 * シリアルI/Oポート初期化ブロックの取出し
111 */
112#define INDEX_SIOPINIB(siopid) ((UINT)((siopid) - 1))
113#define get_siopinib(siopid) (&(siopinib_table[INDEX_SIOPINIB(siopid)]))
114
115
116/*
117 * シリアルI/Oポート管理ブロックのエリア
118 */
119SIOPCB siopcb_table[TNUM_SIOP];
120
121/*
122 * シリアルI/OポートIDから管理ブロックを取り出すためのマクロ
123 */
124#define INDEX_SIOP(siopid) ((UINT)((siopid) - 1))
125#define get_siopcb(siopid) (&(siopcb_table[INDEX_SIOP(siopid)]))
126
127Inline void
128st16c_write(UW addr, UW offset, UB val)
129{
130 sil_wrh_mem((VP)(addr + offset),val);
131}
132
133Inline UB
134st16c_read(UW addr, UW offset)
135{
136 return(sil_reh_mem((VP)(addr + offset)));
137}
138
139
140/*
141 * 文字を受信したか?
142 */
143Inline BOOL
144st16c_getready(SIOPCB *siopcb)
145{
146 UH status;
147
148 status = st16c_read(siopcb->siopinib->reg_base, ST16C_LSR);
149
150 return((status & LSR_RX_DATA_READY));
151}
152
153/*
154 * 文字を送信できるか?
155 */
156Inline BOOL
157st16c_putready(SIOPCB *siopcb)
158{
159 UH status;
160
161 status = st16c_read(siopcb->siopinib->reg_base, ST16C_LSR);
162
163 return (status & LSR_TX_EMPTY);
164}
165
166/*
167 * 受信した文字の取り出し
168 */
169Inline UB
170st16c_getchar(SIOPCB *siopcb)
171{
172 return(st16c_read(siopcb->siopinib->reg_base,ST16C_RHR));
173}
174
175/*
176 * 送信する文字の書き込み
177 */
178Inline void
179st16c_putchar(SIOPCB *siopcb, UB c)
180{
181 st16c_write(siopcb->siopinib->reg_base, ST16C_THR, c);
182}
183
184/*
185 * 送信割込み許可
186 */
187Inline void
188st16c_enable_send(SIOPCB *siopcb)
189{
190 st16c_write(siopcb->siopinib->reg_base, ST16C_IER,
191 (st16c_read(siopcb->siopinib->reg_base,ST16C_IER) | IER_TX));
192}
193
194/*
195 * 送信割込み禁止
196 */
197Inline void
198st16c_disable_send(SIOPCB *siopcb)
199{
200 st16c_write(siopcb->siopinib->reg_base, ST16C_IER,
201 (st16c_read(siopcb->siopinib->reg_base, ST16C_IER) & ~IER_TX));
202
203}
204
205/*
206 * 受信割込み許可
207 */
208Inline void
209st16c_enable_rcv(SIOPCB *siopcb)
210{
211 st16c_write(siopcb->siopinib->reg_base, ST16C_IER,
212 (st16c_read(siopcb->siopinib->reg_base,ST16C_IER) | IER_RX));
213}
214
215/*
216 * 受信割込み禁止
217 */
218Inline void
219st16c_disable_rcv(SIOPCB *siopcb)
220{
221 st16c_write(siopcb->siopinib->reg_base, ST16C_IER,
222 (st16c_read(siopcb->siopinib->reg_base, ST16C_IER) & ~IER_RX));
223
224}
225
226
227/*
228 * SIOドライバの初期化ルーチン
229 */
230void
231st16c2550_initialize()
232{
233 SIOPCB *siopcb;
234 UINT i;
235
236 /*
237 * シリアルI/Oポート管理ブロックの初期化
238 */
239 for (siopcb = siopcb_table, i = 0; i < TNUM_SIOP; siopcb++, i++) {
240 siopcb->siopinib = &(siopinib_table[i]);
241 siopcb->openflag = FALSE;
242 siopcb->sendflag = FALSE;
243 }
244}
245
246
247/*
248 *
249 */
250void
251st16c2550_init_siopinib(const SIOPINIB *siopinib)
252{
253 /*
254 * 分周比の設定
255 */
256 /* Divisor Enable */
257 st16c_write(siopinib->reg_base, ST16C_LCR,
258 (st16c_read(siopinib->reg_base, ST16C_LCR) | LCR_DL_MODE));
259 st16c_write(siopinib->reg_base, ST16C_DLL, siopinib->dll_val);
260 st16c_write(siopinib->reg_base, ST16C_DLM, siopinib->dlm_val);
261 /* Divisor Disable */
262 st16c_write(siopinib->reg_base, ST16C_LCR,
263 (st16c_read(siopinib->reg_base, ST16C_LCR) & ~LCR_DL_MODE));
264
265 /* モード設定 */
266 st16c_write(siopinib->reg_base, ST16C_LCR, siopinib->lcr_val);
267
268 /* FIFO Disable */
269 st16c_write(siopinib->reg_base, ST16C_FCR, FCR_FIFO_DISABLE);
270
271 /* 割込み禁止 */
272 st16c_write(siopinib->reg_base, ST16C_IER, 0x00);
273}
274
275
276/*
277 * カーネル起動時のバーナー出力用の初期化
278 */
279void
280st16c2550_init(void)
281{
282
283 st16c2550_init_siopinib(get_siopinib(1));
284#if TNUM_SIOP > 2
285 st16c2550_init_siopinib(get_siopinib(2));
286#endif /* TNUM_SIOP > 2 */
287
288}
289
290/*
291 * オープンしているポートがあるか
292 */
293BOOL
294st16c2550_openflag(void)
295{
296#if TNUM_SIOP < 2
297 return(siopcb_table[0].openflag);
298#else /* TNUM_SIOP < 2 */
299 return(siopcb_table[0].openflag || siopcb_table[1].openflag);
300#endif /* TNUM_SIOP < 2 */
301}
302
303
304/*
305 * シリアルI/Oポートのオープン
306 */
307SIOPCB *
308st16c2550_opn_por(ID siopid, VP_INT exinf)
309{
310 SIOPCB *siopcb;
311 const SIOPINIB *siopinib;
312
313 siopcb = get_siopcb(siopid);
314 siopinib = siopcb->siopinib;
315
316 /*
317 * 初期化
318 */
319 st16c2550_init_siopinib(siopcb->siopinib);
320
321 /* 受信割込み許可 */
322 st16c_write(siopcb->siopinib->reg_base, ST16C_IER, IER_RX);
323
324 /* 割込み線をイネーブル */
325 st16c_write(siopcb->siopinib->reg_base, ST16C_MCR, MCR_INT_ENABLE);
326
327 siopcb->exinf = exinf;
328 siopcb->getready = siopcb->putready = FALSE;
329 siopcb->openflag = TRUE;
330
331 return(siopcb);
332}
333
334/*
335 * シリアルI/Oポートのクローズ
336 */
337void
338st16c2550_cls_por(SIOPCB *siopcb)
339{
340 /* 割込み禁止 */
341 st16c_write(siopcb->siopinib->reg_base, ST16C_IER, 0x00);
342 siopcb->openflag = FALSE;
343}
344
345
346/*
347 * シリアルI/Oポートへのポーリングでの出力
348 */
349void
350st16c2550_pol_putc(char c, ID siopid)
351{
352 const SIOPINIB *siopinib;
353
354 siopinib = get_siopinib(siopid);
355
356 while((st16c_read(siopinib->reg_base, ST16C_LSR) & LSR_TX_EMPTY)
357 != LSR_TX_EMPTY)
358 ;
359 st16c_write(siopinib->reg_base, ST16C_THR, c);
360}
361
362
363/*
364 * シリアルI/Oポートへの文字送信
365 */
366BOOL
367st16c2550_snd_chr(SIOPCB *siopcb, char c)
368{
369 if (st16c_putready(siopcb)){
370 st16c_putchar(siopcb, c);
371 return(TRUE);
372 }
373 return(FALSE);
374}
375
376/*
377 * シリアルI/Oポートからの文字受信
378 */
379INT
380st16c2550_rcv_chr(SIOPCB *siopcb)
381{
382 if (st16c_getready(siopcb)) {
383 return((INT)(UB) st16c_getchar(siopcb));
384 }
385 return(-1);
386}
387
388
389
390
391
392/*
393 * シリアルI/Oポートからのコールバックの許可
394 */
395void
396st16c2550_ena_cbr(SIOPCB *siopcb, UINT cbrtn)
397{
398
399 switch (cbrtn) {
400 case SIO_ERDY_SND:
401 st16c_enable_send(siopcb);
402 break;
403 case SIO_ERDY_RCV:
404 st16c_enable_rcv(siopcb);
405 break;
406 }
407}
408
409/*
410 * シリアルI/Oポートからのコールバックの禁止
411 */
412void
413st16c2550_dis_cbr(SIOPCB *siopcb, UINT cbrtn)
414{
415 switch (cbrtn) {
416 case SIO_ERDY_SND:
417 st16c_disable_send(siopcb);
418 break;
419 case SIO_ERDY_RCV:
420 st16c_disable_rcv(siopcb);
421 break;
422 }
423}
424
425/*
426 * シリアルI/Oポートに対する割込み処理
427 */
428static void
429st16c2550_isr_siop(SIOPCB *siopcb)
430{
431 if (st16c_getready(siopcb)) {
432 /*
433 * 受信通知コールバックルーチンを呼び出す.
434 */
435 st16c2550_ierdy_rcv(siopcb->exinf);
436 }
437 if (st16c_putready(siopcb)) {
438 /*
439 * 送信可能コールバックルーチンを呼び出す.
440 */
441 st16c2550_ierdy_snd(siopcb->exinf);
442 }
443}
444
445/*
446 * SIOの割込みサービスルーチン
447 */
448void
449st16c2550_isr()
450{
451 st16c2550_isr_siop(&(siopcb_table[0]));
452}
Note: See TracBrowser for help on using the repository browser.