MAC Driver Bug

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
brian360
Posts: 27
Joined: Wed Dec 08, 2010 5:47 pm

MAC Driver Bug

Post 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;
}
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: MAC Driver Bug

Post by Giovanni »

Thanks Brian, I will merge the code in the weekend.

Giovanni
Post Reply