Beispiel #1
0
/**
 * @brief   Starts a receive operation on the UART peripheral.
 * @note    The buffers are organized as uint8_t arrays for data sizes below
 *          or equal to 8 bits else it is organized as uint16_t arrays.
 * @note    This function has to be invoked from a lock zone.
 *
 * @param[in] uartp     pointer to the @p UARTDriver object
 * @param[in] n         number of data frames to send
 * @param[out] rxbuf    the pointer to the receive buffer
 *
 * @iclass
 */
void uartStartReceiveI(UARTDriver *uartp, size_t n, void *rxbuf) {

    chDbgCheckClassI();
    chDbgCheck((uartp != NULL) && (n > 0) && (rxbuf != NULL),
               "uartStartReceiveI");
    chDbgAssert(uartp->state == UART_READY,
                "uartStartReceiveI(), #1", "is active");
    chDbgAssert(uartp->rxstate != UART_RX_ACTIVE,
                "uartStartReceiveI(), #2", "rx active");

    uart_lld_start_receive(uartp, n, rxbuf);
    uartp->rxstate = UART_RX_ACTIVE;
}
/**
 * @brief   Starts a receive operation on the UART peripheral.
 * @note    The buffers are organized as uint8_t arrays for data sizes below
 *          or equal to 8 bits else it is organized as uint16_t arrays.
 *
 * @param[in] uartp     pointer to the @p UARTDriver object
 * @param[in] n         number of data frames to send
 * @param[in] rxbuf     the pointer to the receive buffer
 *
 * @api
 */
void uartStartReceive(UARTDriver *uartp, size_t n, void *rxbuf) {

  chDbgCheck((uartp != NULL) && (n > 0) && (rxbuf != NULL),
             "uartStartReceive");

  chSysLock();
  chDbgAssert((uartp->state == UART_READY) && (uartp->rxstate == UART_RX_IDLE),
              "uartStartReceive(), #1", "not active");

  uart_lld_start_receive(uartp, n, rxbuf);
  uartp->rxstate = UART_RX_ACTIVE;
  chSysUnlock();
}
Beispiel #3
0
/**
 * @brief   Performs a receive operation on the UART peripheral.
 * @note    The function returns when the specified number of frames have been
 *          received or on error/timeout.
 * @note    The buffers are organized as uint8_t arrays for data sizes below
 *          or equal to 8 bits else it is organized as uint16_t arrays.
 *
 * @param[in] uartp     pointer to the @p UARTDriver object
 * @param[in,out] np    number of data frames to receive, on exit the number
 *                      of frames actually received
 * @param[in] rxbuf     the pointer to the receive buffer
 * @param[in] timeout   operation timeout
 *
 * @return              The operation status.
 * @retval MSG_OK       if the operation completed successfully.
 * @retval MSG_TIMEOUT  if the operation timed out.
 * @retval MSG_RESET    in case of a receive error.
 *
 * @api
 */
msg_t uartReceiveTimeout(UARTDriver *uartp, size_t *np,
                         void *rxbuf, systime_t timeout) {
  msg_t msg;

  osalDbgCheck((uartp != NULL) && (*np > 0U) && (rxbuf != NULL));

  osalSysLock();
  osalDbgAssert(uartp->state == UART_READY, "is active");
  osalDbgAssert(uartp->rxstate != UART_RX_ACTIVE, "rx active");

  /* Receive start.*/
  uart_lld_start_receive(uartp, *np, rxbuf);
  uartp->rxstate = UART_RX_ACTIVE;

  /* Waiting for result.*/
  msg = osalThreadSuspendTimeoutS(&uartp->threadrx, timeout);
  if (msg != MSG_OK) {
    *np = uartStopReceiveI(uartp);
  }
  osalSysUnlock();

  return msg;
}