From 4d23437df02e0974cb0fbf6d80fe9039037947bd Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 6 Oct 2012 14:50:37 +0000 Subject: [PATCH] Several bugfixes, mostly from Darcy Gong git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5217 42af7a65-404d-4744-a932-0658087f49c3 --- apps/ChangeLog.txt | 4 + apps/netutils/webclient/webclient.c | 14 +- apps/netutils/webserver/httpd.c | 2 +- nuttx/arch/arm/src/stm32/stm32_eth.c | 1 + nuttx/drivers/mtd/ramtron.c | 218 ++++++++++++++------------- 5 files changed, 128 insertions(+), 111 deletions(-) diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt index bf2a85a9bb..7375adccfc 100644 --- a/apps/ChangeLog.txt +++ b/apps/ChangeLog.txt @@ -364,3 +364,7 @@ There are still a LOT of empty, stub Kconfig files. * Kconfig: Fleshed out apps/examples/buttons/Kconfig. There are still a LOT of empty, stub Kconfig files. + * apps/netutils/webserver/httpd.c: Fix a bug that I introduced in + recent check-ins (Darcy Gong). + * apps/netutils/webclient/webclient.c: Fix another but that I introduced + when I was trying to add correct handling for loss of connection (Darcy Gong) diff --git a/apps/netutils/webclient/webclient.c b/apps/netutils/webclient/webclient.c index 05a63ba381..5a84c4fd12 100644 --- a/apps/netutils/webclient/webclient.c +++ b/apps/netutils/webclient/webclient.c @@ -110,7 +110,7 @@ struct wget_s FAR char *buffer; /* user-provided buffer */ int buflen; /* Length of the user provided buffer */ int offset; /* Offset to the beginning of interesting data */ - int datend; /* Offset+1 to the last valid byte of data in the buffer */ + int datend; /* Offset+1 to the last valid byte of data in the buffer */ /* Buffer HTTP header data and parse line at a time */ @@ -204,7 +204,7 @@ static inline int wget_resolvehost(const char *hostname, in_addr_t *ipaddr) /* 'host' does not point to a valid address string. Try to resolve * the host name to an IP address. */ - + if (resolv_query(hostname, &addr) < 0) { /* Needs to set the errno here */ @@ -401,10 +401,10 @@ exit: * * Returned Value: * 0: if the GET operation completed successfully; - * -1: On a failure with errno set appropriately + * -1: On a failure with errno set appropriately * ****************************************************************************/ - + int wget(FAR const char *url, FAR char *buffer, int buflen, wget_callback_t callback, FAR void *arg) { @@ -524,10 +524,10 @@ int wget(FAR const char *url, FAR char *buffer, int buflen, ret = ws.datend; goto errout_with_errno; } - else if (ret == 0) + else if (ws.datend == 0) { nvdbg("Connection lost\n"); - close(sockfd); + close(sockfd); break; } @@ -567,7 +567,7 @@ int wget(FAR const char *url, FAR char *buffer, int buflen, else { redirected = true; - close(sockfd); + close(sockfd); break; } } diff --git a/apps/netutils/webserver/httpd.c b/apps/netutils/webserver/httpd.c index f96fc5a6c4..9f621d67cf 100644 --- a/apps/netutils/webserver/httpd.c +++ b/apps/netutils/webserver/httpd.c @@ -694,7 +694,7 @@ static inline int httpd_parse(struct httpd_state *pstate) while (state != STATE_BODY); #if !defined(CONFIG_NETUTILS_HTTPD_SENDFILE) && !defined(CONFIG_NETUTILS_HTTPD_MMAP) - if (0 == strcmp(pstate->ht_filename, "/") + if (0 == strcmp(pstate->ht_filename, "/")) { strncpy(pstate->ht_filename, "/" CONFIG_NETUTILS_HTTPD_INDEX, strlen("/" CONFIG_NETUTILS_HTTPD_INDEX)); } diff --git a/nuttx/arch/arm/src/stm32/stm32_eth.c b/nuttx/arch/arm/src/stm32/stm32_eth.c index 13f02679fd..3054142ce8 100644 --- a/nuttx/arch/arm/src/stm32/stm32_eth.c +++ b/nuttx/arch/arm/src/stm32/stm32_eth.c @@ -1656,6 +1656,7 @@ static void stm32_receive(FAR struct stm32_ethmac_s *priv) stm32_freebuffer(priv, dev->d_buf); dev->d_buf = NULL; + dev->d_len = 0; } } } diff --git a/nuttx/drivers/mtd/ramtron.c b/nuttx/drivers/mtd/ramtron.c index 074545e2d9..34273bccfc 100644 --- a/nuttx/drivers/mtd/ramtron.c +++ b/nuttx/drivers/mtd/ramtron.c @@ -98,7 +98,7 @@ #define RAMTRON_WRITE 0x02 /* 1 Write A 0 1-256 */ #define RAMTRON_SLEEP 0xb9 // TODO: #define RAMTRON_RDID 0x9f /* 1 Read Identification 0 0 1-3 */ -#define RAMTRON_SN 0xc3 // TODO: +#define RAMTRON_SN 0xc3 // TODO: /* Status register bit definitions */ @@ -125,12 +125,12 @@ struct ramtron_parts_s { - const char *name; - uint8_t id1; - uint8_t id2; - uint32_t size; - uint8_t addr_len; - uint32_t speed; + const char *name; + uint8_t id1; + uint8_t id2; + uint32_t size; + uint8_t addr_len; + uint32_t speed; }; /* This type represents the state of the MTD device. The struct mtd_dev_s @@ -146,84 +146,86 @@ struct ramtron_dev_s uint8_t pageshift; uint16_t nsectors; uint32_t npages; - const struct ramtron_parts_s *part; /* part instance */ + const struct ramtron_parts_s *part; /* part instance */ }; /************************************************************************************ * Supported Part Lists ************************************************************************************/ -// Defines the initial speed compatible with all devices. In case of RAMTRON -// the defined devices within the part list have all the same speed. -#define RAMTRON_INIT_CLK_MAX 40000000UL +/* Defines the initial speed compatible with all devices. In case of RAMTRON + * the defined devices within the part list have all the same speed. + */ + +#define RAMTRON_INIT_CLK_MAX 40000000UL static struct ramtron_parts_s ramtron_parts[] = { - { - "FM25V02", /* name */ - 0x22, /* id1 */ - 0x00, /* id2 */ - 32L*1024L, /* size */ - 2, /* addr_len */ - 40000000 /* speed */ - }, - { - "FM25VN02", /* name */ - 0x22, /* id1 */ - 0x01, /* id2 */ - 32L*1024L, /* size */ - 2, /* addr_len */ - 40000000 /* speed */ - }, - { - "FM25V05", /* name */ - 0x23, /* id1 */ - 0x00, /* id2 */ - 64L*1024L, /* size */ - 2, /* addr_len */ - 40000000 /* speed */ - }, - { - "FM25VN05", /* name */ - 0x23, /* id1 */ - 0x01, /* id2 */ - 64L*1024L, /* size */ - 2, /* addr_len */ - 40000000 /* speed */ - }, - { - "FM25V10", /* name */ - 0x24, /* id1 */ - 0x00, /* id2 */ - 128L*1024L, /* size */ - 3, /* addr_len */ - 40000000 /* speed */ - }, - { - "FM25VN10", /* name */ - 0x24, /* id1 */ - 0x01, /* id2 */ - 128L*1024L, /* size */ - 3, /* addr_len */ - 40000000 /* speed */ - }, + { + "FM25V02", /* name */ + 0x22, /* id1 */ + 0x00, /* id2 */ + 32L*1024L, /* size */ + 2, /* addr_len */ + 40000000 /* speed */ + }, + { + "FM25VN02", /* name */ + 0x22, /* id1 */ + 0x01, /* id2 */ + 32L*1024L, /* size */ + 2, /* addr_len */ + 40000000 /* speed */ + }, + { + "FM25V05", /* name */ + 0x23, /* id1 */ + 0x00, /* id2 */ + 64L*1024L, /* size */ + 2, /* addr_len */ + 40000000 /* speed */ + }, + { + "FM25VN05", /* name */ + 0x23, /* id1 */ + 0x01, /* id2 */ + 64L*1024L, /* size */ + 2, /* addr_len */ + 40000000 /* speed */ + }, + { + "FM25V10", /* name */ + 0x24, /* id1 */ + 0x00, /* id2 */ + 128L*1024L, /* size */ + 3, /* addr_len */ + 40000000 /* speed */ + }, + { + "FM25VN10", /* name */ + 0x24, /* id1 */ + 0x01, /* id2 */ + 128L*1024L, /* size */ + 3, /* addr_len */ + 40000000 /* speed */ + }, #ifdef CONFIG_RAMTRON_FRAM_NON_JEDEC - { - "FM25H20", /* name */ - 0xff, /* id1 */ - 0xff, /* id2 */ - 256L*1024L, /* size */ - 3, /* addr_len */ - 40000000 /* speed */ - }, - { - NULL, /* name */ - 0, /* id1 */ - 0, /* id2 */ - 0, /* size */ - 0, /* addr_len */ - 0 /* speed */ - } + { + "FM25H20", /* name */ + 0xff, /* id1 */ + 0xff, /* id2 */ + 256L*1024L, /* size */ + 3, /* addr_len */ + 40000000 /* speed */ + }, + { + NULL, /* name */ + 0, /* id1 */ + 0, /* id2 */ + 0, /* size */ + 0, /* addr_len */ + 0 /* speed */ + } #endif }; @@ -240,17 +242,17 @@ static inline int ramtron_readid(struct ramtron_dev_s *priv); static void ramtron_waitwritecomplete(struct ramtron_dev_s *priv); static void ramtron_writeenable(struct ramtron_dev_s *priv); static inline void ramtron_pagewrite(struct ramtron_dev_s *priv, FAR const uint8_t *buffer, - off_t offset); + off_t offset); /* MTD driver methods */ static int ramtron_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks); static ssize_t ramtron_bread(FAR struct mtd_dev_s *dev, off_t startblock, - size_t nblocks, FAR uint8_t *buf); + size_t nblocks, FAR uint8_t *buf); static ssize_t ramtron_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, - size_t nblocks, FAR const uint8_t *buf); + size_t nblocks, FAR const uint8_t *buf); static ssize_t ramtron_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes, - FAR uint8_t *buffer); + FAR uint8_t *buffer); static int ramtron_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg); /************************************************************************************ @@ -317,31 +319,37 @@ static inline int ramtron_readid(struct ramtron_dev_s *priv) /* Send the "Read ID (RDID)" command and read the first three ID bytes */ (void)SPI_SEND(priv->dev, RAMTRON_RDID); - for (i=0; i<6; i++) manufacturer = SPI_SEND(priv->dev, RAMTRON_DUMMY); - memory = SPI_SEND(priv->dev, RAMTRON_DUMMY); - capacity = SPI_SEND(priv->dev, RAMTRON_DUMMY); // fram.id1 - part = SPI_SEND(priv->dev, RAMTRON_DUMMY); // fram.id2 + for (i = 0; i < 6; i++) + { + manufacturer = SPI_SEND(priv->dev, RAMTRON_DUMMY); + } + + memory = SPI_SEND(priv->dev, RAMTRON_DUMMY); + capacity = SPI_SEND(priv->dev, RAMTRON_DUMMY); // fram.id1 + part = SPI_SEND(priv->dev, RAMTRON_DUMMY); // fram.id2 /* Deselect the FLASH and unlock the bus */ SPI_SELECT(priv->dev, SPIDEV_FLASH, false); ramtron_unlock(priv->dev); - // Select part from the part list + /* Select part from the part list */ + for (priv->part = ramtron_parts; - priv->part->name != NULL && !(priv->part->id1 == capacity && priv->part->id2 == part); - priv->part++); - - if (priv->part->name) { - fvdbg("RAMTRON %s of size %d bytes (mf:%02x mem:%02x cap:%02x part:%02x)\n", - priv->part->name, priv->part->size, manufacturer, memory, capacity, part); + priv->part->name != NULL && !(priv->part->id1 == capacity && priv->part->id2 == part); + priv->part++); + + if (priv->part->name) + { + fvdbg("RAMTRON %s of size %d bytes (mf:%02x mem:%02x cap:%02x part:%02x)\n", + priv->part->name, priv->part->size, manufacturer, memory, capacity, part); - priv->sectorshift = RAMTRON_EMULATE_SECTOR_SHIFT; - priv->nsectors = priv->part->size / (1 << RAMTRON_EMULATE_SECTOR_SHIFT); - priv->pageshift = RAMTRON_EMULATE_PAGE_SHIFT; - priv->npages = priv->part->size / (1 << RAMTRON_EMULATE_PAGE_SHIFT); - return OK; - } + priv->sectorshift = RAMTRON_EMULATE_SECTOR_SHIFT; + priv->nsectors = priv->part->size / (1 << RAMTRON_EMULATE_SECTOR_SHIFT); + priv->pageshift = RAMTRON_EMULATE_PAGE_SHIFT; + priv->npages = priv->part->size / (1 << RAMTRON_EMULATE_PAGE_SHIFT); + return OK; + } fvdbg("RAMTRON device not found\n"); return -ENODEV; @@ -408,8 +416,10 @@ static inline void ramtron_sendaddr(const struct ramtron_dev_s *priv, uint32_t a DEBUGASSERT(priv->part->addr_len == 3 || priv->part->addr_len == 2); if (priv->part->addr_len == 3) - (void)SPI_SEND(priv->dev, (addr >> 16) & 0xff); - + { + (void)SPI_SEND(priv->dev, (addr >> 16) & 0xff); + } + (void)SPI_SEND(priv->dev, (addr >> 8) & 0xff); (void)SPI_SEND(priv->dev, addr & 0xff); } @@ -419,7 +429,7 @@ static inline void ramtron_sendaddr(const struct ramtron_dev_s *priv, uint32_t a ************************************************************************************/ static inline void ramtron_pagewrite(struct ramtron_dev_s *priv, FAR const uint8_t *buffer, - off_t page) + off_t page) { off_t offset = page << priv->pageshift; @@ -475,7 +485,7 @@ static int ramtron_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nbl ************************************************************************************/ static ssize_t ramtron_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, - FAR uint8_t *buffer) + FAR uint8_t *buffer) { FAR struct ramtron_dev_s *priv = (FAR struct ramtron_dev_s *)dev; ssize_t nbytes; @@ -489,6 +499,7 @@ static ssize_t ramtron_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t { return nbytes >> priv->pageshift; } + return (int)nbytes; } @@ -497,7 +508,7 @@ static ssize_t ramtron_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t ************************************************************************************/ static ssize_t ramtron_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, - FAR const uint8_t *buffer) + FAR const uint8_t *buffer) { FAR struct ramtron_dev_s *priv = (FAR struct ramtron_dev_s *)dev; size_t blocksleft = nblocks; @@ -512,8 +523,8 @@ static ssize_t ramtron_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_ ramtron_pagewrite(priv, buffer, startblock); startblock++; } - ramtron_unlock(priv->dev); + ramtron_unlock(priv->dev); return nblocks; } @@ -522,7 +533,7 @@ static ssize_t ramtron_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_ ************************************************************************************/ static ssize_t ramtron_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes, - FAR uint8_t *buffer) + FAR uint8_t *buffer) { FAR struct ramtron_dev_s *priv = (FAR struct ramtron_dev_s *)dev; @@ -662,6 +673,7 @@ FAR struct mtd_dev_s *ramtron_initialize(FAR struct spi_dev_s *dev) if (ramtron_readid(priv) != OK) { /* Unrecognized! Discard all of that work we just did and return NULL */ + kfree(priv); priv = NULL; }