1 | /*
|
---|
2 | * TOPPERS/JSP Kernel
|
---|
3 | * Toyohashi Open Platform for Embedded Real-Time Systems/
|
---|
4 | * Just Standard Profile Kernel
|
---|
5 | *
|
---|
6 | * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
|
---|
7 | * Toyohashi Univ. of Technology, JAPAN
|
---|
8 | *
|
---|
9 | * ä¸è¨è使¨©è
|
---|
10 | ã¯ï¼ä»¥ä¸ã® (1)ã(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
11 | * ã«ãã£ã¦å
|
---|
12 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
13 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
14 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
15 | å¸ï¼ä»¥ä¸ï¼
|
---|
16 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
17 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
18 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
19 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
20 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
21 | * ç¨ã§ããå½¢ã§åé
|
---|
22 | å¸ããå ´åã«ã¯ï¼åé
|
---|
23 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
24 | * è
|
---|
25 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è使¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
26 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
27 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
28 | * ç¨ã§ããªãå½¢ã§åé
|
---|
29 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
30 | * ã¨ï¼
|
---|
31 | * (a) åé
|
---|
32 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
33 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
34 | * 使¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
35 | * (b) åé
|
---|
36 | å¸ã®å½¢æ
|
---|
37 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
38 | * å ±åãããã¨ï¼
|
---|
39 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
40 | * 害ãããï¼ä¸è¨è使¨©è
|
---|
41 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
42 | 責ãããã¨ï¼
|
---|
43 | *
|
---|
44 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨è使¨©è
|
---|
45 | ã
|
---|
46 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
47 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
48 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæå®³ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
49 | *
|
---|
50 | */
|
---|
51 |
|
---|
52 | /*
|
---|
53 | * CQ-FRK-NXP-ARM UARTç¨ ç°¡æSIOãã©ã¤ã
|
---|
54 | *
|
---|
55 | * ãã®ãã¡ã¤ã«ã¯ãTOPPERS/JSP 1.4.2ã® pdic/simple_sio/st16c2550.cã
|
---|
56 | * ãªãã¼ã ããå
|
---|
57 | é¨ã®èå¥åã夿´ãããã®ã§ããã
|
---|
58 | */
|
---|
59 | #include <s_services.h>
|
---|
60 | #include "lpc2388uart.h"
|
---|
61 |
|
---|
62 | /*
|
---|
63 | * 8250, 16450, 16550åã¬ã¸ã¹ã¿ã®ã¢ãã¬ã¹ã»ãªãã»ãããUART_RHRãåºç¹ã¨ããã
|
---|
64 | * ã·ã¹ãã ãã¨ã«ç°ãªãã®ã§UART_BOUNDARYã«ãã£ã¦ã¬ã¸ã¹ã¿ã®é
|
---|
65 | ç½®å¢çãæå®ããã
|
---|
66 | * ãã¨ãã°ãã¹ã¦ã®ã¬ã¸ã¹ã¿ã8ãããå¢çã§é
|
---|
67 | ç½®ããã¦ãããªããUART_BOUNDARYã¯1,
|
---|
68 | * 16bitå¢çãªã2, 32ãããå¢çãªã4ãæå®ããã
|
---|
69 | * UART_BOUNDARYã¯sys_config.hã§å®ç¾©ããã
|
---|
70 | */
|
---|
71 |
|
---|
72 |
|
---|
73 | #define UART_RBR (0x00 * UART_BOUNDARY) /* åä¿¡ãããã¡ã¬ã¸ã¹ã¿ */
|
---|
74 | #define UART_THR (0x00 * UART_BOUNDARY) /* éä¿¡ãã¼ã¿ã»ãã¼ã«ãã»ã¬ã¸ã¹ã¿ */
|
---|
75 | #define UART_DLL (0x00 * UART_BOUNDARY) /* åå¨ã¬ã¸ã¹ã¿ä¸ä½ãã¤ã */
|
---|
76 | #define UART_IER (0x01 * UART_BOUNDARY) /* å²è¾¼ã¿ã¤ãã¼ãã«ã¬ã¸ã¹ã¿ */
|
---|
77 | #define UART_DLM (0x01 * UART_BOUNDARY) /* åå¨ã¬ã¸ã¹ã¿ä¸ä½ãã¤ã */
|
---|
78 | #define UART_IIR (0x02 * UART_BOUNDARY) /* å²è¾¼ã¿èå¥ã¬ã¸ã¹ã¿ */
|
---|
79 | #define UART_FCR (0x02 * UART_BOUNDARY) /* FIFOå¶å¾¡ã¬ã¸ã¹ã¿ */
|
---|
80 | #define UART_LCR (0x03 * UART_BOUNDARY) /* ã©ã¤ã³å¶å¾¡ã¬ã¸ã¹ã¿ */
|
---|
81 | #define UART_MCR (0x04 * UART_BOUNDARY) /* ã¢ãã å¶å¾¡ã¬ã¸ã¹ã¿ */
|
---|
82 | #define UART_LSR (0x05 * UART_BOUNDARY) /* ã©ã¤ã³ã»ã¹ãã¼ã¿ã¹ã»ã¬ã¸ã¹ã¿ */
|
---|
83 | #define UART_MSR (0x06 * UART_BOUNDARY) /* ã¢ãã ã»ã¹ãã¼ã¿ã¹ã»ã¬ã¸ã¹ã¿ */
|
---|
84 | #define UART_SCR (0x07 * UART_BOUNDARY) /* ã¹ã¯ã©ããã»ãããã»ã¬ã¸ã¹ã¿ */
|
---|
85 | #define UART_GCTL (0x09 * UART_BOUNDARY) /* Blackfinã®ã¿ãã°ãã¼ãã«å¶å¾¡ã¬ã¸ã¹ã¿ */
|
---|
86 |
|
---|
87 | /*
|
---|
88 | * ã¬ã¸ã¹ã¿ã®ããããã¹ã¯ãç¹æ®æ©è½ã追å ããªãéããæ¸ãæããªãã¦ããã
|
---|
89 | */
|
---|
90 |
|
---|
91 | #define ISR_TX 0x02 /* éä¿¡å²ãè¾¼ã¿çºç */
|
---|
92 | #define IER_TX 0x02 /* éä¿¡å²ãè¾¼ã¿è¨±å¯ */
|
---|
93 | #define ISR_RX 0x01 /* åä¿¡å²ãè¾¼ã¿çºç */
|
---|
94 | #define IER_RX 0x01 /* åä¿¡å²ãè¾¼ã¿è¨±å¯ */
|
---|
95 |
|
---|
96 | #define LCR_DL_MODE 0x80 /* Divisor Enable */
|
---|
97 | #define LCR_NP_8_1 0x03 /* 8bit,1stop,Noparity,No break */
|
---|
98 | #define FCR_FIFO_DISABLE 0x00
|
---|
99 |
|
---|
100 | #define LSR_RX_DATA_READY 0x01
|
---|
101 | #define LSR_TX_EMPTY 0x20
|
---|
102 |
|
---|
103 | #define MCR_INT_ENABLE 0x08
|
---|
104 |
|
---|
105 | #define GCTL_UCEN 0x01 /* Blackfinã®ã¿ */
|
---|
106 |
|
---|
107 |
|
---|
108 | /*
|
---|
109 | * TNUM_SIOP_UART, UART0_ADDRESS, UART0_DIVISOR ã¯sys_config.hã§å®ç¾©ããã
|
---|
110 | * TNUM_SIOP_UART : PDICã管çããUARTã®åæ°
|
---|
111 | * 以ä¸ãPDICã管çããæåã®UARTã®æ
|
---|
112 | å ±
|
---|
113 | * UART0_ADDRESS : THRã®ã¢ãã¬ã¹
|
---|
114 | * UART0_DIVISOR : DLM, DLLã®åæå¤(16bit表è¨)
|
---|
115 | * UART0_14550_FIFO : 14550äºæã®FIFOãæã¤ã¨ãã«ãã¯ãã宣è¨ãã
|
---|
116 | * UART0_BLACKFIN_UCEN : Blackfinå°ç¨ããã¯ãã宣è¨ããã¨åæåã³ã¼ããUART_GCTLã®UCENã1ã«ããã
|
---|
117 | * äºã¤ç®ä»¥éã®UARTããããªã以ä¸ã®ããã«ç¶ããã
|
---|
118 | * UART1_ADDRESS : THRã®ã¢ãã¬ã¹
|
---|
119 | * UART1_DIVISOR : DLM, DLLã®åæå¤(16bit表è¨)
|
---|
120 | * UART1_14550_FIFO : 14550äºæã®FIFOãæã¤ã¨ãã«ãã¯ãã宣è¨ãã
|
---|
121 | * UART1_BLACKFIN_UCEN : Blackfinå°ç¨ããã¯ãã宣è¨ããã¨åæåã³ã¼ããUART_GCTLã®UCENã1ã«ããã
|
---|
122 | * ...
|
---|
123 | */
|
---|
124 |
|
---|
125 |
|
---|
126 | /******************************************************************************************
|
---|
127 | * ã·ãªã¢ã«I/Oãã¼ãåæåãããã¯
|
---|
128 | */
|
---|
129 | #if TNUM_SIOP_UART == 0
|
---|
130 | #error "If you don't use UART, please remove this file from your make file"
|
---|
131 | #endif
|
---|
132 |
|
---|
133 | #if TNUM_SIOP_UART > 3
|
---|
134 | #error "Only TNUM_SIOP_UART < 4 is supported"
|
---|
135 | #endif /* TNUM_SIOP_UART >= 2 */
|
---|
136 |
|
---|
137 | /* ãã£ãã¤ã¶è¨ç®ãã¯ã */
|
---|
138 | #define DLM(divisor) (divisor/256)
|
---|
139 | #define DLL(divisor) (divisor%256)
|
---|
140 |
|
---|
141 | const SIOPINIB siopinib_table[TNUM_SIOP_UART] = {
|
---|
142 | /*-----------------------------------------------------------------
|
---|
143 | * PDICã管çããæåã®UARTã®åæåãã©ã¡ã¼ã¿
|
---|
144 | */
|
---|
145 | {UART0_ADDRESS, DLM(UART0_DIVISOR), DLL(UART0_DIVISOR),
|
---|
146 | #ifdef UART0_BLACKFIN_UCEN
|
---|
147 | 1 /* ãã¯ãUART0_BLACKFIN_UCENãå®ç¾©ããã¦ããããGCTLã®UCENã1ã«ãã¦ã¯ããã¯ãåãã */
|
---|
148 | #else
|
---|
149 | 0
|
---|
150 | #endif
|
---|
151 | }
|
---|
152 |
|
---|
153 | /*-----------------------------------------------------------------
|
---|
154 | * PDICã管çãã2çªç®ã®UARTã®åæåãã©ã¡ã¼ã¿
|
---|
155 | */
|
---|
156 |
|
---|
157 | #if TNUM_SIOP_UART > 1
|
---|
158 | ,{UART1_ADDRESS, DLM(UART1_DIVISOR), DLL(UART1_DIVISOR),
|
---|
159 | #ifdef UART1_BLACKFIN_UCEN
|
---|
160 | 1 /* ãã¯ãUART1_BLACKFIN_UCENãå®ç¾©ããã¦ããããGCTLã®UCENã1ã«ãã¦ã¯ããã¯ãåãã */
|
---|
161 | #else
|
---|
162 | 0
|
---|
163 | #endif
|
---|
164 |
|
---|
165 |
|
---|
166 | }
|
---|
167 | #endif /* if TNUM_SIOP_UART > 1*/
|
---|
168 |
|
---|
169 | /*-----------------------------------------------------------------
|
---|
170 | * PDICã管çãã3çªç®ã®UARTã®åæåãã©ã¡ã¼ã¿
|
---|
171 | */
|
---|
172 | #if TNUM_SIOP_UART > 2
|
---|
173 | ,{UART2_ADDRESS, DLM(UART2_DIVISOR), DLL(UART2_DIVISOR),
|
---|
174 | #ifdef UART2_BLACKFIN_UCEN
|
---|
175 | 1 /* ãã¯ãUART2_BLACKFIN_UCENãå®ç¾©ããã¦ããããGCTLã®UCENã1ã«ãã¦ã¯ããã¯ãåãã */
|
---|
176 | #else
|
---|
177 | 0
|
---|
178 | #endif
|
---|
179 |
|
---|
180 |
|
---|
181 | }
|
---|
182 | #endif /* if TNUM_SIOP_UART > 2*/
|
---|
183 |
|
---|
184 | };
|
---|
185 |
|
---|
186 | /*
|
---|
187 | * ã·ãªã¢ã«I/Oãã¼ãåæåãããã¯ããã¾ã§ã
|
---|
188 | ******************************************************************************************/
|
---|
189 |
|
---|
190 |
|
---|
191 |
|
---|
192 | /*
|
---|
193 | * ã·ãªã¢ã«I/Oãã¼ãåæåãããã¯ã®ååºã
|
---|
194 | */
|
---|
195 | #define INDEX_SIOPINIB(siopid) ((UINT)((siopid) - 1))
|
---|
196 | #define get_siopinib(siopid) (&(siopinib_table[INDEX_SIOPINIB(siopid)]))
|
---|
197 |
|
---|
198 |
|
---|
199 | /*
|
---|
200 | * ã·ãªã¢ã«I/Oãã¼ã管çãããã¯ã®ã¨ãªã¢
|
---|
201 | */
|
---|
202 | SIOPCB siopcb_table[TNUM_SIOP_UART];
|
---|
203 |
|
---|
204 | /*
|
---|
205 | * ã·ãªã¢ã«I/Oãã¼ãIDãã管çãããã¯ãåãåºãããã®ãã¯ã
|
---|
206 | */
|
---|
207 | #define INDEX_SIOP(siopid) ((UINT)((siopid) - 1))
|
---|
208 | #define get_siopcb(siopid) (&(siopcb_table[INDEX_SIOP(siopid)]))
|
---|
209 |
|
---|
210 | Inline void
|
---|
211 | uart_write(UW addr, UW offset, UB val)
|
---|
212 | {
|
---|
213 | #ifdef UART_IOP_ACCESS
|
---|
214 | sil_wrb_iop((VP)(addr + offset),val);
|
---|
215 | #else
|
---|
216 | sil_wrb_mem((VP)(addr + offset),val);
|
---|
217 | #endif
|
---|
218 | }
|
---|
219 |
|
---|
220 | Inline UB
|
---|
221 | uart_read(UW addr, UW offset)
|
---|
222 | {
|
---|
223 | #ifdef UART_IOP_ACCESS
|
---|
224 | return(sil_reb_iop((VP)(addr + offset)));
|
---|
225 | #else
|
---|
226 | return(sil_reb_mem((VP)(addr + offset)));
|
---|
227 | #endif
|
---|
228 | }
|
---|
229 |
|
---|
230 |
|
---|
231 | /*
|
---|
232 | * æåãåä¿¡ããã?
|
---|
233 | */
|
---|
234 | Inline BOOL
|
---|
235 | uart_getready(SIOPCB *siopcb)
|
---|
236 | {
|
---|
237 | UH status;
|
---|
238 |
|
---|
239 | status = uart_read(siopcb->siopinib->reg_base, UART_LSR);
|
---|
240 |
|
---|
241 | return((status & LSR_RX_DATA_READY));
|
---|
242 | }
|
---|
243 |
|
---|
244 | /*
|
---|
245 | * æåãéä¿¡ã§ããã?
|
---|
246 | */
|
---|
247 | Inline BOOL
|
---|
248 | uart_putready(SIOPCB *siopcb)
|
---|
249 | {
|
---|
250 | UH status;
|
---|
251 |
|
---|
252 | status = uart_read(siopcb->siopinib->reg_base, UART_LSR);
|
---|
253 |
|
---|
254 | return (status & LSR_TX_EMPTY);
|
---|
255 | }
|
---|
256 |
|
---|
257 | /*
|
---|
258 | * åä¿¡ããæåã®åãåºã
|
---|
259 | */
|
---|
260 | Inline UB
|
---|
261 | uart_getchar(SIOPCB *siopcb)
|
---|
262 | {
|
---|
263 | return(uart_read(siopcb->siopinib->reg_base,UART_RBR));
|
---|
264 | }
|
---|
265 |
|
---|
266 | /*
|
---|
267 | * éä¿¡ããæåã®æ¸ãè¾¼ã¿
|
---|
268 | */
|
---|
269 | Inline void
|
---|
270 | uart_putchar(SIOPCB *siopcb, UB c)
|
---|
271 | {
|
---|
272 | uart_write(siopcb->siopinib->reg_base, UART_THR, c);
|
---|
273 | }
|
---|
274 |
|
---|
275 | /*
|
---|
276 | * éä¿¡å²è¾¼ã¿è¨±å¯
|
---|
277 | */
|
---|
278 | Inline void
|
---|
279 | uart_enable_send(SIOPCB *siopcb)
|
---|
280 | {
|
---|
281 | uart_write(siopcb->siopinib->reg_base, UART_IER,
|
---|
282 | (uart_read(siopcb->siopinib->reg_base,UART_IER) | IER_TX));
|
---|
283 | }
|
---|
284 |
|
---|
285 | /*
|
---|
286 | * éä¿¡å²è¾¼ã¿ç¦æ¢
|
---|
287 | */
|
---|
288 | Inline void
|
---|
289 | uart_disable_send(SIOPCB *siopcb)
|
---|
290 | {
|
---|
291 | uart_write(siopcb->siopinib->reg_base, UART_IER,
|
---|
292 | (uart_read(siopcb->siopinib->reg_base, UART_IER) & ~IER_TX));
|
---|
293 |
|
---|
294 | }
|
---|
295 |
|
---|
296 | /*
|
---|
297 | * åä¿¡å²è¾¼ã¿è¨±å¯
|
---|
298 | */
|
---|
299 | Inline void
|
---|
300 | uart_enable_rcv(SIOPCB *siopcb)
|
---|
301 | {
|
---|
302 | uart_write(siopcb->siopinib->reg_base, UART_IER,
|
---|
303 | (uart_read(siopcb->siopinib->reg_base,UART_IER) | IER_RX));
|
---|
304 | }
|
---|
305 |
|
---|
306 | /*
|
---|
307 | * åä¿¡å²è¾¼ã¿ç¦æ¢
|
---|
308 | */
|
---|
309 | Inline void
|
---|
310 | uart_disable_rcv(SIOPCB *siopcb)
|
---|
311 | {
|
---|
312 | uart_write(siopcb->siopinib->reg_base, UART_IER,
|
---|
313 | (uart_read(siopcb->siopinib->reg_base, UART_IER) & ~IER_RX));
|
---|
314 |
|
---|
315 | }
|
---|
316 |
|
---|
317 |
|
---|
318 | /*
|
---|
319 | * SIOãã©ã¤ãã®åæåã«ã¼ãã³
|
---|
320 | */
|
---|
321 | void
|
---|
322 | uart_initialize()
|
---|
323 | {
|
---|
324 | SIOPCB *siopcb;
|
---|
325 | UINT i;
|
---|
326 |
|
---|
327 | /*
|
---|
328 | * ã·ãªã¢ã«I/Oãã¼ã管çãããã¯ã®åæå
|
---|
329 | */
|
---|
330 | for (siopcb = siopcb_table, i = 0; i < TNUM_SIOP_UART; siopcb++, i++) {
|
---|
331 | siopcb->siopinib = &(siopinib_table[i]);
|
---|
332 | siopcb->openflag = FALSE;
|
---|
333 | siopcb->sendflag = FALSE;
|
---|
334 | }
|
---|
335 | }
|
---|
336 |
|
---|
337 |
|
---|
338 | /*
|
---|
339 | *
|
---|
340 | */
|
---|
341 | void
|
---|
342 | uart_init_siopinib(const SIOPINIB *siopinib)
|
---|
343 | {
|
---|
344 |
|
---|
345 | /*
|
---|
346 | * Blackfin ADSP-BF531/2/3, BF534/6/7, BF561ã®å
|
---|
347 | èµUARTã«åºæã®ä½æ¥ã
|
---|
348 | * Power Downã¢ã¼ãã®è§£é¤ã
|
---|
349 | */
|
---|
350 | if ( siopinib->set_ucen )
|
---|
351 | uart_write(siopinib->reg_base, UART_GCTL,
|
---|
352 | (uart_read(siopinib->reg_base, UART_GCTL) | GCTL_UCEN ));
|
---|
353 | /*
|
---|
354 | * å卿¯ã®è¨å®
|
---|
355 | */
|
---|
356 | /* Divisor Enable */
|
---|
357 | uart_write(siopinib->reg_base, UART_LCR,
|
---|
358 | (uart_read(siopinib->reg_base, UART_LCR) | LCR_DL_MODE));
|
---|
359 | uart_write(siopinib->reg_base, UART_DLL, siopinib->dll_val);
|
---|
360 | uart_write(siopinib->reg_base, UART_DLM, siopinib->dlm_val);
|
---|
361 | /* Divisor Disable */
|
---|
362 | uart_write(siopinib->reg_base, UART_LCR,
|
---|
363 | (uart_read(siopinib->reg_base, UART_LCR) & ~LCR_DL_MODE));
|
---|
364 |
|
---|
365 | /* ã¢ã¼ãè¨å®, ããªãã£ç¡ã 8bit data, 1 stop bit */
|
---|
366 | uart_write(siopinib->reg_base, UART_LCR, LCR_NP_8_1);
|
---|
367 |
|
---|
368 | /* å²è¾¼ã¿ç¦æ¢ */
|
---|
369 | uart_write(siopinib->reg_base, UART_IER, 0x00);
|
---|
370 | }
|
---|
371 |
|
---|
372 |
|
---|
373 | /*
|
---|
374 | * ã«ã¼ãã«èµ·åæã®ããã¼åºåç¨ã®åæå
|
---|
375 | */
|
---|
376 | void
|
---|
377 | uart_init(void)
|
---|
378 | {
|
---|
379 | int i;
|
---|
380 | /*
|
---|
381 | * ãã¹ã¦ã®uartãåæåãããid ã¯1ããTNUM_SIOP_UARTã¾ã§ã
|
---|
382 | */
|
---|
383 | for ( i=1; i<=TNUM_SIOP_UART; i++ )
|
---|
384 | uart_init_siopinib(get_siopinib(i));
|
---|
385 | }
|
---|
386 |
|
---|
387 | /*
|
---|
388 | * ãªã¼ãã³ãã¦ãããã¼ããããã
|
---|
389 | */
|
---|
390 | BOOL
|
---|
391 | uart_openflag(void)
|
---|
392 | {
|
---|
393 | int i;
|
---|
394 |
|
---|
395 | /*
|
---|
396 | * éãã¦ãããã¼ããããã°0ãè¿ãããªããã°0ãè¿ãã
|
---|
397 | */
|
---|
398 | for ( i=0; i<TNUM_SIOP_UART; i++ )
|
---|
399 | if (siopcb_table[0].openflag)
|
---|
400 | return( 1 );
|
---|
401 | return( 0 );
|
---|
402 | }
|
---|
403 |
|
---|
404 |
|
---|
405 | /*
|
---|
406 | * ã·ãªã¢ã«I/Oãã¼ãã®ãªã¼ãã³
|
---|
407 | */
|
---|
408 | SIOPCB *
|
---|
409 | uart_opn_por(ID siopid, VP_INT exinf)
|
---|
410 | {
|
---|
411 | SIOPCB *siopcb;
|
---|
412 | const SIOPINIB *siopinib;
|
---|
413 |
|
---|
414 | siopcb = get_siopcb(siopid);
|
---|
415 | siopinib = siopcb->siopinib;
|
---|
416 |
|
---|
417 | /*
|
---|
418 | * åæå
|
---|
419 | */
|
---|
420 | uart_init_siopinib(siopcb->siopinib);
|
---|
421 |
|
---|
422 | /* åä¿¡å²è¾¼ã¿è¨±å¯ */
|
---|
423 | uart_write(siopcb->siopinib->reg_base, UART_IER, IER_RX);
|
---|
424 |
|
---|
425 | /* å²è¾¼ã¿ç·ãã¤ãã¼ãã« */
|
---|
426 | uart_write(siopcb->siopinib->reg_base, UART_MCR, MCR_INT_ENABLE);
|
---|
427 |
|
---|
428 | siopcb->exinf = exinf;
|
---|
429 | siopcb->getready = siopcb->putready = FALSE;
|
---|
430 | siopcb->openflag = TRUE;
|
---|
431 |
|
---|
432 | return(siopcb);
|
---|
433 | }
|
---|
434 |
|
---|
435 | /*
|
---|
436 | * ã·ãªã¢ã«I/Oãã¼ãã®ã¯ãã¼ãº
|
---|
437 | */
|
---|
438 | void
|
---|
439 | uart_cls_por(SIOPCB *siopcb)
|
---|
440 | {
|
---|
441 | /* å²è¾¼ã¿ç¦æ¢ */
|
---|
442 | uart_write(siopcb->siopinib->reg_base, UART_IER, 0x00);
|
---|
443 | siopcb->openflag = FALSE;
|
---|
444 | }
|
---|
445 |
|
---|
446 |
|
---|
447 | /*
|
---|
448 | * ã·ãªã¢ã«I/Oãã¼ãã¸ã®ãã¼ãªã³ã°ã§ã®åºå
|
---|
449 | */
|
---|
450 | void
|
---|
451 | uart_pol_putc(char c, ID siopid)
|
---|
452 | {
|
---|
453 | const SIOPINIB *siopinib;
|
---|
454 |
|
---|
455 | siopinib = get_siopinib(siopid);
|
---|
456 |
|
---|
457 | while((uart_read(siopinib->reg_base, UART_LSR) & LSR_TX_EMPTY)
|
---|
458 | != LSR_TX_EMPTY)
|
---|
459 | ;
|
---|
460 | uart_write(siopinib->reg_base, UART_THR, c);
|
---|
461 | }
|
---|
462 |
|
---|
463 |
|
---|
464 | /*
|
---|
465 | * ã·ãªã¢ã«I/Oãã¼ãã¸ã®æåéä¿¡
|
---|
466 | */
|
---|
467 | BOOL
|
---|
468 | uart_snd_chr(SIOPCB *siopcb, char c)
|
---|
469 | {
|
---|
470 | if (uart_putready(siopcb)){
|
---|
471 | uart_putchar(siopcb, c);
|
---|
472 | return(TRUE);
|
---|
473 | }
|
---|
474 | return(FALSE);
|
---|
475 | }
|
---|
476 |
|
---|
477 | /*
|
---|
478 | * ã·ãªã¢ã«I/Oãã¼ãããã®æååä¿¡
|
---|
479 | */
|
---|
480 | INT
|
---|
481 | uart_rcv_chr(SIOPCB *siopcb)
|
---|
482 | {
|
---|
483 | if (uart_getready(siopcb)) {
|
---|
484 | return((INT)(UB) uart_getchar(siopcb));
|
---|
485 | }
|
---|
486 | return(-1);
|
---|
487 | }
|
---|
488 |
|
---|
489 |
|
---|
490 |
|
---|
491 |
|
---|
492 |
|
---|
493 | /*
|
---|
494 | * ã·ãªã¢ã«I/Oãã¼ãããã®ã³ã¼ã«ããã¯ã®è¨±å¯
|
---|
495 | */
|
---|
496 | void
|
---|
497 | uart_ena_cbr(SIOPCB *siopcb, UINT cbrtn)
|
---|
498 | {
|
---|
499 |
|
---|
500 | switch (cbrtn) {
|
---|
501 | case SIO_ERDY_SND:
|
---|
502 | uart_enable_send(siopcb);
|
---|
503 | break;
|
---|
504 | case SIO_ERDY_RCV:
|
---|
505 | uart_enable_rcv(siopcb);
|
---|
506 | break;
|
---|
507 | }
|
---|
508 | }
|
---|
509 |
|
---|
510 | /*
|
---|
511 | * ã·ãªã¢ã«I/Oãã¼ãããã®ã³ã¼ã«ããã¯ã®ç¦æ¢
|
---|
512 | */
|
---|
513 | void
|
---|
514 | uart_dis_cbr(SIOPCB *siopcb, UINT cbrtn)
|
---|
515 | {
|
---|
516 | switch (cbrtn) {
|
---|
517 | case SIO_ERDY_SND:
|
---|
518 | uart_disable_send(siopcb);
|
---|
519 | break;
|
---|
520 | case SIO_ERDY_RCV:
|
---|
521 | uart_disable_rcv(siopcb);
|
---|
522 | break;
|
---|
523 | }
|
---|
524 | }
|
---|
525 |
|
---|
526 | /*
|
---|
527 | * ã·ãªã¢ã«I/Oãã¼ãã«å¯¾ããå²è¾¼ã¿å¦ç
|
---|
528 | */
|
---|
529 | static void
|
---|
530 | uart_rx_isr_siop(SIOPCB *siopcb)
|
---|
531 | {
|
---|
532 | if (uart_getready(siopcb)) {
|
---|
533 | /*
|
---|
534 | * åä¿¡éç¥ã³ã¼ã«ããã¯ã«ã¼ãã³ãå¼ã³åºãï¼
|
---|
535 | */
|
---|
536 | uart_ierdy_rcv(siopcb->exinf);
|
---|
537 | }
|
---|
538 | }
|
---|
539 |
|
---|
540 | static void
|
---|
541 | uart_tx_isr_siop(SIOPCB *siopcb)
|
---|
542 | {
|
---|
543 | if (uart_putready(siopcb)) {
|
---|
544 | /*
|
---|
545 | * éä¿¡å¯è½ã³ã¼ã«ããã¯ã«ã¼ãã³ãå¼ã³åºãï¼
|
---|
546 | */
|
---|
547 | uart_ierdy_snd(siopcb->exinf);
|
---|
548 | }
|
---|
549 | }
|
---|
550 |
|
---|
551 | /*
|
---|
552 | * SIOã®å²è¾¼ã¿ãµã¼ãã¹ã«ã¼ãã³
|
---|
553 | * ADSP-BF533ã®å
|
---|
554 | èµUARTã¯éåã«å¥ã
|
---|
555 | ã®å²è¾¼ã¿è¦æ±ãåºãããã
|
---|
556 | * ISRãåãã¦ãããã¾ããADSP-BF537ã®ããã«äºã¤ä»¥ä¸ã®
|
---|
557 | * UARTãæã¤å ´åãèæ
|
---|
558 | ®ãã¦ãuart0ã®ããã«ãã¼ãçªå·ã
|
---|
559 | * ååã«ãã¼ãã³ã¼ããã¦ããã
|
---|
560 | * ãã ãããã®ãã¼ãçªå·ã¨ã¯ãSIOã®ãã¼ãçªå·ã§ãã£ã¦ã
|
---|
561 | * ãã¼ãã¦ã§ã¢ã®UARTçªå·ã¨åãã ã¨ã¯éããªãã
|
---|
562 | */
|
---|
563 |
|
---|
564 | /*
|
---|
565 | ***** UART0
|
---|
566 | */
|
---|
567 | void
|
---|
568 | uart0_rx_isr()
|
---|
569 | {
|
---|
570 | /* ä¸ä½ã®åä¿¡å¦çãå¼ã¶ */
|
---|
571 | uart_rx_isr_siop(&(siopcb_table[0]));
|
---|
572 | }
|
---|
573 |
|
---|
574 | void
|
---|
575 | uart0_tx_isr()
|
---|
576 | {
|
---|
577 | /* ä¸ä½ã®éä¿¡å¦çãå¼ã¶ */
|
---|
578 | uart_tx_isr_siop(&(siopcb_table[0]));
|
---|
579 | }
|
---|
580 |
|
---|
581 | /*
|
---|
582 | ***** UART1
|
---|
583 | */
|
---|
584 | void
|
---|
585 | uart1_rx_isr()
|
---|
586 | {
|
---|
587 | /* ä¸ä½ã®åä¿¡å¦çãå¼ã¶ */
|
---|
588 | uart_rx_isr_siop(&(siopcb_table[1]));
|
---|
589 | }
|
---|
590 |
|
---|
591 | void
|
---|
592 | uart1_tx_isr()
|
---|
593 | {
|
---|
594 | /* ä¸ä½ã®éä¿¡å¦çãå¼ã¶ */
|
---|
595 | uart_tx_isr_siop(&(siopcb_table[1]));
|
---|
596 | }
|
---|
597 |
|
---|
598 | /*
|
---|
599 | ***** UART2
|
---|
600 | */
|
---|
601 | void
|
---|
602 | uart2_rx_isr()
|
---|
603 | {
|
---|
604 | /* ä¸ä½ã®åä¿¡å¦çãå¼ã¶ */
|
---|
605 | uart_rx_isr_siop(&(siopcb_table[2]));
|
---|
606 | }
|
---|
607 |
|
---|
608 | void
|
---|
609 | uart2_tx_isr()
|
---|
610 | {
|
---|
611 | /* ä¸ä½ã®éä¿¡å¦çãå¼ã¶ */
|
---|
612 | uart_tx_isr_siop(&(siopcb_table[2]));
|
---|
613 | }
|
---|
614 |
|
---|
615 |
|
---|
616 |
|
---|
617 |
|
---|
618 |
|
---|
619 | /*
|
---|
620 | * UARTã®éåã§å²è¾¼ã¿ãå
|
---|
621 | ±æããå ´åï¼ãã¡ãã®ã»ããä¸è¬çï¼ã¯ã
|
---|
622 | * ä¸ã®ã«ã¼ãã³ã§ã¯ãªããã¡ããå²è¾¼ã¿ãµã¼ãã¹ã«ã¼ãã³ã¨ãã¦ä½¿ãã
|
---|
623 | */
|
---|
624 | void
|
---|
625 | uart0_isr()
|
---|
626 | {
|
---|
627 | /* ä¸ä½ã®åä¿¡å¦çãå¼ã¶ */
|
---|
628 | uart_rx_isr_siop(&(siopcb_table[0]));
|
---|
629 | /* ä¸ä½ã®éä¿¡å¦çãå¼ã¶ */
|
---|
630 | uart_tx_isr_siop(&(siopcb_table[0]));
|
---|
631 | }
|
---|
632 |
|
---|
633 | void
|
---|
634 | uart1_isr()
|
---|
635 | {
|
---|
636 | /* ä¸ä½ã®åä¿¡å¦çãå¼ã¶ */
|
---|
637 | uart_rx_isr_siop(&(siopcb_table[1]));
|
---|
638 | /* ä¸ä½ã®éä¿¡å¦çãå¼ã¶ */
|
---|
639 | uart_tx_isr_siop(&(siopcb_table[1]));
|
---|
640 | }
|
---|
641 |
|
---|
642 | void
|
---|
643 | uart2_isr()
|
---|
644 | {
|
---|
645 | /* ä¸ä½ã®åä¿¡å¦çãå¼ã¶ */
|
---|
646 | uart_rx_isr_siop(&(siopcb_table[2]));
|
---|
647 | /* ä¸ä½ã®éä¿¡å¦çãå¼ã¶ */
|
---|
648 | uart_tx_isr_siop(&(siopcb_table[2]));
|
---|
649 | }
|
---|