Page 1 of 1

MAC Driver Bug

Posted: Fri Feb 11, 2011 2:01 am
by brian360
Hi,

I came across a problem in the HAL MAC code that keeps the system locked for a long period of time. When the semaphore times out, there's a break statement that skips calling chSysUnlock(). This is in both macWaitTransmitDescriptor() and macWaitReceiveDescriptor(). My code which fixes this issue is below.

Thanks!

Code: Select all

msg_t macWaitTransmitDescriptor(MACDriver *macp,
                                MACTransmitDescriptor *tdp,
                                systime_t time) {
  msg_t msg;

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

Code: Select all

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) {
      chSysUnlock();
      break;
    }
    if (time != TIME_INFINITE)
      time -= (chTimeNow() - now);
    chSysUnlock();
  }
  return msg;
}

Re: MAC Driver Bug

Posted: Fri Feb 11, 2011 7:24 pm
by Giovanni
Thanks Brian, I will merge the code in the weekend.

Giovanni