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-2015 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 468 2015-12-30 00:56:27Z 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 | case E_RASTER:
|
---|
251 | return(rercd);
|
---|
252 | default:
|
---|
253 | p_spcb->errorflag = true;
|
---|
254 | return(E_SYS);
|
---|
255 | }
|
---|
256 | }
|
---|
257 |
|
---|
258 | /*
|
---|
259 | * ã·ãªã¢ã«ã¤ã³ã¿ãã§ã¼ã¹ãã©ã¤ãã®åæåã«ã¼ãã³
|
---|
260 | */
|
---|
261 | void
|
---|
262 | serial_initialize(intptr_t exinf)
|
---|
263 | {
|
---|
264 | uint_t i;
|
---|
265 | SPCB *p_spcb;
|
---|
266 |
|
---|
267 | for (i = 0; i < TNUM_PORT; i++) {
|
---|
268 | p_spcb = &(spcb_table[i]);
|
---|
269 | p_spcb->p_spinib = &(spinib_table[i]);
|
---|
270 | p_spcb->openflag = false;
|
---|
271 | }
|
---|
272 | }
|
---|
273 |
|
---|
274 | /*
|
---|
275 | * ã·ãªã¢ã«ãã¼ãã®ãªã¼ãã³ï¼ãµã¼ãã¹ã³ã¼ã«ï¼
|
---|
276 | */
|
---|
277 | ER
|
---|
278 | serial_opn_por(ID portid)
|
---|
279 | {
|
---|
280 | SPCB *p_spcb;
|
---|
281 | ER ercd;
|
---|
282 |
|
---|
283 | if (sns_dpn()) { /* ã³ã³ããã¹ãã®ãã§ã㯠*/
|
---|
284 | return(E_CTX);
|
---|
285 | }
|
---|
286 | if (!(1 <= portid && portid <= TNUM_PORT)) {
|
---|
287 | return(E_ID); /* ãã¼ãçªå·ã®ãã§ã㯠*/
|
---|
288 | }
|
---|
289 | p_spcb = get_spcb(portid);
|
---|
290 |
|
---|
291 | SVC(dis_dsp(), gen_ercd_sys(p_spcb));
|
---|
292 | if (p_spcb->openflag) { /* ãªã¼ãã³æ¸ã¿ãã®ãã§ã㯠*/
|
---|
293 | ercd = E_OBJ;
|
---|
294 | }
|
---|
295 | else {
|
---|
296 | /*
|
---|
297 | * å¤æ°ã®åæå
|
---|
298 | */
|
---|
299 | p_spcb->ioctl = (IOCTL_ECHO | IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV);
|
---|
300 |
|
---|
301 | p_spcb->rcv_read_ptr = 0U;
|
---|
302 | p_spcb->rcv_write_ptr = 0U;
|
---|
303 | p_spcb->rcv_count = 0U;
|
---|
304 | p_spcb->rcv_fc_chr = '\0';
|
---|
305 | p_spcb->rcv_stopped = false;
|
---|
306 |
|
---|
307 | p_spcb->snd_read_ptr = 0U;
|
---|
308 | p_spcb->snd_write_ptr = 0U;
|
---|
309 | p_spcb->snd_count = 0U;
|
---|
310 | p_spcb->snd_stopped = false;
|
---|
311 |
|
---|
312 | /*
|
---|
313 | * ãã以éï¼å²è¾¼ã¿ãç¦æ¢ããï¼
|
---|
314 | */
|
---|
315 | if (loc_cpu() < 0) {
|
---|
316 | ercd = E_SYS;
|
---|
317 | goto error_exit_enadsp;
|
---|
318 | }
|
---|
319 |
|
---|
320 | /*
|
---|
321 | * ãã¼ãã¦ã§ã¢ä¾åã®ãªã¼ãã³å¦ç
|
---|
322 | */
|
---|
323 | p_spcb->p_siopcb = sio_opn_por(portid, (intptr_t) p_spcb);
|
---|
324 |
|
---|
325 | /*
|
---|
326 | * åä¿¡éç¥ã³ã¼ã«ããã¯ã許å¯ããï¼
|
---|
327 | */
|
---|
328 | sio_ena_cbr(p_spcb->p_siopcb, SIO_RDY_RCV);
|
---|
329 | p_spcb->openflag = true;
|
---|
330 | p_spcb->errorflag = false;
|
---|
331 |
|
---|
332 | if (unl_cpu() < 0) {
|
---|
333 | p_spcb->errorflag = true;
|
---|
334 | ercd = E_SYS;
|
---|
335 | goto error_exit_enadsp;
|
---|
336 | }
|
---|
337 | ercd = E_OK;
|
---|
338 | }
|
---|
339 |
|
---|
340 | error_exit_enadsp:
|
---|
341 | SVC(ena_dsp(), gen_ercd_sys(p_spcb));
|
---|
342 |
|
---|
343 | error_exit:
|
---|
344 | return(ercd);
|
---|
345 | }
|
---|
346 |
|
---|
347 | /*
|
---|
348 | * ã·ãªã¢ã«ãã¼ãã®ã¯ãã¼ãºï¼ãµã¼ãã¹ã³ã¼ã«ï¼
|
---|
349 | */
|
---|
350 | ER
|
---|
351 | serial_cls_por(ID portid)
|
---|
352 | {
|
---|
353 | SPCB *p_spcb;
|
---|
354 | ER ercd;
|
---|
355 | bool_t eflag = false;
|
---|
356 |
|
---|
357 | if (sns_dpn()) { /* ã³ã³ããã¹ãã®ãã§ã㯠*/
|
---|
358 | return(E_CTX);
|
---|
359 | }
|
---|
360 | if (!(1 <= portid && portid <= TNUM_PORT)) {
|
---|
361 | return(E_ID); /* ãã¼ãçªå·ã®ãã§ã㯠*/
|
---|
362 | }
|
---|
363 | p_spcb = get_spcb(portid);
|
---|
364 |
|
---|
365 | SVC(dis_dsp(), gen_ercd_sys(p_spcb));
|
---|
366 | if (!(p_spcb->openflag)) { /* ãªã¼ãã³æ¸ã¿ãã®ãã§ã㯠*/
|
---|
367 | ercd = E_OBJ;
|
---|
368 | }
|
---|
369 | else {
|
---|
370 | /*
|
---|
371 | * ãã¼ãã¦ã§ã¢ä¾åã®ã¯ãã¼ãºå¦ç
|
---|
372 | */
|
---|
373 | if (loc_cpu() < 0) {
|
---|
374 | eflag = true;
|
---|
375 | }
|
---|
376 | sio_cls_por(p_spcb->p_siopcb);
|
---|
377 | p_spcb->openflag = false;
|
---|
378 | if (unl_cpu() < 0) {
|
---|
379 | eflag = true;
|
---|
380 | }
|
---|
381 |
|
---|
382 | /*
|
---|
383 | * ã»ããã©ã®åæå
|
---|
384 | */
|
---|
385 | if (ini_sem(p_spcb->p_spinib->snd_semid) < 0) {
|
---|
386 | eflag = true;
|
---|
387 | }
|
---|
388 | if (ini_sem(p_spcb->p_spinib->rcv_semid) < 0) {
|
---|
389 | eflag = true;
|
---|
390 | }
|
---|
391 |
|
---|
392 | /*
|
---|
393 | * ã¨ã©ã¼ã³ã¼ãã®è¨å®
|
---|
394 | */
|
---|
395 | if (eflag) {
|
---|
396 | ercd = gen_ercd_sys(p_spcb);
|
---|
397 | }
|
---|
398 | else {
|
---|
399 | ercd = E_OK;
|
---|
400 | }
|
---|
401 | }
|
---|
402 | SVC(ena_dsp(), gen_ercd_sys(p_spcb));
|
---|
403 |
|
---|
404 | error_exit:
|
---|
405 | return(ercd);
|
---|
406 | }
|
---|
407 |
|
---|
408 | /*
|
---|
409 | * ã·ãªã¢ã«ãã¼ãã¸ã®æåéä¿¡
|
---|
410 | *
|
---|
411 | * p_spcbã§æå®ãããã·ãªã¢ã«I/Oãã¼ãã«å¯¾ãã¦ï¼æåcãéä¿¡ããï¼æå
|
---|
412 | * ãéä¿¡ã¬ã¸ã¹ã¿ã«ãããå ´åã«ã¯trueãè¿ãï¼ããã§ãªãå ´åã«ã¯ï¼éä¿¡
|
---|
413 | * ã¬ã¸ã¹ã¿ã空ãããã¨ãéç¥ããã³ã¼ã«ããã¯é¢æ°ã許å¯ãï¼falseãè¿ãï¼
|
---|
414 | * ãã®é¢æ°ã¯ï¼CPUããã¯ç¶æ
|
---|
415 | ã§å¼ã³åºãããï¼
|
---|
416 | */
|
---|
417 | Inline bool_t
|
---|
418 | serial_snd_chr(SPCB *p_spcb, char c)
|
---|
419 | {
|
---|
420 | if (sio_snd_chr(p_spcb->p_siopcb, c)) {
|
---|
421 | return(true);
|
---|
422 | }
|
---|
423 | else {
|
---|
424 | sio_ena_cbr(p_spcb->p_siopcb, SIO_RDY_SND);
|
---|
425 | return(false);
|
---|
426 | }
|
---|
427 | }
|
---|
428 |
|
---|
429 | /*
|
---|
430 | * ã·ãªã¢ã«ãã¼ãã¸ã®1æåéä¿¡
|
---|
431 | */
|
---|
432 | static ER_BOOL
|
---|
433 | serial_wri_chr(SPCB *p_spcb, char c)
|
---|
434 | {
|
---|
435 | bool_t buffer_full;
|
---|
436 | ER ercd, rercd;
|
---|
437 |
|
---|
438 | /*
|
---|
439 | * LFã®åã«CRãéä¿¡ããï¼
|
---|
440 | */
|
---|
441 | if (c == '\n' && (p_spcb->ioctl & IOCTL_CRLF) != 0U) {
|
---|
442 | /*
|
---|
443 | * 以ä¸ã®ã³ã¼ãã¯å帰å¼åºãã«ãªã£ã¦ãããï¼å¼æ°cã'\n'ã®å ´åã«
|
---|
444 | * å¼æ°cã'\r'ã¨ãã¦å¼ã³åºããã¨ããï¼ãã®å帰å¼åºãã¯2åç®ã®
|
---|
445 | * å¼ã³åºãã§å¿
|
---|
446 | ãæ¢ã¾ãï¼
|
---|
447 | */
|
---|
448 | SVC(rercd = serial_wri_chr(p_spcb, '\r'), rercd);
|
---|
449 | if ((bool_t) rercd) {
|
---|
450 | SVC(rercd = wai_sem(p_spcb->p_spinib->snd_semid),
|
---|
451 | gen_ercd_wait(rercd, p_spcb));
|
---|
452 | }
|
---|
453 | }
|
---|
454 |
|
---|
455 | SVC(loc_cpu(), gen_ercd_sys(p_spcb));
|
---|
456 | if (p_spcb->snd_count == 0U && !(p_spcb->snd_stopped)
|
---|
457 | && serial_snd_chr(p_spcb, c)) {
|
---|
458 | /*
|
---|
459 | * ã·ãªã¢ã«I/Oããã¤ã¹ã®éä¿¡ã¬ã¸ã¹ã¿ã«æåãå
|
---|
460 | ¥ãããã¨ã«æåã
|
---|
461 | * ãå ´åï¼
|
---|
462 | */
|
---|
463 | buffer_full = false;
|
---|
464 | }
|
---|
465 | else {
|
---|
466 | /*
|
---|
467 | * éä¿¡ãããã¡ã«æåãå
|
---|
468 | ¥ããï¼
|
---|
469 | */
|
---|
470 | p_spcb->p_spinib->snd_buffer[p_spcb->snd_write_ptr] = c;
|
---|
471 | INC_PTR(p_spcb->snd_write_ptr, p_spcb->p_spinib->snd_bufsz);
|
---|
472 | p_spcb->snd_count++;
|
---|
473 | buffer_full = (p_spcb->snd_count == p_spcb->p_spinib->snd_bufsz);
|
---|
474 | }
|
---|
475 |
|
---|
476 | SVC(unl_cpu(), gen_ercd_sys(p_spcb));
|
---|
477 | ercd = (ER_BOOL) buffer_full;
|
---|
478 |
|
---|
479 | error_exit:
|
---|
480 | return(ercd);
|
---|
481 | }
|
---|
482 |
|
---|
483 | /*
|
---|
484 | * ã·ãªã¢ã«ãã¼ãã¸ã®æååéä¿¡ï¼ãµã¼ãã¹ã³ã¼ã«ï¼
|
---|
485 | */
|
---|
486 | ER_UINT
|
---|
487 | serial_wri_dat(ID portid, const char *buf, uint_t len)
|
---|
488 | {
|
---|
489 | SPCB *p_spcb;
|
---|
490 | bool_t buffer_full;
|
---|
491 | uint_t wricnt = 0U;
|
---|
492 | ER ercd, rercd;
|
---|
493 |
|
---|
494 | if (sns_dpn()) { /* ã³ã³ããã¹ãã®ãã§ã㯠*/
|
---|
495 | return(E_CTX);
|
---|
496 | }
|
---|
497 | if (!(1 <= portid && portid <= TNUM_PORT)) {
|
---|
498 | return(E_ID); /* ãã¼ãçªå·ã®ãã§ã㯠*/
|
---|
499 | }
|
---|
500 |
|
---|
501 | p_spcb = get_spcb(portid);
|
---|
502 | if (!(p_spcb->openflag)) { /* ãªã¼ãã³æ¸ã¿ãã®ãã§ã㯠*/
|
---|
503 | return(E_OBJ);
|
---|
504 | }
|
---|
505 | if (p_spcb->errorflag) { /* ã¨ã©ã¼ç¶æ
|
---|
506 | ãã®ãã§ã㯠*/
|
---|
507 | return(E_SYS);
|
---|
508 | }
|
---|
509 |
|
---|
510 | buffer_full = true; /* ã«ã¼ãã®1åãã¯wai_semãã */
|
---|
511 | while (wricnt < len) {
|
---|
512 | if (buffer_full) {
|
---|
513 | SVC(rercd = wai_sem(p_spcb->p_spinib->snd_semid),
|
---|
514 | gen_ercd_wait(rercd, p_spcb));
|
---|
515 | }
|
---|
516 | SVC(rercd = serial_wri_chr(p_spcb, *buf++), rercd);
|
---|
517 | wricnt++;
|
---|
518 | buffer_full = (bool_t) rercd;
|
---|
519 | }
|
---|
520 | if (!buffer_full) {
|
---|
521 | SVC(sig_sem(p_spcb->p_spinib->snd_semid), gen_ercd_sys(p_spcb));
|
---|
522 | }
|
---|
523 | ercd = E_OK;
|
---|
524 |
|
---|
525 | error_exit:
|
---|
526 | return(wricnt > 0U ? (ER_UINT) wricnt : ercd);
|
---|
527 | }
|
---|
528 |
|
---|
529 | /*
|
---|
530 | * ã·ãªã¢ã«ãã¼ãããã®1æååä¿¡
|
---|
531 | */
|
---|
532 | static bool_t
|
---|
533 | serial_rea_chr(SPCB *p_spcb, char *p_c)
|
---|
534 | {
|
---|
535 | bool_t buffer_empty;
|
---|
536 | ER ercd;
|
---|
537 |
|
---|
538 | SVC(loc_cpu(), gen_ercd_sys(p_spcb));
|
---|
539 |
|
---|
540 | /*
|
---|
541 | * åä¿¡ãããã¡ããæåãåãåºãï¼
|
---|
542 | */
|
---|
543 | *p_c = p_spcb->p_spinib->rcv_buffer[p_spcb->rcv_read_ptr];
|
---|
544 | INC_PTR(p_spcb->rcv_read_ptr, p_spcb->p_spinib->rcv_bufsz);
|
---|
545 | p_spcb->rcv_count--;
|
---|
546 | buffer_empty = (p_spcb->rcv_count == 0U);
|
---|
547 |
|
---|
548 | /*
|
---|
549 | * STARTãéä¿¡ããï¼
|
---|
550 | */
|
---|
551 | if (p_spcb->rcv_stopped && p_spcb->rcv_count
|
---|
552 | <= BUFCNT_START(p_spcb->p_spinib->rcv_bufsz)) {
|
---|
553 | if (!serial_snd_chr(p_spcb, FC_START)) {
|
---|
554 | p_spcb->rcv_fc_chr = FC_START;
|
---|
555 | }
|
---|
556 | p_spcb->rcv_stopped = false;
|
---|
557 | }
|
---|
558 |
|
---|
559 | SVC(unl_cpu(), gen_ercd_sys(p_spcb));
|
---|
560 | ercd = (ER_BOOL) buffer_empty;
|
---|
561 |
|
---|
562 | error_exit:
|
---|
563 | return(ercd);
|
---|
564 | }
|
---|
565 |
|
---|
566 | /*
|
---|
567 | * ã·ãªã¢ã«ãã¼ãããã®æåååä¿¡ï¼ãµã¼ãã¹ã³ã¼ã«ï¼
|
---|
568 | */
|
---|
569 | ER_UINT
|
---|
570 | serial_rea_dat(ID portid, char *buf, uint_t len)
|
---|
571 | {
|
---|
572 | SPCB *p_spcb;
|
---|
573 | bool_t buffer_empty;
|
---|
574 | uint_t reacnt = 0U;
|
---|
575 | char c = '\0'; /* ã³ã³ãã¤ã©ã®è¦åãææ¢ããããã«åæåãã */
|
---|
576 | ER ercd, rercd;
|
---|
577 |
|
---|
578 | if (sns_dpn()) { /* ã³ã³ããã¹ãã®ãã§ã㯠*/
|
---|
579 | return(E_CTX);
|
---|
580 | }
|
---|
581 | if (!(1 <= portid && portid <= TNUM_PORT)) {
|
---|
582 | return(E_ID); /* ãã¼ãçªå·ã®ãã§ã㯠*/
|
---|
583 | }
|
---|
584 |
|
---|
585 | p_spcb = get_spcb(portid);
|
---|
586 | if (!(p_spcb->openflag)) { /* ãªã¼ãã³æ¸ã¿ãã®ãã§ã㯠*/
|
---|
587 | return(E_OBJ);
|
---|
588 | }
|
---|
589 | if (p_spcb->errorflag) { /* ã¨ã©ã¼ç¶æ
|
---|
590 | ãã®ãã§ã㯠*/
|
---|
591 | return(E_SYS);
|
---|
592 | }
|
---|
593 |
|
---|
594 | buffer_empty = true; /* ã«ã¼ãã®1åãã¯wai_semãã */
|
---|
595 | while (reacnt < len) {
|
---|
596 | if (buffer_empty) {
|
---|
597 | SVC(rercd = wai_sem(p_spcb->p_spinib->rcv_semid),
|
---|
598 | gen_ercd_wait(rercd, p_spcb));
|
---|
599 | }
|
---|
600 | SVC(rercd = serial_rea_chr(p_spcb, &c), rercd);
|
---|
601 | *buf++ = c;
|
---|
602 | reacnt++;
|
---|
603 | buffer_empty = (bool_t) rercd;
|
---|
604 |
|
---|
605 | /*
|
---|
606 | * ã¨ã³ã¼ããã¯å¦çï¼
|
---|
607 | */
|
---|
608 | if ((p_spcb->ioctl & IOCTL_ECHO) != 0U) {
|
---|
609 | SVC(rercd = wai_sem(p_spcb->p_spinib->snd_semid),
|
---|
610 | gen_ercd_wait(rercd, p_spcb));
|
---|
611 | SVC(rercd = serial_wri_chr(p_spcb, c), rercd);
|
---|
612 | if (!((bool_t) rercd)) {
|
---|
613 | SVC(sig_sem(p_spcb->p_spinib->snd_semid),
|
---|
614 | gen_ercd_sys(p_spcb));
|
---|
615 | }
|
---|
616 | }
|
---|
617 | }
|
---|
618 | if (!buffer_empty) {
|
---|
619 | SVC(sig_sem(p_spcb->p_spinib->rcv_semid), gen_ercd_sys(p_spcb));
|
---|
620 | }
|
---|
621 | ercd = E_OK;
|
---|
622 |
|
---|
623 | error_exit:
|
---|
624 | return(reacnt > 0U ? (ER_UINT) reacnt : ercd);
|
---|
625 | }
|
---|
626 |
|
---|
627 | /*
|
---|
628 | * ã·ãªã¢ã«ãã¼ãã®å¶å¾¡ï¼ãµã¼ãã¹ã³ã¼ã«ï¼
|
---|
629 | */
|
---|
630 | ER
|
---|
631 | serial_ctl_por(ID portid, uint_t ioctl)
|
---|
632 | {
|
---|
633 | SPCB *p_spcb;
|
---|
634 |
|
---|
635 | if (sns_dpn()) { /* ã³ã³ããã¹ãã®ãã§ã㯠*/
|
---|
636 | return(E_CTX);
|
---|
637 | }
|
---|
638 | if (!(1 <= portid && portid <= TNUM_PORT)) {
|
---|
639 | return(E_ID); /* ãã¼ãçªå·ã®ãã§ã㯠*/
|
---|
640 | }
|
---|
641 |
|
---|
642 | p_spcb = get_spcb(portid);
|
---|
643 | if (!(p_spcb->openflag)) { /* ãªã¼ãã³æ¸ã¿ãã®ãã§ã㯠*/
|
---|
644 | return(E_OBJ);
|
---|
645 | }
|
---|
646 | if (p_spcb->errorflag) { /* ã¨ã©ã¼ç¶æ
|
---|
647 | ãã®ãã§ã㯠*/
|
---|
648 | return(E_SYS);
|
---|
649 | }
|
---|
650 |
|
---|
651 | p_spcb->ioctl = ioctl;
|
---|
652 | return(E_OK);
|
---|
653 | }
|
---|
654 |
|
---|
655 | /*
|
---|
656 | * ã·ãªã¢ã«ãã¼ãç¶æ
|
---|
657 | ã®åç
|
---|
658 | §ï¼ãµã¼ãã¹ã³ã¼ã«ï¼
|
---|
659 | */
|
---|
660 | ER
|
---|
661 | serial_ref_por(ID portid, T_SERIAL_RPOR *pk_rpor)
|
---|
662 | {
|
---|
663 | SPCB *p_spcb;
|
---|
664 |
|
---|
665 | if (sns_dpn()) { /* ã³ã³ããã¹ãã®ãã§ã㯠*/
|
---|
666 | return(E_CTX);
|
---|
667 | }
|
---|
668 | if (!(1 <= portid && portid <= TNUM_PORT)) {
|
---|
669 | return(E_ID); /* ãã¼ãçªå·ã®ãã§ã㯠*/
|
---|
670 | }
|
---|
671 |
|
---|
672 | p_spcb = get_spcb(portid);
|
---|
673 | if (!(p_spcb->openflag)) { /* ãªã¼ãã³æ¸ã¿ãã®ãã§ã㯠*/
|
---|
674 | return(E_OBJ);
|
---|
675 | }
|
---|
676 | if (p_spcb->errorflag) { /* ã¨ã©ã¼ç¶æ
|
---|
677 | ãã®ãã§ã㯠*/
|
---|
678 | return(E_SYS);
|
---|
679 | }
|
---|
680 |
|
---|
681 | pk_rpor->reacnt = p_spcb->rcv_count;
|
---|
682 | pk_rpor->wricnt = p_spcb->snd_count;
|
---|
683 | return(E_OK);
|
---|
684 | }
|
---|
685 |
|
---|
686 | /*
|
---|
687 | * ã·ãªã¢ã«ãã¼ãããã®éä¿¡å¯è½ã³ã¼ã«ããã¯
|
---|
688 | */
|
---|
689 | void
|
---|
690 | sio_irdy_snd(intptr_t exinf)
|
---|
691 | {
|
---|
692 | SPCB *p_spcb;
|
---|
693 |
|
---|
694 | p_spcb = (SPCB *) exinf;
|
---|
695 | if (p_spcb->rcv_fc_chr != '\0') {
|
---|
696 | /*
|
---|
697 | * START/STOP ãéä¿¡ããï¼
|
---|
698 | */
|
---|
699 | (void) sio_snd_chr(p_spcb->p_siopcb, p_spcb->rcv_fc_chr);
|
---|
700 | p_spcb->rcv_fc_chr = '\0';
|
---|
701 | }
|
---|
702 | else if (!(p_spcb->snd_stopped) && p_spcb->snd_count > 0U) {
|
---|
703 | /*
|
---|
704 | * éä¿¡ãããã¡ä¸ããæåãåãåºãã¦éä¿¡ããï¼
|
---|
705 | */
|
---|
706 | (void) sio_snd_chr(p_spcb->p_siopcb,
|
---|
707 | p_spcb->p_spinib->snd_buffer[p_spcb->snd_read_ptr]);
|
---|
708 | INC_PTR(p_spcb->snd_read_ptr, p_spcb->p_spinib->snd_bufsz);
|
---|
709 | if (p_spcb->snd_count == p_spcb->p_spinib->snd_bufsz) {
|
---|
710 | if (sig_sem(p_spcb->p_spinib->snd_semid) < 0) {
|
---|
711 | p_spcb->errorflag = true;
|
---|
712 | }
|
---|
713 | }
|
---|
714 | p_spcb->snd_count--;
|
---|
715 | }
|
---|
716 | else {
|
---|
717 | /*
|
---|
718 | * éä¿¡ãã¹ãæåããªãå ´åã¯ï¼éä¿¡å¯è½ã³ã¼ã«ããã¯ãç¦æ¢ããï¼
|
---|
719 | */
|
---|
720 | sio_dis_cbr(p_spcb->p_siopcb, SIO_RDY_SND);
|
---|
721 | }
|
---|
722 | }
|
---|
723 |
|
---|
724 | /*
|
---|
725 | * ã·ãªã¢ã«ãã¼ãããã®åä¿¡éç¥ã³ã¼ã«ããã¯
|
---|
726 | */
|
---|
727 | void
|
---|
728 | sio_irdy_rcv(intptr_t exinf)
|
---|
729 | {
|
---|
730 | SPCB *p_spcb;
|
---|
731 | char c;
|
---|
732 |
|
---|
733 | p_spcb = (SPCB *) exinf;
|
---|
734 | c = (char) sio_rcv_chr(p_spcb->p_siopcb);
|
---|
735 | if ((p_spcb->ioctl & IOCTL_FCSND) != 0U && c == FC_STOP) {
|
---|
736 | /*
|
---|
737 | * éä¿¡ãä¸æåæ¢ããï¼éä¿¡ä¸ã®æåã¯ãã®ã¾ã¾éä¿¡ããï¼
|
---|
738 | */
|
---|
739 | p_spcb->snd_stopped = true;
|
---|
740 | }
|
---|
741 | else if (p_spcb->snd_stopped && (c == FC_START
|
---|
742 | || (p_spcb->ioctl & IOCTL_FCANY) != 0U)) {
|
---|
743 | /*
|
---|
744 | * éä¿¡ãåéããï¼
|
---|
745 | */
|
---|
746 | p_spcb->snd_stopped = false;
|
---|
747 | if (p_spcb->snd_count > 0U) {
|
---|
748 | c = p_spcb->p_spinib->snd_buffer[p_spcb->snd_read_ptr];
|
---|
749 | if (serial_snd_chr(p_spcb, c)) {
|
---|
750 | INC_PTR(p_spcb->snd_read_ptr, p_spcb->p_spinib->snd_bufsz);
|
---|
751 | if (p_spcb->snd_count == p_spcb->p_spinib->snd_bufsz) {
|
---|
752 | if (sig_sem(p_spcb->p_spinib->snd_semid) < 0) {
|
---|
753 | p_spcb->errorflag = true;
|
---|
754 | }
|
---|
755 | }
|
---|
756 | p_spcb->snd_count--;
|
---|
757 | }
|
---|
758 | }
|
---|
759 | }
|
---|
760 | else if ((p_spcb->ioctl & IOCTL_FCSND) != 0U && c == FC_START) {
|
---|
761 | /*
|
---|
762 | * éä¿¡ã«å¯¾ãã¦ããã¼å¶å¾¡ãã¦ããå ´åï¼START ã¯æ¨ã¦ãï¼
|
---|
763 | */
|
---|
764 | }
|
---|
765 | else if (p_spcb->rcv_count == p_spcb->p_spinib->rcv_bufsz) {
|
---|
766 | /*
|
---|
767 | * ãããã¡ãã«ã®å ´åï¼åä¿¡ããæåãæ¨ã¦ãï¼
|
---|
768 | */
|
---|
769 | }
|
---|
770 | else {
|
---|
771 | /*
|
---|
772 | * åä¿¡ããæåãåä¿¡ãããã¡ã«å
|
---|
773 | ¥ããï¼
|
---|
774 | */
|
---|
775 | p_spcb->p_spinib->rcv_buffer[p_spcb->rcv_write_ptr] = c;
|
---|
776 | INC_PTR(p_spcb->rcv_write_ptr, p_spcb->p_spinib->rcv_bufsz);
|
---|
777 | if (p_spcb->rcv_count == 0U) {
|
---|
778 | if (sig_sem(p_spcb->p_spinib->rcv_semid) < 0) {
|
---|
779 | p_spcb->errorflag = true;
|
---|
780 | }
|
---|
781 | }
|
---|
782 | p_spcb->rcv_count++;
|
---|
783 |
|
---|
784 | /*
|
---|
785 | * STOPãéä¿¡ããï¼
|
---|
786 | */
|
---|
787 | if ((p_spcb->ioctl & IOCTL_FCRCV) != 0U && !(p_spcb->rcv_stopped)
|
---|
788 | && p_spcb->rcv_count
|
---|
789 | >= BUFCNT_STOP(p_spcb->p_spinib->rcv_bufsz)) {
|
---|
790 | if (!serial_snd_chr(p_spcb, FC_STOP)) {
|
---|
791 | p_spcb->rcv_fc_chr = FC_STOP;
|
---|
792 | }
|
---|
793 | p_spcb->rcv_stopped = true;
|
---|
794 | }
|
---|
795 | }
|
---|
796 | }
|
---|
797 |
|
---|
798 | /*
|
---|
799 | * ã·ãªã¢ã«ã¤ã³ã¿ãã§ã¼ã¹ãã©ã¤ãããã®æªéä¿¡æåã®ååºã
|
---|
800 | */
|
---|
801 | bool_t
|
---|
802 | serial_get_chr(ID portid, char *p_c)
|
---|
803 | {
|
---|
804 | SPCB *p_spcb;
|
---|
805 |
|
---|
806 | if (1 <= portid && portid <= TNUM_PORT) { /* ãã¼ãçªå·ã®ãã§ã㯠*/
|
---|
807 | p_spcb = get_spcb(portid);
|
---|
808 | if (p_spcb->openflag) { /* ãªã¼ãã³æ¸ã¿ãã®ãã§ã㯠*/
|
---|
809 | if (p_spcb->snd_count > 0U) {
|
---|
810 | *p_c = p_spcb->p_spinib->snd_buffer[p_spcb->snd_read_ptr];
|
---|
811 | INC_PTR(p_spcb->snd_read_ptr, p_spcb->p_spinib->snd_bufsz);
|
---|
812 | p_spcb->snd_count--;
|
---|
813 | return(true);
|
---|
814 | }
|
---|
815 | }
|
---|
816 | }
|
---|
817 | return(false);
|
---|
818 | }
|
---|