Beispiel #1
0
/**
 * @brief   Waits for a received frame.
 * @details Stops until a frame is received and buffered. If a frame is
 *          not immediately available then the invoking thread is queued
 *          until one is received.
 *
 * @param[in] macp      pointer to the @p MACDriver object
 * @param[out] rdp      pointer to a @p MACReceiveDescriptor structure
 * @param[in] time      the number of ticks before the operation timeouts,
 *                      the following special values are allowed:
 *                      - @a TIME_IMMEDIATE immediate timeout.
 *                      - @a TIME_INFINITE no timeout.
 *                      .
 * @return              The operation status.
 * @retval RDY_OK       the descriptor was obtained.
 * @retval RDY_TIMEOUT  the operation timed out, descriptor not initialized.
 */
msg_t macWaitReceiveDescriptor(MACDriver *macp,
                               MACReceiveDescriptor *rdp,
                               systime_t time) {
  msg_t msg;

  while (((msg = max_lld_get_receive_descriptor(macp, rdp)) != RDY_OK) &&
         (time > 0)) {
    chSysLock();
    systime_t now = chTimeNow();
    if ((msg = chSemWaitTimeoutS(&macp->md_rdsem, time)) == RDY_TIMEOUT)
      break;
    if (time != TIME_INFINITE)
      time -= (chTimeNow() - now);
    chSysUnlock();
  }
  return msg;
}
Beispiel #2
0
/**
 * @brief   Waits for a received frame.
 * @details Stops until a frame is received and buffered. If a frame is
 *          not immediately available then the invoking thread is queued
 *          until one is received.
 *
 * @param[in] macp      pointer to the @p MACDriver object
 * @param[out] rdp      pointer to a @p MACReceiveDescriptor structure
 * @param[in] time      the number of ticks before the operation timeouts,
 *                      the following special values are allowed:
 *                      - @a TIME_IMMEDIATE immediate timeout.
 *                      - @a TIME_INFINITE no timeout.
 *                      .
 * @return              The operation status.
 * @retval RDY_OK       the descriptor was obtained.
 * @retval RDY_TIMEOUT  the operation timed out, descriptor not initialized.
 *
 * @api
 */
msg_t macWaitReceiveDescriptor(MACDriver *macp,
                               MACReceiveDescriptor *rdp,
                               systime_t time) {
    msg_t msg;

    chDbgCheck((macp != NULL) && (rdp != NULL), "macWaitReceiveDescriptor");
    chDbgAssert(macp->state == MAC_ACTIVE, "macWaitReceiveDescriptor(), #1",
                "not active");

    while (((msg = max_lld_get_receive_descriptor(macp, rdp)) != RDY_OK) &&
            (time > 0)) {
        chSysLock();
        systime_t now = chTimeNow();
        if ((msg = chSemWaitTimeoutS(&macp->rdsem, time)) == RDY_TIMEOUT) {
            chSysUnlock();
            break;
        }
        if (time != TIME_INFINITE)
            time -= (chTimeNow() - now);
        chSysUnlock();
    }
    return msg;
}