Several bugfixes, mostly from Darcy Gong

git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5217 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2012-10-06 14:50:37 +00:00
parent a41bc3c2ff
commit 4d23437df0
5 changed files with 128 additions and 111 deletions

View File

@ -364,3 +364,7 @@
There are still a LOT of empty, stub Kconfig files. There are still a LOT of empty, stub Kconfig files.
* Kconfig: Fleshed out apps/examples/buttons/Kconfig. There are still a LOT * Kconfig: Fleshed out apps/examples/buttons/Kconfig. There are still a LOT
of empty, stub Kconfig files. 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)

View File

@ -110,7 +110,7 @@ struct wget_s
FAR char *buffer; /* user-provided buffer */ FAR char *buffer; /* user-provided buffer */
int buflen; /* Length of the user provided buffer */ int buflen; /* Length of the user provided buffer */
int offset; /* Offset to the beginning of interesting data */ 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 */ /* 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 /* 'host' does not point to a valid address string. Try to resolve
* the host name to an IP address. * the host name to an IP address.
*/ */
if (resolv_query(hostname, &addr) < 0) if (resolv_query(hostname, &addr) < 0)
{ {
/* Needs to set the errno here */ /* Needs to set the errno here */
@ -401,10 +401,10 @@ exit:
* *
* Returned Value: * Returned Value:
* 0: if the GET operation completed successfully; * 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, int wget(FAR const char *url, FAR char *buffer, int buflen,
wget_callback_t callback, FAR void *arg) 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; ret = ws.datend;
goto errout_with_errno; goto errout_with_errno;
} }
else if (ret == 0) else if (ws.datend == 0)
{ {
nvdbg("Connection lost\n"); nvdbg("Connection lost\n");
close(sockfd); close(sockfd);
break; break;
} }
@ -567,7 +567,7 @@ int wget(FAR const char *url, FAR char *buffer, int buflen,
else else
{ {
redirected = true; redirected = true;
close(sockfd); close(sockfd);
break; break;
} }
} }

View File

@ -694,7 +694,7 @@ static inline int httpd_parse(struct httpd_state *pstate)
while (state != STATE_BODY); while (state != STATE_BODY);
#if !defined(CONFIG_NETUTILS_HTTPD_SENDFILE) && !defined(CONFIG_NETUTILS_HTTPD_MMAP) #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)); strncpy(pstate->ht_filename, "/" CONFIG_NETUTILS_HTTPD_INDEX, strlen("/" CONFIG_NETUTILS_HTTPD_INDEX));
} }

View File

@ -1656,6 +1656,7 @@ static void stm32_receive(FAR struct stm32_ethmac_s *priv)
stm32_freebuffer(priv, dev->d_buf); stm32_freebuffer(priv, dev->d_buf);
dev->d_buf = NULL; dev->d_buf = NULL;
dev->d_len = 0;
} }
} }
} }

View File

@ -98,7 +98,7 @@
#define RAMTRON_WRITE 0x02 /* 1 Write A 0 1-256 */ #define RAMTRON_WRITE 0x02 /* 1 Write A 0 1-256 */
#define RAMTRON_SLEEP 0xb9 // TODO: #define RAMTRON_SLEEP 0xb9 // TODO:
#define RAMTRON_RDID 0x9f /* 1 Read Identification 0 0 1-3 */ #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 */ /* Status register bit definitions */
@ -125,12 +125,12 @@
struct ramtron_parts_s struct ramtron_parts_s
{ {
const char *name; const char *name;
uint8_t id1; uint8_t id1;
uint8_t id2; uint8_t id2;
uint32_t size; uint32_t size;
uint8_t addr_len; uint8_t addr_len;
uint32_t speed; uint32_t speed;
}; };
/* This type represents the state of the MTD device. The struct mtd_dev_s /* 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; uint8_t pageshift;
uint16_t nsectors; uint16_t nsectors;
uint32_t npages; uint32_t npages;
const struct ramtron_parts_s *part; /* part instance */ const struct ramtron_parts_s *part; /* part instance */
}; };
/************************************************************************************ /************************************************************************************
* Supported Part Lists * Supported Part Lists
************************************************************************************/ ************************************************************************************/
// Defines the initial speed compatible with all devices. In case of RAMTRON /* Defines the initial speed compatible with all devices. In case of RAMTRON
// the defined devices within the part list have all the same speed. * the defined devices within the part list have all the same speed.
#define RAMTRON_INIT_CLK_MAX 40000000UL */
#define RAMTRON_INIT_CLK_MAX 40000000UL
static struct ramtron_parts_s ramtron_parts[] = static struct ramtron_parts_s ramtron_parts[] =
{ {
{ {
"FM25V02", /* name */ "FM25V02", /* name */
0x22, /* id1 */ 0x22, /* id1 */
0x00, /* id2 */ 0x00, /* id2 */
32L*1024L, /* size */ 32L*1024L, /* size */
2, /* addr_len */ 2, /* addr_len */
40000000 /* speed */ 40000000 /* speed */
}, },
{ {
"FM25VN02", /* name */ "FM25VN02", /* name */
0x22, /* id1 */ 0x22, /* id1 */
0x01, /* id2 */ 0x01, /* id2 */
32L*1024L, /* size */ 32L*1024L, /* size */
2, /* addr_len */ 2, /* addr_len */
40000000 /* speed */ 40000000 /* speed */
}, },
{ {
"FM25V05", /* name */ "FM25V05", /* name */
0x23, /* id1 */ 0x23, /* id1 */
0x00, /* id2 */ 0x00, /* id2 */
64L*1024L, /* size */ 64L*1024L, /* size */
2, /* addr_len */ 2, /* addr_len */
40000000 /* speed */ 40000000 /* speed */
}, },
{ {
"FM25VN05", /* name */ "FM25VN05", /* name */
0x23, /* id1 */ 0x23, /* id1 */
0x01, /* id2 */ 0x01, /* id2 */
64L*1024L, /* size */ 64L*1024L, /* size */
2, /* addr_len */ 2, /* addr_len */
40000000 /* speed */ 40000000 /* speed */
}, },
{ {
"FM25V10", /* name */ "FM25V10", /* name */
0x24, /* id1 */ 0x24, /* id1 */
0x00, /* id2 */ 0x00, /* id2 */
128L*1024L, /* size */ 128L*1024L, /* size */
3, /* addr_len */ 3, /* addr_len */
40000000 /* speed */ 40000000 /* speed */
}, },
{ {
"FM25VN10", /* name */ "FM25VN10", /* name */
0x24, /* id1 */ 0x24, /* id1 */
0x01, /* id2 */ 0x01, /* id2 */
128L*1024L, /* size */ 128L*1024L, /* size */
3, /* addr_len */ 3, /* addr_len */
40000000 /* speed */ 40000000 /* speed */
}, },
#ifdef CONFIG_RAMTRON_FRAM_NON_JEDEC #ifdef CONFIG_RAMTRON_FRAM_NON_JEDEC
{ {
"FM25H20", /* name */ "FM25H20", /* name */
0xff, /* id1 */ 0xff, /* id1 */
0xff, /* id2 */ 0xff, /* id2 */
256L*1024L, /* size */ 256L*1024L, /* size */
3, /* addr_len */ 3, /* addr_len */
40000000 /* speed */ 40000000 /* speed */
}, },
{ {
NULL, /* name */ NULL, /* name */
0, /* id1 */ 0, /* id1 */
0, /* id2 */ 0, /* id2 */
0, /* size */ 0, /* size */
0, /* addr_len */ 0, /* addr_len */
0 /* speed */ 0 /* speed */
} }
#endif #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_waitwritecomplete(struct ramtron_dev_s *priv);
static void ramtron_writeenable(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, static inline void ramtron_pagewrite(struct ramtron_dev_s *priv, FAR const uint8_t *buffer,
off_t offset); off_t offset);
/* MTD driver methods */ /* MTD driver methods */
static int ramtron_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks); 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, 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, 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, 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); 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 */ /* Send the "Read ID (RDID)" command and read the first three ID bytes */
(void)SPI_SEND(priv->dev, RAMTRON_RDID); (void)SPI_SEND(priv->dev, RAMTRON_RDID);
for (i=0; i<6; i++) manufacturer = SPI_SEND(priv->dev, RAMTRON_DUMMY); for (i = 0; i < 6; i++)
memory = SPI_SEND(priv->dev, RAMTRON_DUMMY); {
capacity = SPI_SEND(priv->dev, RAMTRON_DUMMY); // fram.id1 manufacturer = SPI_SEND(priv->dev, RAMTRON_DUMMY);
part = SPI_SEND(priv->dev, RAMTRON_DUMMY); // fram.id2 }
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 */ /* Deselect the FLASH and unlock the bus */
SPI_SELECT(priv->dev, SPIDEV_FLASH, false); SPI_SELECT(priv->dev, SPIDEV_FLASH, false);
ramtron_unlock(priv->dev); ramtron_unlock(priv->dev);
// Select part from the part list /* Select part from the part list */
for (priv->part = ramtron_parts; for (priv->part = ramtron_parts;
priv->part->name != NULL && !(priv->part->id1 == capacity && priv->part->id2 == part); priv->part->name != NULL && !(priv->part->id1 == capacity && priv->part->id2 == part);
priv->part++); priv->part++);
if (priv->part->name) { 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); 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->sectorshift = RAMTRON_EMULATE_SECTOR_SHIFT;
priv->nsectors = priv->part->size / (1 << RAMTRON_EMULATE_SECTOR_SHIFT); priv->nsectors = priv->part->size / (1 << RAMTRON_EMULATE_SECTOR_SHIFT);
priv->pageshift = RAMTRON_EMULATE_PAGE_SHIFT; priv->pageshift = RAMTRON_EMULATE_PAGE_SHIFT;
priv->npages = priv->part->size / (1 << RAMTRON_EMULATE_PAGE_SHIFT); priv->npages = priv->part->size / (1 << RAMTRON_EMULATE_PAGE_SHIFT);
return OK; return OK;
} }
fvdbg("RAMTRON device not found\n"); fvdbg("RAMTRON device not found\n");
return -ENODEV; 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); DEBUGASSERT(priv->part->addr_len == 3 || priv->part->addr_len == 2);
if (priv->part->addr_len == 3) 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 >> 8) & 0xff);
(void)SPI_SEND(priv->dev, addr & 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, 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; 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, 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; FAR struct ramtron_dev_s *priv = (FAR struct ramtron_dev_s *)dev;
ssize_t nbytes; 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 nbytes >> priv->pageshift;
} }
return (int)nbytes; 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, 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; FAR struct ramtron_dev_s *priv = (FAR struct ramtron_dev_s *)dev;
size_t blocksleft = nblocks; 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); ramtron_pagewrite(priv, buffer, startblock);
startblock++; startblock++;
} }
ramtron_unlock(priv->dev);
ramtron_unlock(priv->dev);
return nblocks; 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, 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; 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) if (ramtron_readid(priv) != OK)
{ {
/* Unrecognized! Discard all of that work we just did and return NULL */ /* Unrecognized! Discard all of that work we just did and return NULL */
kfree(priv); kfree(priv);
priv = NULL; priv = NULL;
} }