1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- #ifndef CONSOLE_H
- #define CONSOLE_H
- #include "compiler.h"
- #include "io.h"
- #define CON_FLOW_CTL 1 /* Block on connected and output full? */
- void __fmt_printf(1,0) con_vprintf(const char *, va_list);
- void __fmt_printf(1,2) con_printf(const char *, ...);
- static __always_inline void __con_wait_tx_ready(void)
- {
- /*
- * If CON_FLOW_CTL is set, wait here if the TX buffer is above
- * the high index mark *if* we are connected to a host
- */
- while (CON_FLOW_CTL &&
- (CON_STATUS & (TTY_STATUS_TX_HIGH|TTY_STATUS_DTR_IN))
- == (TTY_STATUS_TX_HIGH|TTY_STATUS_DTR_IN))
- pause();
- }
- static __always_inline void __con_putc(char c)
- {
- if (c == '\n')
- CON_DATA = '\r';
- CON_DATA = c;
- }
- static __always_inline void _con_putc(char c)
- {
- __con_wait_tx_ready();
- __con_putc(c);
- }
- static __always_inline void _con_puts(const char *str)
- {
- char c;
-
- __con_wait_tx_ready();
- while ((c = *str++))
- __con_putc(c);
- }
- #if CON_FLOW_CTL
- void con_putc(char c);
- void con_puts(const char *);
- #else
- /* Simple enough to inline if we don't care about flow control */
- static inline void con_putc(char c)
- {
- _con_putc(c);
- }
- static inline con_puts(const char *str)
- {
- _con_puts(str);
- }
- #endif
- static __always_inline void con_flush(void)
- {
- while (CON_FLOW_CTL && !(CON_STATUS & TTY_STATUS_TX_EMPTY))
- pause();
- }
- #endif /* CONSOLE_H */
|