Fixed stream setup io function declarations

This commit is contained in:
Mark Qvist 2018-04-24 14:38:48 +02:00
parent 2c80adbda4
commit 145b1154f9
3 changed files with 12 additions and 9 deletions

View File

@ -11,8 +11,8 @@ bool hw_5v_ref = false;
Afsk *AFSK_modem;
// Forward declerations
int afsk_getchar(void);
void afsk_putchar(char c);
int afsk_getchar(FILE *strem);
int afsk_putchar(char c, FILE *stream);
void AFSK_hw_refDetect(void) {
// This is manual for now
@ -94,13 +94,14 @@ static void AFSK_txStart(Afsk *afsk) {
}
}
void afsk_putchar(char c) {
int afsk_putchar(char c, FILE *stream) {
AFSK_txStart(AFSK_modem);
while(fifo_isfull_locked(&AFSK_modem->txFifo)) { /* Wait */ }
fifo_push_locked(&AFSK_modem->txFifo, c);
return 1;
}
int afsk_getchar(void) {
int afsk_getchar(FILE *stream) {
if (fifo_isempty_locked(&AFSK_modem->rxFifo)) {
return EOF;
} else {
@ -112,7 +113,7 @@ void AFSK_transmit(char *buffer, size_t size) {
fifo_flush(&AFSK_modem->txFifo);
int i = 0;
while (size--) {
afsk_putchar(buffer[i++]);
afsk_putchar(buffer[i++], NULL);
}
}

View File

@ -19,6 +19,7 @@ void serial_init(Serial *serial) {
UCSR0B = _BV(RXEN0) | _BV(TXEN0);
FILE uart0_fd = FDEV_SETUP_STREAM(uart0_putchar, uart0_getchar, _FDEV_SETUP_RW);
//FILE uart0_fd = FDEV_SETUP_STREAM(uart0_putchar, NULL, _FDEV_SETUP_WRITE);
serial->uart0 = uart0_fd;
}
@ -31,12 +32,13 @@ bool serial_available(uint8_t index) {
}
void uart0_putchar(char c) {
int uart0_putchar(char c, FILE *stream) {
loop_until_bit_is_set(UCSR0A, UDRE0);
UDR0 = c;
return 1;
}
char uart0_getchar(void) {
int uart0_getchar(FILE *stream) {
loop_until_bit_is_set(UCSR0A, RXC0);
return UDR0;
}

View File

@ -13,8 +13,8 @@ typedef struct Serial {
void serial_init(Serial *serial);
bool serial_available(uint8_t index);
void uart0_putchar(char c);
char uart0_getchar(void);
int uart0_putchar(char c, FILE *stream);
int uart0_getchar(FILE *stream);
char uart0_getchar_nowait(void);
#endif