Commit 5f0320108870e5d62983d1d5c13a2a087dddf686
Committed by
Wolfgang Denk
1 parent
ec6f149946
Exists in
master
and in
55 other branches
common/console: avoid ifdef CONFIG_CONSOLE_MUX when it's possible
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Showing 1 changed file with 56 additions and 52 deletions Side-by-side Diff
common/console.c
... | ... | @@ -106,7 +106,7 @@ |
106 | 106 | * only from fgetc() which assures it. |
107 | 107 | * No attempt is made to demultiplex multiple input sources. |
108 | 108 | */ |
109 | -static int iomux_getc(void) | |
109 | +static int console_getc(int file) | |
110 | 110 | { |
111 | 111 | unsigned char ret; |
112 | 112 | |
... | ... | @@ -116,7 +116,7 @@ |
116 | 116 | return ret; |
117 | 117 | } |
118 | 118 | |
119 | -static int iomux_tstc(int file) | |
119 | +static int console_tstc(int file) | |
120 | 120 | { |
121 | 121 | int i, ret; |
122 | 122 | device_t *dev; |
... | ... | @@ -138,7 +138,7 @@ |
138 | 138 | return 0; |
139 | 139 | } |
140 | 140 | |
141 | -static void iomux_putc(int file, const char c) | |
141 | +static void console_putc(int file, const char c) | |
142 | 142 | { |
143 | 143 | int i; |
144 | 144 | device_t *dev; |
... | ... | @@ -150,7 +150,7 @@ |
150 | 150 | } |
151 | 151 | } |
152 | 152 | |
153 | -static void iomux_puts(int file, const char *s) | |
153 | +static void console_puts(int file, const char *s) | |
154 | 154 | { |
155 | 155 | int i; |
156 | 156 | device_t *dev; |
... | ... | @@ -161,6 +161,46 @@ |
161 | 161 | dev->puts(s); |
162 | 162 | } |
163 | 163 | } |
164 | + | |
165 | +static inline void console_printdevs(int file) | |
166 | +{ | |
167 | + iomux_printdevs(file); | |
168 | +} | |
169 | + | |
170 | +static inline void console_doenv(int file, device_t *dev) | |
171 | +{ | |
172 | + iomux_doenv(file, dev->name); | |
173 | +} | |
174 | +#else | |
175 | +static inline int console_getc(int file) | |
176 | +{ | |
177 | + return stdio_devices[file]->getc(); | |
178 | +} | |
179 | + | |
180 | +static inline int console_tstc(int file) | |
181 | +{ | |
182 | + return stdio_devices[file]->tstc(); | |
183 | +} | |
184 | + | |
185 | +static inline void console_putc(int file, const char c) | |
186 | +{ | |
187 | + stdio_devices[file]->putc(c); | |
188 | +} | |
189 | + | |
190 | +static inline void console_puts(int file, const char *s) | |
191 | +{ | |
192 | + stdio_devices[file]->puts(s); | |
193 | +} | |
194 | + | |
195 | +static inline void console_printdevs(int file) | |
196 | +{ | |
197 | + printf("%s\n", stdio_devices[file]->name); | |
198 | +} | |
199 | + | |
200 | +static inline void console_doenv(int file, device_t *dev) | |
201 | +{ | |
202 | + console_setfile(file, dev); | |
203 | +} | |
164 | 204 | #endif /* defined(CONFIG_CONSOLE_MUX) */ |
165 | 205 | |
166 | 206 | /** U-Boot INITIAL CONSOLE-NOT COMPATIBLE FUNCTIONS *************************/ |
... | ... | @@ -195,8 +235,8 @@ |
195 | 235 | * check for that first. |
196 | 236 | */ |
197 | 237 | if (tstcdev != NULL) |
198 | - return iomux_getc(); | |
199 | - iomux_tstc(file); | |
238 | + return console_getc(file); | |
239 | + console_tstc(file); | |
200 | 240 | #ifdef CONFIG_WATCHDOG |
201 | 241 | /* |
202 | 242 | * If the watchdog must be rate-limited then it should |
... | ... | @@ -206,7 +246,7 @@ |
206 | 246 | #endif |
207 | 247 | } |
208 | 248 | #else |
209 | - return stdio_devices[file]->getc(); | |
249 | + return console_getc(file); | |
210 | 250 | #endif |
211 | 251 | } |
212 | 252 | |
... | ... | @@ -216,11 +256,7 @@ |
216 | 256 | int ftstc(int file) |
217 | 257 | { |
218 | 258 | if (file < MAX_FILES) |
219 | -#if defined(CONFIG_CONSOLE_MUX) | |
220 | - return iomux_tstc(file); | |
221 | -#else | |
222 | - return stdio_devices[file]->tstc(); | |
223 | -#endif | |
259 | + return console_tstc(file); | |
224 | 260 | |
225 | 261 | return -1; |
226 | 262 | } |
227 | 263 | |
... | ... | @@ -228,21 +264,13 @@ |
228 | 264 | void fputc(int file, const char c) |
229 | 265 | { |
230 | 266 | if (file < MAX_FILES) |
231 | -#if defined(CONFIG_CONSOLE_MUX) | |
232 | - iomux_putc(file, c); | |
233 | -#else | |
234 | - stdio_devices[file]->putc(c); | |
235 | -#endif | |
267 | + console_putc(file, c); | |
236 | 268 | } |
237 | 269 | |
238 | 270 | void fputs(int file, const char *s) |
239 | 271 | { |
240 | 272 | if (file < MAX_FILES) |
241 | -#if defined(CONFIG_CONSOLE_MUX) | |
242 | - iomux_puts(file, s); | |
243 | -#else | |
244 | - stdio_devices[file]->puts(s); | |
245 | -#endif | |
273 | + console_puts(file, s); | |
246 | 274 | } |
247 | 275 | |
248 | 276 | void fprintf(int file, const char *fmt, ...) |
249 | 277 | |
250 | 278 | |
251 | 279 | |
252 | 280 | |
253 | 281 | |
... | ... | @@ -555,28 +583,16 @@ |
555 | 583 | } |
556 | 584 | /* Initializes output console first */ |
557 | 585 | if (outputdev != NULL) { |
558 | -#ifdef CONFIG_CONSOLE_MUX | |
559 | 586 | /* need to set a console if not done above. */ |
560 | - iomux_doenv(stdout, outputdev->name); | |
561 | -#else | |
562 | - console_setfile(stdout, outputdev); | |
563 | -#endif | |
587 | + console_doenv(stdout, outputdev); | |
564 | 588 | } |
565 | 589 | if (errdev != NULL) { |
566 | -#ifdef CONFIG_CONSOLE_MUX | |
567 | 590 | /* need to set a console if not done above. */ |
568 | - iomux_doenv(stderr, errdev->name); | |
569 | -#else | |
570 | - console_setfile(stderr, errdev); | |
571 | -#endif | |
591 | + console_doenv(stderr, errdev); | |
572 | 592 | } |
573 | 593 | if (inputdev != NULL) { |
574 | -#ifdef CONFIG_CONSOLE_MUX | |
575 | 594 | /* need to set a console if not done above. */ |
576 | - iomux_doenv(stdin, inputdev->name); | |
577 | -#else | |
578 | - console_setfile(stdin, inputdev); | |
579 | -#endif | |
595 | + console_doenv(stdin, inputdev); | |
580 | 596 | } |
581 | 597 | |
582 | 598 | #ifdef CONFIG_CONSOLE_MUX |
583 | 599 | |
584 | 600 | |
... | ... | @@ -591,33 +607,21 @@ |
591 | 607 | if (stdio_devices[stdin] == NULL) { |
592 | 608 | puts("No input devices available!\n"); |
593 | 609 | } else { |
594 | -#ifdef CONFIG_CONSOLE_MUX | |
595 | - iomux_printdevs(stdin); | |
596 | -#else | |
597 | - printf("%s\n", stdio_devices[stdin]->name); | |
598 | -#endif | |
610 | + console_printdevs(stdin); | |
599 | 611 | } |
600 | 612 | |
601 | 613 | puts("Out: "); |
602 | 614 | if (stdio_devices[stdout] == NULL) { |
603 | 615 | puts("No output devices available!\n"); |
604 | 616 | } else { |
605 | -#ifdef CONFIG_CONSOLE_MUX | |
606 | - iomux_printdevs(stdout); | |
607 | -#else | |
608 | - printf("%s\n", stdio_devices[stdout]->name); | |
609 | -#endif | |
617 | + console_printdevs(stdout); | |
610 | 618 | } |
611 | 619 | |
612 | 620 | puts("Err: "); |
613 | 621 | if (stdio_devices[stderr] == NULL) { |
614 | 622 | puts("No error devices available!\n"); |
615 | 623 | } else { |
616 | -#ifdef CONFIG_CONSOLE_MUX | |
617 | - iomux_printdevs(stderr); | |
618 | -#else | |
619 | - printf("%s\n", stdio_devices[stderr]->name); | |
620 | -#endif | |
624 | + console_printdevs(stderr); | |
621 | 625 | } |
622 | 626 | #endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */ |
623 | 627 |