source: anotherchoice/tags/jsp-1.4.4-full-UTF8/config/s1c33/dmt33209/hw_serial.h@ 26

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

initial

File size: 7.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 by Embedded and Real-Time Systems Laboratory
7 * Toyohashi Univ. of Technology, JAPAN
8 *
9 * Copyright (C) 2004 by SEIKO EPSON Corp, JAPAN
10 *
11 * 上記著作権者
12は,以下の (1)〜(4) の条件か,Free Software Foundation
13 * によってå…
14¬è¡¨ã•ã‚Œã¦ã„ã‚‹ GNU General Public License の Version 2 に記
15 * 述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
16 * を改変したものを含む.以下同じ)を使用・複製・改変・再é…
17å¸ƒï¼ˆä»¥ä¸‹ï¼Œ
18 * 利用と呼ぶ)することを無償で許諾する.
19 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
20 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
21 * スコード中に含まれていること.
22 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
23 * 用できる形で再é…
24å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œå†é…
25å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨
26 * 者
27マニュアルなど)に,上記の著作権表示,この利用条件および下記
28 * の無保証規定を掲載すること.
29 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
30 * 用できない形で再é…
31å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œæ¬¡ã®ã„ずれかの条件を満たすこ
32 * と.
33 * (a) 再é…
34å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨è€…
35マニュアルなど)に,上記の著
36 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
37 * (b) 再é…
38å¸ƒã®å½¢æ…
39‹ã‚’,別に定める方法によって,TOPPERSプロジェクトに
40 * 報告すること.
41 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
42 * 害からも,上記著作権者
43およびTOPPERSプロジェクトをå…
44è²¬ã™ã‚‹ã“と.
45 *
46 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者
47お
48 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
49 * 含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
50 * 接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
51 *
52 */
53
54/*
55 * ターゲット依存シリアルI/Oモジュール(DMT33209)
56 */
57
58#ifndef _HW_SERIAL_H_
59#define _HW_SERIAL_H_
60
61#include "s_services.h"
62
63/*
64 * シリアルI/Oの割込みハンドラのベクタ番号
65 */
66#define INHNO_SERIAL_IN S1C33_INHNO_SERIAL0RX
67#define INHNO_SERIAL_OUT S1C33_INHNO_SERIAL0TX
68#define INHNO_SERIAL_ERR S1C33_INHNO_SERIAL0ERR
69
70/*
71 * コールバックルーチンの識別番号
72 */
73#define SIO_ERDY_SND 1 /* 送信可能コールバック */
74#define SIO_ERDY_RCV 2 /* 受信通知コールバック */
75
76#define INDEX_SIO(sioid) ((UINT)((sioid) - 1))
77
78/*
79 * SIO割り込み要因フラグ ビット位置
80 */
81#define SIO_INT_ERR 0x01
82#define SIO_INT_RCV 0x02
83#define SIO_INT_SND 0x04
84
85/*
86 * エラーフラグ ビット位置
87 */
88#define SIO_ERR_FRAME 0x10
89#define SIO_ERR_PARITY 0x08
90#define SIO_ERR_OVERRUN 0x04
91
92#ifndef _MACRO_ONLY
93/*
94 * シリアルポートのハードウェア依存情
95報の定義
96 */
97typedef struct {
98 UB ch_no; /* SIOチャネル番号 */
99 UB err_vector; /* 通信エラー割り込みベクタ番号 */
100 UB rx_vector; /* 受信割り込みベクタ番号 */
101 UB tx_vector; /* 送信完了割り込みベクタ番号 */
102} SIOPINIB;
103
104/*
105 * シリアルポートの制御ブロック
106 */
107typedef struct {
108 const SIOPINIB *inib; /* 初期化ブロック */
109 VP_INT exinf; /* 拡張情
110å ± */
111 BOOL openflag; /* オープン済みフラグ */
112 BOOL tx_cbrflag; /* 送信コールバック実行フラグ*/
113 BOOL rx_cbrflag; /* 受信コールバック実行フラグ*/
114} SIOPCB;
115
116extern SIOPCB siopcb_table[TNUM_PORT];
117
118/*
119 * 外部関数の参ç…
120§
121 */
122extern void sio_initialize (void);
123extern void sio_ena_cbr(SIOPCB *siopcb, UINT cbrtn);
124extern void sio_dis_cbr(SIOPCB *siopcb, UINT cbrtn);
125extern void serial_handler_in(ID portid);
126extern void serial_handler_out(ID portid);
127extern void sio_ierdy_snd(VP_INT exinf);
128extern void sio_ierdy_rcv(VP_INT exinf);
129extern ER ena_int(INTNO);
130extern ER dis_int(INTNO);
131
132/*
133 * シリアルポートの初期化
134 */
135Inline SIOPCB
136*sio_opn_por(ID siopid, VP_INT exinf)
137{
138 B temp;
139
140 /*
141 * 割り込みの禁止
142 */
143 if(siopid == 1){
144 dis_int(S1C33_INHNO_SERIAL0RX);
145 dis_int(S1C33_INHNO_SERIAL0TX);
146#ifdef SIO_ERR_HANDLER
147 dis_int(S1C33_INHNO_SERIAL0ERR);
148#endif
149 } else {
150 dis_int(S1C33_INHNO_SERIAL1RX);
151 dis_int(S1C33_INHNO_SERIAL1TX);
152#ifdef SIO_ERR_HANDLER
153 dis_int(S1C33_INHNO_SERIAL1ERR);
154#endif
155 }
156
157 /*
158 * シリアルI/Fの設定
159 *
160 * 8bit調歩同期 パリティなし ストップビット1bit 外部クロック
161 */
162 ((s1c33Serial_t *)S1C33_SERIAL_BASE)->stChannel01[INDEX_SIO(siopid)].bControl = 0x07;
163
164 ((s1c33Port_t *)S1C33_PORT_BASE)->stPPort[INDEX_SIO(siopid)].bFuncSwitch = 0x07;
165 ((s1c33Serial_t *)S1C33_SERIAL_BASE)->stChannel01[INDEX_SIO(siopid)].bIrDA = 0x00;
166
167 ((s1c33Serial_t *)S1C33_SERIAL_BASE)->stChannel01[INDEX_SIO(siopid)].bControl = 0xc7;
168
169 /*
170 * 割込み要因をクリア
171 */
172 (*(s1c33Intc_t *) S1C33_INTC_BASE).bIntFactor[6] |= (0x07 << INDEX_SIO(siopid));
173
174 /*
175 * 受信バッファのクリア
176 */
177 temp = ((s1c33Serial_t *)S1C33_SERIAL_BASE)->stChannel01[INDEX_SIO(siopid)].bRxd;
178
179 /*
180 * 制御情
181報の設定
182 */
183 siopcb_table[INDEX_SIO(siopid)].openflag = TRUE;
184 if(exinf != NULL){
185 siopcb_table[INDEX_SIO(siopid)].exinf = exinf;
186 }
187
188 /*
189 * 割り込みの許可
190 */
191 if(siopid == 1){
192 ena_int(S1C33_INHNO_SERIAL0RX);
193 ena_int(S1C33_INHNO_SERIAL0TX);
194#ifdef SIO_ERR_HANDLER
195 ena_int(S1C33_INHNO_SERIAL0ERR);
196#endif
197 } else {
198 ena_int(S1C33_INHNO_SERIAL1RX);
199 ena_int(S1C33_INHNO_SERIAL1TX);
200#ifdef SIO_ERR_HANDLER
201 ena_int(S1C33_INHNO_SERIAL1ERR);
202#endif
203 }
204
205 return (&(siopcb_table[INDEX_SIO(siopid)]));
206}
207
208/*
209 * 通信の停止
210 */
211Inline void
212sio_cls_por(SIOPCB *siopcb)
213{
214 UB ch_no;
215
216 ch_no = siopcb->inib->ch_no;
217 /*
218 * 転送完了を待
219つ
220 */
221 while(((s1c33Serial_t *)S1C33_SERIAL_BASE)->stChannel01[ch_no].bStatus & 0x20){
222 ;
223 }
224
225 /*
226 * 通信を禁止する
227 */
228 ((s1c33Serial_t *)S1C33_SERIAL_BASE)->stChannel01[ch_no].bControl = 0x07;
229
230 return;
231}
232
233/*
234 * 送信機能の状æ…
235‹ã‚’取得
236 */
237Inline BOOL
238sio_get_txready(UB ch_no)
239{
240 UB bSioSts;
241
242 bSioSts = ((s1c33Serial_t *)S1C33_SERIAL_BASE)->stChannel01[ch_no].bStatus;
243
244 return(!(bSioSts & 0x20));
245}
246
247/*
248 * 受信機能の状æ…
249‹ã‚’取得
250 */
251Inline BOOL
252sio_get_rxready(UB ch_no)
253{
254 UB bSioSts;
255
256 bSioSts = ((s1c33Serial_t *)S1C33_SERIAL_BASE)->stChannel01[ch_no].bStatus;
257
258 return(bSioSts & 0x01);
259}
260
261/*
262 * 受信した1文字を読み込む
263 */
264Inline INT
265sio_rcv_chr(SIOPCB *siopcb)
266{
267 BOOL blRxSts;
268 UB ch_no;
269
270
271 ch_no = siopcb->inib->ch_no;
272 blRxSts = sio_get_rxready(ch_no);
273
274 if(blRxSts){
275 return (((s1c33Serial_t *)S1C33_SERIAL_BASE)->stChannel01[ch_no].bRxd);
276 }
277
278 return (-1);
279}
280
281/*
282 * 送信する1文字を書き込む
283 */
284Inline BOOL
285sio_snd_chr(SIOPCB *siopcb, char c)
286{
287 BOOL blTxSts;
288 UB ch_no;
289
290 ch_no = siopcb->inib->ch_no;
291 blTxSts = sio_get_txready(ch_no);
292 if(blTxSts){
293 ((s1c33Serial_t *)S1C33_SERIAL_BASE)->stChannel01[ch_no].bTxd = c;
294 }
295
296 return(blTxSts);
297}
298
299/*
300 * 指定されたSIOチャネルの割り込み要因をクリアする
301 */
302Inline void
303sio_clr_factor(UB bFlag)
304{
305 ((volatile s1c33Intc_t *) S1C33_INTC_BASE)->bIntFactor[6] |= bFlag;
306}
307
308/* 指定されたSIOチャネルのエラーフラグをクリアする
309 *
310 */
311Inline void
312sio_clr_errflag(UB ch_no)
313{
314 ((volatile s1c33Serial_t *)S1C33_SERIAL_BASE)->stChannel01[ch_no].bStatus
315 &= ~(SIO_ERR_OVERRUN | SIO_ERR_PARITY | SIO_ERR_FRAME);
316}
317
318#endif /* _MACRO_ONLY */
319#endif /* _HW_SERIAL_H_ */
Note: See TracBrowser for help on using the repository browser.