Merge pull request #15733 from liyue75/liyue

drivers/w5100/w5100.c: correct the pointer position when w5100's buf is full
This commit is contained in:
Marian Buschsieweke 2021-01-09 21:51:03 +01:00 committed by GitHub
commit f1367818ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -73,6 +73,7 @@ static void wreg(w5100_t *dev, uint16_t reg, uint8_t data)
static uint16_t raddr(w5100_t *dev, uint16_t addr_high, uint16_t addr_low) static uint16_t raddr(w5100_t *dev, uint16_t addr_high, uint16_t addr_low)
{ {
uint16_t res = (rreg(dev, addr_high) << 8); uint16_t res = (rreg(dev, addr_high) << 8);
res |= rreg(dev, addr_low); res |= rreg(dev, addr_low);
return res; return res;
} }
@ -143,7 +144,7 @@ static int init(netdev_t *netdev)
/* reset the device */ /* reset the device */
wreg(dev, REG_MODE, MODE_RESET); wreg(dev, REG_MODE, MODE_RESET);
while (rreg(dev, REG_MODE) & MODE_RESET) {}; while (rreg(dev, REG_MODE) & MODE_RESET) {}
/* initialize the device, start with writing the MAC address */ /* initialize the device, start with writing the MAC address */
luid_get(hwaddr, ETHERNET_ADDR_LEN); luid_get(hwaddr, ETHERNET_ADDR_LEN);
@ -183,7 +184,7 @@ static uint16_t tx_upload(w5100_t *dev, uint16_t start, void *data, size_t len)
size_t limit = ((S0_TX_BASE + S0_MEMSIZE) - start); size_t limit = ((S0_TX_BASE + S0_MEMSIZE) - start);
wchunk(dev, start, data, limit); wchunk(dev, start, data, limit);
wchunk(dev, S0_TX_BASE, &((uint8_t *)data)[limit], len - limit); wchunk(dev, S0_TX_BASE, &((uint8_t *)data)[limit], len - limit);
return (S0_TX_BASE + limit); return (S0_TX_BASE + len - limit);
} }
else { else {
wchunk(dev, start, data, len); wchunk(dev, start, data, len);
@ -218,7 +219,7 @@ static int send(netdev_t *netdev, const iolist_t *iolist)
/* trigger the sending process */ /* trigger the sending process */
wreg(dev, S0_CR, CR_SEND_MAC); wreg(dev, S0_CR, CR_SEND_MAC);
while (!(rreg(dev, S0_IR) & IR_SEND_OK)) {}; while (!(rreg(dev, S0_IR) & IR_SEND_OK)) {}
wreg(dev, S0_IR, IR_SEND_OK); wreg(dev, S0_IR, IR_SEND_OK);
DEBUG("[w5100] send: transferred %i byte (at 0x%04x)\n", sum, (int)pos); DEBUG("[w5100] send: transferred %i byte (at 0x%04x)\n", sum, (int)pos);
@ -260,7 +261,8 @@ static int recv(netdev_t *netdev, void *buf, size_t max_len, void *info)
(S0_RX_BASE + ((rp + 1) & S0_MASK))); (S0_RX_BASE + ((rp + 1) & S0_MASK)));
len = psize - 2; len = psize - 2;
DEBUG("[w5100] recv: got packet of %i byte (at 0x%04x)\n", len, (int)rp); DEBUG("[w5100] recv: got packet of %i byte (at 0x%04x)\n", len,
(int)rp);
/* read the actual data into the given buffer if wanted */ /* read the actual data into the given buffer if wanted */
if (in_buf != NULL) { if (in_buf != NULL) {