/* Put a string into the print buffer. 
This function puts a string into the print buffer, taking care to not exceed the buffer's free space. If the buffer becomes full, this function will start the UART and wait for enough space to free up until the entire string has been put into buffer. */
static void _dbg_putstr(const char *str, size_t length)
/* Put a string into the print buffer. 
This function puts a string into the print buffer, taking care to not exceed the buffer's free space. If the buffer becomes full, this function will start the UART and wait for enough space to free up until the entire string has been put into buffer. */
static void _dbg_putstr(const char *str, size_t length)
{
	dbg_buffer_space_t write_length;
	_dbg_stop_uart();
	write_length = _dbg_get_free_buffer_space();
	if (write_length) {
		write_length = min(write_length, length);
		_dbg_write_str_to_buffer(str, write_length);
		length -= write_length;
		str += write_length;
	}
	write_length = _dbg_request_free_space(length);
	_dbg_start_uart();
	while (length) {
		_dbg_wait_for_requested_space();
		_dbg_stop_uart();
		_dbg_write_str_to_buffer(str, write_length);
		length -= write_length;
		str += write_length;
		write_length = _dbg_request_free_space(length);
		_dbg_start_uart();
	}
}