source: asp_ccsproject/trunk/asp/target/lm4f120_gcc/target_serial.c@ 85

Last change on this file since 85 was 85, checked in by ecsg-okazaki, 10 years ago

2014/09/26 ECS E.Okazaki Folder configuration change

File size: 6.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-2011 by Embedded and Real-Time Systems Laboratory
7 * Graduate School of Information Science, Nagoya Univ., JAPAN
8 *
9 * 上記著作権者
10は,以下の(1)〜(4)の条件を満たす場合に限り,本ソフトウェ
11 * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
12 * 変・再é…
13å¸ƒï¼ˆä»¥ä¸‹ï¼Œåˆ©ç”¨ã¨å‘¼ã¶ï¼‰ã™ã‚‹ã“とを無償で許諾する.
14 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
15 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
16 * スコード中に含まれていること.
17 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
18 * 用できる形で再é…
19å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œå†é…
20å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨
21 * 者
22マニュアルなど)に,上記の著作権表示,この利用条件および下記
23 * の無保証規定を掲載すること.
24 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
25 * 用できない形で再é…
26å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œæ¬¡ã®ã„ずれかの条件を満たすこ
27 * と.
28 * (a) 再é…
29å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨è€…
30マニュアルなど)に,上記の著
31 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
32 * (b) 再é…
33å¸ƒã®å½¢æ…
34‹ã‚’,別に定める方法によって,TOPPERSプロジェクトに
35 * 報告すること.
36 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
37 * 害からも,上記著作権者
38およびTOPPERSプロジェクトをå…
39è²¬ã™ã‚‹ã“と.
40 * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
41 * 由に基づく請求からも,上記著作権者
42およびTOPPERSプロジェクトを
43 * å…
44è²¬ã™ã‚‹ã“と.
45 *
46 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者
47お
48 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
49 * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
50 * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
51 * の責任を負わない.
52 *
53 * @(#) $Id: target_serial.c 2202 2011-07-26 13:27:11Z ertl-honda $
54 */
55
56/*
57 * シリアルI/Oデバイス(SIO)ドライバ(LM4F120用)
58 */
59
60#include <kernel.h>
61#include <t_syslog.h>
62#include "target_serial.h"
63#include "inc/hw_memmap.h"
64#include "inc/hw_types.h"
65#include "driverlib/uart.h"
66
67/*
68 * シリアルI/Oポート初期化ブロックの定義
69 */
70typedef struct sio_port_initialization_block {
71 uint32_t base;
72 INTNO intno;
73} SIOPINIB;
74
75/*
76 * シリアルI/Oポート管理ブロックの定義
77 */
78struct sio_port_control_block {
79 const SIOPINIB *p_siopinib; /* シリアルI/Oポート初期化ブロック */
80 intptr_t exinf; /* 拡張情
81å ± */
82 bool_t opnflg; /* オープン済みフラグ */
83};
84
85/*
86 * シリアルI/Oポート初期化ブロック
87 */
88const SIOPINIB siopinib_table[TNUM_SIOP] = {
89 {(uint32_t)UART0_BASE, (INTNO)INTNO_SIO}
90};
91
92/*
93 * シリアルI/Oポート管理ブロックのエリア
94 */
95SIOPCB siopcb_table[TNUM_SIOP];
96
97/*
98 * シリアルI/OポートIDから管理ブロックを取り出すためのマクロ
99 */
100#define INDEX_SIOP(siopid) ((uint_t)((siopid) - 1))
101#define get_siopcb(siopid) (&(siopcb_table[INDEX_SIOP(siopid)]))
102
103/*
104 * SIOドライバの初期化
105 */
106void
107sio_initialize(intptr_t exinf)
108{
109 SIOPCB *p_siopcb;
110 uint_t i;
111
112 /*
113 * シリアルI/Oポート管理ブロックの初期化
114 */
115 for (p_siopcb = siopcb_table, i = 0; i < TNUM_SIOP; p_siopcb++, i++) {
116 p_siopcb->p_siopinib = &(siopinib_table[i]);
117 p_siopcb->opnflg = false;
118 }
119}
120
121
122/*
123 * シリアルI/Oポートのオープン
124 */
125SIOPCB *
126sio_opn_por(ID siopid, intptr_t exinf)
127{
128 SIOPCB *p_siopcb;
129 const SIOPINIB *p_siopinib;
130 bool_t opnflg;
131 ER ercd;
132
133 p_siopcb = get_siopcb(siopid);
134 p_siopinib = p_siopcb->p_siopinib;
135
136 /*
137 * オープンしたポートがあるかをopnflgに読んでおく.
138 */
139 opnflg = p_siopcb->opnflg;
140
141 p_siopcb->exinf = exinf;
142
143 /*
144 * ハードウェアの初期化
145 */
146#ifndef TOPPERS_QEMU_CM3
147 UARTConfigSetExpClk(p_siopinib->base, SysCtlClockGet(), 115200,
148 (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
149 UART_CONFIG_PAR_NONE));
150#endif /* TOPPERS_QEMU_CM3 */
151
152 /*
153 * シリアルI/O割込みのマスクを解除する.
154 */
155 if (!opnflg) {
156 ercd = ena_int(p_siopinib->intno);
157 assert(ercd == E_OK);
158 }
159
160 return(p_siopcb);
161}
162
163/*
164 * シリアルI/Oポートのクローズ
165 */
166void
167sio_cls_por(SIOPCB *p_siopcb)
168{
169 /*
170 * シリアルI/O割込みをマスクする.
171 */
172 if (!(p_siopcb->opnflg)) {
173 dis_int(p_siopcb->p_siopinib->intno);
174 }
175}
176
177/*
178 * SIOの割込みサービスルーチン
179 */
180void
181sio_isr(intptr_t exinf)
182{
183 SIOPCB *p_siopcb;
184
185 p_siopcb = get_siopcb(exinf);
186
187 /*
188 * 割込みのクリア
189 */
190 UARTIntClear(p_siopcb->p_siopinib->base,
191 UARTIntStatus(p_siopcb->p_siopinib->base, true));
192
193 if (UARTCharsAvail(p_siopcb->p_siopinib->base)) {
194 /*
195 * 受信通知コールバックルーチンを呼び出す.
196 */
197 sio_irdy_rcv(p_siopcb->exinf);
198 }
199 if (UARTSpaceAvail(p_siopcb->p_siopinib->base)) {
200 /*
201 * 送信可能コールバックルーチンを呼び出す.
202 */
203 sio_irdy_snd(p_siopcb->exinf);
204 }
205}
206
207/*
208 * シリアルI/Oポートへの文字送信
209 */
210bool_t
211sio_snd_chr(SIOPCB *p_siopcb, char c)
212{
213 if(UARTSpaceAvail(p_siopcb->p_siopinib->base)){
214 UARTCharPutNonBlocking(p_siopcb->p_siopinib->base, c);
215 return(true);
216 }
217 return(false);
218}
219
220/*
221 * シリアルI/Oポートからの文字受信
222 */
223int_t
224sio_rcv_chr(SIOPCB *p_siopcb)
225{
226 if(UARTCharsAvail(p_siopcb->p_siopinib->base)){
227 return(UARTCharGetNonBlocking(p_siopcb->p_siopinib->base));
228 }
229 return(-1);
230}
231
232/*
233 * シリアルI/Oポートからのコールバックの許可
234 */
235void
236sio_ena_cbr(SIOPCB *p_siopcb, uint_t cbrtn)
237{
238 switch (cbrtn) {
239 case SIO_RDY_SND:
240 UARTIntEnable(p_siopcb->p_siopinib->base, UART_INT_TX);
241 break;
242 case SIO_RDY_RCV:
243 UARTIntEnable(p_siopcb->p_siopinib->base, UART_INT_RX|UART_INT_RT);
244 break;
245 }
246}
247
248/*
249 * シリアルI/Oポートからのコールバックの禁止
250 */
251void
252sio_dis_cbr(SIOPCB *p_siopcb, uint_t cbrtn)
253{
254 switch (cbrtn) {
255 case SIO_RDY_SND:
256 UARTIntDisable(p_siopcb->p_siopinib->base, UART_INT_TX);
257 break;
258 case SIO_RDY_RCV:
259 UARTIntDisable(p_siopcb->p_siopinib->base, UART_INT_RX|UART_INT_RT);
260 break;
261 }
262}
Note: See TracBrowser for help on using the repository browser.