source: asp3_tinet_ecnl_rx/trunk/asp3_dcre/target/gr_sakura_gcc/target_serial.c@ 374

Last change on this file since 374 was 374, checked in by coas-nagasima, 5 years ago

mbed関連を更新
シリアルドライバをmbedのHALを使うよう変更
ファイルディスクリプタの処理を更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc;charset=UTF-8
File size: 7.3 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) 2000-2003 by Embedded and Real-Time Systems Laboratory
7 * Toyohashi Univ. of Technology, JAPAN
8 * Copyright (C) 2003-2004 by Naoki Saito
9 * Nagoya Municipal Industrial Research Institute, JAPAN
10 * Copyright (C) 2003-2004 by Platform Development Center
11 * RICOH COMPANY,LTD. JAPAN
12 * Copyright (C) 2008-2010 by Witz Corporation, JAPAN
13 * Copyright (C) 2013 by Mitsuhiro Matsuura
14 *
15 * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
16 * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
17 * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
18 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
19 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
20 * スコード中に含まれていること.
21 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
22 * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
23 * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
24 * の無保証規定を掲載すること.
25 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
26 * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
27 * と.
28 * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
29 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
30 * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
31 * 報告すること.
32 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
33 * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
34 * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
35 * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
36 * 免責すること.
37 *
38 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
39 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
40 * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
41 * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
42 * の責任を負わない.
43 *
44 * @(#) $Id$
45 */
46
47/*
48 * RX630 UART用シリアルI/Oモジュール
49 */
50#include "kernel_impl.h"
51#include <sil.h>
52#include "target_serial.h"
53#include "hal/serial_api.h"
54#include "target_syssvc.h"
55#include "syssvc/serial.h"
56
57/*
58 * シリアルI/Oポート初期化ブロックの定義
59 */
60typedef struct sio_port_initialization_block {
61 PinName tx;
62 PinName rx;
63} SIOPINIB;
64
65/*
66 * シリアルI/Oポート管理ブロックの定義
67 */
68struct sio_port_control_block {
69 const SIOPINIB *p_siopinib;
70 intptr_t exinf;
71 bool_t openflag;
72 serial_t serial;
73};
74
75/*
76 * シリアルI/Oポート管理ブロックのエリア
77 */
78SIOPCB siopcb_table[TNUM_PORT];
79
80static const SIOPINIB siopinib_table[TNUM_SIOP] =
81{
82 { P20, P21 },
83#if TNUM_SIOP > 1
84 { P32, P33 },
85#endif
86#if TNUM_SIOP > 2
87 { P50, P52 },
88#endif
89#if TNUM_SIOP > 3
90 { P23, P25 },
91#endif
92#if TNUM_SIOP > 4
93 { PC3, PC2 },
94#endif
95#if TNUM_SIOP > 5
96 { PC7, PC6 },
97#endif
98#if TNUM_SIOP > 6
99 { P26, P30 },
100#endif
101};
102
103/*
104 * シリアルI/OポートIDから管理ブロックを取り出すためのマクロ
105 */
106#define INDEX_SIOP(siopid) ((uint_t)((siopid) - 1))
107#define get_siopcb(siopid) (&(siopcb_table[INDEX_SIOP(siopid)]))
108#define get_siopinib(siopid) (&(siopinib_table[INDEX_SIOP(siopid)]))
109
110static void mbed_serial_irq_handler(uint32_t id, SerialIrq event);
111
112/*
113 * SIOドライバの初期化
114 */
115void
116sio_initialize(intptr_t exinf)
117{
118 SIOPCB *p_siopcb;
119 uint_t i;
120
121 /*
122 * シリアルI/Oポート管理ブロックの初期化
123 */
124 for (p_siopcb = siopcb_table, i = 0; i < TNUM_SIOP; p_siopcb++, i++) {
125 p_siopcb->p_siopinib = &(siopinib_table[i]);
126 p_siopcb->openflag = false;
127 }
128}
129
130/*
131 * シリアルI/Oポートのオープン
132 */
133SIOPCB *
134sio_opn_por(ID siopid, intptr_t exinf)
135{
136 SIOPCB *p_siopcb = NULL;
137 ER ercd;
138 serial_t *serial;
139
140 if ((siopid <= 0) || (siopid > (sizeof(siopcb_table) / sizeof(siopcb_table[0]))))
141 return NULL;
142 p_siopcb = get_siopcb(siopid);
143
144 if (p_siopcb->openflag)
145 return NULL;
146 p_siopcb->openflag = true;
147 p_siopcb->exinf = exinf;
148
149 serial = &p_siopcb->serial;
150 serial_init(serial, p_siopcb->p_siopinib->tx, p_siopcb->p_siopinib->rx);
151 serial_baud(serial, UART_BAUDRATE);
152 serial_format(serial, 8, ParityNone, 1);
153
154 serial_irq_handler(serial, mbed_serial_irq_handler, siopid);
155
156 return p_siopcb;
157}
158
159/*
160 * シリアルI/Oポートのクローズ
161 */
162void
163sio_cls_por(SIOPCB *p_siopcb)
164{
165 ER ercd;
166 serial_t *serial = &p_siopcb->serial;
167
168 /*
169 * デバイス依存のクローズ処理.
170 */
171 serial_free(serial);
172 p_siopcb->openflag = false;
173}
174
175/*
176 * シリアルI/Oポートへの文字送信
177 */
178bool_t
179sio_snd_chr(SIOPCB *p_siopcb, char c)
180{
181 serial_t *serial = &p_siopcb->serial;
182 if (!serial_writable(serial))
183 return false;
184 serial_putc(serial, c);
185 return true;
186}
187
188/*
189 * シリアルI/Oポートからの文字受信
190 */
191int_t
192sio_rcv_chr(SIOPCB *p_siopcb)
193{
194 serial_t *serial = &p_siopcb->serial;
195 if (!serial_readable(serial))
196 return -1;
197 return serial_getc(serial);
198}
199
200/*
201 * シリアルI/Oポートからのコールバックの許可
202 */
203void
204sio_ena_cbr(SIOPCB *p_siopcb, uint_t cbrtn)
205{
206 serial_t *serial = &p_siopcb->serial;
207 switch (cbrtn) {
208 case SIO_RDY_SND:
209 serial_irq_set(serial, TxIrq, true);
210 break;
211 case SIO_RDY_RCV:
212 serial_irq_set(serial, RxIrq, true);
213 break;
214 }
215}
216
217/*
218 * シリアルI/Oポートからのコールバックの禁止
219 */
220void
221sio_dis_cbr(SIOPCB *p_siopcb, uint_t cbrtn)
222{
223 serial_t *serial = &p_siopcb->serial;
224 switch (cbrtn) {
225 case SIO_RDY_SND:
226 serial_irq_set(serial, TxIrq, false);
227 break;
228 case SIO_RDY_RCV:
229 serial_irq_set(serial, RxIrq, false);
230 break;
231 }
232}
233
234/*
235 * シリアルI/Oポートからの送信可能コールバック
236 */
237void
238serial_irdy_snd(SIOPCB *p_siopcb)
239{
240 /* 共通部(syssvc\serial.c)にあるsio_irdy_snd関数を呼び出し*/
241 sio_irdy_snd(p_siopcb->exinf);
242}
243
244/*
245 * シリアルI/Oポートからの受信通知コールバック
246 */
247void
248serial_irdy_rcv(SIOPCB *p_siopcb)
249{
250 /* 共通部(syssvc\serial.c)にあるsio_irdy_rcv関数を呼び出し*/
251 sio_irdy_rcv(p_siopcb->exinf);
252}
253
254/*
255 * SIOの割込みハンドラ
256 */
257void
258mbed_serial_irq_handler(uint32_t siopid, SerialIrq event)
259{
260 SIOPCB *p_siopcb;
261
262 if ((siopid <= 0) || (siopid > (sizeof(siopcb_table) / sizeof(siopcb_table[0]))))
263 return;
264 p_siopcb = get_siopcb(siopid);
265
266 if (!p_siopcb->openflag)
267 return;
268
269 switch (event) {
270 case TxIrq:
271 serial_irdy_snd(p_siopcb);
272 break;
273 case RxIrq:
274 serial_irdy_rcv(p_siopcb);
275 break;
276 }
277}
Note: See TracBrowser for help on using the repository browser.