source: anotherchoice/tags/jsp-1.4.4-full-UTF8/config/sh2/sh7145sci.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 * Copyright (C) 2001-2003 by Industrial Technology Institute,
9 * Miyagi Prefectural Government, JAPAN
10 * Copyright (C) 2002-2004 by Hokkaido Industrial Research Institute, 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: sh7145sci.c,v 1.3 2005/07/06 00:45:07 honda Exp $
54 */
55
56/*
57 * SH2内
58蔵シリアルコミュニケーションインタフェースSCI用 簡易ドライバ
59 */
60
61#include <s_services.h>
62#include "sh7145sci.h"
63
64/*
65 * シリアルI/Oポート初期化ブロック
66 */
67#ifndef GDB_STUB
68const SIOPINIB siopinib_table[TNUM_PORT] = {
69 {0xffff81b0, BRR9600, 0x0, 6}, /* SCI1 */
70#if TNUM_PORT >= 2
71 {0xffff81a0, BRR9600, 0x0, 6}, /* SCI0 */
72#endif /* TNUM_PORT >= 2 */
73};
74#else /* GDB_STUB */
75const SIOPINIB siopinib_table[TNUM_PORT] = {
76 {0xffff81a0, BRR9600, 0x0, 6}, /* SCI0 */
77};
78#endif /* GDB_STUB */
79
80
81/*
82 * シリアルI/Oポート管理ブロックのエリア
83 */
84static SIOPCB siopcb_table[TNUM_PORT];
85
86/*
87 * シリアルI/OポートIDから管理ブロックを取り出すためのマクロ
88 */
89 /* ポートIDからデバイス番号を求めるマクロ */
90#define INDEX_SIOP(siopid) ((UINT)((siopid) - 1))
91#define get_siopcb(siopid) (&(siopcb_table[INDEX_SIOP(siopid)]))
92
93/*
94 * 文字を受信できるか?
95 */
96Inline BOOL
97sh2sci_getready (SIOPCB * siopcb)
98{
99 /* レシーブデータレジスタフル・フラグのチェック */
100 return (sil_reb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SSR)) &
101 SSR_RDRF);
102}
103
104/*
105 * 文字を送信できるか?
106 */
107Inline BOOL
108sh2sci_putready (SIOPCB * siopcb)
109{
110 /* トランスミットデータレジスタエンプティ・フラグのチェック */
111 return (sil_reb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SSR)) &
112 SSR_TDRE);
113}
114
115/*
116 * 受信した文字の取出し
117 */
118Inline char
119sh2sci_getchar (SIOPCB * siopcb)
120{
121 char data;
122
123 data = sil_reb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_RDR));
124 /* レシーブデータレジスタフル・フラグのクリア */
125 sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SSR),
126 sil_reb_mem ((VB *) (siopcb->siopinib->reg_base +
127 SCI_SSR)) & ~SSR_RDRF);
128 return data;
129}
130
131/*
132 * 送信する文字の書込み
133 */
134Inline void
135sh2sci_putchar (SIOPCB * siopcb, char c)
136{
137 sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_TDR), c);
138 sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SSR),
139 sil_reb_mem ((VB *) (siopcb->siopinib->reg_base +
140 SCI_SSR)) & ~SSR_TDRE);
141}
142
143/*
144 * SIOドライバの初期化ルーチン
145 */
146void
147sh2sci_initialize ()
148{
149 SIOPCB *siopcb;
150 UINT i;
151
152 /*
153 * シリアルI/Oポート管理ブロックの初期化
154 */
155 for (siopcb = siopcb_table, i = 0; i < TNUM_PORT; siopcb++, i++) {
156 siopcb->openflag = FALSE;
157 siopcb->siopinib = (&siopinib_table[i]);
158 }
159}
160
161/*
162 * オープンしているポートがあるか?
163 */
164BOOL
165sh2sci_openflag (ID siopid)
166{
167 return (siopcb_table[siopid - 1].openflag);
168}
169
170/*
171 * シリアルI/Oポートのオープン
172 */
173SIOPCB *
174sh2sci_opn_por (ID siopid, VP_INT exinf)
175{
176 SIOPCB *siopcb = get_siopcb (siopid);
177
178 /* 送受信停止 */
179 sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SCR), 0x00);
180
181 /* SCIデータå…
182¥å‡ºåŠ›ãƒãƒ¼ãƒˆã®è¨­å®š */
183 /* ピンアサイン */
184 /* sys_initializeで設定 */
185
186 /* 送受信フォーマット */
187 /* 調歩同期式 */
188 /* 8ビット、パリティなし */
189 /* ストップビットレングス:1 */
190 /* クロックセレクト */
191
192 sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SMR),
193 siopcb->siopinib->smr);
194 sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_BRR),
195 (VB) siopcb->siopinib->brr);
196
197 /*
198 * ボーレートの設定後、1カウント分待
199たなければならない。
200 */
201 sil_dly_nse (sh2sci_DELAY); /* 値はsh1と同じ */
202
203 /* エラーフラグをクリア */
204 sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SSR),
205 sil_reb_mem ((VB *) (siopcb->siopinib->reg_base +
206 SCI_SSR)) & ~(SSR_ORER | SSR_FER |
207 SSR_PER));
208 /*送受信許可、受信割り込み許可 */
209 sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SCR),
210 (VB) (SCI_RIE | SCI_TE | SCI_RE));
211
212 siopcb->exinf = exinf;
213 siopcb->openflag = TRUE;
214 return (siopcb);
215}
216
217/*
218 * シリアルI/Oポートのクローズ
219 */
220void
221sh2sci_cls_por (SIOPCB * siopcb)
222{
223 /* 送受信停止、割込み禁止 */
224 sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SCR),
225 sil_reb_mem ((VB *) (siopcb->siopinib->reg_base +
226 SCI_SCR)) & (VB) ~ (SCI_TIE | SCI_RIE |
227 SCI_TE | SCI_RE));
228 siopcb->openflag = FALSE;
229}
230
231/*
232 * シリアルI/Oポートへの文字送信
233 */
234BOOL
235sh2sci_snd_chr (SIOPCB * siopcb, char c)
236{
237 if (sh2sci_putready (siopcb)) {
238 sh2sci_putchar (siopcb, c);
239 return (TRUE);
240 }
241 return (FALSE);
242}
243
244/*
245 * シリアルI/Oポートからの文字受信
246 */
247INT
248sh2sci_rcv_chr (SIOPCB * siopcb)
249{
250 if (sh2sci_getready (siopcb)) {
251 return ((INT) (UB) sh2sci_getchar (siopcb));
252 /* (UB)でキャストするのはゼロ拡張にするため */
253 }
254 return (-1);
255}
256
257/*
258 * シリアルI/Oポートからのコールバックの許可
259 */
260void
261sh2sci_ena_cbr (SIOPCB * siopcb, UINT cbrtn)
262{
263 switch (cbrtn) {
264 case SIO_ERDY_SND: /* 送信割り込み要求を許可 */
265 sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SCR),
266 sil_reb_mem ((VB *) (siopcb->siopinib->reg_base +
267 SCI_SCR)) | SCI_TIE);
268 break;
269 case SIO_ERDY_RCV: /* 受信割り込み要求を許可 */
270 sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SCR),
271 sil_reb_mem ((VB *) (siopcb->siopinib->reg_base +
272 SCI_SCR)) | SCI_RIE);
273 break;
274 }
275}
276
277/*
278 * シリアルI/Oポートからのコールバックの禁止
279 */
280void
281sh2sci_dis_cbr (SIOPCB * siopcb, UINT cbrtn)
282{
283 switch (cbrtn) {
284 case SIO_ERDY_SND: /* 送信割り込み要求を禁止 */
285 sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SCR),
286 sil_reb_mem ((VB *) (siopcb->siopinib->reg_base +
287 SCI_SCR)) & ~SCI_TIE);
288 break;
289 case SIO_ERDY_RCV: /* 受信割り込み要求を禁止 */
290 sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SCR),
291 sil_reb_mem ((VB *) (siopcb->siopinib->reg_base +
292 SCI_SCR)) & ~SCI_RIE);
293 break;
294 }
295}
296
297/*
298 * シリアルI/Oポートに対する送信割込み処理
299 */
300Inline void
301sh2sci_isr_siop_out (SIOPCB * siopcb)
302{
303 VB scr0 = sil_reb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SCR));
304
305 if ((scr0 & SCI_TIE) != 0 && sh2sci_putready (siopcb)) {
306 /*
307 * 送信通知コールバックルーチンを呼び出す.
308 */
309 sh2sci_ierdy_snd (siopcb->exinf);
310 }
311}
312
313/*
314 * シリアルI/Oポートに対する受信割込み処理
315 */
316Inline void
317sh2sci_isr_siop_in (SIOPCB * siopcb)
318{
319 VB scr0 = sil_reb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SCR));
320
321 if ((scr0 & SCI_RIE) != 0 && sh2sci_getready (siopcb)) {
322 /*
323 * 受信通知コールバックルーチンを呼び出す.
324 */
325 sh2sci_ierdy_rcv (siopcb->exinf);
326 }
327}
328
329/*
330 * シリアルI/Oポートに対する受信エラー割込み処理
331 */
332Inline void
333sh2sci_isr_siop_err (SIOPCB * siopcb)
334{
335 sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCI_SSR),
336 sil_reb_mem ((VB *) (siopcb->siopinib->reg_base +
337 SCI_SSR)) & ~(SSR_ORER | SSR_FER |
338 SSR_PER));
339}
340
341/*
342 * SCI送信割込みサービスルーチン
343 *
344 */
345void
346sh2sci_isr_out (void)
347{
348 if (siopcb_table[0].openflag) {
349 sh2sci_isr_siop_out (get_siopcb (1));
350 }
351}
352
353/*
354 * SIO受信割込みサービスルーチン
355 *
356 */
357void
358sh2sci_isr_in (void)
359{
360 if (siopcb_table[0].openflag) {
361 sh2sci_isr_siop_in (get_siopcb (1));
362 }
363}
364
365/*
366 * SIO受信エラー割込みサービスルーチン
367 */
368void
369sh2sci_isr_error (void)
370{
371 if (siopcb_table[0].openflag) {
372 sh2sci_isr_siop_err (get_siopcb (1));
373 }
374}
375
376/*
377 * ポーリングによる文字の送信
378 */
379void
380sh2sci_putc_pol (ID portid, char c)
381{
382 while (!sh2sci_putready (&siopcb_table[portid - 1]));
383 sh2sci_putchar (&siopcb_table[portid - 1], c);
384}
385
386
387#if TNUM_PORT >= 2
388/*
389 * SIO受信割込みサービスルーチン
390 *
391 */
392void
393sh2sci_isr2_in (void)
394{
395 if (siopcb_table[1].openflag) {
396 sh2sci_isr_siop_in (get_siopcb (2));
397 }
398}
399
400/*
401 * SCI送信割込みサービスルーチン
402 *
403 */
404void
405sh2sci_isr2_out (void)
406{
407 if (siopcb_table[1].openflag) {
408 sh2sci_isr_siop_out (get_siopcb (2));
409 }
410}
411
412/*
413 * SIO受信エラー割込みサービスルーチン
414 */
415void
416sh2sci_isr2_error (void)
417{
418 if (siopcb_table[1].openflag) {
419 sh2sci_isr_siop_err (get_siopcb (2));
420 }
421}
422#endif /* of #if TNUM_PORT >= 2 */
Note: See TracBrowser for help on using the repository browser.