/** * @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] timeout 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 MSG_OK the descriptor was obtained. * @retval MSG_TIMEOUT the operation timed out, descriptor not initialized. * * @api */ msg_t macWaitReceiveDescriptor(MACDriver *macp, MACReceiveDescriptor *rdp, systime_t timeout) { msg_t msg; systime_t now; osalDbgCheck((macp != NULL) && (rdp != NULL)); osalDbgAssert(macp->state == MAC_ACTIVE, "not active"); while (((msg = mac_lld_get_receive_descriptor(macp, rdp)) != MSG_OK) && (timeout > (systime_t)0)) { osalSysLock(); now = osalOsGetSystemTimeX(); msg = osalThreadEnqueueTimeoutS(&macp->rdqueue, timeout); if (msg == MSG_TIMEOUT) { osalSysUnlock(); break; } if (timeout != TIME_INFINITE) { timeout -= (osalOsGetSystemTimeX() - now); } osalSysUnlock(); } return msg; }
/** * @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 = mac_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; }