source: anotherchoice/tags/jsp-1.4.4-full-UTF8/config/tlcs900-toshiba/zup_f16_ex/uart.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: 13.2 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) 2006-2010 by Witz Corporation, JAPAN
7 *
8 * The above copyright holders grant permission gratis to use,
9 * duplicate, modify, or redistribute (hereafter called use) this
10 * software (including the one made by modifying this software),
11 * provided that the following four conditions (1) through (4) are
12 * satisfied.
13 *
14 * (1) When this software is used in the form of source code, the above
15 * copyright notice, this use conditions, and the disclaimer shown
16 * below must be retained in the source code without modification.
17 *
18 * (2) When this software is redistributed in the forms usable for the
19 * development of other software, such as in library form, the above
20 * copyright notice, this use conditions, and the disclaimer shown
21 * below must be shown without modification in the document provided
22 * with the redistributed software, such as the user manual.
23 *
24 * (3) When this software is redistributed in the forms unusable for the
25 * development of other software, such as the case when the software
26 * is embedded in a piece of equipment, either of the following two
27 * conditions must be satisfied:
28 *
29 * (a) The above copyright notice, this use conditions, and the
30 * disclaimer shown below must be shown without modification in
31 * the document provided with the redistributed software, such as
32 * the user manual.
33 *
34 * (b) How the software is to be redistributed must be reported to the
35 * TOPPERS Project according to the procedure described
36 * separately.
37 *
38 * (4) The above copyright holders and the TOPPERS Project are exempt
39 * from responsibility for any type of damage directly or indirectly
40 * caused from the use of this software and are indemnified by any
41 * users or end users of this software from any and all causes of
42 * action whatsoever.
43 *
44 * THIS SOFTWARE IS PROVIDED "AS IS." THE ABOVE COPYRIGHT HOLDERS AND
45 * THE TOPPERS PROJECT DISCLAIM ANY EXPRESS OR IMPLIED WARRANTIES,
46 * INCLUDING, BUT NOT LIMITED TO, ITS APPLICABILITY TO A PARTICULAR
47 * PURPOSE. IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS AND THE
48 * TOPPERS PROJECT BE LIABLE FOR ANY TYPE OF DAMAGE DIRECTLY OR
49 * INDIRECTLY CAUSED FROM THE USE OF THIS SOFTWARE.
50 *
51 * 上記著作権者
52は,以下の (1)〜(4) の条件を満たす場合に限り,本ソフトウェ
53 * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改変・
54 * 再é…
55å¸ƒï¼ˆä»¥ä¸‹ï¼Œåˆ©ç”¨ã¨å‘¼ã¶ï¼‰ã™ã‚‹ã“とを無償で許諾する.
56 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作権
57 * 表示,この利用条件および下記の無保証規定が,そのままの形でソース
58 * コード中に含まれていること.
59 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使用
60 * できる形で再é…
61å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œå†é…
62å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨è€…
63マ
64 * ニュアルなど)に,上記の著作権表示,この利用条件および下記の無保
65 * 証規定を掲載すること.
66 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使用
67 * できない形で再é…
68å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œæ¬¡ã®ã„ずれかの条件を満たすこと.
69 * (a) 再é…
70å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨è€…
71マニュアルなど)に,上記の著作
72 * 権表示,この利用条件および下記の無保証規定を掲載すること.
73 * (b) 再é…
74å¸ƒã®å½¢æ…
75‹ã‚’,別に定める方法によって,TOPPERSプロジェクトに報
76 * 告すること.
77 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損害
78 * からも,上記著作権者
79およびTOPPERSプロジェクトをå…
80è²¬ã™ã‚‹ã“と.また,
81 * 本ソフトウェアのユーザまたはエンドユーザからのいかなる理由に基づ
82 * く請求からも,上記著作権者
83およびTOPPERSプロジェクトをå…
84è²¬ã™ã‚‹ã“と.
85 *
86 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者
87およ
88 * びTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的に対す
89 * る適合性も含めて,いかなる保証も行わない.また,本ソフトウェアの利用
90 * により直接的または間接的に生じたいかなる損害に関しても,その責任を負
91 * わない.
92 *
93 * @(#) $Id: uart.c,v 1.1 2006/04/10 08:19:25 honda Exp $
94 */
95
96/*
97 * 非同期通信 (UART)シリアルチャンネルデバイス(SIO)ドライバ
98 * (Zup-F16拡張ボード用)
99 */
100#include <s_services.h>
101#include <sil.h>
102#include <tmp91cy22.h>
103#include <uart.h>
104
105/*
106 * シリアルI/O制御レジスタへのオフセット定義
107 */
108#define TOFFSET_SC0BUF 0x0000
109#define TOFFSET_SC0CR 0x0001
110#define TOFFSET_SC0MOD0 0x0002
111#define TOFFSET_BR0CR 0x0003
112#define TOFFSET_BR0ADD 0x0004
113#define TOFFSET_SC0MOD1 0x0005
114
115/*
116 * シリアルI/Oポート状æ…
117‹ãƒ•ãƒ©ã‚°ã®å®šç¾©
118 */
119#define TBIT_STS_DEF 0x00
120#define TBIT_TXB_EMPTY 0x01
121#define TBIT_ENE_TXCBR 0x02
122#define TBIT_ENE_RXCBR 0x04
123#define TBIT_LOG_PORT 0x80
124
125/*
126 * シリアルI/Oポート初期化ブロック
127 *
128 * ID = 1 をuart1,ID = 2 をuart0に対応させている.
129 */
130static const SIOPINIB siopinib_table[TNUM_PORT] = {
131 { TADR_SFR_SC1BUF, TADR_SFR_INTES1, 0x08, (TBIT_SIOSMU8 | TBIT_SIORXE | TBIT_SIOSCBRG),
132 0x00, BRCR_19200, BRADD_19200, TBIT_RX1_CLR } /* ID1用 UART1 19200bps */
133/* { TADR_SFR_SC1BUF, TADR_SFR_INTES1, 0x08, (TBIT_SIOSMU8 | TBIT_SIORXE | TBIT_SIOSCBRG),
134 0x00, BRCR_38400, BRADD_38400, TBIT_RX1_CLR }*/ /* ID1用 UART1 38400bps */
135/* { TADR_SFR_SC0BUF, TADR_SFR_INTES0, 0x01, (TBIT_SIOSMU8 | TBIT_SIORXE | TBIT_SIOSCBRG),
136 0x00, BRCR_19200, BRADD_19200, TBIT_RX0_CLR }*/ /* ID2用 UART0 19200bps */
137};
138
139/*
140 * シリアルI/Oポート管理ブロックのエリア
141 */
142static SIOPCB siopcb_table[TNUM_PORT];
143
144/*
145 * シリアルI/OポートIDから管理ブロックを取り出すためのマクロ
146 */
147#define INDEX_SIOP(siopid) ((UINT)((siopid) - 1))
148#define get_siopcb(siopid) (&(siopcb_table[INDEX_SIOP(siopid)]))
149
150/*
151 * SIOドライバの初期化ルーチン
152 */
153void
154uart_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->siopinib = &(siopinib_table[i]);
164 siopcb->sts_flag = TBIT_STS_DEF;
165 siopcb->rxb = -1;
166 }
167}
168
169/*
170 * シリアルI/Oポートのオープン
171 */
172SIOPCB *
173uart_opn_por(ID siopid, VP_INT exinf)
174{
175 SIOPCB *siopcb;
176 const SIOPINIB *siopinib;
177 int i;
178
179 /* ポートIDから管理ブロックを取得 */
180 siopcb = get_siopcb(siopid);
181 siopinib = siopcb->siopinib;
182
183 /* 管理ブロックに情
184報設定 */
185 siopcb->sts_flag |= TBIT_TXB_EMPTY;
186 siopcb->exinf = exinf;
187 if( siopid == LOGTASK_PORTID ){ /* システムログ用のポートの場合 */
188 siopcb->sts_flag |= TBIT_LOG_PORT;
189 if( log_io_busy == TRUE ){
190 /* 送信中の場合は完了まで待
191つ */
192 while( (sil_reb_mem((VP)(siopinib->hint)) & TBIT_INTC_H) == 0 );
193 }
194 log_io_busy = FALSE; /* 初期化なので明示的に行っている */
195 }
196
197 /* 受信停止 */
198 sil_wrb_mem((VP)(siopinib->cntrl+TOFFSET_SC0MOD0), 0x00 );
199 /* ポート設定(TXDとして使用) */
200 sil_wrb_mem((VP)(TADR_SFR_P9FC), siopinib->pcrfc_def );
201 sil_wrb_mem((VP)(TADR_SFR_P9CR), siopinib->pcrfc_def );
202
203 /* 動作モード設定 */
204 sil_wrb_mem((VP)(siopinib->cntrl+TOFFSET_SC0MOD0), siopinib->scmod0_def );
205 sil_reb_mem((VP)(siopinib->cntrl+TOFFSET_SC0CR)); /* 読出しによりエラーフラグクリア */
206 sil_wrb_mem((VP)(siopinib->cntrl+TOFFSET_SC0CR), siopinib->sccr_def );
207 sil_wrb_mem((VP)(siopinib->cntrl+TOFFSET_BR0CR), siopinib->brcr_def);
208 sil_wrb_mem((VP)(siopinib->cntrl+TOFFSET_BR0ADD), siopinib->bradd_def);
209 sil_wrb_mem((VP)(siopinib->cntrl+TOFFSET_SC0MOD1), TBIT_SIOI2S);
210
211 /* シリアル割込みの設定および要求フラグクリア */
212 sil_wrb_mem((VP)TADR_SFR_INTCLR, (siopinib->int_clr) ); /* 受信要求クリア */
213 sil_wrb_mem((VP)TADR_SFR_INTCLR, (VB)(siopinib->int_clr + 1) ); /* 送信要求クリア */
214 sil_wrb_mem((VP)(siopinib->hint), (VB)((INT_LEVEL_UART << 4) | INT_LEVEL_UART) );
215
216 /*
217 * ダミーデータ受信
218 */
219 sil_reb_mem((VP)(siopinib->cntrl+TOFFSET_SC0BUF));
220 sil_reb_mem((VP)(siopinib->cntrl+TOFFSET_SC0BUF));
221
222 return(siopcb);
223}
224
225/*
226 * シリアルI/Oポートのクローズ
227 */
228void
229uart_cls_por(SIOPCB *siopcb)
230{
231 const SIOPINIB *siopinib;
232
233 siopinib = siopcb->siopinib;
234
235 /* 受信停止 */
236 sil_wrb_mem((VP)(siopinib->cntrl+TOFFSET_SC0MOD0), 0x00 );
237
238 /* システムログ用ポートの処理 */
239 if( (siopcb->sts_flag & TBIT_LOG_PORT) == TBIT_LOG_PORT ){
240 if( log_io_busy == TRUE ){
241 /* 送信中の場合は完了まで待
242つ */
243 while( (sil_reb_mem((VP)(TADR_SFR_INTES0)) & TBIT_INTC_H) == 0 );
244 }
245 log_io_busy = FALSE;
246 }
247
248 /* シリアル割込みの禁止および要求フラグクリア */
249 sil_wrb_mem((VP)(siopinib->hint), 0x00 );
250 sil_wrb_mem((VP)TADR_SFR_INTCLR, (siopinib->int_clr) ); /* 受信要求クリア */
251 sil_wrb_mem((VP)TADR_SFR_INTCLR, (VB)(siopinib->int_clr + 1) ); /* 送信要求クリア */
252 /* ポート設定(ポートとして使用) */
253 sil_wrb_mem((VP)(TADR_SFR_P9FC), 0x00 );
254 sil_wrb_mem((VP)(TADR_SFR_P9CR), 0x00 );
255
256 siopcb->sts_flag = TBIT_STS_DEF;
257}
258
259/*
260 * シリアルI/Oポートへの文字送信
261 */
262BOOL
263uart_snd_chr(SIOPCB *siopcb, char c)
264{
265 if( (siopcb->sts_flag & TBIT_TXB_EMPTY) == TBIT_TXB_EMPTY ){
266 siopcb->sts_flag &= (UB)~TBIT_TXB_EMPTY;
267 sil_wrb_mem((VP)(siopcb->siopinib->cntrl+TOFFSET_SC0BUF), c);
268
269 /* システムログ用ポートの処理 */
270 if( (siopcb->sts_flag & TBIT_LOG_PORT) == TBIT_LOG_PORT ){
271 log_io_busy = TRUE; /* 送信中 */
272 }
273 return(TRUE);
274 }
275 return(FALSE);
276}
277
278/*
279 * シリアルI/Oポートからの文字受信
280 */
281INT
282uart_rcv_chr(SIOPCB *siopcb)
283{
284 return(siopcb->rxb);
285}
286
287/*
288 * シリアルI/Oポートからのコールバックの許可
289 */
290void
291uart_ena_cbr(SIOPCB *siopcb, UINT cbrtn)
292{
293 switch (cbrtn) {
294 case UART_ERDY_SND:
295 siopcb->sts_flag |= TBIT_ENE_TXCBR;
296 break;
297 case UART_ERDY_RCV:
298 siopcb->sts_flag |= TBIT_ENE_RXCBR;
299 break;
300 default:
301 break;
302 }
303}
304
305/*
306 * シリアルI/Oポートからのコールバックの禁止
307 */
308void
309uart_dis_cbr(SIOPCB *siopcb, UINT cbrtn)
310{
311 switch (cbrtn) {
312 case UART_ERDY_SND:
313 siopcb->sts_flag &= (UB)~TBIT_ENE_TXCBR;
314 break;
315 case UART_ERDY_RCV:
316 siopcb->sts_flag &= (UB)~TBIT_ENE_RXCBR;
317 break;
318 default:
319 break;
320 }
321}
322
323/*
324 * ポートID=1に指定されているSIOチャンネル(uart1)からの受信割込み
325 */
326void serial_in_handler1()
327{
328 SIOPCB *siopcb = &siopcb_table[0];
329
330 /* エラーの場合処理しない */
331 if( ( sil_reb_mem((VP)(siopcb->siopinib->cntrl+TOFFSET_SC0CR)) & 0x1c ) == 0 ){
332
333 /* データ受信 */
334 siopcb->rxb = (INT)sil_reb_mem((VP)(siopcb->siopinib->cntrl+TOFFSET_SC0BUF));
335
336 /* コールバックが許可されている場合 */
337 if( (siopcb->sts_flag & TBIT_ENE_RXCBR) == TBIT_ENE_RXCBR ){
338 /*
339 * 受信通知コールバックルーチンを呼び出す.
340 */
341 uart_ierdy_rcv(siopcb->exinf);
342 }
343 }
344}
345
346/*
347 * ポートID=1に指定されているSIOチャンネル(uart1)からの送信割込み
348 */
349void serial_out_handler1()
350{
351 SIOPCB *siopcb = &siopcb_table[0];
352
353 /* データ送信完了フラグON */
354 siopcb->sts_flag |= TBIT_TXB_EMPTY;
355
356 /* システムログ用ポートの処理 */
357 if( (siopcb->sts_flag & TBIT_LOG_PORT) == TBIT_LOG_PORT ){
358 log_io_busy = FALSE; /* 送信完了 */
359 }
360
361 /* コールバックが許可されている場合 */
362 if( (siopcb->sts_flag & TBIT_ENE_TXCBR) == TBIT_ENE_TXCBR ){
363 /*
364 * 送信可能コールバックルーチンを呼び出す.
365 */
366 uart_ierdy_snd(siopcb->exinf);
367 }
368}
369
370#if TNUM_PORT >= 2
371/*
372 * ポートID=2に指定されているSIOチャンネル(uart0)からの受信割込み
373 */
374void serial_in_handler2()
375{
376 SIOPCB *siopcb = &siopcb_table[1];
377
378 /* エラーの場合処理しない */
379 if( ( sil_reb_mem((VP)(siopcb->siopinib->cntrl+TOFFSET_SC0CR)) & 0x1c ) == 0 ){
380
381 /* データ受信 */
382 siopcb->rxb = (INT)sil_reb_mem((VP)(siopcb->siopinib->cntrl+TOFFSET_SC0BUF));
383
384 /* コールバックが許可されている場合 */
385 if( (siopcb->sts_flag & TBIT_ENE_RXCBR) == TBIT_ENE_RXCBR ){
386 /*
387 * 受信通知コールバックルーチンを呼び出す.
388 */
389 uart_ierdy_rcv(siopcb->exinf);
390 }
391 }
392}
393
394/*
395 * ポートID=2に指定されているSIOチャンネル(uart0)からの送信割込み
396 */
397void serial_out_handler2()
398{
399 SIOPCB *siopcb = &siopcb_table[1];
400
401 /* データ送信完了フラグON */
402 siopcb->sts_flag |= TBIT_TXB_EMPTY;
403
404 /* システムログ用ポートの処理 */
405 if( (siopcb->sts_flag & TBIT_LOG_PORT) == TBIT_LOG_PORT ){
406 log_io_busy = FALSE; /* 送信完了 */
407 }
408
409 /* コールバックが許可されている場合 */
410 if( (siopcb->sts_flag & TBIT_ENE_TXCBR) == TBIT_ENE_TXCBR ){
411 /*
412 * 送信可能コールバックルーチンを呼び出す.
413 */
414 uart_ierdy_snd(siopcb->exinf);
415 }
416}
417
418#endif
419
Note: See TracBrowser for help on using the repository browser.