Commit 2618ea45d068407367924f8739145a719d6a08b6

Authored by Antonio Carlos Domínguez Brito
1 parent 65d6bcc8
Exists in master

added function available_for_write() to serial objects (now it is possible to as…

…k if the transmission buffer is not full before sending)
Showing 2 changed files with 27 additions and 1 deletions   Show diff stats
fifo.h
... ... @@ -68,6 +68,8 @@ namespace arduino_due
68 68  
69 69 bool is_empty() { return (_first_<0); }
70 70  
  71 + bool is_full() { return (_items_==LENGTH); }
  72 +
71 73 int items() { return _items_; }
72 74  
73 75 void reset() { _init_(); }
... ...
soft_uart.h
... ... @@ -215,7 +215,7 @@ namespace arduino_due
215 215  
216 216 uart() { _mode_=mode_codes::INVALID_MODE; }
217 217  
218   - ~uart() { end(); }
  218 + ~uart() { end(); }
219 219  
220 220 uart(const uart&) = delete;
221 221 uart(uart&&) = delete;
... ... @@ -402,6 +402,17 @@ namespace arduino_due
402 402 bool bad_stop_bit(uint32_t status)
403 403 { return _ctx_.bad_stop_bit(status); }
404 404  
  405 + // is TX buffer full?
  406 + bool is_tx_full()
  407 + {
  408 + return (
  409 + (
  410 + (_mode_==mode_codes::FULL_DUPLEX) ||
  411 + (_mode_==mode_codes::TX_MODE)
  412 + )? _ctx_.is_tx_full(): false
  413 + );
  414 + }
  415 +
405 416 // NOTE: data is 5, 6, 7, 8 or 9 bits length
406 417 bool set_tx_data(uint32_t data)
407 418 {
... ... @@ -414,6 +425,7 @@ namespace arduino_due
414 425 }
415 426  
416 427 tx_status_codes get_tx_status() { return _ctx_.get_tx_status(); }
  428 +
417 429 void flush() { _ctx_.flush(); }
418 430  
419 431 void flush_rx() { _ctx_.flush_rx(); }
... ... @@ -491,6 +503,15 @@ namespace arduino_due
491 503 bool bad_stop_bit(uint32_t status)
492 504 { return (status&rx_data_status_codes::BAD_STOP_BIT); }
493 505  
  506 + // is TX buffer full?
  507 + bool is_tx_full()
  508 + {
  509 + disable_tc_interrupts();
  510 + auto full=tx_buffer.is_full();
  511 + enable_tc_interrupts();
  512 + return full;
  513 + }
  514 +
494 515 // NOTE: only the 5, 6, 7, 8 or 9 lowest significant bits
495 516 // of data are send
496 517 bool set_tx_data(uint32_t data);
... ... @@ -725,6 +746,9 @@ namespace arduino_due
725 746  
726 747 int available(void) { return _tc_uart_.available(); }
727 748  
  749 + int available_for_write(void)
  750 + { return _tc_uart_.is_tx_full(); }
  751 +
728 752 int peek(void)
729 753 {
730 754 if(_peek_data_valid_) return _last_data_;
... ...