Skip to content

serial_putc() to make better use of Tx FIFO #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct pwmout_s {
struct serial_s {
LPC_UART_TypeDef *uart;
int index;
uint8_t count;
};

struct analogin_s {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
case UART_2: obj->index = 2; break;
case UART_3: obj->index = 3; break;
}
obj->count = 0;

is_stdio_uart = (uart == STDIO_UART) ? (1) : (0);

Expand Down Expand Up @@ -283,6 +284,7 @@ int serial_getc(serial_t *obj) {
void serial_putc(serial_t *obj, int c) {
while (!serial_writable(obj));
obj->uart->THR = c;
obj->count++;

uint32_t lsr = obj->uart->LSR;
lsr = lsr;
Expand All @@ -295,7 +297,13 @@ int serial_readable(serial_t *obj) {
}

int serial_writable(serial_t *obj) {
return obj->uart->LSR & 0x20;
int isWritable = 1;
if (obj->uart->LSR & 0x20)
obj->count = 0;
else if (obj->count >= 16)
isWritable = 0;

return isWritable;
}

void serial_clear(serial_t *obj) {
Expand Down