Commit 13a8bfcad02121087b9d7f830f360c936aa6d32e
1 parent
2618ea45
Exists in
master
and in
1 other branch
available_for_write() now in a camelCase version availableForWrite(), and write(…
…) now waits idle until there is space enough in the transmission buffer
Showing
2 changed files
with
29 additions
and
1 deletions
Show diff stats
fifo.h
soft_uart.h
... | ... | @@ -413,6 +413,17 @@ namespace arduino_due |
413 | 413 | ); |
414 | 414 | } |
415 | 415 | |
416 | + // is TX buffer full? | |
417 | + bool available_for_write() | |
418 | + { | |
419 | + return ( | |
420 | + ( | |
421 | + (_mode_==mode_codes::FULL_DUPLEX) || | |
422 | + (_mode_==mode_codes::TX_MODE) | |
423 | + )? _ctx_.available_for_write(): 0 | |
424 | + ); | |
425 | + } | |
426 | + | |
416 | 427 | // NOTE: data is 5, 6, 7, 8 or 9 bits length |
417 | 428 | bool set_tx_data(uint32_t data) |
418 | 429 | { |
... | ... | @@ -512,6 +523,14 @@ namespace arduino_due |
512 | 523 | return full; |
513 | 524 | } |
514 | 525 | |
526 | + int available_for_write() | |
527 | + { | |
528 | + disable_tc_interrupts(); | |
529 | + auto items=tx_buffer.available(); | |
530 | + enable_tc_interrupts(); | |
531 | + return items; | |
532 | + } | |
533 | + | |
515 | 534 | // NOTE: only the 5, 6, 7, 8 or 9 lowest significant bits |
516 | 535 | // of data are send |
517 | 536 | bool set_tx_data(uint32_t data); |
... | ... | @@ -746,8 +765,11 @@ namespace arduino_due |
746 | 765 | |
747 | 766 | int available(void) { return _tc_uart_.available(); } |
748 | 767 | |
768 | + int availableForWrite(void) | |
769 | + { return available_for_write(); } | |
770 | + | |
749 | 771 | int available_for_write(void) |
750 | - { return _tc_uart_.is_tx_full(); } | |
772 | + { return _tc_uart_.available_for_write(); } | |
751 | 773 | |
752 | 774 | int peek(void) |
753 | 775 | { |
... | ... | @@ -795,6 +817,8 @@ namespace arduino_due |
795 | 817 | |
796 | 818 | size_t write(uint8_t data) |
797 | 819 | { |
820 | + while(!available_for_write()) { /* nothing */ } | |
821 | + | |
798 | 822 | return ( |
799 | 823 | (_tc_uart_.set_tx_data(static_cast<uint32_t>(data)))? |
800 | 824 | 1: 0 |
... | ... | @@ -803,6 +827,8 @@ namespace arduino_due |
803 | 827 | |
804 | 828 | size_t write(uint32_t data) |
805 | 829 | { |
830 | + while(!available_for_write()) { /* nothing */ } | |
831 | + | |
806 | 832 | return ( |
807 | 833 | (_tc_uart_.set_tx_data(data))? |
808 | 834 | 1: 0 | ... | ... |