Ejemplo n.º 1
0
int HardwareSerial::available(void)
{
    int result = static_cast<int>(uart_rx_available(_uart));
    if (!result) {
        optimistic_yield(10000);
    }
    return result;
}
Ejemplo n.º 2
0
 int available() {
     auto cb = _available;
     if (cb == 0) {
         cb = _readAll();
     } else {
         optimistic_yield(100);
     }
     return cb;
 }
Ejemplo n.º 3
0
//------------------------------------------------------------------------------
// wait for card to go not busy
uint8_t Sd2Card::waitNotBusy(uint16_t timeoutMillis) {
  uint16_t t0 = millis();
  do {
    #ifdef ESP8266
    optimistic_yield(10000);
    #endif
    if (spiRec() == 0XFF) return true;
  }
  while (((uint16_t)millis() - t0) < timeoutMillis);
  return false;
}
Ejemplo n.º 4
0
int TwoWire::available(void){
  int result = rxBufferLength - rxBufferIndex;

  if (!result) {
    // yielding here will not make more data "available",
    // but it will prevent the system from going into WDT reset
    optimistic_yield(1000);
  }

  return result;
}
Ejemplo n.º 5
0
int WiFiClient::available()
{
    if (!_client)
        return false;

    int result = _client->getSize();

    if (!result) {
        optimistic_yield(100);
    }
    return result;
}
Ejemplo n.º 6
0
int WiFiUDP::parsePacket()
{
    if (!_ctx)
        return 0;

    if (!_ctx->next()) {
        optimistic_yield(100);
        return 0;
    }

    return _ctx->getSize();
}
Ejemplo n.º 7
0
int ICACHE_FLASH_ATTR wire_available(void)
{
	int result = wire_rxBufferLength - wire_rxBufferIndex;

	if (!result) {
		// yielding here will not make more data "available",
		// but it will prevent the system from going into WDT reset
		optimistic_yield(1000);
	}

	return result;
}
Ejemplo n.º 8
0
/* return number of bytes available in the current packet,
   will return zero if parsePacket hasn't been called yet */
int WiFiUDP::available() {
    int result = 0;

    if (_ctx) {
        result = static_cast<int>(_ctx->getSize());
    }

    if (!result) {
        // yielding here will not make more data "available",
        // but it will prevent the system from going into WDT reset
        optimistic_yield(1000);
    }

    return result;
}
Ejemplo n.º 9
0
extern "C" int ax_port_read(int fd, uint8_t* buffer, size_t count) {
    ClientContext* _client = reinterpret_cast<ClientContext*>(fd);
    if (_client->state() != ESTABLISHED && !_client->getSize()) {
        return -1;
        errno = EIO;
    }
    size_t cb = _client->read((char*) buffer, count);
    if (cb != count) {
        errno = EAGAIN;
    }
    if (cb == 0) {
        optimistic_yield(100);
        return -1;
    }
    return cb;
}
Ejemplo n.º 10
0
/* serial1 can not rx data, just tx for debug */
irom int serial_available()
{
	uart_t *_uart = uart0;
    if(!_uart || !uart_rx_enabled(_uart)) {
        return 0;
    }

    int result = uart_rx_available(_uart);
    if (_peek_char != -1) {
        result += 1;
    }
    if (!result) {
        optimistic_yield(10000);
    }
    return result;
}
Ejemplo n.º 11
0
int32_t spiffs_hal_erase(uint32_t addr, uint32_t size) {
    if ((size & (SPI_FLASH_SEC_SIZE - 1)) != 0 ||
        (addr & (SPI_FLASH_SEC_SIZE - 1)) != 0) {
        DEBUGV("_spif_erase called with addr=%x, size=%d\r\n", addr, size);
        abort();
    }
    const uint32_t sector = addr / SPI_FLASH_SEC_SIZE;
    const uint32_t sectorCount = size / SPI_FLASH_SEC_SIZE;
    for (uint32_t i = 0; i < sectorCount; ++i) {
        optimistic_yield(10000);
        if (!ESP.flashEraseSector(sector + i)) {
            DEBUGV("_spif_erase addr=%x size=%d i=%d\r\n", addr, size, i);
            return SPIFFS_ERR_INTERNAL;
        }
    }
    return SPIFFS_OK;
}
Ejemplo n.º 12
0
extern "C" int __ax_port_read(int fd, uint8_t* buffer, size_t count)
{
    ClientContext* _client = SSLContext::getIOContext(fd);
    if (!_client || (_client->state() != ESTABLISHED && !_client->getSize())) {
        errno = EIO;
        return -1;
    }
    size_t cb = _client->read((char*) buffer, count);
    if (cb != count) {
        errno = EAGAIN;
    }
    if (cb == 0) {
        optimistic_yield(100);
        return -1;
    }
    return cb;
}
Ejemplo n.º 13
0
int32_t spiffs_hal_read(uint32_t addr, uint32_t size, uint8_t *dst) {
    optimistic_yield(10000);

    uint32_t result = SPIFFS_OK;
    uint32_t alignedBegin = (addr + 3) & (~3);
    uint32_t alignedEnd = (addr + size) & (~3);
    if (alignedEnd < alignedBegin) {
        alignedEnd = alignedBegin;
    }

    if (addr < alignedBegin) {
        uint32_t nb = alignedBegin - addr;
        uint32_t tmp;
        if (!ESP.flashRead(alignedBegin - 4, &tmp, 4)) {
            DEBUGV("_spif_read(%d) addr=%x size=%x ab=%x ae=%x\r\n",
                __LINE__, addr, size, alignedBegin, alignedEnd);
            return SPIFFS_ERR_INTERNAL;
        }
        memcpy(dst, &tmp + 4 - nb, nb);
    }

    if (alignedEnd != alignedBegin) {
        if (!ESP.flashRead(alignedBegin, (uint32_t*) (dst + alignedBegin - addr),
                alignedEnd - alignedBegin)) {
            DEBUGV("_spif_read(%d) addr=%x size=%x ab=%x ae=%x\r\n",
                __LINE__, addr, size, alignedBegin, alignedEnd);
            return SPIFFS_ERR_INTERNAL;
        }
    }

    if (addr + size > alignedEnd) {
        uint32_t nb = addr + size - alignedEnd;
        uint32_t tmp;
        if (!ESP.flashRead(alignedEnd, &tmp, 4)) {
            DEBUGV("_spif_read(%d) addr=%x size=%x ab=%x ae=%x\r\n",
                __LINE__, addr, size, alignedBegin, alignedEnd);
            return SPIFFS_ERR_INTERNAL;
        }

        memcpy(dst + size - nb, &tmp, nb);
    }

    return result;
}
Ejemplo n.º 14
0
    int _readAll() {
        if (!_ssl)
            return 0;

        optimistic_yield(100);

        uint8_t* data;
        int rc = ssl_read(_ssl, &data);
        if (rc <= 0) {
            if (rc < SSL_OK && rc != SSL_CLOSE_NOTIFY && rc != SSL_ERROR_CONN_LOST) {
                ssl_free(_ssl);
                _ssl = nullptr;
            }
            return 0;
        }
        DEBUGV(":wcs ra %d", rc);
        _read_ptr = data;
        _available = rc;
        return _available;
    }
Ejemplo n.º 15
0
/** Wait for start block token */
uint8_t Sd2Card::waitStartBlock(void) {
  uint16_t t0 = millis();
  while ((status_ = spiRec()) == 0XFF) {
    #ifdef ESP8266
    optimistic_yield(10000);
    #endif
    if (((uint16_t)millis() - t0) > SD_READ_TIMEOUT) {
      error(SD_CARD_ERROR_READ_TIMEOUT);
      goto fail;
    }
  }
  if (status_ != DATA_START_BLOCK) {
    error(SD_CARD_ERROR_READ);
    goto fail;
  }
  return true;

 fail:
  chipSelectHigh();
  return false;
}
Ejemplo n.º 16
0
//------------------------------------------------------------------------------
// send command and return error code.  Return zero for OK
uint8_t Sd2Card::cardCommand(uint8_t cmd, uint32_t arg) {
  // end read if in partialBlockRead mode
  readEnd();

  // select card
  chipSelectLow();

  // wait up to 300 ms if busy
  waitNotBusy(300);

  // send command
  spiSend(cmd | 0x40);

#ifdef ESP8266
  // send argument
  SPI.write32(arg, true);
#else
  // send argument
  for (int8_t s = 24; s >= 0; s -= 8) spiSend(arg >> s);
#endif


  // send CRC
  uint8_t crc = 0xFF;
  if (cmd == CMD0) crc = 0x95;  // correct crc for CMD0 with arg 0
  if (cmd == CMD8) crc = 0x87;  // correct crc for CMD8 with arg 0X1AA
  spiSend(crc);

  // wait for response
  for (uint8_t i = 0; ((status_ = spiRec()) & 0x80) && i != 0xFF; i++)
    ;
  #ifdef ESP8266
  optimistic_yield(10000);
  #endif
  return status_;
}
Ejemplo n.º 17
0
extern "C" void __ax_wdt_feed()
{
    optimistic_yield(10000);
}
Ejemplo n.º 18
0
int32_t spiffs_hal_write(uint32_t addr, uint32_t size, uint8_t *src) {
    optimistic_yield(10000);

    uint32_t alignedBegin = (addr + 3) & (~3);
    uint32_t alignedEnd = (addr + size) & (~3);
    if (alignedEnd < alignedBegin) {
        alignedEnd = alignedBegin;
    }

    if (addr < alignedBegin) {
        uint32_t ofs = alignedBegin - addr;
        uint32_t nb = (size < ofs) ? size : ofs;
        uint8_t tmp[4] __attribute__((aligned(4))) = {0xff, 0xff, 0xff, 0xff};
        memcpy(tmp + 4 - ofs, src, nb);
        if (!ESP.flashWrite(alignedBegin - 4, (uint32_t*) tmp, 4)) {
            DEBUGV("_spif_write(%d) addr=%x size=%x ab=%x ae=%x\r\n",
                __LINE__, addr, size, alignedBegin, alignedEnd);
            return SPIFFS_ERR_INTERNAL;
        }
    }

    if (alignedEnd != alignedBegin) {
        uint32_t* srcLeftover = (uint32_t*) (src + alignedBegin - addr);
        uint32_t srcAlign = ((uint32_t) srcLeftover) & 3;
        if (!srcAlign) {
            if (!ESP.flashWrite(alignedBegin, (uint32_t*) srcLeftover,
                    alignedEnd - alignedBegin)) {
                DEBUGV("_spif_write(%d) addr=%x size=%x ab=%x ae=%x\r\n",
                    __LINE__, addr, size, alignedBegin, alignedEnd);
                return SPIFFS_ERR_INTERNAL;
            }
        }
        else {
            uint8_t buf[UNALIGNED_WRITE_BUFFER_SIZE];
            for (uint32_t sizeLeft = alignedEnd - alignedBegin; sizeLeft; ) {
                size_t willCopy = std::min(sizeLeft, sizeof(buf));
                memcpy(buf, srcLeftover, willCopy);

                if (!ESP.flashWrite(alignedBegin, (uint32_t*) buf, willCopy)) {
                    DEBUGV("_spif_write(%d) addr=%x size=%x ab=%x ae=%x\r\n",
                        __LINE__, addr, size, alignedBegin, alignedEnd);
                    return SPIFFS_ERR_INTERNAL;
                }

                sizeLeft -= willCopy;
                srcLeftover += willCopy;
                alignedBegin += willCopy;
            }
        }
    }

    if (addr + size > alignedEnd) {
        uint32_t nb = addr + size - alignedEnd;
        uint32_t tmp = 0xffffffff;
        memcpy(&tmp, src + size - nb, nb);

        if (!ESP.flashWrite(alignedEnd, &tmp, 4)) {
            DEBUGV("_spif_write(%d) addr=%x size=%x ab=%x ae=%x\r\n",
                __LINE__, addr, size, alignedBegin, alignedEnd);
            return SPIFFS_ERR_INTERNAL;
        }
    }

    return SPIFFS_OK;
}