source: asp_nios2/trunk/arch/nios2_gcc/jtag_uart.c@ 1

Last change on this file since 1 was 1, checked in by ertl-ichiba, 14 years ago

ASP 1.4.0対応のNios2依存部を追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.8 KB
Line 
1/*
2 * TOPPERS/ASP Kernel
3 * Toyohashi Open Platform for Embedded Real-Time Systems/
4 * Advanced Standard Profile Kernel
5 *
6 * Copyright (C) 2008 by Embedded and Real-Time Systems Laboratory
7 * Graduate School of Information Science, Nagoya Univ., JAPAN
8 *
9 * 上記著作権者は,以下の(1)〜(4)の条件を満たす場合に限り,本ソフトウェ
10 * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
11 * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
12 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
13 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
14 * スコード中に含まれていること.
15 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
16 * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
17 * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
18 * の無保証規定を掲載すること.
19 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
20 * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
21 * と.
22 * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
23 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
24 * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
25 * 報告すること.
26 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
27 * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
28 * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
29 * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
30 * 免責すること.
31 *
32 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
33 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
34 * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
35 * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
36 * の責任を負わない.
37 *
38 * @(#) $Id: jtag_uart.c 1 2010-06-14 02:33:52Z ertl-ichiba $
39 */
40
41/*
42 * シリアルI/Oデバイス(SIO)ドライバ(JTAG UART用)
43 */
44
45#include <kernel.h>
46#include <t_syslog.h>
47#include "target_syssvc.h"
48#include "target_serial.h"
49
50/*
51 * シリアルI/Oポート初期化ブロックの定義
52 */
53typedef struct sio_port_initialization_block
54{
55 void* ctrl;
56 void* data;
57 uint32_t intno;
58}
59SIOPINIB;
60
61/*
62 * シリアルI/Oポート管理ブロックの定義
63 */
64struct sio_port_control_block
65{
66 const SIOPINIB *p_siopinib; /* シリアルI/Oポート初期化ブロック */
67 intptr_t exinf; /* 拡張情報 */
68 bool_t openflag; /* オープン済みフラグ */
69 bool_t sendflag; /* 送信割込みイネーブルフラグ */
70 bool_t getready; /* 文字を受信した状態 */
71 bool_t putready; /* 文字を送信できる状態 */
72};
73
74/*
75 * シリアルI/Oポート初期化ブロック
76 */
77const SIOPINIB siopinib_table[TNUM_PORT] = {
78 {
79 (void*)(JTAG_UART_PORT1_BASE + JTAG_UART_CONTROL_OFFSET),
80 (void*)(JTAG_UART_PORT1_BASE + JTAG_UART_DATA_OFFSET),
81 (uint32_t)INTNO_SIO_PORT1
82 },
83#if TNUM_PORT >= 2
84 {
85 (void*)(JTAG_UART_PORT2_BASE + JTAG_UART_CONTROL_OFFSET),
86 (void*)(JTAG_UART_PORT2_BASE + JTAG_UART_DATA_OFFSET),
87 (uint32_t)INTNO_SIO_PORT2
88 },
89#endif /* TNUM_PORT >= 2 */
90#if TNUM_PORT >= 3
91 {
92 (void*)(JTAG_UART_PORT3_BASE + JTAG_UART_CONTROL_OFFSET),
93 (void*)(JTAG_UART_PORT3_BASE + JTAG_UART_DATA_OFFSET),
94 (uint32_t)INTNO_SIO_PORT3
95 },
96#endif /* TNUM_PORT >= 3 */
97};
98
99/*
100 * シリアルI/Oポート管理ブロックのエリア
101 */
102SIOPCB siopcb_table[TNUM_PORT];
103
104/*
105 * シリアルI/OポートIDから管理ブロックを取り出すためのマクロ
106 */
107#define INDEX_SIOP(siopid) ((uint_t)((siopid) - 1))
108#define get_siopcb(siopid) (&(siopcb_table[INDEX_SIOP(siopid)]))
109
110/*
111 * JTAG_UART はステータスとデータを同時に取得するため,ステータスを
112 * チェックするとデータを読み込んでしまう.そのため,uart_getready()
113 * を実行した後のデータを入れる.
114 */
115static int8_t jtag_uart_buf = -1;
116
117/*
118 * 文字を受信したか?
119 */
120Inline bool_t
121uart_getready(SIOPCB *p_siopcb)
122{
123 uint32_t tmp = sil_rew_iop(p_siopcb->p_siopinib->data);
124 jtag_uart_buf = (uint8_t)tmp;
125 return ((tmp & JTAG_UART_DATA_RVALID) != 0);
126}
127
128/*
129 * 文字を送信できるか?
130 */
131Inline bool_t
132uart_putready(SIOPCB *p_siopcb)
133{
134 return((sil_rew_iop(p_siopcb->p_siopinib->ctrl)
135 & JTAG_UART_CONTROL_WSAPCE) > 0);
136}
137
138/*
139 * 受信した文字の取り出し
140 */
141Inline uint8_t
142uart_getchar(SIOPCB *p_siopcb)
143{
144 return((uint8_t)(sil_rew_iop(p_siopcb->p_siopinib->data)));
145}
146
147/*
148 * 送信する文字の書き込み
149 */
150Inline void
151uart_putchar(SIOPCB *p_siopcb, uint8_t c)
152{
153 sil_wrw_iop(p_siopcb->p_siopinib->data, c);
154}
155
156/*
157 * 送信制御関数
158 */
159/*
160 * 送信割込み許可
161 */
162Inline void
163uart_enable_send(SIOPCB *p_siopcb)
164{
165 sil_wrw_iop(p_siopcb->p_siopinib->ctrl,
166 sil_rew_iop(p_siopcb->p_siopinib->ctrl)
167 |JTAG_UART_CONTROL_WIE);
168}
169
170/*
171 * 送信割込み禁止
172 */
173Inline void
174uart_disable_send(SIOPCB *p_siopcb)
175{
176 sil_wrw_iop(p_siopcb->p_siopinib->ctrl,
177 sil_rew_iop(p_siopcb->p_siopinib->ctrl)
178 & ~JTAG_UART_CONTROL_WIE);
179}
180
181
182/*
183 * 受信割込み許可
184 */
185Inline void
186uart_enable_rcv(SIOPCB *p_siopcb)
187{
188 sil_wrw_iop(p_siopcb->p_siopinib->ctrl,
189 sil_rew_iop(p_siopcb->p_siopinib->ctrl)
190 | JTAG_UART_CONTROL_RIE);
191}
192
193/*
194 * 受信割込み禁止
195 */
196Inline void
197uart_disable_rcv(SIOPCB *p_siopcb)
198{
199 sil_wrw_iop(p_siopcb->p_siopinib->ctrl,
200 sil_rew_iop(p_siopcb->p_siopinib->ctrl)
201 & ~JTAG_UART_CONTROL_RIE);
202}
203
204
205/*
206 * SIOドライバの初期化
207 */
208void
209sio_initialize(intptr_t exinf)
210{
211 SIOPCB *p_siopcb;
212 uint_t i;
213
214 /*
215 * シリアルI/Oポート管理ブロックの初期化
216 */
217 for (p_siopcb = siopcb_table, i = 0; i < TNUM_PORT; p_siopcb++, i++) {
218 p_siopcb->p_siopinib = &(siopinib_table[i]);
219 p_siopcb->openflag = false;
220 p_siopcb->sendflag = false;
221 }
222}
223
224/*
225 * シリアルI/Oポートのオープン
226 */
227SIOPCB *
228jtag_uartl_opn_por(SIOPCB *p_siopcb, intptr_t exinf)
229{
230 const SIOPINIB *p_siopinib;
231 p_siopinib = p_siopcb->p_siopinib;
232
233 p_siopcb->exinf = exinf;
234 p_siopcb->getready = p_siopcb->putready = false;
235 p_siopcb->openflag = true;
236
237 return(p_siopcb);
238}
239
240/*
241 * シリアルI/Oポートのオープン
242 */
243SIOPCB *
244sio_opn_por(ID siopid, intptr_t exinf)
245{
246 SIOPCB *p_siopcb = get_siopcb(siopid);
247 bool_t opnflg;
248 ER ercd;
249
250 /*
251 * オープンしたポートがあるかをopnflgに読んでおく.
252 */
253 opnflg = p_siopcb->openflag;
254
255 /*
256 * デバイス依存のオープン処理.
257 */
258 jtag_uartl_opn_por(p_siopcb, exinf);
259
260 /*
261 * シリアルI/O割込みのマスクを解除する.
262 */
263 if (!opnflg) {
264 ercd = ena_int(p_siopcb->p_siopinib->intno);
265 assert(ercd == E_OK);
266 }
267 return(p_siopcb);
268}
269
270/*
271 * シリアルI/Oポートのクローズ
272 */
273void
274sio_cls_por(SIOPCB *p_siopcb)
275{
276 const SIOPINIB *p_siopinib;
277
278 p_siopinib = p_siopcb->p_siopinib;
279
280 /* 割込みの禁止 */
281 sil_wrw_iop(p_siopcb->p_siopinib->ctrl, 0x00);
282
283 p_siopcb->openflag = false;
284
285 /*
286 * シリアルI/O割込みをマスクする.
287 */
288 dis_int(p_siopcb->p_siopinib->intno);
289}
290
291/*
292 * SIOの割込みハンドラ
293 */
294void
295sio_isr(intptr_t siopid)
296{
297 SIOPCB *p_siopcb = get_siopcb((ID)siopid);
298
299 if (uart_getready(p_siopcb)) {
300 /*
301 * 受信通知コールバックルーチンを呼び出す.
302 */
303 sio_irdy_rcv(p_siopcb->exinf);
304 }
305 if (uart_putready(p_siopcb)) {
306 /*
307 * 送信可能コールバックルーチンを呼び出す.
308 */
309 sio_irdy_snd(p_siopcb->exinf);
310 }
311}
312
313/*
314 * シリアルI/Oポートへの文字送信
315 */
316bool_t
317sio_snd_chr(SIOPCB *siopcb, char_t c)
318{
319 if (uart_putready(siopcb)) {
320 uart_putchar(siopcb, c);
321 return(true);
322 }
323 return(false);
324}
325
326/*
327 * シリアルI/Oポートからの文字受信
328 */
329int_t
330sio_rcv_chr(SIOPCB *siopcb)
331{
332 uint8_t tmp;
333
334 if (jtag_uart_buf != -1) {
335 tmp = jtag_uart_buf;
336 jtag_uart_buf = -1;
337 return tmp;
338 }
339 return(false);
340}
341
342/*
343 * シリアルI/Oポートからのコールバックの許可
344 */
345void
346sio_ena_cbr(SIOPCB *siopcb, uint_t cbrtn)
347{
348 switch (cbrtn) {
349 case SIO_RDY_SND:
350 uart_enable_send(siopcb);
351 break;
352 case SIO_RDY_RCV:
353 uart_enable_rcv(siopcb);
354 break;
355 }
356}
357
358/*
359 * シリアルI/Oポートからのコールバックの禁止
360 */
361void
362sio_dis_cbr(SIOPCB *siopcb, uint_t cbrtn)
363{
364 switch (cbrtn) {
365 case SIO_RDY_SND:
366 uart_disable_send(siopcb);
367 break;
368 case SIO_RDY_RCV:
369 uart_disable_rcv(siopcb);
370 break;
371 }
372}
Note: See TracBrowser for help on using the repository browser.