Beispiel #1
0
/*-----------------------------------------------------------*/
uint8_t serial_send_byte(serial_p handle, uint8_t byte )
{
	if ( (handle->_tx_buf != 0)) {
		if (buffer_put_item(handle->_tx_buf,byte) == BUFFER_OK) {
			_serial_tx_int_on(handle->ser_UDR);
			return BUFFER_OK;
		}
	}
	return BUFFER_FULL;
}
Beispiel #2
0
/*-----------------------------------------------------------*/
uint8_t serial_send_bytes(serial_p handle, uint8_t *buf, uint8_t len )
{
	// Check if buffer is full
	if ( ((handle->_tx_buf != 0) && (len > (BUFFER_SIZE - handle->_tx_buf->no_in_buffer))) || ((handle->_tx_buf == 0) && (len > 1)) ) {
		return BUFFER_FULL;
	}
	
	// Put in the tx buffer
	for (uint8_t i = 0; i < len; i++) {
		buffer_put_item(handle->_tx_buf, buf[i]);
	}
	_serial_tx_int_on(handle->ser_UDR);
	return BUFFER_OK;
}
Beispiel #3
0
/**
@ingroup spi_function
@brief Send a single byte to the SPI bus.

@return \n
SPI_OK: OK byte send to SPI bus.\n
SPI_NO_ROOM_IN_TX_BUFFER: Buffer full no data send.\n
SPI_ILLEGAL_INSTANCE: instance is null.

@param spi to send to.
@param byte to be send.
*/
uint8_t spi_send_byte(spi_p spi, uint8_t byte) {
	if (spi == 0) {
		return SPI_ILLEGAL_INSTANCE;
	}

	// Select correct instance
	if (_this != spi ) {
		_select_instance(spi);
	}

	uint8_t result = SPI_OK;

	// Critical section
	{
		// disable interrupt
		uint8_t c_sreg = SREG;
		cli();

		// If SPI in idle send the first byte
		if (!_spi_active) {
			_spi_active = 1;
			_set_cs(CS_ACTIVE);
			// Enable SPI interrupt
			SPCR |= _BV(SPIE);
			// Send first byte
			SPDR = byte;
		}
		#if SPI_USE_BUFFER == 0
		else {
			result = SPI_BUSY;
		}
		#else
		else {
			// Check if buffer is free
			if ( ((spi->_tx_buf != 0) && (BUFFER_SIZE - spi->_tx_buf->no_in_buffer)) || (spi->_tx_buf == 0) ) {
				// Put in the tx buffer
				buffer_put_item(spi->_tx_buf, byte);
				}else {
				result = SPI_NO_ROOM_IN_TX_BUFFER;
			}
		}
		#endif

		// restore interrupt state
		SREG = c_sreg;
	}