source: anotherchoice/tags/jsp-1.4.4-full-UTF8/config/sh2/sh726xscif.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: 12.8 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) 2000-2003 by Industrial Technology Institute,
9 * Miyagi Prefectural Government, JAPAN
10 * Copyright (C) 2002-2004 by Hokkaido Industrial Research Institute, JAPAN
11 * Copyright (C) 2010 by Cronus Computer Works, JAPAN
12 *
13 * 上記著作権者
14は,以下の (1)〜(4) の条件か,Free Software Foundation
15 * によってå…
16¬è¡¨ã•ã‚Œã¦ã„ã‚‹ GNU General Public License の Version 2 に記
17 * 述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
18 * を改変したものを含む.以下同じ)を使用・複製・改変・再é…
19å¸ƒï¼ˆä»¥ä¸‹ï¼Œ
20 * 利用と呼ぶ)することを無償で許諾する.
21 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
22 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
23 * スコード中に含まれていること.
24 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
25 * 用できる形で再é…
26å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œå†é…
27å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨
28 * 者
29マニュアルなど)に,上記の著作権表示,この利用条件および下記
30 * の無保証規定を掲載すること.
31 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
32 * 用できない形で再é…
33å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œæ¬¡ã®ã„ずれかの条件を満たすこ
34 * と.
35 * (a) 再é…
36å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨è€…
37マニュアルなど)に,上記の著
38 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
39 * (b) 再é…
40å¸ƒã®å½¢æ…
41‹ã‚’,別に定める方法によって,TOPPERSプロジェクトに
42 * 報告すること.
43 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
44 * 害からも,上記著作権者
45およびTOPPERSプロジェクトをå…
46è²¬ã™ã‚‹ã“と.
47 *
48 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者
49お
50 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
51 * 含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
52 * 接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
53 *
54 * @(#) $Id
55 */
56
57/*
58 * SH2内
59蔵シリアルコミュニケーションインタフェースSCIF用 簡易ドライバ
60 */
61
62#include <s_services.h>
63#include "sh726xscif.h"
64#define _MACRO_ONLY
65#include "hw_serial.h"
66
67/*
68 * シリアルI/Oポート管理ブロックの定義
69 */
70
71#ifndef GDB_STUB
72
73const SIOPINIB siopinib_table[TNUM_PORT] = {
74 {REGBASE_SERIAL, BRR_VALUE(SCIF_BPS), 0x0, SCIF_INTLVL},
75#if TNUM_PORT >= 2
76 {REGBASE_SERIAL2, BRR_VALUE(SCIF_BPS), 0x0, SCIF_INTLVL},
77#endif /* TNUM_PORT >= 2 */
78};
79
80#else /* GDB_STUB */
81
82const SIOPINIB siopinib_table[TNUM_PORT] = {
83 {REGBASE_SERIAL, BRR_VALUE(SCIF_BPS), 0x0, SCIF_INTLVL},
84};
85
86#endif /* GDB_STUB */
87
88/*
89 * シリアルI/Oポート管理ブロックのエリア
90 */
91static SIOPCB siopcb_table[TNUM_PORT];
92
93/*
94 * シリアルI/OポートIDから管理ブロックを取り出すためのマクロ
95 */
96#define INDEX_SIOP(siopid) ((UINT)((siopid) - 1))
97#define get_siopcb(siopid) (&(siopcb_table[INDEX_SIOP(siopid)]))
98
99/*
100 * 文字を受信できるか?
101 */
102Inline BOOL
103sh2scif_getready (SIOPCB * siopcb)
104{
105 /* レシーブデータレジスタフル・フラグのチェック */
106 return (sil_reh_mem ((VH *) (siopcb->siopinib->reg_base + SCIF_SCFSR)) &
107 SCFSR_RDRF);
108}
109
110/*
111 * 文字を送信できるか?
112 */
113Inline BOOL
114sh2scif_putready (SIOPCB * siopcb)
115{
116 /* トランスミットFIFOデータレジスタエンプティ・フラグのチェック */
117 return (sil_reh_mem ((VH *) (siopcb->siopinib->reg_base + SCIF_SCFSR)) &
118 SCFSR_TDFE);
119}
120
121/*
122 * 受信した文字の取出し
123 */
124Inline char
125sh2scif_getchar (SIOPCB * siopcb)
126{
127 VB data;
128
129 data = sil_reb_mem ((VB *) (siopcb->siopinib->reg_base + SCIF_SCFRDR));
130 /* レシーブデータレジスタフル・フラグのクリア */
131 sil_wrh_mem ((VH *) (siopcb->siopinib->reg_base + SCIF_SCFSR),
132 sil_reh_mem ((VH *) (siopcb->siopinib->reg_base +
133 SCIF_SCFSR)) & ~SCFSR_RDRF);
134 return data;
135}
136
137/*
138 * 送信する文字の書込み
139 */
140Inline void
141sh2scif_putchar (SIOPCB * siopcb, char c)
142{
143 /* トランスミットFIFOデータレジスタエンプティ・フラグのクリア */
144 sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCIF_SCFTDR), c);
145 sil_wrh_mem ((VH *) (siopcb->siopinib->reg_base + SCIF_SCFSR),
146 sil_reh_mem ((VH *) (siopcb->siopinib->reg_base +
147 SCIF_SCFSR)) & ~SCFSR_TDFE);
148}
149
150/*
151 * SIOドライバの初期化ルーチン
152 */
153void
154sh2scif_initialize ()
155{
156 SIOPCB *siopcb;
157 UINT i;
158
159 /*
160 * シルアルI/Oポート管理ブロックの初期化
161 */
162 for (siopcb = siopcb_table, i = 0; i < TNUM_PORT; siopcb++, i++) {
163 siopcb->openflag = FALSE;
164 siopcb->siopinib = (&siopinib_table[i]);
165 }
166}
167
168/*
169 * オープンしているポートがあるか?
170 */
171BOOL
172sh2scif_openflag (ID siopid)
173{
174 return (siopcb_table[siopid - 1].openflag);
175}
176
177/*
178 * シリアルI/Oポートのオープン
179 */
180SIOPCB *
181sh2scif_opn_por (ID siopid, VP_INT exinf)
182{
183 SIOPCB *siopcb;
184
185 siopcb = get_siopcb (siopid);
186
187 /* 送受信停止 */
188 sil_wrh_mem ((VH *) (siopcb->siopinib->reg_base + SCIF_SCSCR),
189 sil_reh_mem ((VH *) (siopcb->siopinib->reg_base +
190 SCIF_SCSCR)) & ~(SCSCR_TE | SCSCR_RE));
191
192 /* SCIFデータå…
193¥å‡ºåŠ›ãƒãƒ¼ãƒˆã®è¨­å®š */
194 /* ピンアサイン */
195 /* sys_initializeで設定 */
196
197 /* FIFOの初期化 */
198 sil_wrh_mem ((VH *) (siopcb->siopinib->reg_base + SCIF_SCFCR),
199 (VH) (SCFCR_TFRST | SCFCR_RFRST));
200
201 /* 送受信フォーマット */
202 sil_wrh_mem ((VH *) (siopcb->siopinib->reg_base + SCIF_SCSMR), 0x0000);
203 /* 調歩同期式 */
204 /* 8ビット、パリティなし */
205 /* ストップビットレングス:1 */
206 /* クロックセレクト */
207
208 sil_wrb_mem ((VB *) (siopcb->siopinib->reg_base + SCIF_SCBRR),
209 (VB) siopcb->siopinib->brr); /* ボーレート設定 */
210
211
212 /*
213 * ボーレートの設定後、1カウント分待
214たなければならない。
215 */
216 sil_dly_nse (sh2scif_DELAY);
217
218 /* FIFOの設定 */
219 sil_wrh_mem ((VH *) (siopcb->siopinib->reg_base + SCIF_SCFCR), 0x0030);
220
221 /* エラーフラグをクリア */
222 sil_wrh_mem ((VH *) (siopcb->siopinib->reg_base + SCIF_SCFSR),
223 sil_reh_mem ((VH *) (siopcb->siopinib->reg_base +
224 SCIF_SCFSR)) & ~SCFSR_ER);
225
226 /* 送受信開始 */
227 sil_wrh_mem ((VH *) (siopcb->siopinib->reg_base + SCIF_SCSCR),
228 (VH) (SCSCR_TE | SCSCR_RE));
229
230 siopcb->exinf = exinf;
231 siopcb->openflag = TRUE;
232 return (siopcb);
233}
234
235/*
236 * シリアルI/Oポートのクローズ
237 */
238void
239sh2scif_cls_por (SIOPCB * siopcb)
240{
241 /* 送受信停止、割込み禁止 */
242 sil_wrh_mem ((VH *) (siopcb->siopinib->reg_base + SCIF_SCSCR),
243 (VH) ~ (SCSCR_TIE | SCSCR_RIE | SCSCR_TE | SCSCR_RE));
244
245 siopcb->openflag = FALSE;
246}
247
248/*
249 * シリアルI/Oポートへの文字送信
250 */
251BOOL
252sh2scif_snd_chr (SIOPCB * siopcb, char c)
253{
254 if (sh2scif_putready (siopcb)) {
255 sh2scif_putchar (siopcb, c);
256 return (TRUE);
257 }
258 return (FALSE);
259}
260
261/*
262 * シリアルI/Oポートからの文字受信
263 */
264INT
265sh2scif_rcv_chr (SIOPCB * siopcb)
266{
267 if (sh2scif_getready (siopcb)) {
268 return ((INT) (UB) sh2scif_getchar (siopcb));
269 }
270 return (-1);
271}
272
273/*
274 * シリアルI/Oポートからのコールバックの許可
275 */
276void
277sh2scif_ena_cbr (SIOPCB * siopcb, UINT cbrtn)
278{
279 switch (cbrtn) {
280 case SIO_ERDY_SND: /* 送信割り込み要求を許可 */
281 sil_wrh_mem ((VH *) (siopcb->siopinib->reg_base + SCIF_SCSCR),
282 sil_reh_mem ((VH *) (siopcb->siopinib->reg_base +
283 SCIF_SCSCR)) | SCSCR_TIE);
284 break;
285 case SIO_ERDY_RCV: /* 受信割り込み要求を許可 */
286 sil_wrh_mem ((VH *) (siopcb->siopinib->reg_base + SCIF_SCSCR),
287 sil_reh_mem ((VH *) (siopcb->siopinib->reg_base +
288 SCIF_SCSCR)) | SCSCR_RIE);
289 break;
290 }
291}
292
293/*
294 * シリアルI/Oポートからのコールバックの禁止
295 */
296void
297sh2scif_dis_cbr (SIOPCB * siopcb, UINT cbrtn)
298{
299 switch (cbrtn) {
300 case SIO_ERDY_SND: /* 送信割り込み要求を禁止 */
301 sil_wrh_mem ((VH *) (siopcb->siopinib->reg_base + SCIF_SCSCR),
302 sil_reh_mem ((VH *) (siopcb->siopinib->reg_base +
303 SCIF_SCSCR)) & ~SCSCR_TIE);
304 break;
305 case SIO_ERDY_RCV: /* 受信割り込み要求を禁止 */
306 sil_wrh_mem ((VH *) (siopcb->siopinib->reg_base + SCIF_SCSCR),
307 sil_reh_mem ((VH *) (siopcb->siopinib->reg_base +
308 SCIF_SCSCR)) & ~SCSCR_RIE);
309 break;
310 }
311}
312
313/*
314 * シリアルI/Oポートに対する送信割込み処理
315 */
316Inline void
317sh2scif_isr_siop_out (SIOPCB * siopcb)
318{
319 VH scr0 = sil_reh_mem ((VH *) (siopcb->siopinib->reg_base + SCIF_SCSCR));
320
321 if ((scr0 & SCSCR_TIE) != 0 && sh2scif_putready (siopcb)) {
322 /*
323 * 送信通知コールバックルーチンを呼び出す.
324 */
325 sh2scif_ierdy_snd (siopcb->exinf);
326 }
327}
328
329/*
330 * シリアルI/Oポートに対する受信割込み処理
331 */
332Inline void
333sh2scif_isr_siop_in (SIOPCB * siopcb)
334{
335 VH scr0 = sil_reh_mem ((VH *) (siopcb->siopinib->reg_base + SCIF_SCSCR));
336
337 if ((scr0 & SCSCR_RIE) != 0 && sh2scif_getready (siopcb)) {
338 /*
339 * 受信通知コールバックルーチンを呼び出す.
340 */
341 sh2scif_ierdy_rcv (siopcb->exinf);
342 }
343}
344
345/*
346 * シリアルI/Oポートに対する受信エラー割込み処理
347 */
348Inline void
349sh2scif_isr_siop_err (SIOPCB * siopcb)
350{
351 /* エラーフラグをクリア */
352 sil_wrh_mem ((VH *) (siopcb->siopinib->reg_base + SCIF_SCFSR),
353 sil_reh_mem ((VH *) (siopcb->siopinib->reg_base +
354 SCIF_SCFSR)) & ~SCFSR_ER);
355 /* FIFOの初期化 */
356 sil_wrh_mem ((VH *) (siopcb->siopinib->reg_base + SCIF_SCFCR),
357 (VH) SCFCR_RFRST);
358 sil_wrh_mem ((VH *) (siopcb->siopinib->reg_base + SCIF_SCFCR), 0x0030);
359}
360
361/* ブレーク検出処理 */
362/* フラグをリセットする */
363Inline void
364sh2scif_isr_siop_brk (SIOPCB * siopcb)
365{
366 /* フラグをクリア */
367 sil_wrh_mem ((VH *) (siopcb->siopinib->reg_base + SCIF_SCFSR),
368 sil_reh_mem ((VH *) (siopcb->siopinib->reg_base +
369 SCIF_SCFSR)) & ~SCFSR_BRK);
370}
371
372/*
373 * SCIF送信割込みサービスルーチン
374 *
375 *  SH2内
376蔵のSCIFでは割込み番号が送受信別、チャネル別に分かれているので、
377 *  SCIFの送信割込み以外でこのルーチンが呼ばれることはない
378 *
379 */
380void
381sh2scif_isr_out ()
382{
383 if (siopcb_table[0].openflag) {
384 sh2scif_isr_siop_out (get_siopcb (1));
385 }
386}
387
388/*
389 * SCIF受信割込みサービスルーチン
390 *
391 *  SH2内
392蔵のSCIFでは割込み番号が送受信別、チャネル別に分かれているので、
393 *  SCIFの受信割込み以外でこのルーチンが呼ばれることはない
394 *
395 */
396void
397sh2scif_isr_in ()
398{
399 if (siopcb_table[0].openflag) {
400 sh2scif_isr_siop_in (get_siopcb (1));
401 }
402}
403
404/*
405 * SIO受信エラー割込みサービスルーチン
406 *
407 *  SH2内
408蔵のSCIFでは割込み番号がチャネル別に分かれているので、
409 *  SCIFの受信エラー割込み以外でこのルーチンが呼ばれることはない
410 *  
411 *  エラー処理自体はエラーフラグのクリアのみにとどめている。
412 *    ・オーバーランエラー
413 *    ・フレーミングエラー
414 *    ・パリティエラー
415 */
416void
417sh2scif_isr_error (void)
418{
419
420 if (siopcb_table[0].openflag) {
421 sh2scif_isr_siop_err (get_siopcb (1));
422 }
423}
424
425/* ブレーク検出 */
426void
427sh2scif_isr_brk (void)
428{
429
430 if (siopcb_table[0].openflag) {
431 sh2scif_isr_siop_brk (get_siopcb (1));
432 }
433}
434
435/*
436 * ポーリングによる文字の送信
437 */
438void
439sh2scif_putc_pol (ID portid, char c)
440{
441 while (!sh2scif_putready (&siopcb_table[portid - 1]));
442 sh2scif_putchar (&siopcb_table[portid - 1], c);
443}
444
445#if TNUM_PORT >= 2
446/*
447 * SCIF受信割込みサービスルーチン
448 *
449 */
450void
451sh2scif_isr2_in (void)
452{
453 if (siopcb_table[1].openflag) {
454 sh2scif_isr_siop_in (get_siopcb (2));
455 }
456}
457
458/*
459 * SCIF送信割込みサービスルーチン
460 *
461 */
462void
463sh2scif_isr2_out (void)
464{
465 if (siopcb_table[1].openflag) {
466 sh2scif_isr_siop_out (get_siopcb (2));
467 }
468}
469
470/*
471 * SCIF受信エラー割込みサービスルーチン
472 */
473void
474sh2scif_isr2_error (void)
475{
476 if (siopcb_table[1].openflag) {
477 sh2scif_isr_siop_err (get_siopcb (2));
478 }
479}
480
481/* ブレーク検出 */
482void
483sh2scif_isr2_brk (void)
484{
485
486 if (siopcb_table[1].openflag) {
487 sh2scif_isr_siop_brk (get_siopcb (2));
488 }
489}
490#endif /* of #if TNUM_PORT >= 2 */
Note: See TracBrowser for help on using the repository browser.