/** * @brief Allocates a transmission descriptor. * @details One of the available transmission descriptors is locked and * returned. If a descriptor is not currently available then the * invoking thread is queued until one is freed. * * @param[in] macp pointer to the @p MACDriver object * @param[out] tdp pointer to a @p MACTransmitDescriptor 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 macWaitTransmitDescriptor(MACDriver *macp, MACTransmitDescriptor *tdp, systime_t timeout) { msg_t msg; systime_t now; osalDbgCheck((macp != NULL) && (tdp != NULL)); osalDbgAssert(macp->state == MAC_ACTIVE, "not active"); while (((msg = mac_lld_get_transmit_descriptor(macp, tdp)) != MSG_OK) && (timeout > (systime_t)0)) { osalSysLock(); now = osalOsGetSystemTimeX(); msg = osalThreadEnqueueTimeoutS(&macp->tdqueue, timeout); if (msg == MSG_TIMEOUT) { osalSysUnlock(); break; } if (timeout != TIME_INFINITE) { timeout -= (osalOsGetSystemTimeX() - now); } osalSysUnlock(); } return msg; }
/** * @brief Allocates a transmission descriptor. * @details One of the available transmission descriptors is locked and * returned. If a descriptor is not currently available then the * invoking thread is queued until one is freed. * * @param[in] macp pointer to the @p MACDriver object * @param[out] tdp pointer to a @p MACTransmitDescriptor 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 macWaitTransmitDescriptor(MACDriver *macp, MACTransmitDescriptor *tdp, systime_t time) { msg_t msg; chDbgCheck((macp != NULL) && (tdp != NULL), "macWaitTransmitDescriptor"); chDbgAssert(macp->state == MAC_ACTIVE, "macWaitTransmitDescriptor(), #1", "not active"); while (((msg = mac_lld_get_transmit_descriptor(macp, tdp)) != RDY_OK) && (time > 0)) { chSysLock(); systime_t now = chTimeNow(); if ((msg = chSemWaitTimeoutS(&macp->tdsem, time)) == RDY_TIMEOUT) { chSysUnlock(); break; } if (time != TIME_INFINITE) time -= (chTimeNow() - now); chSysUnlock(); } return msg; }