Beispiel #1
0
u8 findNodesInBootloaderMode (IEEEAddr *eui64, u8 maxEUI64)
{
  u8 status;
  u8 reply[3];
  u8 count = 0;

  txBufferInit(TRUE);
  rxBufferInit();

  status = bootloadCommand(GET_VERSION, NULL, sizeof(reply), reply);

  if (status == BOOTLOAD_COMMAND_SUCCESS) {
    if (count < maxEUI64) {
	halCommonMemCopy(eui64[count++], &rxBuffer.srcEui64, sizeof(IEEEAddr));
    }
    while (count < maxEUI64) {
      u32 startTime;
      u8 found = FALSE;

      startTime = TIME_CurrentTime();
      while (TIME_ELAPSED(startTime) < 1000000) {
	if (rxBuffer.packetReceived) {
	  halCommonMemCopy(eui64[count++], &rxBuffer.srcEui64, sizeof(IEEEAddr));
	  rxBuffer.packetReceived = FALSE;
	  found = TRUE;
	  break;
	}
      }
      if (! found)
	break;
    }
  }
  return count;
}
Beispiel #2
0
// timeout -1 forever, or milliseconds
int poll(pollfh fhs[], unsigned nfhs, int timeout)
{
    /**
     * TODO Proper wake-up mechanism.
     * In order to correctly detect availability of read/write a FileHandle, we needed
     * a select or poll mechanisms. We opted for poll as POSIX defines in
     * http://pubs.opengroup.org/onlinepubs/009695399/functions/poll.html Currently,
     * mbed::poll() just spins and scans filehandles looking for any events we are
     * interested in. In future, his spinning behaviour will be replaced with
     * condition variables.
     */
#if MBED_CONF_RTOS_PRESENT
    uint64_t start_time = 0;
    if (timeout > 0) {
        start_time = Kernel::get_ms_count();
    }
#define TIME_ELAPSED() int64_t(Kernel::get_ms_count() - start_time)
#else
#if MBED_CONF_PLATFORM_POLL_USE_LOWPOWER_TIMER
    LowPowerTimer timer;
#else
    Timer timer;
#endif
    if (timeout > 0) {
        timer.start();
    }
#define TIME_ELAPSED() timer.read_ms()
#endif // MBED_CONF_RTOS_PRESENT

    int count = 0;
    for (;;) {
        /* Scan the file handles */
        for (unsigned n = 0; n < nfhs; n++) {
            FileHandle *fh = fhs[n].fh;
            short mask = fhs[n].events | POLLERR | POLLHUP | POLLNVAL;
            if (fh) {
                fhs[n].revents = fh->poll(mask) & mask;
            } else {
                fhs[n].revents = POLLNVAL;
            }
            if (fhs[n].revents) {
                count++;
            }
        }

        if (count) {
            break;
        }

        /* Nothing selected - this is where timeout handling would be needed */
        if (timeout == 0 || (timeout > 0 && TIME_ELAPSED() > timeout)) {
            break;
        }
#ifdef MBED_CONF_RTOS_PRESENT
        // TODO - proper blocking
        // wait for condition variable, wait queue whatever here
        rtos::Thread::wait(1);
#endif
    }
    return count;
}