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) 2006-2013 by Embedded and Real-Time Systems Laboratory
|
---|
9 | * Graduate School of Information Science, Nagoya Univ., JAPAN
|
---|
10 | *
|
---|
11 | * ä¸è¨èä½æ¨©è
|
---|
12 | ã¯ï¼ä»¥ä¸ã®(1)ï½(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§
|
---|
13 | * ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹
|
---|
14 | * å¤ã»åé
|
---|
15 | å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
16 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
17 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
18 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
19 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
20 | * ç¨ã§ããå½¢ã§åé
|
---|
21 | å¸ããå ´åã«ã¯ï¼åé
|
---|
22 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
23 | * è
|
---|
24 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
25 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
26 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
27 | * ç¨ã§ããªãå½¢ã§åé
|
---|
28 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
29 | * ã¨ï¼
|
---|
30 | * (a) åé
|
---|
31 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
32 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
33 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
34 | * (b) åé
|
---|
35 | å¸ã®å½¢æ
|
---|
36 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
37 | * å ±åãããã¨ï¼
|
---|
38 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
39 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
40 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
41 | 責ãããã¨ï¼
|
---|
42 | * ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç
|
---|
43 | * ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨èä½æ¨©è
|
---|
44 | ããã³TOPPERSããã¸ã§ã¯ãã
|
---|
45 | * å
|
---|
46 | 責ãããã¨ï¼
|
---|
47 | *
|
---|
48 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
49 | ã
|
---|
50 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç
|
---|
51 | * ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§
|
---|
52 | * ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ã
|
---|
53 | * ã®è²¬ä»»ãè² ããªãï¼
|
---|
54 | *
|
---|
55 | * @(#) $Id: serial.c 2524 2013-09-15 17:40:06Z ertl-hiro $
|
---|
56 | */
|
---|
57 |
|
---|
58 | /*
|
---|
59 | * ã·ãªã¢ã«ã¤ã³ã¿ãã§ã¼ã¹ãã©ã¤ã
|
---|
60 | */
|
---|
61 |
|
---|
62 | #include <kernel.h>
|
---|
63 | #include <t_syslog.h>
|
---|
64 | #include "target_syssvc.h"
|
---|
65 | #include "target_serial.h"
|
---|
66 | #include "serial.h"
|
---|
67 | #include "kernel_cfg.h"
|
---|
68 |
|
---|
69 | /*
|
---|
70 | * ãããã¡ãµã¤ãºã®ããã©ã«ãå¤ã¨ãããã¡ã®å®ç¾©
|
---|
71 | */
|
---|
72 | #ifndef SERIAL_RCV_BUFSZ1
|
---|
73 | #define SERIAL_RCV_BUFSZ1 256 /* ãã¼ã1ã®åä¿¡ãããã¡ãµã¤ãº */
|
---|
74 | #endif /* SERIAL_RCV_BUFSZ1 */
|
---|
75 |
|
---|
76 | #ifndef SERIAL_SND_BUFSZ1
|
---|
77 | #define SERIAL_SND_BUFSZ1 256 /* ãã¼ã1ã®éä¿¡ãããã¡ãµã¤ãº */
|
---|
78 | #endif /* SERIAL_SND_BUFSZ1 */
|
---|
79 |
|
---|
80 | static char rcv_buffer1[SERIAL_RCV_BUFSZ1];
|
---|
81 | static char snd_buffer1[SERIAL_SND_BUFSZ1];
|
---|
82 |
|
---|
83 | #if TNUM_PORT >= 2 /* ãã¼ã2ã«é¢ããå®ç¾© */
|
---|
84 |
|
---|
85 | #ifndef SERIAL_RCV_BUFSZ2
|
---|
86 | #define SERIAL_RCV_BUFSZ2 256 /* ãã¼ã2ã®åä¿¡ãããã¡ãµã¤ãº */
|
---|
87 | #endif /* SERIAL_RCV_BUFSZ2 */
|
---|
88 |
|
---|
89 | #ifndef SERIAL_SND_BUFSZ2
|
---|
90 | #define SERIAL_SND_BUFSZ2 256 /* ãã¼ã2ã®éä¿¡ãããã¡ãµã¤ãº */
|
---|
91 | #endif /* SERIAL_SND_BUFSZ2 */
|
---|
92 |
|
---|
93 | static char rcv_buffer2[SERIAL_RCV_BUFSZ2];
|
---|
94 | static char snd_buffer2[SERIAL_SND_BUFSZ2];
|
---|
95 |
|
---|
96 | #endif /* TNUM_PORT >= 2 */
|
---|
97 |
|
---|
98 | #if TNUM_PORT >= 3 /* ãã¼ã3ã«é¢ããå®ç¾© */
|
---|
99 |
|
---|
100 | #ifndef SERIAL_RCV_BUFSZ3
|
---|
101 | #define SERIAL_RCV_BUFSZ3 256 /* ãã¼ã3ã®åä¿¡ãããã¡ãµã¤ãº */
|
---|
102 | #endif /* SERIAL_RCV_BUFSZ3 */
|
---|
103 |
|
---|
104 | #ifndef SERIAL_SND_BUFSZ3
|
---|
105 | #define SERIAL_SND_BUFSZ3 256 /* ãã¼ã3ã®éä¿¡ãããã¡ãµã¤ãº */
|
---|
106 | #endif /* SERIAL_SND_BUFSZ3 */
|
---|
107 |
|
---|
108 | static char rcv_buffer3[SERIAL_RCV_BUFSZ3];
|
---|
109 | static char snd_buffer3[SERIAL_SND_BUFSZ3];
|
---|
110 |
|
---|
111 | #endif /* TNUM_PORT >= 3 */
|
---|
112 |
|
---|
113 | #if TNUM_PORT >= 4 /* ãã¼ã4ã«é¢ããå®ç¾© */
|
---|
114 |
|
---|
115 | #ifndef SERIAL_RCV_BUFSZ4
|
---|
116 | #define SERIAL_RCV_BUFSZ4 256 /* ãã¼ã4ã®åä¿¡ãããã¡ãµã¤ãº */
|
---|
117 | #endif /* SERIAL_RCV_BUFSZ4 */
|
---|
118 |
|
---|
119 | #ifndef SERIAL_SND_BUFSZ4
|
---|
120 | #define SERIAL_SND_BUFSZ4 256 /* ãã¼ã4ã®éä¿¡ãããã¡ãµã¤ãº */
|
---|
121 | #endif /* SERIAL_SND_BUFSZ4 */
|
---|
122 |
|
---|
123 | static char rcv_buffer4[SERIAL_RCV_BUFSZ4];
|
---|
124 | static char snd_buffer4[SERIAL_SND_BUFSZ4];
|
---|
125 |
|
---|
126 | #endif /* TNUM_PORT >= 4 */
|
---|
127 |
|
---|
128 | #if TNUM_PORT >= 5
|
---|
129 | #error Serial interface driver supports up to 4 ports.
|
---|
130 | #endif /* TNUM_PORT >= 5 */
|
---|
131 |
|
---|
132 | /*
|
---|
133 | * ããã¼å¶å¾¡ã«é¢é£ããå®æ°ã¨ãã¯ã
|
---|
134 | */
|
---|
135 | #define FC_STOP '\023' /* ã³ã³ããã¼ã«-S */
|
---|
136 | #define FC_START '\021' /* ã³ã³ããã¼ã«-Q */
|
---|
137 |
|
---|
138 | #define BUFCNT_STOP(bufsz) ((bufsz) * 3 / 4) /* STOPãéãåºæºæåæ° */
|
---|
139 | #define BUFCNT_START(bufsz) ((bufsz) / 2) /* STARTãéãåºæºæåæ° */
|
---|
140 |
|
---|
141 | /*
|
---|
142 | * ã·ãªã¢ã«ãã¼ãåæåãããã¯
|
---|
143 | */
|
---|
144 | typedef struct serial_port_initialization_block {
|
---|
145 | ID rcv_semid; /* åä¿¡ãããã¡ç®¡çç¨ã»ããã©ã®ID */
|
---|
146 | ID snd_semid; /* éä¿¡ãããã¡ç®¡çç¨ã»ããã©ã®ID */
|
---|
147 | uint_t rcv_bufsz; /* åä¿¡ãããã¡ãµã¤ãº */
|
---|
148 | char *rcv_buffer; /* åä¿¡ãããã¡ */
|
---|
149 | uint_t snd_bufsz; /* éä¿¡ãããã¡ãµã¤ãº */
|
---|
150 | char *snd_buffer; /* éä¿¡ãããã¡ */
|
---|
151 | } SPINIB;
|
---|
152 |
|
---|
153 | static const SPINIB spinib_table[TNUM_PORT] = {
|
---|
154 | { SERIAL_RCV_SEM1, SERIAL_SND_SEM1,
|
---|
155 | SERIAL_RCV_BUFSZ1, rcv_buffer1,
|
---|
156 | SERIAL_SND_BUFSZ1, snd_buffer1 },
|
---|
157 | #if TNUM_PORT >= 2
|
---|
158 | { SERIAL_RCV_SEM2, SERIAL_SND_SEM2,
|
---|
159 | SERIAL_RCV_BUFSZ2, rcv_buffer2,
|
---|
160 | SERIAL_SND_BUFSZ2, snd_buffer2 },
|
---|
161 | #endif /* TNUM_PORT >= 2 */
|
---|
162 | #if TNUM_PORT >= 3
|
---|
163 | { SERIAL_RCV_SEM3, SERIAL_SND_SEM3,
|
---|
164 | SERIAL_RCV_BUFSZ3, rcv_buffer3,
|
---|
165 | SERIAL_SND_BUFSZ3, snd_buffer3 },
|
---|
166 | #endif /* TNUM_PORT >= 3 */
|
---|
167 | #if TNUM_PORT >= 4
|
---|
168 | { SERIAL_RCV_SEM4, SERIAL_SND_SEM4,
|
---|
169 | SERIAL_RCV_BUFSZ4, rcv_buffer4,
|
---|
170 | SERIAL_SND_BUFSZ4, snd_buffer4 },
|
---|
171 | #endif /* TNUM_PORT >= 4 */
|
---|
172 | };
|
---|
173 |
|
---|
174 | /*
|
---|
175 | * ã·ãªã¢ã«ãã¼ã管çãããã¯
|
---|
176 | */
|
---|
177 | typedef struct serial_port_control_block {
|
---|
178 | const SPINIB *p_spinib; /* ã·ãªã¢ã«ãã¼ãåæåããã㯠*/
|
---|
179 | SIOPCB *p_siopcb; /* ã·ãªã¢ã«I/Oãã¼ã管çããã㯠*/
|
---|
180 | bool_t openflag; /* ãªã¼ãã³æ¸ã¿ãã©ã° */
|
---|
181 | bool_t errorflag; /* ã¨ã©ã¼ãã©ã° */
|
---|
182 | uint_t ioctl; /* åä½å¶å¾¡ã®è¨å®å¤ */
|
---|
183 |
|
---|
184 | uint_t rcv_read_ptr; /* åä¿¡ãããã¡èªåºããã¤ã³ã¿ */
|
---|
185 | uint_t rcv_write_ptr; /* åä¿¡ãããã¡æ¸è¾¼ã¿ãã¤ã³ã¿ */
|
---|
186 | uint_t rcv_count; /* åä¿¡ãããã¡ä¸ã®æåæ° */
|
---|
187 | char rcv_fc_chr; /* éãã¹ãSTART/STOP */
|
---|
188 | bool_t rcv_stopped; /* STOPãéã£ãç¶æ
|
---|
189 | ãï¼ */
|
---|
190 |
|
---|
191 | uint_t snd_read_ptr; /* éä¿¡ãããã¡èªåºããã¤ã³ã¿ */
|
---|
192 | uint_t snd_write_ptr; /* éä¿¡ãããã¡æ¸è¾¼ã¿ãã¤ã³ã¿ */
|
---|
193 | uint_t snd_count; /* éä¿¡ãããã¡ä¸ã®æåæ° */
|
---|
194 | bool_t snd_stopped; /* STOPãåãåã£ãç¶æ
|
---|
195 | ãï¼ */
|
---|
196 | } SPCB;
|
---|
197 |
|
---|
198 | static SPCB spcb_table[TNUM_PORT];
|
---|
199 |
|
---|
200 | /*
|
---|
201 | * ã·ãªã¢ã«ãã¼ãIDããã·ãªã¢ã«ãã¼ã管çãããã¯ãåãåºãããã®ãã¯ã
|
---|
202 | */
|
---|
203 | #define INDEX_PORT(portid) ((uint_t)((portid) - 1))
|
---|
204 | #define get_spcb(portid) (&(spcb_table[INDEX_PORT(portid)]))
|
---|
205 |
|
---|
206 | /*
|
---|
207 | * ãã¤ã³ã¿ã®ã¤ã³ã¯ãªã¡ã³ã
|
---|
208 | */
|
---|
209 | #define INC_PTR(ptr, bufsz) do { \
|
---|
210 | if (++(ptr) == (bufsz)) { \
|
---|
211 | (ptr) = 0; \
|
---|
212 | } \
|
---|
213 | } while (false)
|
---|
214 |
|
---|
215 | /*
|
---|
216 | * ãµã¼ãã¹ã³ã¼ã«å¼åºããã¯ã
|
---|
217 | *
|
---|
218 | * ãµã¼ãã¹ã³ã¼ã«å¼åºããå«ãå¼expãè©ä¾¡ãï¼è¿å¤ãã¨ã©ã¼ï¼è² ã®å¤ï¼ã®å ´
|
---|
219 | * åã«ã¯ï¼ercã«ercd_expãè©ä¾¡ããå¤ã代å
|
---|
220 | ¥ãï¼error_exitã«gotoããï¼
|
---|
221 | */
|
---|
222 | #define SVC(exp, ercd_exp) do { \
|
---|
223 | if ((exp) < 0) { \
|
---|
224 | ercd = (ercd_exp); \
|
---|
225 | goto error_exit; \
|
---|
226 | } \
|
---|
227 | } while (false)
|
---|
228 |
|
---|
229 | /*
|
---|
230 | * E_SYSã¨ã©ã¼ã®çæ
|
---|
231 | */
|
---|
232 | static ER
|
---|
233 | gen_ercd_sys(SPCB *p_spcb)
|
---|
234 | {
|
---|
235 | p_spcb->errorflag = true;
|
---|
236 | return(E_SYS);
|
---|
237 | }
|
---|
238 |
|
---|
239 | /*
|
---|
240 | * å¾
|
---|
241 | ã¡ã«å
|
---|
242 | ¥ããµã¼ãã¹ã³ã¼ã«ããã®ã¨ã©ã¼ã®å¤æ
|
---|
243 | */
|
---|
244 | static ER
|
---|
245 | gen_ercd_wait(ER rercd, SPCB *p_spcb)
|
---|
246 | {
|
---|
247 | switch (MERCD(rercd)) {
|
---|
248 | case E_RLWAI:
|
---|
249 | case E_DLT:
|
---|
250 | return(rercd);
|
---|
251 | default:
|
---|
252 | p_spcb->errorflag = true;
|
---|
253 | return(E_SYS);
|
---|
254 | }
|
---|
255 | }
|
---|
256 |
|
---|
257 | /*
|
---|
258 | * ã·ãªã¢ã«ã¤ã³ã¿ãã§ã¼ã¹ãã©ã¤ãã®åæåã«ã¼ãã³
|
---|
259 | */
|
---|
260 | void
|
---|
261 | serial_initialize(intptr_t exinf)
|
---|
262 | {
|
---|
263 | uint_t i;
|
---|
264 | SPCB *p_spcb;
|
---|
265 |
|
---|
266 | for (i = 0; i < TNUM_PORT; i++) {
|
---|
267 | p_spcb = &(spcb_table[i]);
|
---|
268 | p_spcb->p_spinib = &(spinib_table[i]);
|
---|
269 | p_spcb->openflag = false;
|
---|
270 | }
|
---|
271 | }
|
---|
272 |
|
---|
273 | /*
|
---|
274 | * ã·ãªã¢ã«ãã¼ãã®ãªã¼ãã³ï¼ãµã¼ãã¹ã³ã¼ã«ï¼
|
---|
275 | */
|
---|
276 | ER
|
---|
277 | serial_opn_por(ID portid)
|
---|
278 | {
|
---|
279 | SPCB *p_spcb;
|
---|
280 | ER ercd;
|
---|
281 |
|
---|
282 | if (sns_dpn()) { /* ã³ã³ããã¹ãã®ãã§ã㯠*/
|
---|
283 | return(E_CTX);
|
---|
284 | }
|
---|
285 | if (!(1 <= portid && portid <= TNUM_PORT)) {
|
---|
286 | return(E_ID); /* ãã¼ãçªå·ã®ãã§ã㯠*/
|
---|
287 | }
|
---|
288 | p_spcb = get_spcb(portid);
|
---|
289 |
|
---|
290 | SVC(dis_dsp(), gen_ercd_sys(p_spcb));
|
---|
291 | if (p_spcb->openflag) { /* ãªã¼ãã³æ¸ã¿ãã®ãã§ã㯠*/
|
---|
292 | ercd = E_OBJ;
|
---|
293 | }
|
---|
294 | else {
|
---|
295 | /*
|
---|
296 | * å¤æ°ã®åæå
|
---|
297 | */
|
---|
298 | p_spcb->ioctl = (IOCTL_ECHO | IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV);
|
---|
299 |
|
---|
300 | p_spcb->rcv_read_ptr = 0U;
|
---|
301 | p_spcb->rcv_write_ptr = 0U;
|
---|
302 | p_spcb->rcv_count = 0U;
|
---|
303 | p_spcb->rcv_fc_chr = '\0';
|
---|
304 | p_spcb->rcv_stopped = false;
|
---|
305 |
|
---|
306 | p_spcb->snd_read_ptr = 0U;
|
---|
307 | p_spcb->snd_write_ptr = 0U;
|
---|
308 | p_spcb->snd_count = 0U;
|
---|
309 | p_spcb->snd_stopped = false;
|
---|
310 |
|
---|
311 | /*
|
---|
312 | * ãã以éï¼å²è¾¼ã¿ãç¦æ¢ããï¼
|
---|
313 | */
|
---|
314 | if (loc_cpu() < 0) {
|
---|
315 | ercd = E_SYS;
|
---|
316 | goto error_exit_enadsp;
|
---|
317 | }
|
---|
318 |
|
---|
319 | /*
|
---|
320 | * ãã¼ãã¦ã§ã¢ä¾åã®ãªã¼ãã³å¦ç
|
---|
321 | */
|
---|
322 | p_spcb->p_siopcb = sio_opn_por(portid, (intptr_t) p_spcb);
|
---|
323 |
|
---|
324 | /*
|
---|
325 | * åä¿¡éç¥ã³ã¼ã«ããã¯ã許å¯ããï¼
|
---|
326 | */
|
---|
327 | sio_ena_cbr(p_spcb->p_siopcb, SIO_RDY_RCV);
|
---|
328 | p_spcb->openflag = true;
|
---|
329 | p_spcb->errorflag = false;
|
---|
330 |
|
---|
331 | if (unl_cpu() < 0) {
|
---|
332 | p_spcb->errorflag = true;
|
---|
333 | ercd = E_SYS;
|
---|
334 | goto error_exit_enadsp;
|
---|
335 | }
|
---|
336 | ercd = E_OK;
|
---|
337 | }
|
---|
338 |
|
---|
339 | error_exit_enadsp:
|
---|
340 | SVC(ena_dsp(), gen_ercd_sys(p_spcb));
|
---|
341 |
|
---|
342 | error_exit:
|
---|
343 | return(ercd);
|
---|
344 | }
|
---|
345 |
|
---|
346 | /*
|
---|
347 | * ã·ãªã¢ã«ãã¼ãã®ã¯ãã¼ãºï¼ãµã¼ãã¹ã³ã¼ã«ï¼
|
---|
348 | */
|
---|
349 | ER
|
---|
350 | serial_cls_por(ID portid)
|
---|
351 | {
|
---|
352 | SPCB *p_spcb;
|
---|
353 | ER ercd;
|
---|
354 | bool_t eflag = false;
|
---|
355 |
|
---|
356 | if (sns_dpn()) { /* ã³ã³ããã¹ãã®ãã§ã㯠*/
|
---|
357 | return(E_CTX);
|
---|
358 | }
|
---|
359 | if (!(1 <= portid && portid <= TNUM_PORT)) {
|
---|
360 | return(E_ID); /* ãã¼ãçªå·ã®ãã§ã㯠*/
|
---|
361 | }
|
---|
362 | p_spcb = get_spcb(portid);
|
---|
363 |
|
---|
364 | SVC(dis_dsp(), gen_ercd_sys(p_spcb));
|
---|
365 | if (!(p_spcb->openflag)) { /* ãªã¼ãã³æ¸ã¿ãã®ãã§ã㯠*/
|
---|
366 | ercd = E_OBJ;
|
---|
367 | }
|
---|
368 | else {
|
---|
369 | /*
|
---|
370 | * ãã¼ãã¦ã§ã¢ä¾åã®ã¯ãã¼ãºå¦ç
|
---|
371 | */
|
---|
372 | if (loc_cpu() < 0) {
|
---|
373 | eflag = true;
|
---|
374 | }
|
---|
375 | sio_cls_por(p_spcb->p_siopcb);
|
---|
376 | p_spcb->openflag = false;
|
---|
377 | if (unl_cpu() < 0) {
|
---|
378 | eflag = true;
|
---|
379 | }
|
---|
380 |
|
---|
381 | /*
|
---|
382 | * ã»ããã©ã®åæå
|
---|
383 | */
|
---|
384 | if (ini_sem(p_spcb->p_spinib->snd_semid) < 0) {
|
---|
385 | eflag = true;
|
---|
386 | }
|
---|
387 | if (ini_sem(p_spcb->p_spinib->rcv_semid) < 0) {
|
---|
388 | eflag = true;
|
---|
389 | }
|
---|
390 |
|
---|
391 | /*
|
---|
392 | * ã¨ã©ã¼ã³ã¼ãã®è¨å®
|
---|
393 | */
|
---|
394 | if (eflag) {
|
---|
395 | ercd = gen_ercd_sys(p_spcb);
|
---|
396 | }
|
---|
397 | else {
|
---|
398 | ercd = E_OK;
|
---|
399 | }
|
---|
400 | }
|
---|
401 | SVC(ena_dsp(), gen_ercd_sys(p_spcb));
|
---|
402 |
|
---|
403 | error_exit:
|
---|
404 | return(ercd);
|
---|
405 | }
|
---|
406 |
|
---|
407 | /*
|
---|
408 | * ã·ãªã¢ã«ãã¼ãã¸ã®æåéä¿¡
|
---|
409 | *
|
---|
410 | * p_spcbã§æå®ãããã·ãªã¢ã«I/Oãã¼ãã«å¯¾ãã¦ï¼æåcãéä¿¡ããï¼æå
|
---|
411 | * ãéä¿¡ã¬ã¸ã¹ã¿ã«ãããå ´åã«ã¯trueãè¿ãï¼ããã§ãªãå ´åã«ã¯ï¼éä¿¡
|
---|
412 | * ã¬ã¸ã¹ã¿ã空ãããã¨ãéç¥ããã³ã¼ã«ããã¯é¢æ°ã許å¯ãï¼falseãè¿ãï¼
|
---|
413 | * ãã®é¢æ°ã¯ï¼CPUããã¯ç¶æ
|
---|
414 | ã§å¼ã³åºãããï¼
|
---|
415 | */
|
---|
416 | Inline bool_t
|
---|
417 | serial_snd_chr(SPCB *p_spcb, char c)
|
---|
418 | {
|
---|
419 | if (sio_snd_chr(p_spcb->p_siopcb, c)) {
|
---|
420 | return(true);
|
---|
421 | }
|
---|
422 | else {
|
---|
423 | sio_ena_cbr(p_spcb->p_siopcb, SIO_RDY_SND);
|
---|
424 | return(false);
|
---|
425 | }
|
---|
426 | }
|
---|
427 |
|
---|
428 | /*
|
---|
429 | * ã·ãªã¢ã«ãã¼ãã¸ã®1æåéä¿¡
|
---|
430 | */
|
---|
431 | static ER_BOOL
|
---|
432 | serial_wri_chr(SPCB *p_spcb, char c)
|
---|
433 | {
|
---|
434 | bool_t buffer_full;
|
---|
435 | ER ercd, rercd;
|
---|
436 |
|
---|
437 | /*
|
---|
438 | * LFã®åã«CRãéä¿¡ããï¼
|
---|
439 | */
|
---|
440 | if (c == '\n' && (p_spcb->ioctl & IOCTL_CRLF) != 0U) {
|
---|
441 | /*
|
---|
442 | * 以ä¸ã®ã³ã¼ãã¯å帰å¼åºãã«ãªã£ã¦ãããï¼å¼æ°cã'\n'ã®å ´åã«
|
---|
443 | * å¼æ°cã'\r'ã¨ãã¦å¼ã³åºããã¨ããï¼ãã®å帰å¼åºãã¯2åç®ã®
|
---|
444 | * å¼ã³åºãã§å¿
|
---|
445 | ãæ¢ã¾ãï¼
|
---|
446 | */
|
---|
447 | SVC(rercd = serial_wri_chr(p_spcb, '\r'), rercd);
|
---|
448 | if ((bool_t) rercd) {
|
---|
449 | SVC(rercd = wai_sem(p_spcb->p_spinib->snd_semid),
|
---|
450 | gen_ercd_wait(rercd, p_spcb));
|
---|
451 | }
|
---|
452 | }
|
---|
453 |
|
---|
454 | SVC(loc_cpu(), gen_ercd_sys(p_spcb));
|
---|
455 | if (p_spcb->snd_count == 0U && !(p_spcb->snd_stopped)
|
---|
456 | && serial_snd_chr(p_spcb, c)) {
|
---|
457 | /*
|
---|
458 | * ã·ãªã¢ã«I/Oããã¤ã¹ã®éä¿¡ã¬ã¸ã¹ã¿ã«æåãå
|
---|
459 | ¥ãããã¨ã«æåã
|
---|
460 | * ãå ´åï¼
|
---|
461 | */
|
---|
462 | buffer_full = false;
|
---|
463 | }
|
---|
464 | else {
|
---|
465 | /*
|
---|
466 | * éä¿¡ãããã¡ã«æåãå
|
---|
467 | ¥ããï¼
|
---|
468 | */
|
---|
469 | p_spcb->p_spinib->snd_buffer[p_spcb->snd_write_ptr] = c;
|
---|
470 | INC_PTR(p_spcb->snd_write_ptr, p_spcb->p_spinib->snd_bufsz);
|
---|
471 | p_spcb->snd_count++;
|
---|
472 | buffer_full = (p_spcb->snd_count == p_spcb->p_spinib->snd_bufsz);
|
---|
473 | }
|
---|
474 |
|
---|
475 | SVC(unl_cpu(), gen_ercd_sys(p_spcb));
|
---|
476 | ercd = (ER_BOOL) buffer_full;
|
---|
477 |
|
---|
478 | error_exit:
|
---|
479 | return(ercd);
|
---|
480 | }
|
---|
481 |
|
---|
482 | /*
|
---|
483 | * ã·ãªã¢ã«ãã¼ãã¸ã®æååéä¿¡ï¼ãµã¼ãã¹ã³ã¼ã«ï¼
|
---|
484 | */
|
---|
485 | ER_UINT
|
---|
486 | serial_wri_dat(ID portid, const char *buf, uint_t len)
|
---|
487 | {
|
---|
488 | SPCB *p_spcb;
|
---|
489 | bool_t buffer_full;
|
---|
490 | uint_t wricnt = 0U;
|
---|
491 | ER ercd, rercd;
|
---|
492 |
|
---|
493 | if (sns_dpn()) { /* ã³ã³ããã¹ãã®ãã§ã㯠*/
|
---|
494 | return(E_CTX);
|
---|
495 | }
|
---|
496 | if (!(1 <= portid && portid <= TNUM_PORT)) {
|
---|
497 | return(E_ID); /* ãã¼ãçªå·ã®ãã§ã㯠*/
|
---|
498 | }
|
---|
499 |
|
---|
500 | p_spcb = get_spcb(portid);
|
---|
501 | if (!(p_spcb->openflag)) { /* ãªã¼ãã³æ¸ã¿ãã®ãã§ã㯠*/
|
---|
502 | return(E_OBJ);
|
---|
503 | }
|
---|
504 | if (p_spcb->errorflag) { /* ã¨ã©ã¼ç¶æ
|
---|
505 | ãã®ãã§ã㯠*/
|
---|
506 | return(E_SYS);
|
---|
507 | }
|
---|
508 |
|
---|
509 | buffer_full = true; /* ã«ã¼ãã®1åãã¯wai_semãã */
|
---|
510 | while (wricnt < len) {
|
---|
511 | if (buffer_full) {
|
---|
512 | SVC(rercd = wai_sem(p_spcb->p_spinib->snd_semid),
|
---|
513 | gen_ercd_wait(rercd, p_spcb));
|
---|
514 | }
|
---|
515 | SVC(rercd = serial_wri_chr(p_spcb, *buf++), rercd);
|
---|
516 | wricnt++;
|
---|
517 | buffer_full = (bool_t) rercd;
|
---|
518 | }
|
---|
519 | if (!buffer_full) {
|
---|
520 | SVC(sig_sem(p_spcb->p_spinib->snd_semid), gen_ercd_sys(p_spcb));
|
---|
521 | }
|
---|
522 | ercd = E_OK;
|
---|
523 |
|
---|
524 | error_exit:
|
---|
525 | return(wricnt > 0U ? (ER_UINT) wricnt : ercd);
|
---|
526 | }
|
---|
527 |
|
---|
528 | /*
|
---|
529 | * ã·ãªã¢ã«ãã¼ãããã®1æååä¿¡
|
---|
530 | */
|
---|
531 | static bool_t
|
---|
532 | serial_rea_chr(SPCB *p_spcb, char *p_c)
|
---|
533 | {
|
---|
534 | bool_t buffer_empty;
|
---|
535 | ER ercd;
|
---|
536 |
|
---|
537 | SVC(loc_cpu(), gen_ercd_sys(p_spcb));
|
---|
538 |
|
---|
539 | /*
|
---|
540 | * åä¿¡ãããã¡ããæåãåãåºãï¼
|
---|
541 | */
|
---|
542 | *p_c = p_spcb->p_spinib->rcv_buffer[p_spcb->rcv_read_ptr];
|
---|
543 | INC_PTR(p_spcb->rcv_read_ptr, p_spcb->p_spinib->rcv_bufsz);
|
---|
544 | p_spcb->rcv_count--;
|
---|
545 | buffer_empty = (p_spcb->rcv_count == 0U);
|
---|
546 |
|
---|
547 | /*
|
---|
548 | * STARTãéä¿¡ããï¼
|
---|
549 | */
|
---|
550 | if (p_spcb->rcv_stopped && p_spcb->rcv_count
|
---|
551 | <= BUFCNT_START(p_spcb->p_spinib->rcv_bufsz)) {
|
---|
552 | if (!serial_snd_chr(p_spcb, FC_START)) {
|
---|
553 | p_spcb->rcv_fc_chr = FC_START;
|
---|
554 | }
|
---|
555 | p_spcb->rcv_stopped = false;
|
---|
556 | }
|
---|
557 |
|
---|
558 | SVC(unl_cpu(), gen_ercd_sys(p_spcb));
|
---|
559 | ercd = (ER_BOOL) buffer_empty;
|
---|
560 |
|
---|
561 | error_exit:
|
---|
562 | return(ercd);
|
---|
563 | }
|
---|
564 |
|
---|
565 | /*
|
---|
566 | * ã·ãªã¢ã«ãã¼ãããã®æåååä¿¡ï¼ãµã¼ãã¹ã³ã¼ã«ï¼
|
---|
567 | */
|
---|
568 | ER_UINT
|
---|
569 | serial_rea_dat(ID portid, char *buf, uint_t len)
|
---|
570 | {
|
---|
571 | SPCB *p_spcb;
|
---|
572 | bool_t buffer_empty;
|
---|
573 | uint_t reacnt = 0U;
|
---|
574 | char c = '\0'; /* ã³ã³ãã¤ã©ã®è¦åãææ¢ããããã«åæåãã */
|
---|
575 | ER ercd, rercd;
|
---|
576 |
|
---|
577 | if (sns_dpn()) { /* ã³ã³ããã¹ãã®ãã§ã㯠*/
|
---|
578 | return(E_CTX);
|
---|
579 | }
|
---|
580 | if (!(1 <= portid && portid <= TNUM_PORT)) {
|
---|
581 | return(E_ID); /* ãã¼ãçªå·ã®ãã§ã㯠*/
|
---|
582 | }
|
---|
583 |
|
---|
584 | p_spcb = get_spcb(portid);
|
---|
585 | if (!(p_spcb->openflag)) { /* ãªã¼ãã³æ¸ã¿ãã®ãã§ã㯠*/
|
---|
586 | return(E_OBJ);
|
---|
587 | }
|
---|
588 | if (p_spcb->errorflag) { /* ã¨ã©ã¼ç¶æ
|
---|
589 | ãã®ãã§ã㯠*/
|
---|
590 | return(E_SYS);
|
---|
591 | }
|
---|
592 |
|
---|
593 | buffer_empty = true; /* ã«ã¼ãã®1åãã¯wai_semãã */
|
---|
594 | while (reacnt < len) {
|
---|
595 | if (buffer_empty) {
|
---|
596 | SVC(rercd = wai_sem(p_spcb->p_spinib->rcv_semid),
|
---|
597 | gen_ercd_wait(rercd, p_spcb));
|
---|
598 | }
|
---|
599 | SVC(rercd = serial_rea_chr(p_spcb, &c), rercd);
|
---|
600 | *buf++ = c;
|
---|
601 | reacnt++;
|
---|
602 | buffer_empty = (bool_t) rercd;
|
---|
603 |
|
---|
604 | /*
|
---|
605 | * ã¨ã³ã¼ããã¯å¦çï¼
|
---|
606 | */
|
---|
607 | if ((p_spcb->ioctl & IOCTL_ECHO) != 0U) {
|
---|
608 | SVC(rercd = wai_sem(p_spcb->p_spinib->snd_semid),
|
---|
609 | gen_ercd_wait(rercd, p_spcb));
|
---|
610 | SVC(rercd = serial_wri_chr(p_spcb, c), rercd);
|
---|
611 | if (!((bool_t) rercd)) {
|
---|
612 | SVC(sig_sem(p_spcb->p_spinib->snd_semid),
|
---|
613 | gen_ercd_sys(p_spcb));
|
---|
614 | }
|
---|
615 | }
|
---|
616 | }
|
---|
617 | if (!buffer_empty) {
|
---|
618 | SVC(sig_sem(p_spcb->p_spinib->rcv_semid), gen_ercd_sys(p_spcb));
|
---|
619 | }
|
---|
620 | ercd = E_OK;
|
---|
621 |
|
---|
622 | error_exit:
|
---|
623 | return(reacnt > 0U ? (ER_UINT) reacnt : ercd);
|
---|
624 | }
|
---|
625 |
|
---|
626 | /*
|
---|
627 | * ã·ãªã¢ã«ãã¼ãã®å¶å¾¡ï¼ãµã¼ãã¹ã³ã¼ã«ï¼
|
---|
628 | */
|
---|
629 | ER
|
---|
630 | serial_ctl_por(ID portid, uint_t ioctl)
|
---|
631 | {
|
---|
632 | SPCB *p_spcb;
|
---|
633 |
|
---|
634 | if (sns_dpn()) { /* ã³ã³ããã¹ãã®ãã§ã㯠*/
|
---|
635 | return(E_CTX);
|
---|
636 | }
|
---|
637 | if (!(1 <= portid && portid <= TNUM_PORT)) {
|
---|
638 | return(E_ID); /* ãã¼ãçªå·ã®ãã§ã㯠*/
|
---|
639 | }
|
---|
640 |
|
---|
641 | p_spcb = get_spcb(portid);
|
---|
642 | if (!(p_spcb->openflag)) { /* ãªã¼ãã³æ¸ã¿ãã®ãã§ã㯠*/
|
---|
643 | return(E_OBJ);
|
---|
644 | }
|
---|
645 | if (p_spcb->errorflag) { /* ã¨ã©ã¼ç¶æ
|
---|
646 | ãã®ãã§ã㯠*/
|
---|
647 | return(E_SYS);
|
---|
648 | }
|
---|
649 |
|
---|
650 | p_spcb->ioctl = ioctl;
|
---|
651 | return(E_OK);
|
---|
652 | }
|
---|
653 |
|
---|
654 | /*
|
---|
655 | * ã·ãªã¢ã«ãã¼ãç¶æ
|
---|
656 | ã®åç
|
---|
657 | §ï¼ãµã¼ãã¹ã³ã¼ã«ï¼
|
---|
658 | */
|
---|
659 | ER
|
---|
660 | serial_ref_por(ID portid, T_SERIAL_RPOR *pk_rpor)
|
---|
661 | {
|
---|
662 | SPCB *p_spcb;
|
---|
663 |
|
---|
664 | if (sns_dpn()) { /* ã³ã³ããã¹ãã®ãã§ã㯠*/
|
---|
665 | return(E_CTX);
|
---|
666 | }
|
---|
667 | if (!(1 <= portid && portid <= TNUM_PORT)) {
|
---|
668 | return(E_ID); /* ãã¼ãçªå·ã®ãã§ã㯠*/
|
---|
669 | }
|
---|
670 |
|
---|
671 | p_spcb = get_spcb(portid);
|
---|
672 | if (!(p_spcb->openflag)) { /* ãªã¼ãã³æ¸ã¿ãã®ãã§ã㯠*/
|
---|
673 | return(E_OBJ);
|
---|
674 | }
|
---|
675 | if (p_spcb->errorflag) { /* ã¨ã©ã¼ç¶æ
|
---|
676 | ãã®ãã§ã㯠*/
|
---|
677 | return(E_SYS);
|
---|
678 | }
|
---|
679 |
|
---|
680 | pk_rpor->reacnt = p_spcb->rcv_count;
|
---|
681 | pk_rpor->wricnt = p_spcb->snd_count;
|
---|
682 | return(E_OK);
|
---|
683 | }
|
---|
684 |
|
---|
685 | /*
|
---|
686 | * ã·ãªã¢ã«ãã¼ãããã®éä¿¡å¯è½ã³ã¼ã«ããã¯
|
---|
687 | */
|
---|
688 | void
|
---|
689 | sio_irdy_snd(intptr_t exinf)
|
---|
690 | {
|
---|
691 | SPCB *p_spcb;
|
---|
692 |
|
---|
693 | p_spcb = (SPCB *) exinf;
|
---|
694 | if (p_spcb->rcv_fc_chr != '\0') {
|
---|
695 | /*
|
---|
696 | * START/STOP ãéä¿¡ããï¼
|
---|
697 | */
|
---|
698 | (void) sio_snd_chr(p_spcb->p_siopcb, p_spcb->rcv_fc_chr);
|
---|
699 | p_spcb->rcv_fc_chr = '\0';
|
---|
700 | }
|
---|
701 | else if (!(p_spcb->snd_stopped) && p_spcb->snd_count > 0U) {
|
---|
702 | /*
|
---|
703 | * éä¿¡ãããã¡ä¸ããæåãåãåºãã¦éä¿¡ããï¼
|
---|
704 | */
|
---|
705 | (void) sio_snd_chr(p_spcb->p_siopcb,
|
---|
706 | p_spcb->p_spinib->snd_buffer[p_spcb->snd_read_ptr]);
|
---|
707 | INC_PTR(p_spcb->snd_read_ptr, p_spcb->p_spinib->snd_bufsz);
|
---|
708 | if (p_spcb->snd_count == p_spcb->p_spinib->snd_bufsz) {
|
---|
709 | if (isig_sem(p_spcb->p_spinib->snd_semid) < 0) {
|
---|
710 | p_spcb->errorflag = true;
|
---|
711 | }
|
---|
712 | }
|
---|
713 | p_spcb->snd_count--;
|
---|
714 | }
|
---|
715 | else {
|
---|
716 | /*
|
---|
717 | * éä¿¡ãã¹ãæåããªãå ´åã¯ï¼éä¿¡å¯è½ã³ã¼ã«ããã¯ãç¦æ¢ããï¼
|
---|
718 | */
|
---|
719 | sio_dis_cbr(p_spcb->p_siopcb, SIO_RDY_SND);
|
---|
720 | }
|
---|
721 | }
|
---|
722 |
|
---|
723 | /*
|
---|
724 | * ã·ãªã¢ã«ãã¼ãããã®åä¿¡éç¥ã³ã¼ã«ããã¯
|
---|
725 | */
|
---|
726 | void
|
---|
727 | sio_irdy_rcv(intptr_t exinf)
|
---|
728 | {
|
---|
729 | SPCB *p_spcb;
|
---|
730 | char c;
|
---|
731 |
|
---|
732 | p_spcb = (SPCB *) exinf;
|
---|
733 | c = (char) sio_rcv_chr(p_spcb->p_siopcb);
|
---|
734 | if ((p_spcb->ioctl & IOCTL_FCSND) != 0U && c == FC_STOP) {
|
---|
735 | /*
|
---|
736 | * éä¿¡ãä¸æåæ¢ããï¼éä¿¡ä¸ã®æåã¯ãã®ã¾ã¾éä¿¡ããï¼
|
---|
737 | */
|
---|
738 | p_spcb->snd_stopped = true;
|
---|
739 | }
|
---|
740 | else if (p_spcb->snd_stopped && (c == FC_START
|
---|
741 | || (p_spcb->ioctl & IOCTL_FCANY) != 0U)) {
|
---|
742 | /*
|
---|
743 | * éä¿¡ãåéããï¼
|
---|
744 | */
|
---|
745 | p_spcb->snd_stopped = false;
|
---|
746 | if (p_spcb->snd_count > 0U) {
|
---|
747 | c = p_spcb->p_spinib->snd_buffer[p_spcb->snd_read_ptr];
|
---|
748 | if (serial_snd_chr(p_spcb, c)) {
|
---|
749 | INC_PTR(p_spcb->snd_read_ptr, p_spcb->p_spinib->snd_bufsz);
|
---|
750 | if (p_spcb->snd_count == p_spcb->p_spinib->snd_bufsz) {
|
---|
751 | if (isig_sem(p_spcb->p_spinib->snd_semid) < 0) {
|
---|
752 | p_spcb->errorflag = true;
|
---|
753 | }
|
---|
754 | }
|
---|
755 | p_spcb->snd_count--;
|
---|
756 | }
|
---|
757 | }
|
---|
758 | }
|
---|
759 | else if ((p_spcb->ioctl & IOCTL_FCSND) != 0U && c == FC_START) {
|
---|
760 | /*
|
---|
761 | * éä¿¡ã«å¯¾ãã¦ããã¼å¶å¾¡ãã¦ããå ´åï¼START ã¯æ¨ã¦ãï¼
|
---|
762 | */
|
---|
763 | }
|
---|
764 | else if (p_spcb->rcv_count == p_spcb->p_spinib->rcv_bufsz) {
|
---|
765 | /*
|
---|
766 | * ãããã¡ãã«ã®å ´åï¼åä¿¡ããæåãæ¨ã¦ãï¼
|
---|
767 | */
|
---|
768 | }
|
---|
769 | else {
|
---|
770 | /*
|
---|
771 | * åä¿¡ããæåãåä¿¡ãããã¡ã«å
|
---|
772 | ¥ããï¼
|
---|
773 | */
|
---|
774 | p_spcb->p_spinib->rcv_buffer[p_spcb->rcv_write_ptr] = c;
|
---|
775 | INC_PTR(p_spcb->rcv_write_ptr, p_spcb->p_spinib->rcv_bufsz);
|
---|
776 | if (p_spcb->rcv_count == 0U) {
|
---|
777 | if (isig_sem(p_spcb->p_spinib->rcv_semid) < 0) {
|
---|
778 | p_spcb->errorflag = true;
|
---|
779 | }
|
---|
780 | }
|
---|
781 | p_spcb->rcv_count++;
|
---|
782 |
|
---|
783 | /*
|
---|
784 | * STOPãéä¿¡ããï¼
|
---|
785 | */
|
---|
786 | if ((p_spcb->ioctl & IOCTL_FCRCV) != 0U && !(p_spcb->rcv_stopped)
|
---|
787 | && p_spcb->rcv_count
|
---|
788 | >= BUFCNT_STOP(p_spcb->p_spinib->rcv_bufsz)) {
|
---|
789 | if (!serial_snd_chr(p_spcb, FC_STOP)) {
|
---|
790 | p_spcb->rcv_fc_chr = FC_STOP;
|
---|
791 | }
|
---|
792 | p_spcb->rcv_stopped = true;
|
---|
793 | }
|
---|
794 | }
|
---|
795 | }
|
---|
796 |
|
---|
797 | /*
|
---|
798 | * ã·ãªã¢ã«ã¤ã³ã¿ãã§ã¼ã¹ãã©ã¤ãããã®æªéä¿¡æåã®ååºã
|
---|
799 | */
|
---|
800 | bool_t
|
---|
801 | serial_get_chr(ID portid, char *p_c)
|
---|
802 | {
|
---|
803 | SPCB *p_spcb;
|
---|
804 |
|
---|
805 | if (1 <= portid && portid <= TNUM_PORT) { /* ãã¼ãçªå·ã®ãã§ã㯠*/
|
---|
806 | p_spcb = get_spcb(portid);
|
---|
807 | if (p_spcb->openflag) { /* ãªã¼ãã³æ¸ã¿ãã®ãã§ã㯠*/
|
---|
808 | if (p_spcb->snd_count > 0U) {
|
---|
809 | *p_c = p_spcb->p_spinib->snd_buffer[p_spcb->snd_read_ptr];
|
---|
810 | INC_PTR(p_spcb->snd_read_ptr, p_spcb->p_spinib->snd_bufsz);
|
---|
811 | p_spcb->snd_count--;
|
---|
812 | return(true);
|
---|
813 | }
|
---|
814 | }
|
---|
815 | }
|
---|
816 | return(false);
|
---|
817 | }
|
---|