示例#1
0
文件: pios_com.c 项目: Crash1/TauLabs
static uint16_t PIOS_COM_TxOutCallback(uint32_t context, uint8_t * buf, uint16_t buf_len, uint16_t * headroom, bool * need_yield)
{
	struct pios_com_dev * com_dev = PIOS_COM_find_dev(context);

	bool valid = PIOS_COM_validate(com_dev);
	PIOS_Assert(valid);
	PIOS_Assert(buf);
	PIOS_Assert(buf_len);
	PIOS_Assert(com_dev->has_tx);

	PIOS_IRQ_Disable();
	uint16_t bytes_from_fifo = fifoBuf_getData(&com_dev->tx, buf, buf_len);
	PIOS_IRQ_Enable();

	if (bytes_from_fifo > 0) {
		/* More space has been made in the buffer */
		PIOS_COM_UnblockTx(com_dev, need_yield);
	}

	if (headroom) {
		*headroom = fifoBuf_getUsed(&com_dev->tx);
	}

	return (bytes_from_fifo);
}
示例#2
0
/**
 * @brief Get data from fifo
 * @param [out] buffer pointer to a @ref pios_bma180_data structure to receive data
 * @return 0 for success, -1 for failure (no data available)
 */
int32_t PIOS_BMA180_ReadFifo(struct pios_bma180_data * buffer)
{
	if(PIOS_BMA180_Validate(dev) != 0)
		return -1;

	if(fifoBuf_getUsed(&dev->fifo) < sizeof(*buffer))
		return -1;
	
	fifoBuf_getData(&dev->fifo, (uint8_t *) buffer, sizeof(*buffer));
	
	return 0;
}
示例#3
0
/**
 * Transfer bytes from port buffers into another buffer
 * \param[in] port COM port
 * \returns Byte from buffer
 */
uint16_t PIOS_COM_ReceiveBuffer(uint32_t com_id, uint8_t *buf, uint16_t buf_len, uint32_t timeout_ms)
{
    PIOS_Assert(buf);
    PIOS_Assert(buf_len);
    uint16_t bytes_from_fifo;

    struct pios_com_dev *com_dev = (struct pios_com_dev *)com_id;

    if (!PIOS_COM_validate(com_dev)) {
        /* Undefined COM port for this board (see pios_board.c) */
        PIOS_Assert(0);
    }
    PIOS_Assert(com_dev->has_rx);

check_again:
    bytes_from_fifo = fifoBuf_getData(&com_dev->rx, buf, buf_len);

    if (bytes_from_fifo == 0) {
        /* No more bytes in receive buffer */
        /* Make sure the receiver is running while we wait */
        if (com_dev->driver->rx_start) {
            /* Notify the lower layer that there is now room in the rx buffer */
            (com_dev->driver->rx_start)(com_dev->lower_id,
                                        fifoBuf_getFree(&com_dev->rx));
        }
        if (timeout_ms > 0) {
#if defined(PIOS_INCLUDE_FREERTOS)
            if (xSemaphoreTake(com_dev->rx_sem, timeout_ms / portTICK_RATE_MS) == pdTRUE) {
                /* Make sure we don't come back here again */
                timeout_ms = 0;
                goto check_again;
            }
#else
            PIOS_DELAY_WaitmS(1);
            timeout_ms--;
            goto check_again;
#endif
        }
    }

    /* Return received byte */
    return bytes_from_fifo;
}